summaryrefslogtreecommitdiff
path: root/SConstruct
diff options
context:
space:
mode:
authorRichard Samuels <richard.l.samuels@gmail.com>2022-07-28 09:54:57 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-07-28 14:53:04 +0000
commite1c7b19f7e2379e43ae7837193f36a255d66e273 (patch)
tree57c0bddc370ddddbd20e56b8b106d13a95515113 /SConstruct
parent0ee599ffdf49064e2d29368810d7ee9eb9eee6a3 (diff)
downloadmongo-e1c7b19f7e2379e43ae7837193f36a255d66e273.tar.gz
SERVER-65901 scons.py silently ignores invalid variable-files parameter
Diffstat (limited to 'SConstruct')
-rwxr-xr-xSConstruct33
1 files changed, 33 insertions, 0 deletions
diff --git a/SConstruct b/SConstruct
index 7267eed814d..8caf9ea8d6d 100755
--- a/SConstruct
+++ b/SConstruct
@@ -19,6 +19,7 @@ from glob import glob
from pkg_resources import parse_version
import SCons
+import SCons.Script
# This must be first, even before EnsureSConsVersion, if
# we are to avoid bulk loading all tools in the DefaultEnvironment.
@@ -55,8 +56,18 @@ print('scons: running with args {}'.format(scons_invocation))
atexit.register(mongo.print_build_failures)
+# An extra instance of the SCons parser is used to manually validate options
+# flags. We use it detect some common misspellings/unknown options and
+# communicate with the user more effectively than just allowing Configure to
+# fail.
+# This is to work around issue #4187
+# (https://github.com/SCons/scons/issues/4187). Upon a future upgrade to SCons
+# that incorporates #4187, we should replace this solution with that.
+_parser = SCons.Script.SConsOptions.Parser("")
+
def add_option(name, **kwargs):
+ _parser.add_option('--' + name, **{"default": None, **kwargs})
if 'dest' not in kwargs:
kwargs['dest'] = name
@@ -1492,6 +1503,7 @@ if get_option('build-tools') == 'next':
env = Environment(variables=env_vars, **envDict)
del envDict
+env.AddMethod(lambda env, name, **kwargs: add_option(name, **kwargs), 'AddOption')
if get_option('build-metrics'):
env.Tool('build_metrics')
@@ -6024,6 +6036,27 @@ env.SConscript(
],
)
+# Critically, this approach is technically incorrect. While all MongoDB
+# SConscript files use our add_option wrapper, builtin tools can
+# access SCons's GetOption/AddOption methods directly, causing their options
+# to not be validated by this block.
+(_, leftover) = _parser.parse_args(sys.argv)
+# leftover contains unrecognized options, including environment variables,and
+# the argv[0]. If we only look at flags starting with --, and we skip the first
+# leftover value (argv[0]), anything that remains is an invalid option
+invalid_options = list(filter(lambda x: x.startswith("--"), leftover[1:]))
+if len(invalid_options) > 0:
+ # users frequently misspell "variables-files" (note two `s`s) as
+ # "variable-files" or "variables-file". Detect and help them out.
+ for opt in invalid_options:
+ bad_var_file_opts = ["--variable-file", "--variables-file", "--variable-files"]
+ if opt in bad_var_file_opts or any(
+ [opt.startswith(f"{bad_opt}=") for bad_opt in bad_var_file_opts]):
+ print(
+ f"WARNING: You supplied the invalid parameter '{opt}' to SCons. Did you mean --variables-files (both words plural)?"
+ )
+ fatal_error(None, f"ERROR: unknown options supplied to scons: {invalid_options}")
+
# Declare the cache prune target
cachePrune = env.Command(
target="#cache-prune",