Package: scons-compiledb
SCons Compilation DB supportscons-compiledb adds a support for generating JSON formatted compilation
database defined byClang.Features:Multiple construction environments support.compile_commands.json merge across SCons invocationsCustomisation for DB entry generation.Build with command line option, --compiledbSimpler installation with PyPIAt the moment, SCons mainline does not have compilation DB generation
functionality and it is likely to have it in the near feature. However, this
module can still provide some advantages such as supporting old version of SCons
and other useful features.The module was tested with Python 2.x/3.x along with SCons 2.x/3.x.InstallationInstall and update usingpippip install scons-compiledbUsageEnable and use CompileDb builderimportscons_compiledbenv=DefaultEnvironment()# Or with any other wayscons_compiledb.enable(env)## ... use env normally ...#env.CompileDb()enable(env)adds a new builder,CompileDbto the specified environment,env. In order to build thecompile_commands.jsonfile,CompileDb()should
be called. It can also specify the DB file name as an optional argument.Note thatenable(env)should be called before theenvis used to compile any
targets.Simpler usage with command line option --compiledbInstead ofenable(),enable_with_cmdline()can be used to add a command line
option--compiledb, which, when specified, generates 'compile_commands.json'
as default target.importscons_compiledbenv=DefaultEnvironment()# Or with any other wayscons_compiledb.enable_with_cmdline(env)## ... Use env normnally ...#With the above build script,compile_commands.jsonfile will be generated when
SCons is invoked with--compiledbcommand line option as follows:$ scons --compiledb=Note that the command line option requires an option string as argument and the trailing=means empty.
The comma-separated option string can specify the bool type config options(see below) as follows:$ scons --compiledb=reset,multiIn order to build DB while building other target,compiledbcan be used as an
alias as follows:$ scons --compiledb= compiledb other_targetsCustomisationWhile enabling, aConfigobject can be passed. For example:config = scons_compiledb.Config(db='foo.json')
scons_compiledb.enable(env, config)ParameterValueDefaultdbfilename of compilation DB.'#/compile_commands.json'entry_funcfunction to determine the entry dict for each source file.entry_func_defaultcxx_suffixesSuffixes for C++ files.('.cpp', '.cc')cc_suffixesSuffixes for C files.('.c',)resetWhether to remove existing entriesFalsemultiWhether to allow multiple entries with the same 'file'.Falseentry_funcentry_funcis the main logic to convert source file node in SCons to a dict
containingdirectory,sourceandcommandas keys. There are predefined
entry functions as follows:entry_func_defaultThis is default and it should work for the most of cases.entry_func_simpleUseCPPPATHandCPPDEFINESonly andclang/clang++as compiler tool name.
This will be useful to use clangd with compilers, which use command line
arguments clangd cannot understand.entry_funccan be easily customised. Please refer to the source code ofthe
predefined functionsresetAs default,compile_commands.jsonfile is merged across the multiple
invocations of SCons so that one DB file can be used. This is usually good
thing. However, if it is not desirable for any reasons,resetconfig can be
used to remove any existing entries before generating new ones.multiAs default,compile_commands.jsonfile keeps only one entry with the samefileas the key. However, some tools can handle multiple entries with the same
key. Ifmultiis set, multiple entries are stored as long as they generate the
different target(output) files.Detailsenable(env)modifies the builders related to the compilations, such as
StaticObject, to add an additional Scanner, which make sure that the compilation
commands are captured.enable(env)also adds a new builderCompileDb, which
generatescompile_commands.jsonfrom the captured commands.scons_compiledbmaintains an internal dot file.compile_commands.jsonas
default, to merge compile commands across the multiple SCons invocations. The
final file,compile_commands.jsonis touched only when the internal dot file
is changed.When the compile commands are merged, it is based on source/output file name. It
means that the entry with the same pair will be overwritten.enabled(env)can be called to check whether it is enabled before or not.ExamplesPlease check SConscript files intest folderCreditsThe core functionality of scons-compiledb is based onMongoDB source
code.