diff options
author | William Deegan <bill@baddogconsulting.com> | 2022-08-13 16:20:49 -0700 |
---|---|---|
committer | William Deegan <bill@baddogconsulting.com> | 2022-08-13 16:20:49 -0700 |
commit | 0d7d394d98ec72dc34496bce0d7824806a79f35d (patch) | |
tree | 84ce743e00b8be14f8a3cd91c869f9f90de8c306 /SCons/Script | |
parent | c7deb78684a518c59ed05c40bef266e9d27a9957 (diff) | |
download | scons-git-0d7d394d98ec72dc34496bce0d7824806a79f35d.tar.gz |
Add ValidateOption() API which validates that all command line options are either SCons specified or specifie by AddOption calls. It will error out if there are any unknown options. Resolves Issue #4187
Diffstat (limited to 'SCons/Script')
-rw-r--r-- | SCons/Script/Main.py | 11 | ||||
-rw-r--r-- | SCons/Script/Main.xml | 20 | ||||
-rw-r--r-- | SCons/Script/SConscript.py | 1 | ||||
-rw-r--r-- | SCons/Script/__init__.py | 1 |
4 files changed, 33 insertions, 0 deletions
diff --git a/SCons/Script/Main.py b/SCons/Script/Main.py index ab2dc0e04..850ca71ff 100644 --- a/SCons/Script/Main.py +++ b/SCons/Script/Main.py @@ -492,6 +492,16 @@ def GetOption(name): def SetOption(name, value): return OptionsParser.values.set_option(name, value) +def ValidateOptions(): + """ + 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. + """ + OptionsParser.preserve_unknown_options = False + OptionsParser.parse_args(OptionsParser.largs, OptionsParser.values) + def PrintHelp(file=None): OptionsParser.print_help(file=file) @@ -1364,6 +1374,7 @@ def _exec_main(parser, values): else: _main(parser) + def main(): global OptionsParser global exit_status diff --git a/SCons/Script/Main.xml b/SCons/Script/Main.xml index f4f470507..746c1dcde 100644 --- a/SCons/Script/Main.xml +++ b/SCons/Script/Main.xml @@ -740,6 +740,7 @@ Multiple targets can be passed in to a single call to </para> </summary> </scons_function> + <scons_function name="SetOption"> <arguments> (name, value) @@ -943,6 +944,25 @@ Example: SetOption('max_drift', 0) </example_commands> </summary> + + </scons_function> + <scons_function name="ValidateOptions"> + <summary> + <para> + Check that all the options provided by the user on the command line are either defined by SCons itself + or + defined by &f-link-AddOption;. + </para> + <para> + If there are any command line options not defined. + Calling this function will cause SCons to issue an error message and then exit with and error exit + status. + </para> + <para> + This function should only be called after the last &f-link-AddOption; call in your &SConscript; logic. + </para> + </summary> + </scons_function> </sconsdoc> diff --git a/SCons/Script/SConscript.py b/SCons/Script/SConscript.py index 61881515e..548ef44d4 100644 --- a/SCons/Script/SConscript.py +++ b/SCons/Script/SConscript.py @@ -528,6 +528,7 @@ class SConsEnvironment(SCons.Environment.Base): name = self.subst(name) return SCons.Script.Main.GetOption(name) + def Help(self, text, append=False): text = self.subst(text, raw=1) SCons.Script.HelpFunction(text, append=append) diff --git a/SCons/Script/__init__.py b/SCons/Script/__init__.py index 40be95e70..aed31a574 100644 --- a/SCons/Script/__init__.py +++ b/SCons/Script/__init__.py @@ -107,6 +107,7 @@ AddOption = Main.AddOption PrintHelp = Main.PrintHelp GetOption = Main.GetOption SetOption = Main.SetOption +ValidateOptions = Main.ValidateOptions Progress = Main.Progress GetBuildFailures = Main.GetBuildFailures |