diff --git a/SConstruct b/SConstruct index b028676f2..2a5e5629d 100644 --- a/SConstruct +++ b/SConstruct @@ -85,6 +85,11 @@ if env.GetOption("num_jobs") == altered_num_jobs: # Custom options and profile flags. customs = ["custom.py"] +try: + customs += Import("customs") +except: + pass + profile = ARGUMENTS.get("profile", "") if profile: if os.path.isfile(profile): @@ -265,9 +270,11 @@ if env["precision"] == "double": env.Append(CPPDEFINES=["REAL_T_IS_DOUBLE"]) # compile_commands.json +compilation_db = None if env.get("compiledb", False): env.Tool("compilation_db") - env.Alias("compiledb", env.CompilationDatabase(normalize_path(env["compiledb_file"]))) + compilation_db = env.CompilationDatabase(normalize_path(env["compiledb_file"])) + env.Alias("compiledb", compilation_db) # Generate bindings env.Append(BUILDERS={"GenerateBindings": Builder(action=scons_generate_bindings, emitter=scons_emit_files)}) @@ -316,7 +323,10 @@ library_name = "libgodot-cpp{}{}".format(suffix, env["LIBSUFFIX"]) if env["build_library"]: library = env.StaticLibrary(target=env.File("bin/%s" % library_name), source=sources) - Default(library) + default_args = [library] + if not compilation_db is None: + default_args += [compilation_db] + Default(*default_args) env.Append(LIBPATH=[env.Dir("bin")]) env.Append(LIBS=library_name) diff --git a/test/.gitignore b/test/.gitignore index c6d839430..f21e645b7 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -23,3 +23,6 @@ mono_crash.*.json # System/tool-specific ignores .directory *~ + +# Build configuarion. +/custom.py diff --git a/test/SConstruct b/test/SConstruct index 1732ecd43..3b4e33b22 100644 --- a/test/SConstruct +++ b/test/SConstruct @@ -1,8 +1,49 @@ #!/usr/bin/env python import os import sys +from SCons.Errors import UserError -env = SConscript("../SConstruct") + +def normalize_path(val, env): + return val if os.path.isabs(val) else os.path.join(env.Dir("#").abspath, val) + + +def validate_parent_dir(key, val, env): + if not os.path.isdir(normalize_path(os.path.dirname(val), env)): + raise UserError("'%s' is not a directory: %s" % (key, os.path.dirname(val))) + + +localEnv = Environment() +customs = ["custom.py"] +opts = Variables(customs, ARGUMENTS) + +opts.Add( + BoolVariable( + key="compiledb", + help="Generate compilation DB (`compile_commands.json`) for external tools", + default=localEnv.get("compiledb", False), + ) +) +opts.Add( + PathVariable( + key="compiledb_file", + help="Path to a custom `compile_commands.json` file", + default=localEnv.get("compiledb_file", "compile_commands.json"), + validator=validate_parent_dir, + ) +) + +opts.Update(localEnv) + +env = localEnv.Clone() +env["compiledb"] = False +env = SConscript("../SConstruct", {"env": env, "customs": customs}) + +compilation_db = None +if localEnv.get("compiledb", False): + env.Tool("compilation_db") + compilation_db = env.CompilationDatabase(normalize_path(env["compiledb_file"], env)) + env.Alias("compiledb", compilation_db) # For the reference: # - CCFLAGS are compilation flags shared between C and C++ @@ -29,4 +70,8 @@ else: source=sources, ) -Default(library) +default_args = [library] +if not compilation_db is None: + default_args += [compilation_db] + +Default(*default_args)