SCons: Make compilation database generation optional

Saves around 3 s on incremental rebuilds to have it disabled by default.
Can be enabled with `compiledb=yes`.

(cherry picked from commit f94df6fa2b)
This commit is contained in:
Rémi Verschelde 2022-02-08 21:46:47 +01:00
parent ec12e24e18
commit 6dbb67cc73
No known key found for this signature in database
GPG key ID: C3336907360768E1

View file

@ -133,6 +133,7 @@ opts.Add(BoolVariable("custom_modules_recursive", "Detect custom modules recursi
# Advanced options # Advanced options
opts.Add(BoolVariable("dev", "If yes, alias for verbose=yes warnings=extra werror=yes", False)) opts.Add(BoolVariable("dev", "If yes, alias for verbose=yes warnings=extra werror=yes", False))
opts.Add(BoolVariable("fast_unsafe", "Enable unsafe options for faster rebuilds", False)) opts.Add(BoolVariable("fast_unsafe", "Enable unsafe options for faster rebuilds", False))
opts.Add(BoolVariable("compiledb", "Generate compilation DB (`compile_commands.json`) for external tools", False))
opts.Add(BoolVariable("verbose", "Enable verbose output for the compilation", False)) opts.Add(BoolVariable("verbose", "Enable verbose output for the compilation", False))
opts.Add(BoolVariable("progress", "Show a progress indicator during compilation", True)) opts.Add(BoolVariable("progress", "Show a progress indicator during compilation", True))
opts.Add(EnumVariable("warnings", "Level of compilation warnings", "all", ("extra", "all", "moderate", "no"))) opts.Add(EnumVariable("warnings", "Level of compilation warnings", "all", ("extra", "all", "moderate", "no")))
@ -360,6 +361,7 @@ if selected_platform in platform_list:
else: else:
env = env_base.Clone() env = env_base.Clone()
if env["compiledb"]:
# Generating the compilation DB (`compile_commands.json`) requires SCons 4.0.0 or later. # Generating the compilation DB (`compile_commands.json`) requires SCons 4.0.0 or later.
from SCons import __version__ as scons_raw_version from SCons import __version__ as scons_raw_version
@ -720,6 +722,7 @@ elif selected_platform != "":
# The following only makes sense when the 'env' is defined, and assumes it is. # The following only makes sense when the 'env' is defined, and assumes it is.
if "env" in locals(): if "env" in locals():
# FIXME: This method mixes both cosmetic progress stuff and cache handling...
methods.show_progress(env) methods.show_progress(env)
# TODO: replace this with `env.Dump(format="json")` # TODO: replace this with `env.Dump(format="json")`
# once we start requiring SCons 4.0 as min version. # once we start requiring SCons 4.0 as min version.