diff options
author | Andrew Morrow <acm@mongodb.com> | 2020-04-24 11:33:22 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-04-29 13:17:45 +0000 |
commit | ef57b6e4aff21564bebdc6dcd38983eebbb3f8fe (patch) | |
tree | 5dc3ea6f2cdc634cab745e6b04fe36ce30428ea7 /site_scons | |
parent | e350287d6bf433c509884916ff5ca998efebaced (diff) | |
download | mongo-ef57b6e4aff21564bebdc6dcd38983eebbb3f8fe.tar.gz |
SERVER-45785 Simplify implementation of DESTDIR
Also:
- Correctly honor default targets in hygienic mode.
- Fix a latent variable reuse bug in auto_install_pseudobuilder
(cherry picked from commit 404e44ce81b762db8ceee31df8e5b344f717e6a5)
Diffstat (limited to 'site_scons')
-rw-r--r-- | site_scons/site_tools/auto_archive.py | 16 | ||||
-rw-r--r-- | site_scons/site_tools/auto_install_binaries.py | 60 |
2 files changed, 21 insertions, 55 deletions
diff --git a/site_scons/site_tools/auto_archive.py b/site_scons/site_tools/auto_archive.py index fba09f54ae4..37cafc42148 100644 --- a/site_scons/site_tools/auto_archive.py +++ b/site_scons/site_tools/auto_archive.py @@ -166,25 +166,17 @@ def archive_builder(source, target, env, for_signature): # # We pass the common_ancestor to tar via -C so that $PREFIX is # preserved in the tarball. - dest_dir_elems = env.Dir("$DESTDIR").get_abspath() - prefix_elems = env.subst("$PREFIX") - - # In python slicing a string with [:-0] gives an empty string. So - # make sure we have a prefix to slice off before trying it. - if prefix_elems: - common_ancestor = dest_dir_elems[: -len(prefix_elems)] - else: - common_ancestor = dest_dir_elems + common_ancestor = env.Dir("$DESTDIR") archive_type = env["__AUTO_ARCHIVE_TYPE"] - make_archive_script = source[0].get_abspath() + 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}" else: command_prefix = "{python} {make_archive_script} {archive_type} {archive_name} {common_ancestor}" - archive_name = env.File(target[0]).get_abspath() + archive_name = env.File(target[0]) command_prefix = command_prefix.format( tar=tar_cmd, python=sys.executable, @@ -231,7 +223,7 @@ def archive_builder(source, target, env, for_signature): # 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)) + escape_func(os.path.relpath(file.get_abspath(), common_ancestor.get_abspath())) for file in transitive_files ] diff --git a/site_scons/site_tools/auto_install_binaries.py b/site_scons/site_tools/auto_install_binaries.py index cbe2c553a17..a3e7290c0a1 100644 --- a/site_scons/site_tools/auto_install_binaries.py +++ b/site_scons/site_tools/auto_install_binaries.py @@ -360,7 +360,10 @@ def auto_install_pseudobuilder(env, target, source, **kwargs): installed_files = [] for s in source: - if not target: + + target_for_source = target + + if not target_for_source: # AIB currently uses file suffixes to do mapping. However, sometimes we need # to do the mapping based on a different suffix. This is used for things like @@ -377,6 +380,8 @@ def auto_install_pseudobuilder(env, target, source, **kwargs): "No target provided and no auto install mapping found for:", str(s) ) + target_for_source = auto_install_mapping.directory + # We've already auto installed this file and it may have belonged to a # different role since it wouldn't get retagged above. So we just skip # this files since SCons will already wire the dependency since s is a @@ -389,12 +394,13 @@ def auto_install_pseudobuilder(env, target, source, **kwargs): # We must do an early subst here so that the _aib_debugdir # generator has a chance to run while seeing 'source'. - target = env.Dir(env.subst(target, source=s)) + target_for_source = env.Dir(env.subst('$DESTDIR/$TARGET', target=target_for_source, source=s)) + aib_additional_directory = getattr(s.attributes, "aib_additional_directory", None) if aib_additional_directory is not None: - target = env.Dir(aib_additional_directory, directory=target) + target_for_source = env.Dir(aib_additional_directory, directory=target_for_source) - new_installed_files = env.Install(target=target, source=s) + new_installed_files = env.Install(target=target_for_source, source=s) setattr(s.attributes, INSTALLED_FILES, new_installed_files) installed_files.extend(new_installed_files) @@ -499,44 +505,11 @@ def add_suffix_mapping(env, suffix, role=None): env[SUFFIX_MAP].update({env.subst(key): value for key, value in suffix.items()}) -def suffix_mapping(env, directory=False, default_role=False): +def suffix_mapping(env, directory="", default_role=False): """Generate a SuffixMap object from source and target.""" return SuffixMap(directory=directory, default_role=default_role) -def dest_dir_generator(initial_value=None): - """Memoized dest_dir_generator""" - dd = (None, None) - - def generator(source, target, env, for_signature): - nonlocal dd - - # SCons does not perform substitution for "sub" Dir calls on a - # Dir Node. Additionally we need to determine if it's an - # absolute path here because if it is the sub Dir call will - # not expand correctly. - prefix = env.subst("$PREFIX") - if prefix and prefix[0] == "/": - prefix = prefix[1:] - - if dd[1] is not None and dd[0] == prefix: - return dd[1] - - if initial_value is None: - dest_dir = env.Dir("#install") - elif isinstance(initial_value, str): - dest_dir = env.Dir(initial_value) - elif isinstance(initial_value, SCons.Node.FS.Dir): - dest_dir = initial_value - else: - raise Exception("initial DESTDIR value must be string or Dir") - - dd = (prefix, dest_dir.Dir(prefix)) - return dd[1] - - return generator - - def get_auto_installed_files(env, node): return getattr(node.attributes, INSTALLED_FILES, []) @@ -585,12 +558,13 @@ def generate(env): # pylint: disable=too-many-statements # Matches the autoconf documentation: # https://www.gnu.org/prep/standards/html_node/Directory-Variables.html - env["DESTDIR"] = dest_dir_generator(env.get("DESTDIR", None)) - env["PREFIX_BINDIR"] = env.get("PREFIX_BINDIR", "$DESTDIR/bin") - env["PREFIX_LIBDIR"] = env.get("PREFIX_LIBDIR", "$DESTDIR/lib") - env["PREFIX_SHAREDIR"] = env.get("PREFIX_SHAREDIR", "$DESTDIR/share") + env["DESTDIR"] = env.Dir(env.get("DESTDIR", "#install")) + env["PREFIX"] = env.get("PREFIX", ".") + env["PREFIX_BINDIR"] = env.get("PREFIX_BINDIR", "$PREFIX/bin") + env["PREFIX_LIBDIR"] = env.get("PREFIX_LIBDIR", "$PREFIX/lib") + env["PREFIX_SHAREDIR"] = env.get("PREFIX_SHAREDIR", "$PREFIX/share") env["PREFIX_DOCDIR"] = env.get("PREFIX_DOCDIR", "$PREFIX_SHAREDIR/doc") - env["PREFIX_INCLUDEDIR"] = env.get("PREFIX_INCLUDEDIR", "$DESTDIR/include") + env["PREFIX_INCLUDEDIR"] = env.get("PREFIX_INCLUDEDIR", "$PREFIX/include") env[SUFFIX_MAP] = {} env[ALIAS_MAP] = defaultdict(dict) |