summaryrefslogtreecommitdiffstats
path: root/SCons/Script/Main.py
diff options
context:
space:
mode:
Diffstat (limited to 'SCons/Script/Main.py')
-rw-r--r--SCons/Script/Main.py40
1 files changed, 25 insertions, 15 deletions
diff --git a/SCons/Script/Main.py b/SCons/Script/Main.py
index ab2dc0e..b902842 100644
--- a/SCons/Script/Main.py
+++ b/SCons/Script/Main.py
@@ -52,7 +52,7 @@ import SCons.Debug
import SCons.Defaults
import SCons.Environment
import SCons.Errors
-import SCons.Job
+import SCons.Taskmaster.Job
import SCons.Node
import SCons.Node.FS
import SCons.Platform
@@ -492,6 +492,26 @@ def GetOption(name):
def SetOption(name, value):
return OptionsParser.values.set_option(name, value)
+
+def ValidateOptions(throw_exception=False) -> None:
+ """Validate options passed to SCons on the command line.
+
+ If you call this after you set all your command line options with AddOption(),
+ it will verify that all command line options are valid.
+ So if you added an option --xyz and you call SCons with --xyy you can cause
+ SCons to issue an error message and exit by calling this function.
+
+ :param bool throw_exception: (Optional) Should this function raise an error if there's an invalid option on the command line, or issue a message and exit with error status.
+
+ :raises SConsBadOptionError: If throw_exception is True and there are invalid options on command line.
+
+ .. versionadded:: 4.4.1
+ """
+
+ OptionsParser.raise_exception_on_error = throw_exception
+ OptionsParser.preserve_unknown_options = False
+ OptionsParser.parse_args(OptionsParser.largs, OptionsParser.values)
+
def PrintHelp(file=None):
OptionsParser.print_help(file=file)
@@ -1114,7 +1134,7 @@ def _main(parser):
SCons.Node.FS.set_duplicate(options.duplicate)
fs.set_max_drift(options.max_drift)
- SCons.Job.explicit_stack_size = options.stack_size
+ SCons.Taskmaster.Job.explicit_stack_size = options.stack_size
# Hash format and chunksize are set late to support SetOption being called
# in a SConscript or SConstruct file.
@@ -1271,23 +1291,12 @@ def _build_targets(fs, options, targets, target_top):
"""Leave the order of dependencies alone."""
return dependencies
- def tmtrace_cleanup(tfile):
- tfile.close()
-
- if options.taskmastertrace_file == '-':
- tmtrace = sys.stdout
- elif options.taskmastertrace_file:
- tmtrace = open(options.taskmastertrace_file, 'w')
- atexit.register(tmtrace_cleanup, tmtrace)
- else:
- tmtrace = None
- taskmaster = SCons.Taskmaster.Taskmaster(nodes, task_class, order, tmtrace)
+ taskmaster = SCons.Taskmaster.Taskmaster(nodes, task_class, order, options.taskmastertrace_file)
# Let the BuildTask objects get at the options to respond to the
# various print_* settings, tree_printer list, etc.
BuildTask.options = options
-
is_pypy = platform.python_implementation() == 'PyPy'
# As of 3.7, python removed support for threadless platforms.
# See https://www.python.org/dev/peps/pep-0011/
@@ -1301,7 +1310,7 @@ def _build_targets(fs, options, targets, target_top):
# to check if python configured with threads.
global num_jobs
num_jobs = options.num_jobs
- jobs = SCons.Job.Jobs(num_jobs, taskmaster)
+ jobs = SCons.Taskmaster.Job.Jobs(num_jobs, taskmaster)
if num_jobs > 1:
msg = None
if jobs.num_jobs == 1 or not python_has_threads:
@@ -1364,6 +1373,7 @@ def _exec_main(parser, values):
else:
_main(parser)
+
def main():
global OptionsParser
global exit_status