diff options
author | Andrew Morrow <acm@mongodb.com> | 2020-04-09 12:28:12 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-04-17 17:46:01 +0000 |
commit | cfa89fbaf0b397f07d8f9c884a04776224b4e918 (patch) | |
tree | 356a708d1b92692cc6cd0f1a1434225488852f98 /site_scons | |
parent | 65c979794dc643c0b432be89de47bda7c8e7bd8c (diff) | |
download | mongo-cfa89fbaf0b397f07d8f9c884a04776224b4e918.tar.gz |
SERVER-46744 Install unit test debug info without increasing disk utilization
Diffstat (limited to 'site_scons')
-rw-r--r-- | site_scons/mongo/install_actions.py | 136 | ||||
-rw-r--r-- | site_scons/site_tools/auto_archive.py | 2 |
2 files changed, 137 insertions, 1 deletions
diff --git a/site_scons/mongo/install_actions.py b/site_scons/mongo/install_actions.py new file mode 100644 index 00000000000..c0eeac3a84e --- /dev/null +++ b/site_scons/mongo/install_actions.py @@ -0,0 +1,136 @@ +# -*- mode: python; -*- + +import os +import shutil +import stat + + + +def _copy(src, dst): + shutil.copy2(src, dst) + st = os.stat(src) + os.chmod(dst, stat.S_IMODE(st[stat.ST_MODE]) | stat.S_IWRITE) + +def _symlink(src, dst): + os.symlink(os.path.relpath(src, os.path.dirname(dst)), dst) + +def _hardlink(src, dst): + try: + os.link(src, dst) + except: + _copy(src, dst) + +available_actions = { + "copy" : _copy, + "hardlink" : _hardlink, + "symlink" : _symlink, +} + +class _CopytreeError(EnvironmentError): + pass + +def _generate_install_actions(base_action): + + # This is a patched version of shutil.copytree from python 2.5. It + # doesn't fail if the dir exists, which regular copytree does + # (annoyingly). Note the XXX comment in the docstring. + def _mongo_copytree(src, dst, symlinks=False): + """Recursively copy a directory tree using copy2(). + + The destination directory must not already exist. + If exception(s) occur, an _CopytreeError is raised with a list of reasons. + + If the optional symlinks flag is true, symbolic links in the + source tree result in symbolic links in the destination tree; if + it is false, the contents of the files pointed to by symbolic + links are copied. + + XXX Consider this example code rather than the ultimate tool. + + """ + names = os.listdir(src) + # garyo@genarts.com fix: check for dir before making dirs. + if not os.path.exists(dst): + os.makedirs(dst) + errors = [] + for name in names: + srcname = os.path.join(src, name) + dstname = os.path.join(dst, name) + try: + if symlinks and os.path.islink(srcname): + linkto = os.readlink(srcname) + os.symlink(linkto, dstname) + elif os.path.isdir(srcname): + _mongo_copytree(srcname, dstname, symlinks) + else: + base_action(srcname, dstname) + # XXX What about devices, sockets etc.? + except (IOError, os.error) as why: + errors.append((srcname, dstname, str(why))) + # catch the _CopytreeError from the recursive copytree so that we can + # continue with other files + except _CopytreeError as err: + errors.extend(err.args[0]) + try: + shutil.copystat(src, dst) + except SCons.Util.WinError: + # can't copy file access times on Windows + pass + except OSError as why: + errors.extend((src, dst, str(why))) + if errors: + raise _CopytreeError(errors) + + + # + # Functions doing the actual work of the Install Builder. + # + def _mongo_copyFunc(dest, source, env): + """Install a source file or directory into a destination by copying, + (including copying permission/mode bits).""" + + if os.path.isdir(source): + if os.path.exists(dest): + if not os.path.isdir(dest): + raise SCons.Errors.UserError("cannot overwrite non-directory `%s' with a directory `%s'" % (str(dest), str(source))) + else: + parent = os.path.split(dest)[0] + if not os.path.exists(parent): + os.makedirs(parent) + _mongo_copytree(source, dest) + else: + base_action(source, dest) + + return 0 + + # + # Functions doing the actual work of the InstallVersionedLib Builder. + # + def _mongo_copyFuncVersionedLib(dest, source, env): + """Install a versioned library into a destination by copying, + (including copying permission/mode bits) and then creating + required symlinks.""" + + if os.path.isdir(source): + raise SCons.Errors.UserError("cannot install directory `%s' as a version library" % str(source) ) + else: + # remove the link if it is already there + try: + os.remove(dest) + except: + pass + base_action(source, dest) + SCons.tool.install.installShlibLinks(dest, source, env) + + return 0 + + return (_mongo_copyFunc, _mongo_copyFuncVersionedLib) + + +def setup(env, action): + if action == "default": + return + base_action = available_actions.get(action, None) + handlers = _generate_install_actions(base_action) + env['INSTALL'] = handlers[0] + env['INSTALLVERSIONEDLIB'] = handlers[1] diff --git a/site_scons/site_tools/auto_archive.py b/site_scons/site_tools/auto_archive.py index ff0f5dbee11..fba09f54ae4 100644 --- a/site_scons/site_tools/auto_archive.py +++ b/site_scons/site_tools/auto_archive.py @@ -136,7 +136,7 @@ def auto_archive_gen(first_env, make_archive_script, pkg_fmt): pkg_suffix = "$AUTO_ARCHIVE_TARBALL_SUFFIX" archive = env.AutoArchive( - target="#{}.{}".format(pkg_name, pkg_suffix), + target="$PKGDIR/{}.{}".format(pkg_name, pkg_suffix), source=[make_archive_script] + env.Alias(install_alias), __AUTO_ARCHIVE_TYPE=pkg_fmt, AIB_COMPONENT=component, |