diff options
author | William Deegan <bill@baddogconsulting.com> | 2021-04-12 00:31:45 (GMT) |
---|---|---|
committer | William Deegan <bill@baddogconsulting.com> | 2021-04-12 00:31:45 (GMT) |
commit | 1b6f61fc02e796fa754b728b797b1c1f6a360f03 (patch) | |
tree | c008d75d32d9c360f3c637cf6a349c9a5508237f | |
parent | cef62d1719abb82f32a50d0c51aed03ca7f5cce0 (diff) | |
download | SCons-1b6f61fc02e796fa754b728b797b1c1f6a360f03.zip SCons-1b6f61fc02e796fa754b728b797b1c1f6a360f03.tar.gz SCons-1b6f61fc02e796fa754b728b797b1c1f6a360f03.tar.bz2 |
better handle all/none and multiple options, expanded tests to cover such
-rw-r--r-- | SCons/Script/SConsOptions.py | 33 | ||||
-rw-r--r-- | test/option/fixture/SConstruct__experimental | 7 | ||||
-rw-r--r-- | test/option/option--experimental.py | 16 |
3 files changed, 42 insertions, 14 deletions
diff --git a/SCons/Script/SConsOptions.py b/SCons/Script/SConsOptions.py index c61f910..4e56c68 100644 --- a/SCons/Script/SConsOptions.py +++ b/SCons/Script/SConsOptions.py @@ -39,7 +39,7 @@ SUPPRESS_HELP = optparse.SUPPRESS_HELP diskcheck_all = SCons.Node.FS.diskcheck_types() -experimental_options = ['all', 'none'] +experimental_features = {'warp_speed', 'transporter'} def diskcheck_convert(value): @@ -708,11 +708,36 @@ def Parser(version): action="store_true", help="Import certain virtualenv variables to SCons") + def experimental_callback(option, opt, value, parser): + experimental = getattr(parser.values, option.dest) + + if ',' in value: + value = value.split(',') + else: + value = [value, ] + + for v in value: + if v == 'none': + experimental = set() + elif v == 'all': + experimental = experimental_features + elif v not in experimental_features: + raise OptionValueError("option --experimental: invalid choice: '%s' (choose from 'all','none',%s)" % ( + v, ','.join(["'%s'" % e for e in sorted(experimental_features)]))) + else: + experimental |= {v} + + setattr(parser.values, option.dest, experimental) + + + op.add_option('--experimental', dest='experimental', - action='append', - default=[], - choices=experimental_options, + action='callback', + default={}, # empty set + type='str', + # choices=experimental_options+experimental_features, + callback =experimental_callback, help='Enable experimental features') op.add_option('-f', '--file', '--makefile', '--sconstruct', diff --git a/test/option/fixture/SConstruct__experimental b/test/option/fixture/SConstruct__experimental index aa5f4c3..2348b9a 100644 --- a/test/option/fixture/SConstruct__experimental +++ b/test/option/fixture/SConstruct__experimental @@ -1,6 +1,9 @@ +from SCons.Script.SConsOptions import experimental_features + +print("All Features=%s" % ','.join(sorted(experimental_features))) + DefaultEnvironment(tools=[]) env = Environment(tools=[]) exp = GetOption('experimental') -print("Experimental=%s" % exp) -print("All=%s" % ('all' in exp)) +print("Experimental=%s" % sorted(exp)) diff --git a/test/option/option--experimental.py b/test/option/option--experimental.py index d8e2875..0f0e9ec 100644 --- a/test/option/option--experimental.py +++ b/test/option/option--experimental.py @@ -34,22 +34,22 @@ test = TestSCons.TestSCons() test.file_fixture('fixture/SConstruct__experimental', 'SConstruct') tests = [ - ('.', [], 'False'), - ('--experimental=all', ['all'], 'True'), - ('--experimental=none', ['none'], 'False'), + ('.', []), + ('--experimental=all', ['transporter', 'warp_speed']), + ('--experimental=none', []), ] -for args, exper, all_str in tests: - read_string = """Experimental=%s -All=%s -""" % (exper, all_str) +for args, exper in tests: + read_string = """All Features=transporter,warp_speed +Experimental=%s +""" % (exper) test.run(arguments=args, stdout=test.wrap_stdout(read_str=read_string, build_str="scons: `.' is up to date.\n")) test.run(arguments='--experimental=warp_drive', stderr="""usage: scons [OPTION] [TARGET] ... -SCons Error: option --experimental: invalid choice: 'warp_drive' (choose from 'all', 'none') +SCons Error: option --experimental: invalid choice: 'warp_drive' (choose from 'all','none','transporter','warp_speed') """, status=2) |