Skip to content

Commit 50b478f

Browse files
authored
Merge branch 'master' into perf/env-setitem
2 parents 78a26bb + 70cfb31 commit 50b478f

25 files changed

+387
-231
lines changed

.appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ image:
88
# linux builds done in Travis CI for now
99
- Visual Studio 2017
1010
- Visual Studio 2019
11-
- Visual Studio 2022
11+
#- Visual Studio 2022 XXX Temporary disable while failing on .10 versions
1212

1313
cache:
1414
- downloads -> appveyor.yml

CHANGES.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,18 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
102102
- Performance tweak: the __setitem__ method of an Environment, used for
103103
setting construction variables, now uses the string method isidentifier
104104
to validate the name (updated from microbenchmark results).
105+
- AddOption and the internal add_local_option which AddOption calls now
106+
recognize a "settable" keyword argument to indicate a project-added
107+
option can also be modified using SetOption. Fixes #3983.
108+
NOTE: If you were using ninja and using SetOption() for ninja options
109+
in your SConscripts prior to loading the ninja tool, you will now
110+
see an error. The fix is to move the SetOption() to after you've loaded
111+
the ninja tool.
112+
- ListVariable now has a separate validator, with the functionality
113+
that was previously part of the converter. The main effect is to
114+
allow a developer to supply a custom validator, which previously
115+
could be inhibited by the converter failing before the validator
116+
is reached.
105117

106118

107119
RELEASE 4.7.0 - Sun, 17 Mar 2024 17:22:20 -0700

RELEASE.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ CHANGED/ENHANCED EXISTING FUNCTIONALITY
5353
- The Variables object Add method now accepts a subst keyword argument
5454
(defaults to True) which can be set to inhibit substitution prior to
5555
calling the variable's converter and validator.
56+
- AddOption and the internal add_local_option which AddOption calls now
57+
recognize a "settable" keyword argument to indicate a project-added
58+
option can also be modified using SetOption.
59+
NOTE: If you were using ninja and using SetOption() for ninja options
60+
in your SConscripts prior to loading the ninja tool, you will now
61+
see an error. The fix is to move the SetOption() to after you've loaded
62+
the ninja tool.
63+
- ListVariable now has a separate validator, with the functionality
64+
that was previously part of the converter. The main effect is to
65+
allow a developer to supply a custom validator, which previously
66+
could be inhibited by the converter failing before the validator
67+
is reached.
5668

5769
FIXES
5870
-----

SCons/Script/Main.py

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import traceback
4242
import platform
4343
import threading
44-
from typing import Optional, List
44+
from typing import Optional, List, TYPE_CHECKING
4545

4646
import SCons.CacheDir
4747
import SCons.Debug
@@ -59,6 +59,8 @@
5959
import SCons.Util
6060
import SCons.Warnings
6161
import SCons.Script.Interactive
62+
if TYPE_CHECKING:
63+
from SCons.Script import SConsOption
6264
from SCons.Util.stats import count_stats, memory_stats, time_stats, ENABLE_JSON, write_scons_stats_file, JSON_OUTPUT_FILE
6365

6466
from SCons import __version__ as SConsVersion
@@ -174,6 +176,7 @@ def __call__(self, node) -> None:
174176
ProgressObject = SCons.Util.Null()
175177

176178
def Progress(*args, **kw) -> None:
179+
"""Show progress during building - Public API."""
177180
global ProgressObject
178181
ProgressObject = Progressor(*args, **kw)
179182

@@ -501,29 +504,47 @@ def __getattr__(self, attr):
501504
# TODO: to quiet checkers, FakeOptionParser should also define
502505
# raise_exception_on_error, preserve_unknown_options, largs and parse_args
503506

504-
def add_local_option(self, *args, **kw) -> None:
507+
def add_local_option(self, *args, **kw) -> "SConsOption":
505508
pass
506509

507510

508511
OptionsParser = FakeOptionParser()
509512

510-
def AddOption(*args, **kw):
513+
def AddOption(*args, settable: bool = False, **kw) -> "SConsOption":
514+
"""Add a local option to the option parser - Public API.
515+
516+
If the *settable* parameter is true, the option will be included in the
517+
list of settable options; all other keyword arguments are passed on to
518+
:meth:`~SCons.Script.SConsOptions.SConsOptionParser.add_local_option`.
519+
520+
.. versionchanged:: 4.8.0
521+
The *settable* parameter added to allow including the new option
522+
to the table of options eligible to use :func:`SetOption`.
523+
524+
"""
511525
if 'default' not in kw:
512526
kw['default'] = None
527+
kw['settable'] = settable
513528
result = OptionsParser.add_local_option(*args, **kw)
514529
return result
515530

516-
def GetOption(name):
531+
def GetOption(name: str):
532+
"""Get the value from an option - Public API."""
517533
return getattr(OptionsParser.values, name)
518534

519-
def SetOption(name, value):
535+
def SetOption(name: str, value):
536+
"""Set the value of an option - Public API."""
520537
return OptionsParser.values.set_option(name, value)
521538

522-
def DebugOptions(json=None):
523-
"""
524-
API to allow specifying options to SCons debug logic
525-
Currently only json is supported which changes the
526-
json file written by --debug=json from the default
539+
def DebugOptions(json: Optional[str] = None) -> None:
540+
"""Specify options to SCons debug logic - Public API.
541+
542+
Currently only *json* is supported, which changes the JSON file
543+
written to if the ``--debug=json`` command-line option is specified
544+
to the value supplied.
545+
546+
.. versionadded:: 4.6.0
547+
527548
"""
528549
if json is not None:
529550
json_node = SCons.Defaults.DefaultEnvironment().arg2nodes(json)
@@ -540,7 +561,7 @@ def DebugOptions(json=None):
540561
raise SCons.Errors.UserError(f"Unable to create directory for JSON debug output file: {SCons.Util.stats.JSON_OUTPUT_FILE}")
541562

542563

543-
def ValidateOptions(throw_exception: bool=False) -> None:
564+
def ValidateOptions(throw_exception: bool = False) -> None:
544565
"""Validate options passed to SCons on the command line.
545566
546567
Checks that all options given on the command line are known to this

SCons/Script/Main.xml

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,21 +93,25 @@ the option value may be accessed using
9393
&f-link-GetOption;
9494
or
9595
&f-link-env-GetOption;.
96-
&f-link-SetOption; is not currently supported for
97-
options added with &f-AddOption;.
98-
<!-- was:
99-
The value may also be set using
100-
&f-SetOption;
96+
If the <parameter>settable=True</parameter> argument
97+
was supplied in the &AddOption; call,
98+
the value may also be set later using
99+
&f-link-SetOption;
101100
or
102-
&f-env.SetOption;,
103-
if conditions in a
104-
&SConscript;
101+
&f-link-env-SetOption;,
102+
if conditions in an
103+
&SConscript; file
105104
require overriding any default value.
106105
Note however that a
107106
value specified on the command line will
108107
<emphasis>always</emphasis>
109-
override a value set by any SConscript file.
110-
-->
108+
override a value set in an SConscript file.
109+
</para>
110+
111+
<para>
112+
<emphasis>Changed in 4.8.0</emphasis>: added the
113+
<parameter>settable</parameter> keyword argument
114+
to enable an added option to be settable via &SetOption;.
111115
</para>
112116

113117
<para>
@@ -196,6 +200,7 @@ Allows setting options for SCons debug options. Currently the only supported val
196200
<example_commands>
197201
DebugOptions(json='#/build/output/scons_stats.json')
198202
</example_commands>
203+
<para><emphasis>New in version 4.6.0.</emphasis></para>
199204
</summary>
200205
</scons_function>
201206

@@ -334,9 +339,10 @@ atexit.register(print_build_failures)
334339
<summary>
335340
<para>
336341
Query the value of settable options which may have been set
337-
on the command line, or by using the &f-link-SetOption; function.
342+
on the command line, via option defaults,
343+
or by using the &f-link-SetOption; function.
338344
The value of the option is returned in a type matching how the
339-
option was declared - see the documentation for the
345+
option was declared - see the documentation of the
340346
corresponding command line option for information about each specific
341347
option.
342348
</para>
@@ -801,6 +807,16 @@ are not settable using &f-SetOption; since those files must
801807
be read in order to find the &f-SetOption; call in the first place.
802808
</para>
803809

810+
<para>
811+
For project-specific options (sometimes called
812+
<firstterm>local options</firstterm>)
813+
added via an &f-link-AddOption; call,
814+
&f-SetOption; is available only after the
815+
&f-AddOption; call has completed successfully,
816+
and only if that call included the
817+
<parameter>settable=True</parameter> argument.
818+
</para>
819+
804820
<para>
805821
The settable variables with their associated command-line options are:
806822
</para>

0 commit comments

Comments
 (0)