diff options
author | Richard Samuels <richard.l.samuels@gmail.com> | 2022-04-21 13:19:59 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-04-21 13:45:41 +0000 |
commit | f517542b0aff150da32a795b5d9dc6a7fb0f54b9 (patch) | |
tree | 68aa48d9c1451fa2e67d388a76b24926f4f84c71 /src | |
parent | d001194fb86b590f73a7171c7cb6a317a93a2300 (diff) | |
download | mongo-f517542b0aff150da32a795b5d9dc6a7fb0f54b9.tar.gz |
SERVER-62992 Remove need for resmoke.ini (v5.0)
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/SConscript | 1 | ||||
-rw-r--r-- | src/mongo/resmoke/SConscript | 28 | ||||
-rw-r--r-- | src/mongo/resmoke/resmoke.py.in | 55 |
3 files changed, 84 insertions, 0 deletions
diff --git a/src/mongo/SConscript b/src/mongo/SConscript index 0714eba23ac..b1bf7f777ba 100644 --- a/src/mongo/SConscript +++ b/src/mongo/SConscript @@ -62,6 +62,7 @@ env.SConscript( 'installer', 'logv2', 'platform', + 'resmoke', 'rpc', 's', 'scripting', diff --git a/src/mongo/resmoke/SConscript b/src/mongo/resmoke/SConscript new file mode 100644 index 00000000000..fb80ab1a713 --- /dev/null +++ b/src/mongo/resmoke/SConscript @@ -0,0 +1,28 @@ +# -*- mode: python -*- +import os +import SCons +Import('env') + +env = env.Clone() + +install_dir = env.Dir('$DESTDIR/$PREFIX_BINDIR').path.replace("\\", r"\\") +resmoke_py = env.Substfile( + target="resmoke.py", + source='resmoke.py.in', + SUBST_DICT = { + '@install_dir@': install_dir, + } +) +resmoke_py_install = env.AutoInstall( + '$PREFIX_BINDIR', + source=resmoke_py, + AIB_COMPONENT='common', + AIB_ROLE='runtime', +) +# TODO SERVER-61013: We shouldn't have to setattr this once AutoInstall is a +# real builder +setattr(resmoke_py_install[0].attributes, 'AIB_NO_ARCHIVE', True) +env.AddPostAction( + resmoke_py_install, + action=SCons.Defaults.Chmod('$TARGET', "u+x"), +) diff --git a/src/mongo/resmoke/resmoke.py.in b/src/mongo/resmoke/resmoke.py.in new file mode 100644 index 00000000000..8b5d4106480 --- /dev/null +++ b/src/mongo/resmoke/resmoke.py.in @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 +import importlib.util +import os +import os.path +import argparse +import sys +import shlex +import textwrap + +BUILD_BIN_DIR=r"@install_dir@" + +class _SilentArgumentParser(argparse.ArgumentParser): + """ArgumentParser variant that silently swallows errors.""" + def error(self, message): + pass + +# We do not want people to use this wrapper and provide --installDir, +# especially if the user tries to supply the wrong installDir. Prevent that +# by parsing the command line flags and make sure that --installDir is not +# passed in. (only the run command supports this flag) +try: + parser = _SilentArgumentParser(add_help=False) + + subparsers = parser.add_subparsers(dest="cmd") + run = subparsers.add_parser("run") + run.add_argument("--installDir") + args, _ = parser.parse_known_args() + if "installDir" in args and args.installDir is not None: + err = textwrap.dedent(f"""\ +Argument '--installDir' passed to resmoke wrapper script, but this action can +have unforeseen consequences. Either remove --installDir, or call resmoke as +`buildscripts/resmoke.py run --installDir={shlex.quote(args.installDir)}`""") + raise RuntimeError(err) + + run_cmd_called = args.cmd == "run" +except RuntimeError: + raise +except: + run_cmd_called = False + +# If the run subcommand is being used, inject installDir +if run_cmd_called: + i = sys.argv.index("run") + sys.argv.insert(i+1, "--installDir") + sys.argv.insert(i+2, BUILD_BIN_DIR) + +path_to_resmoke_py = os.path.join("buildscripts", "resmoke.py") + +# import and run the cli +spec = importlib.util.spec_from_file_location("__main__", path_to_resmoke_py) +resmoke = importlib.util.module_from_spec(spec) +resmoke.__package__ = None +spec.loader.exec_module(resmoke) + +# -*- mode: python -*- |