summaryrefslogtreecommitdiff
path: root/src/mongo/resmoke
diff options
context:
space:
mode:
authorRichard Samuels <richard.l.samuels@gmail.com>2022-03-30 13:20:48 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-03-30 14:08:19 +0000
commitd4206bdeb19f4c5862280c04cd6b831c9ec03a40 (patch)
treecac56a77ed5ba54eb5ec167bd5c7cef5ee73f41d /src/mongo/resmoke
parent93243e0c29ba1f3eae4dc0251e775dc4f6a90c6c (diff)
downloadmongo-d4206bdeb19f4c5862280c04cd6b831c9ec03a40.tar.gz
SERVER-62992 Remove need for resmoke.ini
Diffstat (limited to 'src/mongo/resmoke')
-rw-r--r--src/mongo/resmoke/SConscript28
-rw-r--r--src/mongo/resmoke/resmoke.py.in55
2 files changed, 83 insertions, 0 deletions
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 -*-