Skip to content

Commit 6364bcd

Browse files
authored
Merge pull request SCons#4508 from mwichmann/doc/Tools
Tools update, mainly documentation
2 parents a592001 + e696718 commit 6364bcd

File tree

8 files changed

+262
-157
lines changed

8 files changed

+262
-157
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
3030
- Drop duplicated __getstate__ and __setstate__ methods in AliasNodeInfo,
3131
FileNodeInfo and ValueNodeInfo classes, as they are identical to the
3232
ones in parent NodeInfoBase and can just be inherited.
33+
- Update manpage for Tools, and for TOOL, which also gets a minor
34+
tweak for how it's handled (should be more accurate in a few situations).
3335

3436

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

RELEASE.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ DOCUMENTATION
6262
-------------
6363

6464
- Updated Value Node docs.
65+
- Update manpage for Tools, and for the TOOL variable.
6566

6667

6768

SCons/Environment.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import shlex
3838
from collections import UserDict, UserList, deque
3939
from subprocess import PIPE, DEVNULL
40-
from typing import Optional, Sequence
40+
from typing import Callable, Collection, Optional, Sequence, Union
4141

4242
import SCons.Action
4343
import SCons.Builder
@@ -1250,9 +1250,11 @@ def __init__(
12501250
SCons.Tool.Initializers(self)
12511251

12521252
if tools is None:
1253-
tools = self._dict.get('TOOLS', None)
1254-
if tools is None:
1255-
tools = ['default']
1253+
tools = self._dict.get('TOOLS', ['default'])
1254+
else:
1255+
# for a new env, if we didn't use TOOLS, make sure it starts empty
1256+
# so it only shows tools actually initialized.
1257+
self._dict['TOOLS'] = []
12561258
apply_tools(self, tools, toolpath)
12571259

12581260
# Now restore the passed-in and customized variables
@@ -2014,11 +2016,20 @@ def SetDefault(self, **kw) -> None:
20142016
def _find_toolpath_dir(self, tp):
20152017
return self.fs.Dir(self.subst(tp)).srcnode().get_abspath()
20162018

2017-
def Tool(self, tool, toolpath=None, **kwargs) -> SCons.Tool.Tool:
2019+
def Tool(
2020+
self, tool: Union[str, Callable], toolpath: Optional[Collection[str]] = None, **kwargs
2021+
) -> Callable:
20182022
"""Find and run tool module *tool*.
20192023
2024+
*tool* is generally a string, but can also be a callable object,
2025+
in which case it is just called, without any of the setup.
2026+
The skipped setup includes storing *kwargs* into the created
2027+
:class:`~SCons.Tool.Tool` instance, which is extracted and used
2028+
when the instance is called, so in the skip case, the called
2029+
object will not get the *kwargs*.
2030+
20202031
.. versionchanged:: 4.2
2021-
returns the tool module rather than ``None``.
2032+
returns the tool object rather than ``None``.
20222033
"""
20232034
if is_String(tool):
20242035
tool = self.subst(tool)

SCons/Environment.xml

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,11 @@ for more information).
241241
<cvar name="TOOLS">
242242
<summary>
243243
<para>
244-
A list of the names of the Tool specifications
245-
that are part of this construction environment.
244+
A list of the names of the Tool specification modules
245+
that were actually initialized in the current &consenv;.
246+
This may be useful as a diagnostic aid
247+
to see if a tool did (or did not) run.
248+
The value is informative and is not guaranteed to be complete.
246249
</para>
247250
</summary>
248251
</cvar>
@@ -3437,32 +3440,43 @@ source_nodes = env.subst('$EXPAND_TO_NODELIST', conv=lambda x: x)
34373440
<para>
34383441
Locates the tool specification module <parameter>name</parameter>
34393442
and returns a callable tool object for that tool.
3440-
The tool module is searched for in standard locations
3441-
and in any paths specified by the optional
3442-
<parameter>toolpath</parameter> parameter.
3443-
The standard locations are &SCons;' own internal
3444-
path for tools plus the toolpath, if any (see the
3445-
<emphasis role="bold">Tools</emphasis> section in the manual page
3446-
for more details).
3447-
Any additional keyword arguments
3448-
<parameter>kwargs</parameter> are passed
3449-
to the tool module's <function>generate</function> function
3450-
during tool object construction.
3443+
When the environment method (&f-env-Tool;) form is used,
3444+
the tool object is automatically called before the method returns
3445+
to update <varname>env</varname>,
3446+
and <parameter>name</parameter> is
3447+
appended to the &cv-link-TOOLS;
3448+
&consvar; in that environment.
3449+
When the global function &f-Tool; form is used,
3450+
the tool object is constructed but not called,
3451+
as it lacks the context of an environment to update,
3452+
and the returned object needs to be used to arrange for the call.
34513453
</para>
34523454

34533455
<para>
3454-
When called, the tool object
3455-
updates a &consenv; with &consvars; and arranges
3456+
The tool module is searched for in the tool search paths (see the
3457+
<emphasis role="bold">Tools</emphasis> section in the manual page
3458+
for details)
3459+
and in any paths specified by the optional
3460+
<parameter>toolpath</parameter> parameter,
3461+
which must be a list of strings.
3462+
If <parameter>toolpath</parameter> is omitted,
3463+
the <parameter>toolpath</parameter>
3464+
supplied when the environment was created,
3465+
if any, is used.
3466+
</para>
3467+
3468+
<para>
3469+
Any remaining keyword arguments are saved in
3470+
the tool object,
3471+
and will be passed to the tool module's
3472+
<function>generate</function> function
3473+
when the tool object is actually called.
3474+
The <function>generate</function> function
3475+
can update the &consenv; with &consvars; and arrange
34563476
any other initialization
3457-
needed to use the mechanisms that tool describes.
3458-
</para>
3459-
3460-
<para>
3461-
When the &f-env-Tool; form is used,
3462-
the tool object is automatically called to update <varname>env</varname>
3463-
and the value of <parameter>tool</parameter> is
3464-
appended to the &cv-link-TOOLS;
3465-
&consvar; in that environment.
3477+
needed to use the mechanisms that tool describes,
3478+
and can use these extra arguments to help
3479+
guide its actions.
34663480
</para>
34673481

34683482
<para>
@@ -3481,10 +3495,7 @@ env.Tool('opengl', toolpath=['build/tools'])
34813495
</example_commands>
34823496

34833497
<para>
3484-
When the global function &f-Tool; form is used,
3485-
the tool object is constructed but not called,
3486-
as it lacks the context of an environment to update.
3487-
The tool object can be passed to an
3498+
The returned tool object can be passed to an
34883499
&f-link-Environment; or &f-link-Clone; call
34893500
as part of the <parameter>tools</parameter> keyword argument,
34903501
in which case the tool is applied to the environment being constructed,

SCons/Tool/ToolTests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ def Detect(self, progs):
3939
return progs[0]
4040
def Append(self, **kw) -> None:
4141
self.dict.update(kw)
42+
# Adding a tool now calls AppendUnique so we need a mocked one. Since
43+
# the only usage is adding one tool, using Append is good enough.
44+
AppendUnique = Append
4245
def __getitem__(self, key):
4346
return self.dict[key]
4447
def __setitem__(self, key, val) -> None:

SCons/Tool/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def __call__(self, env, *args, **kw) -> None:
251251
kw.update(call_kw)
252252
else:
253253
kw = self.init_kw
254-
env.Append(TOOLS=[self.name])
254+
env.AppendUnique(TOOLS=[self.name])
255255
if hasattr(self, 'options'):
256256
import SCons.Variables
257257
if 'options' not in env:

0 commit comments

Comments
 (0)