Skip to content

Commit

Permalink
SERVER-45785 Simplify implementation of DESTDIR
Browse files Browse the repository at this point in the history
Also:

- Correctly honor default targets in hygienic mode.
- Fix a latent variable reuse bug in auto_install_pseudobuilder
  • Loading branch information
acmorrow authored and Evergreen Agent committed Apr 27, 2020
1 parent 0f69c4c commit 404e44c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 59 deletions.
9 changes: 7 additions & 2 deletions SConstruct
Expand Up @@ -3884,7 +3884,6 @@ if get_option('ninja') != 'disabled':
else:
ninja_builder = Tool("ninja_next")
ninja_builder.generate(env)
env.Default(env.Alias("install-all-meta"))

# idlc.py has the ability to print it's implicit dependencies
# while generating, Ninja can consume these prints using the
Expand Down Expand Up @@ -4161,6 +4160,9 @@ if get_option('install-mode') == 'hygienic':
"-Wl,-install_name,@rpath/${TARGET.file}",
],
)

env.Default(env.Alias("install-default"))

elif get_option('separate-debug') == "on":
env.FatalError('Cannot use --separate-debug without --install-mode=hygienic')

Expand Down Expand Up @@ -4504,7 +4506,10 @@ if has_option("cache"):
addNoCacheEmitter(env['BUILDERS']['LoadableModule'])


resmoke_install_dir = env.subst("$PREFIX_BINDIR") if get_option("install-mode") == "hygienic" else env.Dir("#").abspath
# We need to be explicit about including $DESTDIR here, unlike most
# other places. Normally, auto_install_binaries will take care of
# injecting DESTDIR for us, but we aren't using that now.
resmoke_install_dir = env.subst("$DESTDIR/$PREFIX_BINDIR") if get_option("install-mode") == "hygienic" else env.Dir("#").abspath
resmoke_install_dir = os.path.normpath(resmoke_install_dir).replace("\\", r"\\")

# Much blood sweat and tears were shed getting to this point. Any version of
Expand Down
16 changes: 4 additions & 12 deletions site_scons/site_tools/auto_archive.py
Expand Up @@ -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,
Expand Down Expand Up @@ -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
]

Expand Down
60 changes: 17 additions & 43 deletions site_scons/site_tools/auto_install_binaries.py
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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, [])

Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions src/mongo/SConscript
Expand Up @@ -779,7 +779,7 @@ if not hygienic:
distsrc = env.Dir('#distsrc')
if hygienic:
env.AutoInstall(
target='$DESTDIR',
target='$PREFIX',
source=[
distsrc.File('README'),
# TODO: we need figure out what to do when we use a different
Expand Down Expand Up @@ -811,7 +811,7 @@ if not len(module_banner_filenames) == len(env['MODULE_BANNERS']):

if hygienic:
env.AutoInstall(
target='$DESTDIR',
target='$PREFIX',
source=env.get('MODULE_BANNERS', []),
AIB_COMPONENT='common',
AIB_COMPONENTS_EXTRA=['dist', 'dist-test'],
Expand Down

0 comments on commit 404e44c

Please sign in to comment.