60 lines
2.5 KiB
Python
60 lines
2.5 KiB
Python
# Generates "mongo.h" config header file containing feature flags generated by checking for the availability of certain compiler features.
|
|
# This script is invoked by the Bazel build system to generate the "mongo.h" file automatically as part of the build.
|
|
# Example usage:
|
|
# python generate_config_header.py \
|
|
# --compiler-path /usr/bin/gcc --compiler-args "-O2 -Wall" \
|
|
# --output-path mongo.h --template-path mongo.h.in \
|
|
# --check-path mongo_checks.py --log-path mongo.h.log
|
|
import argparse
|
|
import importlib
|
|
from typing import Dict
|
|
import sys
|
|
import os
|
|
|
|
|
|
def write_config_header(input_path: str, output_path: str, definitions: Dict[str, str]) -> None:
|
|
with open(input_path) as in_file:
|
|
content = in_file.read()
|
|
|
|
with open(output_path, "w", newline="\n") as file:
|
|
output_content = content
|
|
|
|
for key, value in definitions.items():
|
|
output_content = output_content.replace(key, value)
|
|
file.write(output_content)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description="Generate a config header file")
|
|
parser.add_argument("--compiler-path", help="Path to the compiler executable", required=True)
|
|
parser.add_argument("--compiler-args", help="Extra compiler arguments", required=True)
|
|
parser.add_argument("--env-vars", help="Extra environment variables", required=True)
|
|
parser.add_argument(
|
|
"--output-path", help="Path to the output config header file", required=True
|
|
)
|
|
parser.add_argument(
|
|
"--template-path", help="Path to the config header's template file", required=True
|
|
)
|
|
parser.add_argument("--extra-definitions", help="Extra header definitions")
|
|
parser.add_argument("--check-path", help="Path to the suppored configure checks", required=True)
|
|
parser.add_argument("--log-path", help="Path to the suppored configure checks", required=True)
|
|
parser.add_argument("--additional-input", help="extra files", action="append")
|
|
|
|
args = parser.parse_args()
|
|
|
|
sys.path.append(".")
|
|
module = __import__(
|
|
os.path.splitext(args.check_path)[0].replace("/", "."), fromlist=["generate_config_header"]
|
|
)
|
|
generate_config_header = getattr(module, "generate_config_header")
|
|
|
|
definitions = generate_config_header(
|
|
args.compiler_path,
|
|
args.compiler_args,
|
|
args.env_vars,
|
|
args.log_path,
|
|
args.additional_input,
|
|
args.extra_definitions,
|
|
)
|
|
write_config_header(args.template_path, args.output_path, definitions)
|