summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--SConstruct10
-rw-r--r--site_scons/site_tools/compilation_db.py34
-rw-r--r--site_scons/site_tools/split_dwarf.py65
3 files changed, 93 insertions, 16 deletions
diff --git a/SConstruct b/SConstruct
index b1942eac382..19e0e671c4b 100644
--- a/SConstruct
+++ b/SConstruct
@@ -887,8 +887,8 @@ envDict = dict(BUILD_ROOT=buildDir,
UNITTEST_LIST='$BUILD_ROOT/unittests.txt',
INTEGRATION_TEST_ALIAS='integration_tests',
INTEGRATION_TEST_LIST='$BUILD_ROOT/integration_tests.txt',
- CONFIGUREDIR=sconsDataDir.Dir('sconf_temp'),
- CONFIGURELOG=sconsDataDir.File('config.log'),
+ CONFIGUREDIR='$BUILD_ROOT/scons/$VARIANT_DIR/sconf_temp',
+ CONFIGURELOG='$BUILD_ROOT/scons/config.log',
INSTALL_DIR=installDir,
CONFIG_HEADER_DEFINES={},
LIBDEPS_TAG_EXPANSIONS=[],
@@ -2892,6 +2892,12 @@ def doConfigure(myenv):
env = doConfigure( env )
+# If the flags in the environment are configured for -gsplit-dwarf,
+# inject the necessary emitter.
+split_dwarf = Tool('split_dwarf')
+if split_dwarf.exists(env):
+ split_dwarf(env)
+
# Load the compilation_db tool. We want to do this after configure so we don't end up with
# compilation database entries for the configure tests, which is weird.
env.Tool("compilation_db")
diff --git a/site_scons/site_tools/compilation_db.py b/site_scons/site_tools/compilation_db.py
index cd4619dcfa4..a8a9c8e603b 100644
--- a/site_scons/site_tools/compilation_db.py
+++ b/site_scons/site_tools/compilation_db.py
@@ -30,6 +30,16 @@ 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.
class __CompilationDbNode(SCons.Node.Node):
@@ -99,20 +109,15 @@ def generate(env, **kwargs):
static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
- # TODO: Is there a way to obtain the configured suffixes for C and C++
- # from the existing obj builders? Seems unfortunate to re-iterate them.
- CSuffixes = ['.c']
- CXXSuffixes = ['.cc', '.cxx', '.cpp']
-
env['COMPILATIONDB_COMSTR'] = kwargs.get(
'COMPILATIONDB_COMSTR', 'Building compilation database $TARGET')
components_by_suffix = itertools.chain(
- itertools.product(CSuffixes, [
+ itertools.product(_CSuffixes, [
(static_obj, SCons.Defaults.StaticObjectEmitter, '$CCCOM'),
(shared_obj, SCons.Defaults.SharedObjectEmitter, '$SHCCCOM'),
]),
- itertools.product(CXXSuffixes, [
+ itertools.product(_CXXSuffixes, [
(static_obj, SCons.Defaults.StaticObjectEmitter, '$CXXCOM'),
(shared_obj, SCons.Defaults.SharedObjectEmitter, '$SHCXXCOM'),
]),
@@ -122,13 +127,14 @@ def generate(env, **kwargs):
suffix = entry[0]
builder, base_emitter, command = entry[1]
- builder.add_emitter(
- suffix, SCons.Builder.ListEmitter(
- [
- makeEmitCompilationDbEntry(command),
- base_emitter,
- ]
- ))
+ # 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),
diff --git a/site_scons/site_tools/split_dwarf.py b/site_scons/site_tools/split_dwarf.py
new file mode 100644
index 00000000000..95130c9e9a3
--- /dev/null
+++ b/site_scons/site_tools/split_dwarf.py
@@ -0,0 +1,65 @@
+# Copyright 2017 MongoDB Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import SCons
+
+_splitDwarfFlag = '-gsplit-dwarf'
+
+# 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')
+
+def _dwo_emitter(target, source, env):
+ new_targets = []
+ for t in target:
+ base, ext = SCons.Util.splitext(str(t))
+ if not any(ext == env[osuffix] for osuffix in ['OBJSUFFIX', 'SHOBJSUFFIX']):
+ continue
+ # TODO: Move 'dwo' into DWOSUFFIX so it can be customized? For
+ # now, GCC doesn't let you control the output filename, so it
+ # doesn't matter.
+ dwotarget = (t.builder.target_factory or env.File)(base + ".dwo")
+ new_targets.append(dwotarget)
+ targets = target + new_targets
+ return (targets, source)
+
+def generate(env):
+ suffixes = []
+ if _splitDwarfFlag in env['CCFLAGS']:
+ suffixes = _CSuffixes + _CXXSuffixes
+ else:
+ if _splitDwarfFlag in env['CFLAGS']:
+ suffixes.extend(_CSuffixes)
+ if _splitDwarfFlag in env['CXXFLAGS']:
+ suffixes.extend(_CXXSuffixes)
+
+ for object_builder in SCons.Tool.createObjBuilders(env):
+ emitterdict = object_builder.builder.emitter
+ for suffix in emitterdict.iterkeys():
+ if not suffix in suffixes:
+ continue
+ base = emitterdict[suffix]
+ emitterdict[suffix] = SCons.Builder.ListEmitter([
+ base,
+ _dwo_emitter,
+ ])
+
+def exists(env):
+ return any(_splitDwarfFlag in env[f] for f in ['CCFLAGS', 'CFLAGS', 'CXXFLAGS'])