diff options
| author | Daniel Moody <daniel.moody@mongodb.com> | 2022-08-05 00:24:49 -0500 |
|---|---|---|
| committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-08-10 05:34:54 +0000 |
| commit | 2a470e69477e119cf7cb855b13f2aed01ae22b2e (patch) | |
| tree | a19f850e5883460c59871f3d68f306de7e2c16c2 /site_scons | |
| parent | 10e65755f6a20afdedab57736d1b1648232a6194 (diff) | |
| download | mongo-2a470e69477e119cf7cb855b13f2aed01ae22b2e.tar.gz | |
SERVER-68474 added dwp files for split dwarf builds
Diffstat (limited to 'site_scons')
| -rw-r--r-- | site_scons/site_tools/auto_archive.py | 53 | ||||
| -rw-r--r-- | site_scons/site_tools/mongo_test_execution.py | 10 | ||||
| -rw-r--r-- | site_scons/site_tools/separate_debug.py | 15 | ||||
| -rw-r--r-- | site_scons/site_tools/split_dwarf.py | 72 |
4 files changed, 111 insertions, 39 deletions
diff --git a/site_scons/site_tools/auto_archive.py b/site_scons/site_tools/auto_archive.py index 91cd0c282c7..d7dc6dfd5fb 100644 --- a/site_scons/site_tools/auto_archive.py +++ b/site_scons/site_tools/auto_archive.py @@ -47,7 +47,11 @@ if __name__ == "__main__": archive_type = sys.argv[1] archive_name = sys.argv[2] root_dir = sys.argv[3] - files = sys.argv[4:] + file_list = sys.argv[4] + + files = [] + with open(file_list) as f: + files = f.read().splitlines() if archive_type not in ("zip", "tar"): print("unsupported archive_type", archive_type) @@ -200,25 +204,26 @@ def archive_builder(source, target, env, for_signature): make_archive_script = source[0] tar_cmd = env.WhereIs("tar") if archive_type == "tar" and tar_cmd: - command_prefix = "{tar} -C {common_ancestor} -czf {archive_name}" + command_prefix = "{tar} -C {common_ancestor} -T {file_list} -czf {archive_name}" else: - command_prefix = "{python} {make_archive_script} {archive_type} {archive_name} {common_ancestor}" + command_prefix = "{python} {make_archive_script} {archive_type} {archive_name} {common_ancestor} {file_list}" archive_name = env.File(target[0]) - command_prefix = command_prefix.format( + command_sig = command_prefix.format( tar=tar_cmd, python=sys.executable, archive_type=archive_type, archive_name=archive_name, make_archive_script=make_archive_script, common_ancestor=common_ancestor, + file_list='', ) # If we are just being invoked for our signature, we can omit the indirect dependencies # found by expanding the transitive dependencies, since we really only have a hard dependency # on our direct dependencies. if for_signature: - return command_prefix + return command_sig component = env["AIB_COMPONENT"] role = env["AIB_ROLE"] @@ -237,25 +242,40 @@ def archive_builder(source, target, env, for_signature): if not transitive_files: return [] - # The env["ESCAPE"] function is used by scons to make arguments - # valid for the platform that we're running on. For instance it - # will properly quote paths that have spaces in them on Posix - # platforms and handle \ / on Windows. - escape_func = env.get("ESCAPE", lambda x: x) - # TODO: relpath is costly, and we do it for every file in the archive here. # We should find a way to avoid the repeated relpath invocation, probably by # bucketing by directory. relative_files = [ - escape_func(os.path.relpath(file.get_abspath(), common_ancestor.get_abspath())) + os.path.relpath(file.get_abspath(), common_ancestor.get_abspath()) for file in transitive_files ] - return "{prefix} {files}".format( - prefix=command_prefix, - files=" ".join(relative_files), + # This is not great for ninja, essentially we are doing realtime operations here, which is + # not terrible for scons CommandActionGenerators, because the generation happens right before + # executing the command. However, this means for ninja that the realtime things happen during + # ninja generation, and are far removed from ninja execution. Even if we split this into a + # separate action for ninja's sake, there would still be issues because the reason to make + # such a filelist is to prevent creating command lines which are too long, and actions must + # be converted to command lines for ninja. When the ninja tool is able to process scons + # callbacks in order and not via aggregation then this could be moved to a simple Textfile call. + file_list = str(target[0].abspath) + ".filelist" + os.makedirs(os.path.dirname(file_list), exist_ok=True) + with open(file_list, 'w') as f: + for file in relative_files: + f.write(file + '\n') + + cmd = command_prefix.format( + tar=tar_cmd, + python=sys.executable, + archive_type=archive_type, + archive_name=archive_name, + make_archive_script=make_archive_script, + common_ancestor=common_ancestor, + file_list=file_list, ) + return cmd + def exists(env): return True @@ -268,7 +288,8 @@ def generate(env): bld = SCons.Builder.Builder( action=SCons.Action.CommandGeneratorAction( archive_builder, - {"cmdstr": "Building package ${TARGETS[0]} from ${SOURCES[1:]}"}, + {"cmdstr": "Building package ${TARGETS[0]} from ${SOURCES[1:]}"} + if not env.Verbose() else {"cmdstr": ""}, )) env.Append(BUILDERS={"AutoArchive": bld}) env["AUTO_ARCHIVE_TARBALL_SUFFIX"] = env.get( diff --git a/site_scons/site_tools/mongo_test_execution.py b/site_scons/site_tools/mongo_test_execution.py index 5c233ef97d0..ba4821dfcff 100644 --- a/site_scons/site_tools/mongo_test_execution.py +++ b/site_scons/site_tools/mongo_test_execution.py @@ -24,6 +24,8 @@ import os import SCons +from SCons.Node.Alias import default_ans + import auto_install_binaries _proof_scanner_cache_key = "proof_scanner_cache" @@ -104,12 +106,12 @@ def generate_test_execution_aliases(env, test): if target_name == source_name: continue - alias = env.Alias(f'+{source_name}', verbose_source_command) - if len(alias[0].children()) > 1: + if default_ans.lookup(f'+{source_name}') is not None: raise SCons.Errors.BuildError( - alias[0].children()[0], - f"Multiple unit test programs contain a source file named '{source_name}' which would result in an ambiguous test execution alias. Unit test source filenames are required to be globally unique." + str(verbose_source_command[0]), + f"There exists multiple unittests with a source file named {source_name}: {source.abspath} and {env.Alias(f'+{source_name}')[0].children()[1].abspath}" ) + env.Alias(f'+{source_name}', [verbose_source_command, source]) proof_generator_command = test_env.Command( target=[ diff --git a/site_scons/site_tools/separate_debug.py b/site_scons/site_tools/separate_debug.py index 08c78f4ef32..d69a0bc5298 100644 --- a/site_scons/site_tools/separate_debug.py +++ b/site_scons/site_tools/separate_debug.py @@ -59,7 +59,7 @@ def _update_builder(env, builder): if env.TargetOSIs("darwin"): base_action.list.extend([ SCons.Action.Action( - "$DSYMUTIL -num-threads 1 $TARGET -o ${TARGET}.dSYM", + "$DSYMUTIL -num-threads 1 $TARGET -o ${TARGET}$SEPDBG_SUFFIX", "$DSYMUTILCOMSTR", ), SCons.Action.Action( @@ -70,11 +70,11 @@ def _update_builder(env, builder): elif env.TargetOSIs("posix"): base_action.list.extend([ SCons.Action.Action( - "$OBJCOPY --only-keep-debug $TARGET ${TARGET}.debug", + "$OBJCOPY --only-keep-debug $TARGET ${TARGET}$SEPDBG_SUFFIX", "$OBJCOPY_ONLY_KEEP_DEBUG_COMSTR", ), SCons.Action.Action( - "$OBJCOPY --strip-debug --add-gnu-debuglink ${TARGET}.debug ${TARGET}", + "$OBJCOPY --strip-debug --add-gnu-debuglink ${TARGET}$SEPDBG_SUFFIX ${TARGET}", "$DEBUGSTRIPCOMSTR", ), ]) @@ -118,7 +118,7 @@ def _update_builder(env, builder): debug_files.extend([plist_file, dwarf_file]) elif env.TargetOSIs("posix"): - debug_file = env.File(str(target[0]) + ".debug") + debug_file = env.File(f"{target[0]}$SEPDBG_SUFFIX") debug_files.append(debug_file) elif env.TargetOSIs("windows"): debug_file = env.File(env.subst("${PDB}", target=target)) @@ -154,6 +154,8 @@ def generate(env): if env.TargetOSIs("darwin"): + env['SEPDBG_SUFFIX'] = '.dSYM' + if env.get("DSYMUTIL", None) is None: env["DSYMUTIL"] = env.WhereIs("dsymutil") @@ -167,15 +169,16 @@ def generate(env): ) elif env.TargetOSIs("posix"): + env['SEPDBG_SUFFIX'] = env.get('SEPDBG_SUFFIX', '.debug') if env.get("OBJCOPY", None) is None: env["OBJCOPY"] = env.Whereis("objcopy") if not env.Verbose(): env.Append( OBJCOPY_ONLY_KEEP_DEBUG_COMSTR= - "Generating debug info for $TARGET into ${TARGET}.dSYM", + "Generating debug info for $TARGET into ${TARGET}${SEPDBG_SUFFIX}", DEBUGSTRIPCOMSTR= - "Stripping debug info from ${TARGET} and adding .gnu.debuglink to ${TARGET}.debug", + "Stripping debug info from ${TARGET} and adding .gnu.debuglink to ${TARGET}${SEPDBG_SUFFIX}", ) for builder in ["Program", "SharedLibrary", "LoadableModule"]: diff --git a/site_scons/site_tools/split_dwarf.py b/site_scons/site_tools/split_dwarf.py index 72316dfb968..0892d069bfe 100644 --- a/site_scons/site_tools/split_dwarf.py +++ b/site_scons/site_tools/split_dwarf.py @@ -20,6 +20,8 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # +import os + import SCons _splitDwarfFlag = "-gsplit-dwarf" @@ -41,29 +43,60 @@ def _dwo_emitter(target, source, env): 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") + dwotarget = (t.builder.target_factory or env.File)(base + env['DWOSUFFIX']) new_targets.append(dwotarget) targets = target + new_targets return (targets, source) +def _dwp_emitter(target, source, env): + if "conftest" not in str(target[0]) and env.get('SPLIT_DWARF_DWP_FILES'): + + # Check if the information regarding where the dwo files is located are stored in + # the binary or a separate debug file. + if len(target) > 1 and os.path.splitext(str(target[1]))[1] == env.get('SEPDBG_SUFFIX'): + target_file = target[1] + else: + target_file = target[0] + + dwp_file = env.DWP( + target=env.File(os.path.splitext(target_file.name)[0] + env['DWPSUFFIX']), + source=target_file, + ) + env.NoCache(dwp_file) + + if hasattr(env, "AutoInstall") and env.get("AIB_COMPONENT"): + env.AutoInstall( + "$PREFIX_BINDIR", + dwp_file, + AIB_COMPONENT=env.get("AIB_COMPONENT"), + AIB_ROLE="debug", + AIB_EXTRA_COMPONENTS=env.get("AIB_EXTRA_COMPONENTS", []), + ) + + return target, source + + +def options(opts): + opts.AddVariables( + ('DWP', "Path to dwp binary."), + ("SPLIT_DWARF_DWP_FILES", "Set to enable DWP file creation from split dwarf."), + ) + + 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) + + # these suffixes are not adjustable to the underlying tools (gcc) + # but we leave them adjustable in scons in case this changes in certain circumstances + env['DWOSUFFIX'] = env.get('DWOSUFFIX', '.dwo') + env['DWPSUFFIX'] = env.get('DWPSUFFIX', '.dwp') + + env.Append(CCFLAGS=[_splitDwarfFlag]) for object_builder in SCons.Tool.createObjBuilders(env): emitterdict = object_builder.builder.emitter for suffix in emitterdict.keys(): - if not suffix in suffixes: + if not suffix in _CSuffixes + _CXXSuffixes: continue base = emitterdict[suffix] emitterdict[suffix] = SCons.Builder.ListEmitter([ @@ -71,6 +104,19 @@ def generate(env): _dwo_emitter, ]) + for builder in ["Program"]: + builder = env["BUILDERS"][builder] + base_emitter = builder.emitter + new_emitter = SCons.Builder.ListEmitter([base_emitter, _dwp_emitter]) + builder.emitter = new_emitter + + env['DWP'] = env.get('DWP', 'dwp') + env['BUILDERS']['DWP'] = SCons.Builder.Builder( + action=SCons.Action.Action( + "$DWP -e $SOURCE -o $TARGET", + "Building dwp file from $SOURCE" if not env.Verbose() else "", + )) + def exists(env): return any(_splitDwarfFlag in env[f] for f in ["CCFLAGS", "CFLAGS", "CXXFLAGS"]) |
