From 686672aa5062a0363c037635b6d945160e9094c4 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Tue, 12 May 2020 13:57:08 -0700 Subject: Initial import from mongodb tree. https://github.com/mongodb/mongo --- SCons/Tool/compilation_db.py | 211 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 211 insertions(+) create mode 100644 SCons/Tool/compilation_db.py diff --git a/SCons/Tool/compilation_db.py b/SCons/Tool/compilation_db.py new file mode 100644 index 0000000..833be4a --- /dev/null +++ b/SCons/Tool/compilation_db.py @@ -0,0 +1,211 @@ +# Copyright 2020 MongoDB Inc. +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +import json +import SCons +import itertools + +# Implements the ability for SCons to emit a compilation database for the MongoDB project. See +# http://clang.llvm.org/docs/JSONCompilationDatabase.html for details on what a compilation +# database is, and why you might want one. The only user visible entry point here is +# 'env.CompilationDatabase'. This method takes an optional 'target' to name the file that +# should hold the compilation database, otherwise, the file defaults to compile_commands.json, +# which is the name that most clang tools search for by default. + +# TODO: Is there a better way to do this than this global? Right now this exists so that the +# emitter we add can record all of the things it emits, so that the scanner for the top level +# compilation database can access the complete list, and also so that the writer has easy +# access to write all of the files. But it seems clunky. How can the emitter and the scanner +# communicate more gracefully? +__COMPILATION_DB_ENTRIES = [] + +# Cribbed from Tool/cc.py and Tool/c++.py. It would be better if +# we could obtain this from SCons. +_CSuffixes = [".c"] +if not SCons.Util.case_sensitive_suffixes(".c", ".C"): + _CSuffixes.append(".C") + +_CXXSuffixes = [".cpp", ".cc", ".cxx", ".c++", ".C++"] +if SCons.Util.case_sensitive_suffixes(".c", ".C"): + _CXXSuffixes.append(".C") + + +# We make no effort to avoid rebuilding the entries. Someday, perhaps we could and even +# integrate with the cache, but there doesn't seem to be much call for it. +class __CompilationDbNode(SCons.Node.Python.Value): + def __init__(self, value): + SCons.Node.Python.Value.__init__(self, value) + self.Decider(changed_since_last_build_node) + + +def changed_since_last_build_node(child, target, prev_ni, node): + """ Dummy decider to force always building""" + return True + + +def makeEmitCompilationDbEntry(comstr): + """ + Effectively this creates a lambda function to capture: + * command line + * source + * target + :param comstr: unevaluated command line + :return: an emitter which has captured the above + """ + user_action = SCons.Action.Action(comstr) + + def EmitCompilationDbEntry(target, source, env): + """ + This emitter will be added to each c/c++ object build to capture the info needed + for clang tools + :param target: target node(s) + :param source: source node(s) + :param env: Environment for use building this node + :return: target(s), source(s) + """ + + dbtarget = __CompilationDbNode(source) + + entry = env.__COMPILATIONDB_Entry( + target=dbtarget, + source=[], + __COMPILATIONDB_UTARGET=target, + __COMPILATIONDB_USOURCE=source, + __COMPILATIONDB_UACTION=user_action, + __COMPILATIONDB_ENV=env, + ) + + # TODO: Technically, these next two lines should not be required: it should be fine to + # cache the entries. However, they don't seem to update properly. Since they are quick + # to re-generate disable caching and sidestep this problem. + env.AlwaysBuild(entry) + env.NoCache(entry) + + __COMPILATION_DB_ENTRIES.append(dbtarget) + + return target, source + + return EmitCompilationDbEntry + + +def CompilationDbEntryAction(target, source, env, **kw): + """ + Create a dictionary with evaluated command line, target, source + and store that info as an attribute on the target + (Which has been stored in __COMPILATION_DB_ENTRIES array + :param target: target node(s) + :param source: source node(s) + :param env: Environment for use building this node + :param kw: + :return: None + """ + + command = env["__COMPILATIONDB_UACTION"].strfunction( + target=env["__COMPILATIONDB_UTARGET"], + source=env["__COMPILATIONDB_USOURCE"], + env=env["__COMPILATIONDB_ENV"], + ) + + entry = { + "directory": env.Dir("#").abspath, + "command": command, + "file": str(env["__COMPILATIONDB_USOURCE"][0]), + } + + target[0].write(entry) + + +def WriteCompilationDb(target, source, env): + entries = [] + + for s in __COMPILATION_DB_ENTRIES: + entries.append(s.read()) + + with open(str(target[0]), "w") as target_file: + json.dump( + entries, target_file, sort_keys=True, indent=4, separators=(",", ": ") + ) + + +def ScanCompilationDb(node, env, path): + return __COMPILATION_DB_ENTRIES + + +def generate(env, **kwargs): + + static_obj, shared_obj = SCons.Tool.createObjBuilders(env) + + env["COMPILATIONDB_COMSTR"] = kwargs.get( + "COMPILATIONDB_COMSTR", "Building compilation database $TARGET" + ) + + components_by_suffix = itertools.chain( + itertools.product( + _CSuffixes, + [ + (static_obj, SCons.Defaults.StaticObjectEmitter, "$CCCOM"), + (shared_obj, SCons.Defaults.SharedObjectEmitter, "$SHCCCOM"), + ], + ), + itertools.product( + _CXXSuffixes, + [ + (static_obj, SCons.Defaults.StaticObjectEmitter, "$CXXCOM"), + (shared_obj, SCons.Defaults.SharedObjectEmitter, "$SHCXXCOM"), + ], + ), + ) + + for entry in components_by_suffix: + suffix = entry[0] + builder, base_emitter, command = entry[1] + + # Assumes a dictionary emitter + emitter = builder.emitter[suffix] + builder.emitter[suffix] = SCons.Builder.ListEmitter( + [emitter, makeEmitCompilationDbEntry(command),] + ) + + env["BUILDERS"]["__COMPILATIONDB_Entry"] = SCons.Builder.Builder( + action=SCons.Action.Action(CompilationDbEntryAction, None), + ) + + env["BUILDERS"]["__COMPILATIONDB_Database"] = SCons.Builder.Builder( + action=SCons.Action.Action(WriteCompilationDb, "$COMPILATIONDB_COMSTR"), + target_scanner=SCons.Scanner.Scanner( + function=ScanCompilationDb, node_class=None + ), + ) + + def CompilationDatabase(env, target): + result = env.__COMPILATIONDB_Database(target=target, source=[]) + + env.AlwaysBuild(result) + env.NoCache(result) + + return result + + env.AddMethod(CompilationDatabase, "CompilationDatabase") + + +def exists(env): + return True -- cgit v0.12 From bf151381fc07a335c87766cc8165b64c54b67f2a Mon Sep 17 00:00:00 2001 From: William Deegan Date: Tue, 12 May 2020 14:16:57 -0700 Subject: refactor function names per PEP8. Pull C & C++ file extensions from cc and cxx tools respectively --- SCons/Tool/compilation_db.py | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/SCons/Tool/compilation_db.py b/SCons/Tool/compilation_db.py index 833be4a..75fa696 100644 --- a/SCons/Tool/compilation_db.py +++ b/SCons/Tool/compilation_db.py @@ -23,6 +23,8 @@ import json import SCons import itertools +from cxx import CXXSuffixes +from cc import CSuffixes # Implements the ability for SCons to emit a compilation database for the MongoDB project. See # http://clang.llvm.org/docs/JSONCompilationDatabase.html for details on what a compilation @@ -38,16 +40,6 @@ import itertools # communicate more gracefully? __COMPILATION_DB_ENTRIES = [] -# Cribbed from Tool/cc.py and Tool/c++.py. It would be better if -# we could obtain this from SCons. -_CSuffixes = [".c"] -if not SCons.Util.case_sensitive_suffixes(".c", ".C"): - _CSuffixes.append(".C") - -_CXXSuffixes = [".cpp", ".cc", ".cxx", ".c++", ".C++"] -if SCons.Util.case_sensitive_suffixes(".c", ".C"): - _CXXSuffixes.append(".C") - # We make no effort to avoid rebuilding the entries. Someday, perhaps we could and even # integrate with the cache, but there doesn't seem to be much call for it. @@ -62,7 +54,7 @@ def changed_since_last_build_node(child, target, prev_ni, node): return True -def makeEmitCompilationDbEntry(comstr): +def make_emit_compilation_DB_entry(comstr): """ Effectively this creates a lambda function to capture: * command line @@ -73,7 +65,7 @@ def makeEmitCompilationDbEntry(comstr): """ user_action = SCons.Action.Action(comstr) - def EmitCompilationDbEntry(target, source, env): + def emit_compilation_db_entry(target, source, env): """ This emitter will be added to each c/c++ object build to capture the info needed for clang tools @@ -104,10 +96,10 @@ def makeEmitCompilationDbEntry(comstr): return target, source - return EmitCompilationDbEntry + return emit_compilation_db_entry -def CompilationDbEntryAction(target, source, env, **kw): +def compilation_db_entry_action(target, source, env, **kw): """ Create a dictionary with evaluated command line, target, source and store that info as an attribute on the target @@ -134,7 +126,7 @@ def CompilationDbEntryAction(target, source, env, **kw): target[0].write(entry) -def WriteCompilationDb(target, source, env): +def write_compilation_db(target, source, env): entries = [] for s in __COMPILATION_DB_ENTRIES: @@ -146,7 +138,7 @@ def WriteCompilationDb(target, source, env): ) -def ScanCompilationDb(node, env, path): +def scan_compilation_db(node, env, path): return __COMPILATION_DB_ENTRIES @@ -160,14 +152,14 @@ def generate(env, **kwargs): components_by_suffix = itertools.chain( itertools.product( - _CSuffixes, + CSuffixes, [ (static_obj, SCons.Defaults.StaticObjectEmitter, "$CCCOM"), (shared_obj, SCons.Defaults.SharedObjectEmitter, "$SHCCCOM"), ], ), itertools.product( - _CXXSuffixes, + CXXSuffixes, [ (static_obj, SCons.Defaults.StaticObjectEmitter, "$CXXCOM"), (shared_obj, SCons.Defaults.SharedObjectEmitter, "$SHCXXCOM"), @@ -182,17 +174,17 @@ def generate(env, **kwargs): # Assumes a dictionary emitter emitter = builder.emitter[suffix] builder.emitter[suffix] = SCons.Builder.ListEmitter( - [emitter, makeEmitCompilationDbEntry(command),] + [emitter, make_emit_compilation_DB_entry(command), ] ) env["BUILDERS"]["__COMPILATIONDB_Entry"] = SCons.Builder.Builder( - action=SCons.Action.Action(CompilationDbEntryAction, None), + action=SCons.Action.Action(compilation_db_entry_action, None), ) env["BUILDERS"]["__COMPILATIONDB_Database"] = SCons.Builder.Builder( - action=SCons.Action.Action(WriteCompilationDb, "$COMPILATIONDB_COMSTR"), + action=SCons.Action.Action(write_compilation_db, "$COMPILATIONDB_COMSTR"), target_scanner=SCons.Scanner.Scanner( - function=ScanCompilationDb, node_class=None + function=scan_compilation_db, node_class=None ), ) -- cgit v0.12 From 02dbb38a03e88cbce75af348d3045874f3fa8acc Mon Sep 17 00:00:00 2001 From: William Deegan Date: Tue, 19 May 2020 13:18:46 -0700 Subject: Rename as.py to asm.py and add to TOOL_ALIASES. 'as' is reserved keyword so couldn't be imported into compilation_db tool. Add initial bits of test and docs --- CHANGES.txt | 3 + SCons/Tool/__init__.py | 7 +- SCons/Tool/as.py | 40 +----- SCons/Tool/asm.py | 78 +++++++++++ SCons/Tool/compilation_db.py | 62 ++++++--- SCons/Tool/compilation_db.xml | 209 ++++++++++++++++++++++++++++ test/CompilationDatabase/basic.py | 7 + test/CompilationDatabase/fixture/SConstruct | 6 + 8 files changed, 354 insertions(+), 58 deletions(-) create mode 100644 SCons/Tool/asm.py create mode 100644 SCons/Tool/compilation_db.xml create mode 100644 test/CompilationDatabase/basic.py create mode 100644 test/CompilationDatabase/fixture/SConstruct diff --git a/CHANGES.txt b/CHANGES.txt index f336170..414825d 100755 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -53,6 +53,9 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER - Speedup bin/docs-update-generated by caching parsed docbook schema. (60x speedup) - Reorganized source tree. Moved src/engine/SCons to SCons to be more in line with current Python source tree organization practices. + - Renamed as.py to asm.py and left redirecting tool. 'as' is a reserved word and so + changing the name was required as we wanted to import symbols for use in compilation_db + tool. From Jeremy Elson: - Updated design doc to use the correct syntax for Depends() diff --git a/SCons/Tool/__init__.py b/SCons/Tool/__init__.py index 7aab554..dc9fb45 100644 --- a/SCons/Tool/__init__.py +++ b/SCons/Tool/__init__.py @@ -94,11 +94,14 @@ for suffix in LaTeXSuffixes: SourceFileScanner.add_scanner(suffix, PDFLaTeXScanner) # Tool aliases are needed for those tools whose module names also -# occur in the python standard library. This causes module shadowing and -# can break using python library functions under python3 +# occur in the python standard library (This causes module shadowing and +# can break using python library functions under python3) or if the current tool/file names +# are not legal module names (violate python's identifier rules or are +# python language keywords). TOOL_ALIASES = { 'gettext': 'gettext_tool', 'clang++': 'clangxx', + 'as': 'asm', } diff --git a/SCons/Tool/as.py b/SCons/Tool/as.py index c748251..2c9f1a1 100644 --- a/SCons/Tool/as.py +++ b/SCons/Tool/as.py @@ -1,11 +1,10 @@ """SCons.Tool.as -Tool-specific initialization for as, the generic Posix assembler. +Tool-specific initialization for generic assembler. There normally shouldn't be any need to import this module directly. It will usually be imported through the generic SCons.Tool.Tool() selection method. - """ # @@ -33,43 +32,10 @@ selection method. __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" -import SCons.Defaults -import SCons.Tool -import SCons.Util - -assemblers = ['as'] - -ASSuffixes = ['.s', '.asm', '.ASM'] -ASPPSuffixes = ['.spp', '.SPP', '.sx'] -if SCons.Util.case_sensitive_suffixes('.s', '.S'): - ASPPSuffixes.extend(['.S']) -else: - ASSuffixes.extend(['.S']) - -def generate(env): - """Add Builders and construction variables for as to an Environment.""" - static_obj, shared_obj = SCons.Tool.createObjBuilders(env) - - for suffix in ASSuffixes: - static_obj.add_action(suffix, SCons.Defaults.ASAction) - shared_obj.add_action(suffix, SCons.Defaults.ASAction) - static_obj.add_emitter(suffix, SCons.Defaults.StaticObjectEmitter) - shared_obj.add_emitter(suffix, SCons.Defaults.SharedObjectEmitter) - - for suffix in ASPPSuffixes: - static_obj.add_action(suffix, SCons.Defaults.ASPPAction) - shared_obj.add_action(suffix, SCons.Defaults.ASPPAction) - static_obj.add_emitter(suffix, SCons.Defaults.StaticObjectEmitter) - shared_obj.add_emitter(suffix, SCons.Defaults.SharedObjectEmitter) - env['AS'] = env.Detect(assemblers) or 'as' - env['ASFLAGS'] = SCons.Util.CLVar('') - env['ASCOM'] = '$AS $ASFLAGS -o $TARGET $SOURCES' - env['ASPPFLAGS'] = '$ASFLAGS' - env['ASPPCOM'] = '$CC $ASPPFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS -c -o $TARGET $SOURCES' +#forward proxy to the preffered asm version +from SCons.Tool.asm import * -def exists(env): - return env.Detect(assemblers) # Local Variables: # tab-width:4 diff --git a/SCons/Tool/asm.py b/SCons/Tool/asm.py new file mode 100644 index 0000000..c748251 --- /dev/null +++ b/SCons/Tool/asm.py @@ -0,0 +1,78 @@ +"""SCons.Tool.as + +Tool-specific initialization for as, the generic Posix assembler. + +There normally shouldn't be any need to import this module directly. +It will usually be imported through the generic SCons.Tool.Tool() +selection method. + +""" + +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import SCons.Defaults +import SCons.Tool +import SCons.Util + +assemblers = ['as'] + +ASSuffixes = ['.s', '.asm', '.ASM'] +ASPPSuffixes = ['.spp', '.SPP', '.sx'] +if SCons.Util.case_sensitive_suffixes('.s', '.S'): + ASPPSuffixes.extend(['.S']) +else: + ASSuffixes.extend(['.S']) + +def generate(env): + """Add Builders and construction variables for as to an Environment.""" + static_obj, shared_obj = SCons.Tool.createObjBuilders(env) + + for suffix in ASSuffixes: + static_obj.add_action(suffix, SCons.Defaults.ASAction) + shared_obj.add_action(suffix, SCons.Defaults.ASAction) + static_obj.add_emitter(suffix, SCons.Defaults.StaticObjectEmitter) + shared_obj.add_emitter(suffix, SCons.Defaults.SharedObjectEmitter) + + for suffix in ASPPSuffixes: + static_obj.add_action(suffix, SCons.Defaults.ASPPAction) + shared_obj.add_action(suffix, SCons.Defaults.ASPPAction) + static_obj.add_emitter(suffix, SCons.Defaults.StaticObjectEmitter) + shared_obj.add_emitter(suffix, SCons.Defaults.SharedObjectEmitter) + + env['AS'] = env.Detect(assemblers) or 'as' + env['ASFLAGS'] = SCons.Util.CLVar('') + env['ASCOM'] = '$AS $ASFLAGS -o $TARGET $SOURCES' + env['ASPPFLAGS'] = '$ASFLAGS' + env['ASPPCOM'] = '$CC $ASPPFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS -c -o $TARGET $SOURCES' + +def exists(env): + return env.Detect(assemblers) + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/SCons/Tool/compilation_db.py b/SCons/Tool/compilation_db.py index 75fa696..4767d9e 100644 --- a/SCons/Tool/compilation_db.py +++ b/SCons/Tool/compilation_db.py @@ -1,3 +1,12 @@ +""" +Implements the ability for SCons to emit a compilation database for the MongoDB project. See +http://clang.llvm.org/docs/JSONCompilationDatabase.html for details on what a compilation +database is, and why you might want one. The only user visible entry point here is +'env.CompilationDatabase'. This method takes an optional 'target' to name the file that +should hold the compilation database, otherwise, the file defaults to compile_commands.json, +which is the name that most clang tools search for by default. +""" + # Copyright 2020 MongoDB Inc. # # Permission is hereby granted, free of charge, to any person obtaining @@ -21,17 +30,12 @@ # import json -import SCons import itertools -from cxx import CXXSuffixes -from cc import CSuffixes +import SCons -# Implements the ability for SCons to emit a compilation database for the MongoDB project. See -# http://clang.llvm.org/docs/JSONCompilationDatabase.html for details on what a compilation -# database is, and why you might want one. The only user visible entry point here is -# 'env.CompilationDatabase'. This method takes an optional 'target' to name the file that -# should hold the compilation database, otherwise, the file defaults to compile_commands.json, -# which is the name that most clang tools search for by default. +from .cxx import CXXSuffixes +from .cc import CSuffixes +from .asm import ASSuffixes, ASPPSuffixes # TODO: Is there a better way to do this than this global? Right now this exists so that the # emitter we add can record all of the things it emits, so that the scanner for the top level @@ -117,10 +121,18 @@ def compilation_db_entry_action(target, source, env, **kw): env=env["__COMPILATIONDB_ENV"], ) + if env['COMPILATIONDB_USE_ABSPATH']: + filename = env["__COMPILATIONDB_USOURCE"][0].abspath + target_name = env['__COMPILATIONDB_UTARGET'][0].abspath + else: + filename = env["__COMPILATIONDB_USOURCE"][0].path + target_name = env['__COMPILATIONDB_UTARGET'][0].path + entry = { "directory": env.Dir("#").abspath, "command": command, - "file": str(env["__COMPILATIONDB_USOURCE"][0]), + "file": filename, + "target": target_name } target[0].write(entry) @@ -132,7 +144,7 @@ def write_compilation_db(target, source, env): for s in __COMPILATION_DB_ENTRIES: entries.append(s.read()) - with open(str(target[0]), "w") as target_file: + with open(target[0].path, "w") as target_file: json.dump( entries, target_file, sort_keys=True, indent=4, separators=(",", ": ") ) @@ -142,8 +154,16 @@ def scan_compilation_db(node, env, path): return __COMPILATION_DB_ENTRIES -def generate(env, **kwargs): +def CompilationDatabase(env, target='compile_commands.json'): + result = env.__COMPILATIONDB_Database(target=target, source=[]) + + env.AlwaysBuild(result) + env.NoCache(result) + + return result + +def generate(env, **kwargs): static_obj, shared_obj = SCons.Tool.createObjBuilders(env) env["COMPILATIONDB_COMSTR"] = kwargs.get( @@ -165,6 +185,16 @@ def generate(env, **kwargs): (shared_obj, SCons.Defaults.SharedObjectEmitter, "$SHCXXCOM"), ], ), + itertools.product( + ASSuffixes, + [(static_obj, SCons.Defaults.StaticObjectEmitter, "$ASCOM")], + [(shared_obj, SCons.Defaults.SharedObjectEmitter, "$ASCOM")], + ), + itertools.product( + ASPPSuffixes, + [(static_obj, SCons.Defaults.StaticObjectEmitter, "$ASPPCOM")], + [(shared_obj, SCons.Defaults.SharedObjectEmitter, "$ASPPCOM")], + ), ) for entry in components_by_suffix: @@ -188,13 +218,7 @@ def generate(env, **kwargs): ), ) - def CompilationDatabase(env, target): - result = env.__COMPILATIONDB_Database(target=target, source=[]) - - env.AlwaysBuild(result) - env.NoCache(result) - - return result + env['COMPILATIONDB_USE_ABSPATH'] = False env.AddMethod(CompilationDatabase, "CompilationDatabase") diff --git a/SCons/Tool/compilation_db.xml b/SCons/Tool/compilation_db.xml new file mode 100644 index 0000000..bb7bfb6 --- /dev/null +++ b/SCons/Tool/compilation_db.xml @@ -0,0 +1,209 @@ + + + + +%scons; + +%builders-mod; + +%functions-mod; + +%tools-mod; + +%variables-mod; +]> + + + + + + +Sets up CompilationDatabase builder. + + + This builder generates a clang tooling compatible compilation database. + + + +COMPILATIONDB_COMSTR +__COMPILATIONDB_UACTION +__COMPILATIONDB_UTARGET +__COMPILATIONDB_USOURCE +__COMPILATIONDB_ENV +COMPILATIONDB_USE_ABSPATH + + + + + + + + + + + +The C compiler. + + + + + + + +The command line used to compile a C source file to a (static) object +file. Any options specified in the &cv-link-CFLAGS;, &cv-link-CCFLAGS; and +&cv-link-CPPFLAGS; construction variables are included on this command line. +See also &cv-link-SHCCCOM; for compiling to shared objects. + + + + + + + +If set, the string displayed when a C source file +is compiled to a (static) object file. +If not set, then &cv-link-CCCOM; (the command line) is displayed. +See also &cv-link-SHCCCOMSTR; for compiling to shared objects. + + + +env = Environment(CCCOMSTR = "Compiling static object $TARGET") + + + + + + + +General options that are passed to the C and C++ compilers. +See also &cv-link-SHCCFLAGS; for compiling to shared objects. + + + + + + + +General options that are passed to the C compiler (C only; not C++). +See also &cv-link-SHCFLAGS; for compiling to shared objects. + + + + + + + +User-specified C preprocessor options. +These will be included in any command that uses the C preprocessor, +including not just compilation of C and C++ source files +via the &cv-link-CCCOM;, +&cv-link-SHCCCOM;, +&cv-link-CXXCOM; and +&cv-link-SHCXXCOM; command lines, +but also the &cv-link-FORTRANPPCOM;, +&cv-link-SHFORTRANPPCOM;, +&cv-link-F77PPCOM; and +&cv-link-SHF77PPCOM; command lines +used to compile a Fortran source file, +and the &cv-link-ASPPCOM; command line +used to assemble an assembly language source file, +after first running each file through the C preprocessor. +Note that this variable does +not +contain + +(or similar) include search path options +that scons generates automatically from &cv-link-CPPPATH;. +See &cv-link-_CPPINCFLAGS;, below, +for the variable that expands to those options. + + + + + + + +The list of suffixes of files that will be scanned +for C preprocessor implicit dependencies +(#include lines). +The default list is: + + + +[".c", ".C", ".cxx", ".cpp", ".c++", ".cc", + ".h", ".H", ".hxx", ".hpp", ".hh", + ".F", ".fpp", ".FPP", + ".m", ".mm", + ".S", ".spp", ".SPP"] + + + + + + + +The C compiler used for generating shared-library objects. +See also &cv-link-CC; for compiling to static objects. + + + + + + + +The command line used to compile a C source file +to a shared-library object file. +Any options specified in the &cv-link-SHCFLAGS;, +&cv-link-SHCCFLAGS; and +&cv-link-CPPFLAGS; construction variables +are included on this command line. +See also &cv-link-CCCOM; for compiling to static objects. + + + + + + + +If set, the string displayed when a C source file +is compiled to a shared object file. +If not set, then &cv-link-SHCCCOM; (the command line) is displayed. +See also &cv-link-CCCOMSTR; for compiling to static objects. + + + +env = Environment(SHCCCOMSTR = "Compiling shared object $TARGET") + + + + + + + +Options that are passed to the C and C++ compilers +to generate shared-library objects. +See also &cv-link-CCFLAGS; for compiling to static objects. + + + + + + + +Options that are passed to the C compiler (only; not C++) +to generate shared-library objects. +See also &cv-link-CFLAGS; for compiling to static objects. + + + + + diff --git a/test/CompilationDatabase/basic.py b/test/CompilationDatabase/basic.py new file mode 100644 index 0000000..b2808eb --- /dev/null +++ b/test/CompilationDatabase/basic.py @@ -0,0 +1,7 @@ +import TestSCons + +test = TestSCons.TestSCons() +test.file_fixture('fixture/SConstruct') +test.file_fixture('test_main.c') +test.run() +test.must_exist('compile_commands.jxson') \ No newline at end of file diff --git a/test/CompilationDatabase/fixture/SConstruct b/test/CompilationDatabase/fixture/SConstruct new file mode 100644 index 0000000..d01ac91 --- /dev/null +++ b/test/CompilationDatabase/fixture/SConstruct @@ -0,0 +1,6 @@ +DefaultEnvironment(tools=[]) +env = Environment() +env.Tool('compilation_db') + +env.Program('main', 'test_main.c') +env.CompilationDatabase('compile_commands.json') -- cgit v0.12 From a1a47b77666e20e391ebbf81053caf0154a93093 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Tue, 19 May 2020 14:53:13 -0700 Subject: Updates to doc. Still WIP --- SCons/Tool/compilation_db.xml | 290 ++++++++++++++---------------------------- bin/SConsDoc.py | 1 + 2 files changed, 99 insertions(+), 192 deletions(-) diff --git a/SCons/Tool/compilation_db.xml b/SCons/Tool/compilation_db.xml index bb7bfb6..b9141b6 100644 --- a/SCons/Tool/compilation_db.xml +++ b/SCons/Tool/compilation_db.xml @@ -7,203 +7,109 @@ See its __doc__ string for a discussion of the format. --> -%scons; - -%builders-mod; - -%functions-mod; - -%tools-mod; - -%variables-mod; -]> + + %scons; + + %builders-mod; + + %functions-mod; + + %tools-mod; + + %variables-mod; + ]> - - - -Sets up CompilationDatabase builder. - - - This builder generates a clang tooling compatible compilation database. - - - -COMPILATIONDB_COMSTR -__COMPILATIONDB_UACTION -__COMPILATIONDB_UTARGET -__COMPILATIONDB_USOURCE -__COMPILATIONDB_ENV -COMPILATIONDB_USE_ABSPATH - - - - - - - + + + + Sets up &b-CompilationDatabase; Pseudo builder. + + + This builder generates a clang tooling compatible compilation database. + Note: If there's no specified target file, it will default to + compile_commands.json + + + + COMPILATIONDB_COMSTR + __COMPILATIONDB_UACTION + __COMPILATIONDB_UTARGET + __COMPILATIONDB_USOURCE + __COMPILATIONDB_ENV + COMPILATIONDB_USE_ABSPATH + + + + + + + The &b-CompilationDatabase; builder writes a + clang formatted compilation + database + + + + This is consumed by a number of clang tools. + + + + + + + + The string displayed when CompilationDatabase builder's action is run. + + + + + + + + This is a boolean flag to instruct &b-link-CompilationDatabase; to + write the file and target members + in the target file with absolute or relative path. + + + The default value is False. + + + + + + + This variable stores the action for building a target. + It's intended for internal usage by &b-link-CompilationDatabase; only. + + + + + + + This variable stores the action for building a target. + It's intended for internal usage by &b-link-CompilationDatabase; only. + + + + + + + This variable stores the action for building a target. + It's intended for internal usage by &b-link-CompilationDatabase; only. + + + + + + + This variable stores the action for building a target. + It's intended for internal usage by &b-link-CompilationDatabase; only. + + + - - - -The C compiler. - - - - - - - -The command line used to compile a C source file to a (static) object -file. Any options specified in the &cv-link-CFLAGS;, &cv-link-CCFLAGS; and -&cv-link-CPPFLAGS; construction variables are included on this command line. -See also &cv-link-SHCCCOM; for compiling to shared objects. - - - - - - - -If set, the string displayed when a C source file -is compiled to a (static) object file. -If not set, then &cv-link-CCCOM; (the command line) is displayed. -See also &cv-link-SHCCCOMSTR; for compiling to shared objects. - - - -env = Environment(CCCOMSTR = "Compiling static object $TARGET") - - - - - - - -General options that are passed to the C and C++ compilers. -See also &cv-link-SHCCFLAGS; for compiling to shared objects. - - - - - - - -General options that are passed to the C compiler (C only; not C++). -See also &cv-link-SHCFLAGS; for compiling to shared objects. - - - - - - - -User-specified C preprocessor options. -These will be included in any command that uses the C preprocessor, -including not just compilation of C and C++ source files -via the &cv-link-CCCOM;, -&cv-link-SHCCCOM;, -&cv-link-CXXCOM; and -&cv-link-SHCXXCOM; command lines, -but also the &cv-link-FORTRANPPCOM;, -&cv-link-SHFORTRANPPCOM;, -&cv-link-F77PPCOM; and -&cv-link-SHF77PPCOM; command lines -used to compile a Fortran source file, -and the &cv-link-ASPPCOM; command line -used to assemble an assembly language source file, -after first running each file through the C preprocessor. -Note that this variable does -not -contain - -(or similar) include search path options -that scons generates automatically from &cv-link-CPPPATH;. -See &cv-link-_CPPINCFLAGS;, below, -for the variable that expands to those options. - - - - - - - -The list of suffixes of files that will be scanned -for C preprocessor implicit dependencies -(#include lines). -The default list is: - - - -[".c", ".C", ".cxx", ".cpp", ".c++", ".cc", - ".h", ".H", ".hxx", ".hpp", ".hh", - ".F", ".fpp", ".FPP", - ".m", ".mm", - ".S", ".spp", ".SPP"] - - - - - - - -The C compiler used for generating shared-library objects. -See also &cv-link-CC; for compiling to static objects. - - - - - - - -The command line used to compile a C source file -to a shared-library object file. -Any options specified in the &cv-link-SHCFLAGS;, -&cv-link-SHCCFLAGS; and -&cv-link-CPPFLAGS; construction variables -are included on this command line. -See also &cv-link-CCCOM; for compiling to static objects. - - - - - - - -If set, the string displayed when a C source file -is compiled to a shared object file. -If not set, then &cv-link-SHCCCOM; (the command line) is displayed. -See also &cv-link-CCCOMSTR; for compiling to static objects. - - - -env = Environment(SHCCCOMSTR = "Compiling shared object $TARGET") - - - - - - - -Options that are passed to the C and C++ compilers -to generate shared-library objects. -See also &cv-link-CCFLAGS; for compiling to static objects. - - - - - - - -Options that are passed to the C compiler (only; not C++) -to generate shared-library objects. -See also &cv-link-CFLAGS; for compiling to static objects. - - - diff --git a/bin/SConsDoc.py b/bin/SConsDoc.py index 960a0c9..e869146 100644 --- a/bin/SConsDoc.py +++ b/bin/SConsDoc.py @@ -688,6 +688,7 @@ def validate_all_xml(dpaths, xsdfile=default_xsd): fpaths.append(fp) fails = [] + fpaths = sorted(fpaths) for idx, fp in enumerate(fpaths): fpath = os.path.join(path, fp) print("%.2f%s (%d/%d) %s" % (float(idx + 1) * 100.0 /float(len(fpaths)), -- cgit v0.12 From 97bc344bcb78a8cfbea0e5417b7b461f1d066ce7 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Tue, 19 May 2020 16:14:50 -0700 Subject: extract fake gcc and link python scripts to fixture. We'll use these for CompilationDatabase tests --- test/CPPFLAGS.py | 57 ++++---------------------------------------- test/fixture/mygcc.py | 17 +++++++++++++ test/fixture/mylink_win32.py | 0 3 files changed, 21 insertions(+), 53 deletions(-) create mode 100644 test/fixture/mygcc.py create mode 100644 test/fixture/mylink_win32.py diff --git a/test/CPPFLAGS.py b/test/CPPFLAGS.py index 4c656a1..78d28e8 100644 --- a/test/CPPFLAGS.py +++ b/test/CPPFLAGS.py @@ -32,68 +32,19 @@ _python_ = TestSCons._python_ test = TestSCons.TestSCons() -# Writing this to accomodate both our in-line tool chain and the +# Writing this to accommodate both our in-line tool chain and the # MSVC command lines is too hard, and will be completely unnecessary # some day when we separate our tests. Punt for now. if sys.platform == 'win32': test.skip_test('Skipping on win32.\n') - - if sys.platform == 'win32': - - test.write('mylink.py', r""" -import sys -args = sys.argv[1:] -while args: - a = args[0] - if a[0] != '/': - break - args.pop(0) - if a[:5] == '/OUT:': out = a[5:] -with open(out, 'w') as ofp, open(args[0], 'r') as ifp: - for l in ifp.readlines(): - if l[:5] != '#link': - ofp.write(l) -sys.exit(0) -""") - + test.file_fixture('mylink_win32.py', 'mylink.py') else: + test.file_fixture('mylink.py') - test.write('mylink.py', r""" -import getopt -import sys -opts, args = getopt.getopt(sys.argv[1:], 'o:s:') -for opt, arg in opts: - if opt == '-o': out = arg -with open(out, 'w') as ofp: - for f in args: - with open(f, 'r') as ifp: - for l in ifp.readlines(): - if l[:5] != '#link': - ofp.write(l) -sys.exit(0) -""") - -test.write('mygcc.py', r""" -import getopt -import os -import sys -compiler = sys.argv[1] -clen = len(compiler) + 1 -opts, args = getopt.getopt(sys.argv[2:], 'co:xf:K:') -for opt, arg in opts: - if opt == '-o': out = arg - elif opt == '-x': - with open('mygcc.out', 'a') as f: - f.write(compiler + "\n") -with open(out, 'w') as ofp, open(args[0], 'r') as ifp: - for l in ifp.readlines(): - if l[:clen] != '#' + compiler: - ofp.write(l) -sys.exit(0) -""") +test.file_fixture('mygcc.py') test.write('SConstruct', """ diff --git a/test/fixture/mygcc.py b/test/fixture/mygcc.py new file mode 100644 index 0000000..76634cb --- /dev/null +++ b/test/fixture/mygcc.py @@ -0,0 +1,17 @@ + +import getopt +import os +import sys +compiler = sys.argv[1] +clen = len(compiler) + 1 +opts, args = getopt.getopt(sys.argv[2:], 'co:xf:K:') +for opt, arg in opts: + if opt == '-o': out = arg + elif opt == '-x': + with open('mygcc.out', 'a') as f: + f.write(compiler + "\n") +with open(out, 'w') as ofp, open(args[0], 'r') as ifp: + for l in ifp.readlines(): + if l[:clen] != '#' + compiler: + ofp.write(l) +sys.exit(0) diff --git a/test/fixture/mylink_win32.py b/test/fixture/mylink_win32.py new file mode 100644 index 0000000..e69de29 -- cgit v0.12 From 9d1cae7754e208dbb5a45769563eb5581d4b3dd4 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Tue, 19 May 2020 16:21:58 -0700 Subject: more test updates --- test/CPPFLAGS.py | 1 - test/CompilationDatabase/basic.py | 17 +++++++++- test/CompilationDatabase/fixture/SConstruct | 17 ++++++++-- test/fixture/mygcc.py | 6 ++-- test/fixture/mylink.py | 50 ++++++++--------------------- test/fixture/mylink_win32.py | 16 +++++++++ 6 files changed, 64 insertions(+), 43 deletions(-) diff --git a/test/CPPFLAGS.py b/test/CPPFLAGS.py index 78d28e8..2808a53 100644 --- a/test/CPPFLAGS.py +++ b/test/CPPFLAGS.py @@ -43,7 +43,6 @@ if sys.platform == 'win32': else: test.file_fixture('mylink.py') - test.file_fixture('mygcc.py') diff --git a/test/CompilationDatabase/basic.py b/test/CompilationDatabase/basic.py index b2808eb..927bec7 100644 --- a/test/CompilationDatabase/basic.py +++ b/test/CompilationDatabase/basic.py @@ -1,7 +1,22 @@ +import sys import TestSCons + test = TestSCons.TestSCons() + +if sys.platform == 'win32': + test.file_fixture('mylink_win32.py', 'mylink.py') +else: + test.file_fixture('mylink.py') + +test.file_fixture('mygcc.py') + +test.verbose_set(1) test.file_fixture('fixture/SConstruct') test.file_fixture('test_main.c') test.run() -test.must_exist('compile_commands.jxson') \ No newline at end of file +test.must_exist('compile_commands.json') + +# Now test with absolute paths +test.run(arguments='ABSPATH=1') +test.must_exist('compile_commands_abs.json') diff --git a/test/CompilationDatabase/fixture/SConstruct b/test/CompilationDatabase/fixture/SConstruct index d01ac91..0f8944e 100644 --- a/test/CompilationDatabase/fixture/SConstruct +++ b/test/CompilationDatabase/fixture/SConstruct @@ -1,6 +1,19 @@ +import sys + DefaultEnvironment(tools=[]) -env = Environment() +env = Environment( + PYTHON=sys.executable, + LINK='$PYTHON mylink.py', + LINKFLAGS=[], + CC='$PYTHON mygcc.py cc', + CXX='$PYTHON mygcc.py c++', +) env.Tool('compilation_db') +if ARGUMENTS.get('ABSPATH', False): + env['COMPILATIONDB_USE_ABSPATH'] = True + env.CompilationDatabase('compile_commands_abs.json') +else: + env.CompilationDatabase('compile_commands.json') + env.Program('main', 'test_main.c') -env.CompilationDatabase('compile_commands.json') diff --git a/test/fixture/mygcc.py b/test/fixture/mygcc.py index 76634cb..02480ee 100644 --- a/test/fixture/mygcc.py +++ b/test/fixture/mygcc.py @@ -1,15 +1,17 @@ - import getopt import os import sys + compiler = sys.argv[1] clen = len(compiler) + 1 opts, args = getopt.getopt(sys.argv[2:], 'co:xf:K:') for opt, arg in opts: - if opt == '-o': out = arg + if opt == '-o': + out = arg elif opt == '-x': with open('mygcc.out', 'a') as f: f.write(compiler + "\n") + with open(out, 'w') as ofp, open(args[0], 'r') as ifp: for l in ifp.readlines(): if l[:clen] != '#' + compiler: diff --git a/test/fixture/mylink.py b/test/fixture/mylink.py index 38d9846..85646a4 100644 --- a/test/fixture/mylink.py +++ b/test/fixture/mylink.py @@ -1,39 +1,15 @@ -r""" -Phony "linker" for testing SCons. - -Recognizes the option to specify an output file, ignoring -all others; copies input lines to the output file except -ones that contain a pattern, so we can recognize the tool -has made a modification. -""" - +import getopt import sys -if __name__ == '__main__': - if sys.platform == 'win32': - args = sys.argv[1:] - while args: - a = args[0] - if a == '-o': - out = args[1] - args = args[2:] - continue - if not a[0] in '/-': - break - args = args[1:] - if a[:5].lower() == '/out:': out = a[5:] - with open(args[0], 'rb') as ifp, open(out, 'wb') as ofp: - for line in ifp: - if not line.startswith(b'#link'): - ofp.write(line) - sys.exit(0) - else: - import getopt - opts, args = getopt.getopt(sys.argv[1:], 'o:') - for opt, arg in opts: - if opt == '-o': out = arg - with open(args[0], 'rb') as ifp, open(out, 'wb') as ofp: - for line in ifp: - if not line.startswith(b'#link'): - ofp.write(line) - sys.exit(0) +opts, args = getopt.getopt(sys.argv[1:], 'o:s:') +for opt, arg in opts: + if opt == '-o': + out = arg + +with open(out, 'w') as ofp: + for f in args: + with open(f, 'r') as ifp: + for l in ifp.readlines(): + if l[:5] != '#link': + ofp.write(l) +sys.exit(0) diff --git a/test/fixture/mylink_win32.py b/test/fixture/mylink_win32.py index e69de29..438e920 100644 --- a/test/fixture/mylink_win32.py +++ b/test/fixture/mylink_win32.py @@ -0,0 +1,16 @@ +import sys + +args = sys.argv[1:] +while args: + a = args[0] + if a[0] != '/': + break + args.pop(0) + if a[:5] == '/OUT:': + out = a[5:] + +with open(out, 'w') as ofp, open(args[0], 'r') as ifp: + for l in ifp.readlines(): + if l[:5] != '#link': + ofp.write(l) +sys.exit(0) -- cgit v0.12 From 97650c632c4798f939cef6222292e4cf24c7595e Mon Sep 17 00:00:00 2001 From: William Deegan Date: Tue, 19 May 2020 16:28:17 -0700 Subject: address sider issues --- SCons/Tool/as.py | 7 ++++--- test/fixture/mygcc.py | 1 - 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/SCons/Tool/as.py b/SCons/Tool/as.py index 2c9f1a1..8ec0ce2 100644 --- a/SCons/Tool/as.py +++ b/SCons/Tool/as.py @@ -32,9 +32,10 @@ selection method. __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" - -#forward proxy to the preffered asm version -from SCons.Tool.asm import * +# +# forward proxy to the preffered asm version +# +from SCons.Tool.asm import generate, exists # Local Variables: diff --git a/test/fixture/mygcc.py b/test/fixture/mygcc.py index 02480ee..d701883 100644 --- a/test/fixture/mygcc.py +++ b/test/fixture/mygcc.py @@ -1,5 +1,4 @@ import getopt -import os import sys compiler = sys.argv[1] -- cgit v0.12 From 876f98d2d546a82fc1aba0d7b6421a1b06c4f0b7 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Tue, 19 May 2020 16:30:51 -0700 Subject: fix typo --- SCons/Tool/as.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SCons/Tool/as.py b/SCons/Tool/as.py index 8ec0ce2..03cea82 100644 --- a/SCons/Tool/as.py +++ b/SCons/Tool/as.py @@ -33,7 +33,7 @@ selection method. __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" # -# forward proxy to the preffered asm version +# forward proxy to the preferred asm version # from SCons.Tool.asm import generate, exists -- cgit v0.12 From 7d8ea4182d67e2a1e803f266bb92c4ab8c10d0e6 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Tue, 19 May 2020 16:33:35 -0700 Subject: Don't use from..import, rather import and copy generate,exists to address sider complaint --- SCons/Tool/as.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/SCons/Tool/as.py b/SCons/Tool/as.py index 03cea82..d21cc8e 100644 --- a/SCons/Tool/as.py +++ b/SCons/Tool/as.py @@ -35,7 +35,11 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" # # forward proxy to the preferred asm version # -from SCons.Tool.asm import generate, exists +import SCons.Tool.asm + +# Resolve FLAKE8 F401 (make sider happy) +generate = SCons.Tool.asm.generate +exists = SCons.Tool.asm.exists # Local Variables: -- cgit v0.12 From 6878db720dbcf12e50208917268a47326452735d Mon Sep 17 00:00:00 2001 From: William Deegan Date: Tue, 19 May 2020 20:26:42 -0700 Subject: More doc updates. Hide internal env variables. Fix broken test/import.py. Handle when not all of cc,cxx and as tools are configured --- SCons/Tool/compilation_db.py | 12 +++++--- SCons/Tool/compilation_db.xml | 65 ++++++++++++++++++++++--------------------- 2 files changed, 41 insertions(+), 36 deletions(-) diff --git a/SCons/Tool/compilation_db.py b/SCons/Tool/compilation_db.py index 4767d9e..6433d96 100644 --- a/SCons/Tool/compilation_db.py +++ b/SCons/Tool/compilation_db.py @@ -122,6 +122,7 @@ def compilation_db_entry_action(target, source, env, **kw): ) if env['COMPILATIONDB_USE_ABSPATH']: + print("ABSPATH") filename = env["__COMPILATIONDB_USOURCE"][0].abspath target_name = env['__COMPILATIONDB_UTARGET'][0].abspath else: @@ -202,10 +203,13 @@ def generate(env, **kwargs): builder, base_emitter, command = entry[1] # Assumes a dictionary emitter - emitter = builder.emitter[suffix] - builder.emitter[suffix] = SCons.Builder.ListEmitter( - [emitter, make_emit_compilation_DB_entry(command), ] - ) + emitter = builder.emitter.get(suffix, False) + if emitter: + # We may not have tools installed which initialize all or any of + # cxx, cc, or assembly. If not skip resetting the respective emitter. + builder.emitter[suffix] = SCons.Builder.ListEmitter( + [emitter, make_emit_compilation_DB_entry(command), ] + ) env["BUILDERS"]["__COMPILATIONDB_Entry"] = SCons.Builder.Builder( action=SCons.Action.Action(compilation_db_entry_action, None), diff --git a/SCons/Tool/compilation_db.xml b/SCons/Tool/compilation_db.xml index b9141b6..65b557b 100644 --- a/SCons/Tool/compilation_db.xml +++ b/SCons/Tool/compilation_db.xml @@ -78,38 +78,39 @@ See its __doc__ string for a discussion of the format. - - - - This variable stores the action for building a target. - It's intended for internal usage by &b-link-CompilationDatabase; only. - - - - - - - This variable stores the action for building a target. - It's intended for internal usage by &b-link-CompilationDatabase; only. - - - - - - - This variable stores the action for building a target. - It's intended for internal usage by &b-link-CompilationDatabase; only. - - - - - - - This variable stores the action for building a target. - It's intended for internal usage by &b-link-CompilationDatabase; only. - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v0.12 From 45df0d7e82d792f8f66bfe41d9123ea0b9c77f74 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Fri, 22 May 2020 11:19:40 -0700 Subject: resolve sider complaints in test fixtures --- test/fixture/mygcc.py | 6 +++--- test/fixture/mylink.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/fixture/mygcc.py b/test/fixture/mygcc.py index d701883..ceb10e5 100644 --- a/test/fixture/mygcc.py +++ b/test/fixture/mygcc.py @@ -12,7 +12,7 @@ for opt, arg in opts: f.write(compiler + "\n") with open(out, 'w') as ofp, open(args[0], 'r') as ifp: - for l in ifp.readlines(): - if l[:clen] != '#' + compiler: - ofp.write(l) + for line in ifp.readlines(): + if line[:clen] != '#' + compiler: + ofp.write(line) sys.exit(0) diff --git a/test/fixture/mylink.py b/test/fixture/mylink.py index 85646a4..fe4af58 100644 --- a/test/fixture/mylink.py +++ b/test/fixture/mylink.py @@ -9,7 +9,7 @@ for opt, arg in opts: with open(out, 'w') as ofp: for f in args: with open(f, 'r') as ifp: - for l in ifp.readlines(): - if l[:5] != '#link': - ofp.write(l) + for line in ifp.readlines(): + if line[:5] != '#link': + ofp.write(line) sys.exit(0) -- cgit v0.12 From 10b7f6beb261c41ac87e915cbd20e7f069f67c45 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Fri, 22 May 2020 11:27:34 -0700 Subject: [skip appveyor] [skip travis] resolve sider complaints in test fixtures --- test/fixture/mylink_win32.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/fixture/mylink_win32.py b/test/fixture/mylink_win32.py index 438e920..477fc95 100644 --- a/test/fixture/mylink_win32.py +++ b/test/fixture/mylink_win32.py @@ -10,7 +10,7 @@ while args: out = a[5:] with open(out, 'w') as ofp, open(args[0], 'r') as ifp: - for l in ifp.readlines(): - if l[:5] != '#link': - ofp.write(l) + for line in ifp.readlines(): + if line[:5] != '#link': + ofp.write(line) sys.exit(0) -- cgit v0.12 From 4b4eadbcbb8a9017321b8a508ec6af6b9d22b9e7 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Fri, 22 May 2020 13:55:00 -0700 Subject: Remove debug output --- SCons/Tool/compilation_db.py | 1 - 1 file changed, 1 deletion(-) diff --git a/SCons/Tool/compilation_db.py b/SCons/Tool/compilation_db.py index 6433d96..0b7c9b8 100644 --- a/SCons/Tool/compilation_db.py +++ b/SCons/Tool/compilation_db.py @@ -122,7 +122,6 @@ def compilation_db_entry_action(target, source, env, **kw): ) if env['COMPILATIONDB_USE_ABSPATH']: - print("ABSPATH") filename = env["__COMPILATIONDB_USOURCE"][0].abspath target_name = env['__COMPILATIONDB_UTARGET'][0].abspath else: -- cgit v0.12 From a56a563e1a21b8dd02bd5fb8267cec92da525ea2 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Tue, 26 May 2020 18:54:30 -0700 Subject: add comment to indicate which sections are appendix --- doc/user/main.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/user/main.xml b/doc/user/main.xml index 85dcf00..34555af 100644 --- a/doc/user/main.xml +++ b/doc/user/main.xml @@ -159,6 +159,8 @@ + + -- cgit v0.12 From 8c28b830c282acd4338bc4c250f04854cce1dada Mon Sep 17 00:00:00 2001 From: William Deegan Date: Tue, 26 May 2020 18:54:57 -0700 Subject: add commented out XSLTFLAGS info which may enable creating PDF bookmarks --- doc/user/SConstruct | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/user/SConstruct b/doc/user/SConstruct index 4e96319..cfd85cf 100644 --- a/doc/user/SConstruct +++ b/doc/user/SConstruct @@ -29,6 +29,7 @@ import os env = Environment(ENV={'PATH' : os.environ['PATH']}, tools=['docbook','gs','zip'], toolpath=['../../SCons/Tool'], + # DOCBOOK_XSLTPROCFLAGS="--stringparam fop.extensions 1", DOCBOOK_DEFAULT_XSL_HTML='html.xsl', DOCBOOK_DEFAULT_XSL_HTMLCHUNKED='chtml.xsl', DOCBOOK_DEFAULT_XSL_PDF='pdf.xsl') -- cgit v0.12 From 897e738e626f528618ff3c2f97e67767d2644fdf Mon Sep 17 00:00:00 2001 From: William Deegan Date: Tue, 26 May 2020 18:55:24 -0700 Subject: [ci skip] Add initial section for Users Guide misc section for compilation database --- doc/user/misc.xml | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/doc/user/misc.xml b/doc/user/misc.xml index b093629..f2531b6 100644 --- a/doc/user/misc.xml +++ b/doc/user/misc.xml @@ -675,4 +675,46 @@ env.Command('directory_build_info', +
+ Creating LLVM Compilation Database + + + + LLVM has defined a JSON Compilation Database Format. This file is in common use as input into LLVM tools and many IDE's and editors as well. + + + See JSON Compilation Database Format Specification¶ for complete information + + + + + Currently SCons supports two variations. One is to output source and target files with paths relative to the top of the SCons build, or to output those files with their absolute path. + + This is controlled by COMPILATIONDB_USE_ABSPATH=(True|False) + + Example of absolute paths for target and source + +[ + { + "command": "gcc -o test_main.o -c test_main.c", + "directory": "/home/user/sandbox", + "file": "/home/user/sandbox/test_main.c", + "target": "/home/user/sandbox/test_main.o" + } +] + + Example of relative paths for target and source + + +[ + { + "command": "gcc -o test_main.o -c test_main.c", + "directory": "/home/user/sandbox", + "file": "test_main.c", + "target": "test_main.o" + } +] + + +
-- cgit v0.12 From ef7265e6b2bc4f005a48fcc5c8f9e724f08d0ed6 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Fri, 29 May 2020 15:22:08 -0700 Subject: [ci skip] a little formatting change --- doc/user/misc.xml | 57 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/doc/user/misc.xml b/doc/user/misc.xml index f2531b6..e9b078d 100644 --- a/doc/user/misc.xml +++ b/doc/user/misc.xml @@ -675,25 +675,34 @@ env.Command('directory_build_info', -
- Creating LLVM Compilation Database - - - - LLVM has defined a JSON Compilation Database Format. This file is in common use as input into LLVM tools and many IDE's and editors as well. - - - See JSON Compilation Database Format Specification¶ for complete information - - - - - Currently SCons supports two variations. One is to output source and target files with paths relative to the top of the SCons build, or to output those files with their absolute path. - - This is controlled by COMPILATIONDB_USE_ABSPATH=(True|False) - - Example of absolute paths for target and source - +
+ Creating LLVM Compilation Database + + + + LLVM has defined a JSON Compilation Database Format. This file is in common use as input into LLVM tools + and many IDE's and editors as well. + + + See + + JSON Compilation Database Format Specification¶ + + for complete information + + + + + Currently SCons supports two variations. One is to output source and target files with paths relative to the + top + of the SCons build, or to output those files with their absolute path. + + This is controlled by + COMPILATIONDB_USE_ABSPATH=(True|False) + + + Example of absolute paths for target and source + [ { "command": "gcc -o test_main.o -c test_main.c", @@ -702,10 +711,10 @@ env.Command('directory_build_info', "target": "/home/user/sandbox/test_main.o" } ] - - Example of relative paths for target and source + + Example of relative paths for target and source - + [ { "command": "gcc -o test_main.o -c test_main.c", @@ -714,7 +723,7 @@ env.Command('directory_build_info', "target": "test_main.o" } ] - + -
+
-- cgit v0.12 From d53f6129f48e1c0ed755e4aedda0085a528a1426 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Sat, 6 Jun 2020 11:28:41 -0700 Subject: change CompilationDatabase from psuedo builder to builder. Add emitter to clear source and set default target as 'compile_commands.json'. --- CHANGES.txt | 1 + SCons/Tool/compilation_db.py | 21 +++++++++++++-------- SCons/Tool/compilation_db.xml | 8 +++++--- doc/user/misc.xml | 15 +++++++++++++++ test/CompilationDatabase/fixture/SConstruct | 4 ++-- 5 files changed, 36 insertions(+), 13 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 414825d..b04615f 100755 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -56,6 +56,7 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER - Renamed as.py to asm.py and left redirecting tool. 'as' is a reserved word and so changing the name was required as we wanted to import symbols for use in compilation_db tool. + - Add CompilationDatabase() builder in compilation_db tool. Contributed by MongoDB. From Jeremy Elson: - Updated design doc to use the correct syntax for Depends() diff --git a/SCons/Tool/compilation_db.py b/SCons/Tool/compilation_db.py index 0b7c9b8..788f454 100644 --- a/SCons/Tool/compilation_db.py +++ b/SCons/Tool/compilation_db.py @@ -154,13 +154,18 @@ def scan_compilation_db(node, env, path): return __COMPILATION_DB_ENTRIES -def CompilationDatabase(env, target='compile_commands.json'): - result = env.__COMPILATIONDB_Database(target=target, source=[]) +def compilation_db_emitter(target, source, env): + """ fix up the source/targets """ - env.AlwaysBuild(result) - env.NoCache(result) + # Default target name is compilation_db.json + if not target: + target = ['compile_commands.json', ] - return result + # No source should have been passed. Drop it. + if source: + source = [] + + return target, source def generate(env, **kwargs): @@ -214,17 +219,17 @@ def generate(env, **kwargs): action=SCons.Action.Action(compilation_db_entry_action, None), ) - env["BUILDERS"]["__COMPILATIONDB_Database"] = SCons.Builder.Builder( + env["BUILDERS"]["CompilationDatabase"] = SCons.Builder.Builder( action=SCons.Action.Action(write_compilation_db, "$COMPILATIONDB_COMSTR"), target_scanner=SCons.Scanner.Scanner( function=scan_compilation_db, node_class=None ), + emitter=compilation_db_emitter, + suffix='json', ) env['COMPILATIONDB_USE_ABSPATH'] = False - env.AddMethod(CompilationDatabase, "CompilationDatabase") - def exists(env): return True diff --git a/SCons/Tool/compilation_db.xml b/SCons/Tool/compilation_db.xml index 65b557b..12a4db0 100644 --- a/SCons/Tool/compilation_db.xml +++ b/SCons/Tool/compilation_db.xml @@ -26,12 +26,14 @@ See its __doc__ string for a discussion of the format. - Sets up &b-CompilationDatabase; Pseudo builder. + Sets up &b-CompilationDatabase; builder. This builder generates a clang tooling compatible compilation database. - Note: If there's no specified target file, it will default to - compile_commands.json + + + Note: The target file is typically named + compile_commands.json. diff --git a/doc/user/misc.xml b/doc/user/misc.xml index e9b078d..8aa7d62 100644 --- a/doc/user/misc.xml +++ b/doc/user/misc.xml @@ -699,9 +699,17 @@ env.Command('directory_build_info', This is controlled by COMPILATIONDB_USE_ABSPATH=(True|False) + which defaults to False. Example of absolute paths for target and source + + +env = Environment(COMPILATIONDB_USE_ABSPATH=True) +env.Tool('compilation_db') +env.CompilationDatabase('compile_commands.json') + + [ { @@ -712,8 +720,15 @@ env.Command('directory_build_info', } ] + + Example of relative paths for target and source + +env = Environment() +env.Tool('compilation_db') +env.CompilationDatabase('compile_commands.json') + [ { diff --git a/test/CompilationDatabase/fixture/SConstruct b/test/CompilationDatabase/fixture/SConstruct index 0f8944e..0bbcafa 100644 --- a/test/CompilationDatabase/fixture/SConstruct +++ b/test/CompilationDatabase/fixture/SConstruct @@ -12,8 +12,8 @@ env.Tool('compilation_db') if ARGUMENTS.get('ABSPATH', False): env['COMPILATIONDB_USE_ABSPATH'] = True - env.CompilationDatabase('compile_commands_abs.json') + env.CompilationDatabase('compile_commands_abs.json', source=[]) else: - env.CompilationDatabase('compile_commands.json') + env.CompilationDatabase('compile_commands.json', source=[]) env.Program('main', 'test_main.c') -- cgit v0.12 From f65a1d8642381193c3673c3642a2f7b2b1bafddb Mon Sep 17 00:00:00 2001 From: William Deegan Date: Sat, 6 Jun 2020 12:23:29 -0700 Subject: [ci skip] Updates to docs --- SCons/Tool/compilation_db.xml | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/SCons/Tool/compilation_db.xml b/SCons/Tool/compilation_db.xml index 12a4db0..1aec177 100644 --- a/SCons/Tool/compilation_db.xml +++ b/SCons/Tool/compilation_db.xml @@ -26,14 +26,7 @@ See its __doc__ string for a discussion of the format. - Sets up &b-CompilationDatabase; builder. - - - This builder generates a clang tooling compatible compilation database. - - - Note: The target file is typically named - compile_commands.json. + Sets up &b-CompilationDatabase; builder which generates a clang tooling compatible compilation database. @@ -52,10 +45,25 @@ See its __doc__ string for a discussion of the format. The &b-CompilationDatabase; builder writes a clang formatted compilation database - + which is consumed by a number of clang tools, editors, and other tools. + + + If you don't specify any files, the builder will default to compile_commands.json. + + + If you specify a single file as below + +env.CompilationDatabase('my_output.json') + + SCons will automatically use that as the target file. + If you specify more than one source, the source list will be ignored. + + + You should not specify source files. The &b-CompilationDatabase; builder instruments SCons to collect them from all + the C, C++, assembly source/target pairs. - This is consumed by a number of clang tools. + New in &SCons; 4.0.0 -- cgit v0.12 From 9e70741b4508367bb064c4d783e522fb80479df2 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Sat, 6 Jun 2020 12:25:10 -0700 Subject: Allow override environments to affect whether output file has abs or relative paths. If user doesn't specify target CompilationDatabase('my_output.json') SCons will swap what is by default the source to be the target and clear the source list. If no target specified use compile_commands.json. If more than one item specified as source, source is set to empty list --- SCons/Tool/compilation_db.py | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/SCons/Tool/compilation_db.py b/SCons/Tool/compilation_db.py index 788f454..171e7f1 100644 --- a/SCons/Tool/compilation_db.py +++ b/SCons/Tool/compilation_db.py @@ -121,18 +121,11 @@ def compilation_db_entry_action(target, source, env, **kw): env=env["__COMPILATIONDB_ENV"], ) - if env['COMPILATIONDB_USE_ABSPATH']: - filename = env["__COMPILATIONDB_USOURCE"][0].abspath - target_name = env['__COMPILATIONDB_UTARGET'][0].abspath - else: - filename = env["__COMPILATIONDB_USOURCE"][0].path - target_name = env['__COMPILATIONDB_UTARGET'][0].path - entry = { "directory": env.Dir("#").abspath, "command": command, - "file": filename, - "target": target_name + "file": env["__COMPILATIONDB_USOURCE"][0], + "target": env['__COMPILATIONDB_UTARGET'][0] } target[0].write(entry) @@ -141,8 +134,26 @@ def compilation_db_entry_action(target, source, env, **kw): def write_compilation_db(target, source, env): entries = [] + use_abspath = env['COMPILATIONDB_USE_ABSPATH'] in [True, 1, 'True', 'true'] + for s in __COMPILATION_DB_ENTRIES: - entries.append(s.read()) + entry = s.read() + source_file = entry['file'] + target_file = entry['target'] + + if use_abspath: + source_file = source_file.abspath + target_file = target_file.abspath + else: + source_file = source_file.path + target_file = target_file.path + + path_entry = {'directory': entry['directory'], + 'command': entry['command'], + 'file': source_file, + 'target': target_file} + + entries.append(path_entry) with open(target[0].path, "w") as target_file: json.dump( @@ -157,6 +168,10 @@ def scan_compilation_db(node, env, path): def compilation_db_emitter(target, source, env): """ fix up the source/targets """ + # Someone called env.CompilationDatabase('my_targetname.json') + if not target and len(source) == 1: + target = source + # Default target name is compilation_db.json if not target: target = ['compile_commands.json', ] -- cgit v0.12 From cddeec37f196eeb279ea9f06ec658d21c0971975 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Sat, 6 Jun 2020 16:25:53 -0700 Subject: Added tests which should cover all the variations of ways to call CompilationDatabase --- CHANGES.txt | 2 + SCons/Tool/compilation_db.xml | 4 ++ test/CompilationDatabase/basic.py | 79 ++++++++++++++++++++++++++--- test/CompilationDatabase/fixture/SConstruct | 27 ++++++++-- 4 files changed, 101 insertions(+), 11 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index b04615f..26df3c5 100755 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -57,6 +57,8 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER changing the name was required as we wanted to import symbols for use in compilation_db tool. - Add CompilationDatabase() builder in compilation_db tool. Contributed by MongoDB. + Setting COMPILATIONDB_USE_ABSPATH to True|False controls whether the files are absolute or relative + paths. From Jeremy Elson: - Updated design doc to use the correct syntax for Depends() diff --git a/SCons/Tool/compilation_db.xml b/SCons/Tool/compilation_db.xml index 1aec177..47126a7 100644 --- a/SCons/Tool/compilation_db.xml +++ b/SCons/Tool/compilation_db.xml @@ -63,6 +63,10 @@ env.CompilationDatabase('my_output.json') the C, C++, assembly source/target pairs. + NOTE: You must load the compilation_db tool prior to specifying any part of your build or some source/target + files will not show up in your output file. + + New in &SCons; 4.0.0 diff --git a/test/CompilationDatabase/basic.py b/test/CompilationDatabase/basic.py index 927bec7..b06098b 100644 --- a/test/CompilationDatabase/basic.py +++ b/test/CompilationDatabase/basic.py @@ -1,13 +1,40 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +""" +Test CompilationDatabase and several variations of ways to call it +and values of COMPILATIONDB_USE_ABSPATH +""" + import sys import TestSCons - test = TestSCons.TestSCons() if sys.platform == 'win32': test.file_fixture('mylink_win32.py', 'mylink.py') else: - test.file_fixture('mylink.py') + test.file_fixture('mylink.py') test.file_fixture('mygcc.py') @@ -15,8 +42,48 @@ test.verbose_set(1) test.file_fixture('fixture/SConstruct') test.file_fixture('test_main.c') test.run() -test.must_exist('compile_commands.json') -# Now test with absolute paths -test.run(arguments='ABSPATH=1') -test.must_exist('compile_commands_abs.json') +rel_files = [ + 'compile_commands_only_arg.json', + 'compile_commands_target.json', + 'compile_commands.json', + 'compile_commands_over_rel.json', + 'compile_commands_over_abs_0.json' +] + +abs_files = [ + 'compile_commands_clone_abs.json', + 'compile_commands_over_abs.json', + 'compile_commands_target_over_abs.json', + 'compile_commands_over_abs_1.json', +] + +example_rel_file = """[ + { + "command": "%s mygcc.py cc -o test_main.o -c test_main.c", + "directory": "%s", + "file": "test_main.c", + "target": "test_main.o" + } +]""" % (sys.executable, test.workdir) + +for f in rel_files: + # print("Checking:%s" % f) + test.must_exist(f) + test.must_match(f, example_rel_file) + +example_abs_file = """[ + { + "command": "%s mygcc.py cc -o test_main.o -c test_main.c", + "directory": "%s", + "file": "%s/test_main.c", + "target": "%s/test_main.o" + } +]""" % (sys.executable, test.workdir, test.workdir, test.workdir) + +for f in abs_files: + test.must_exist(f) + test.must_match(f, example_abs_file) + + +test.pass_test() diff --git a/test/CompilationDatabase/fixture/SConstruct b/test/CompilationDatabase/fixture/SConstruct index 0bbcafa..7453161 100644 --- a/test/CompilationDatabase/fixture/SConstruct +++ b/test/CompilationDatabase/fixture/SConstruct @@ -10,10 +10,27 @@ env = Environment( ) env.Tool('compilation_db') -if ARGUMENTS.get('ABSPATH', False): - env['COMPILATIONDB_USE_ABSPATH'] = True - env.CompilationDatabase('compile_commands_abs.json', source=[]) -else: - env.CompilationDatabase('compile_commands.json', source=[]) +env_abs = env.Clone(COMPILATIONDB_USE_ABSPATH=True) +env_abs.CompilationDatabase('compile_commands_clone_abs.json') + +# Should be relative paths +env.CompilationDatabase('compile_commands_only_arg.json') +env.CompilationDatabase(target='compile_commands_target.json') + +# Should default name compile_commands.json +env.CompilationDatabase() + +# Should be absolute paths +env.CompilationDatabase('compile_commands_over_abs.json', COMPILATIONDB_USE_ABSPATH=True) +env.CompilationDatabase(target='compile_commands_target_over_abs.json', COMPILATIONDB_USE_ABSPATH=True) + +# Should be relative paths +env.CompilationDatabase('compile_commands_over_rel.json', COMPILATIONDB_USE_ABSPATH=False) + + +# Try 1/0 for COMPILATIONDB_USE_ABSPATH +env.CompilationDatabase('compile_commands_over_abs_1.json', COMPILATIONDB_USE_ABSPATH=1) +env.CompilationDatabase('compile_commands_over_abs_0.json', COMPILATIONDB_USE_ABSPATH=0) + env.Program('main', 'test_main.c') -- cgit v0.12 From 12739bbdb2d67a376c23fbffc9fd6e53b8b77403 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Sat, 6 Jun 2020 16:26:47 -0700 Subject: Fix test SConstruct formatting --- test/CompilationDatabase/fixture/SConstruct | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/CompilationDatabase/fixture/SConstruct b/test/CompilationDatabase/fixture/SConstruct index 7453161..4043b5a 100644 --- a/test/CompilationDatabase/fixture/SConstruct +++ b/test/CompilationDatabase/fixture/SConstruct @@ -27,10 +27,8 @@ env.CompilationDatabase(target='compile_commands_target_over_abs.json', COMPILAT # Should be relative paths env.CompilationDatabase('compile_commands_over_rel.json', COMPILATIONDB_USE_ABSPATH=False) - # Try 1/0 for COMPILATIONDB_USE_ABSPATH env.CompilationDatabase('compile_commands_over_abs_1.json', COMPILATIONDB_USE_ABSPATH=1) env.CompilationDatabase('compile_commands_over_abs_0.json', COMPILATIONDB_USE_ABSPATH=0) - env.Program('main', 'test_main.c') -- cgit v0.12 From c2829674b04927e17784dd9653298ee25c440376 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Sun, 7 Jun 2020 11:41:40 -0700 Subject: [ci skip] updates based on mwichmann's review of the PR --- SCons/Tool/compilation_db.xml | 14 +++++++------- doc/user/misc.xml | 5 ++--- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/SCons/Tool/compilation_db.xml b/SCons/Tool/compilation_db.xml index 47126a7..038e9cb 100644 --- a/SCons/Tool/compilation_db.xml +++ b/SCons/Tool/compilation_db.xml @@ -26,7 +26,7 @@ See its __doc__ string for a discussion of the format. - Sets up &b-CompilationDatabase; builder which generates a clang tooling compatible compilation database. + Sets up &b-link-CompilationDatabase; builder which generates a clang tooling compatible compilation database. @@ -42,9 +42,9 @@ See its __doc__ string for a discussion of the format. - The &b-CompilationDatabase; builder writes a - clang formatted compilation - database + The &b-CompilationDatabase; builder writes a JSON formatted compilation + database according to the + LLVM specification which is consumed by a number of clang tools, editors, and other tools. @@ -63,7 +63,7 @@ env.CompilationDatabase('my_output.json') the C, C++, assembly source/target pairs. - NOTE: You must load the compilation_db tool prior to specifying any part of your build or some source/target + NOTE: You must load the &t-compilation_db; tool prior to specifying any part of your build or some source/target files will not show up in your output file. @@ -85,10 +85,10 @@ env.CompilationDatabase('my_output.json') This is a boolean flag to instruct &b-link-CompilationDatabase; to write the file and target members - in the target file with absolute or relative path. + in the compilation database with absolute or relative paths. - The default value is False. + The default value is False (use relative paths) diff --git a/doc/user/misc.xml b/doc/user/misc.xml index 8aa7d62..e430897 100644 --- a/doc/user/misc.xml +++ b/doc/user/misc.xml @@ -693,9 +693,8 @@ env.Command('directory_build_info', - Currently SCons supports two variations. One is to output source and target files with paths relative to the - top - of the SCons build, or to output those files with their absolute path. + The compilation database can be populated with source and target files either with paths relative to the + top of the build, or using absolute paths. This is controlled by COMPILATIONDB_USE_ABSPATH=(True|False) -- cgit v0.12