Skip to content

Commit 9f75371

Browse files
authored
Merge pull request SCons#4535 from mwichmann/doc/Command
Tweak some things about Command() docs
2 parents 7040ecc + fa7fecb commit 9f75371

File tree

9 files changed

+290
-234
lines changed

9 files changed

+290
-234
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
7070
on a given page *before* the submodule docs, not after. Also
7171
tweaked the Util package doc build so it's structured more like the
7272
other packages (a missed part of the transition when it was split).
73+
- Updated manpage description of Command "builder" and function.
7374

7475

7576
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
@@ -74,6 +74,7 @@ DOCUMENTATION
7474
- Update manpage and user guide for Variables usage.
7575
- Restructured API Docs build so main package contents are listed
7676
before contents of package submodules.
77+
- Updated manpage description of Command "builder" and function.
7778

7879

7980

SCons/Builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ def __init__(self, action = None,
387387
target_scanner = None,
388388
source_scanner = None,
389389
emitter = None,
390-
multi: int = 0,
390+
multi: bool = False,
391391
env = None,
392392
single_source: bool = False,
393393
name = None,

SCons/Environment.py

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2208,52 +2208,44 @@ def Configure(self, *args, **kw):
22082208
return SCons.SConf.SConf(*nargs, **nkw)
22092209

22102210
def Command(self, target, source, action, **kw):
2211-
"""Builds the supplied target files from the supplied
2212-
source files using the supplied action. Action may
2213-
be any type that the Builder constructor will accept
2214-
for an action."""
2211+
"""Set up a one-off build command.
2212+
2213+
Builds *target* from *source* using *action*, which may be
2214+
be any type that the Builder factory will accept for an action.
2215+
Generates an anonymous builder and calls it, to add the details
2216+
to the build graph. The builder is not named, added to ``BUILDERS``,
2217+
or otherwise saved.
2218+
2219+
Recognizes the :func:`~SCons.Builder.Builder` keywords
2220+
``source_scanner``, ``target_scanner``, ``source_factory`` and
2221+
``target_factory``. All other arguments from *kw* are passed on
2222+
to the builder when it is called.
2223+
"""
2224+
# Build a kwarg dict for the builder construction
22152225
bkw = {
22162226
'action': action,
22172227
'target_factory': self.fs.Entry,
22182228
'source_factory': self.fs.Entry,
22192229
}
2220-
# source scanner
2221-
try:
2222-
bkw['source_scanner'] = kw['source_scanner']
2223-
except KeyError:
2224-
pass
2225-
else:
2226-
del kw['source_scanner']
2227-
2228-
# target scanner
2229-
try:
2230-
bkw['target_scanner'] = kw['target_scanner']
2231-
except KeyError:
2232-
pass
2233-
else:
2234-
del kw['target_scanner']
2235-
2236-
# source factory
2237-
try:
2238-
bkw['source_factory'] = kw['source_factory']
2239-
except KeyError:
2240-
pass
2241-
else:
2242-
del kw['source_factory']
22432230

2244-
# target factory
2245-
try:
2246-
bkw['target_factory'] = kw['target_factory']
2247-
except KeyError:
2248-
pass
2249-
else:
2250-
del kw['target_factory']
2231+
# Recognize these kwargs for the builder construction and take
2232+
# them out of the args for the subsequent builder call.
2233+
for arg in [
2234+
'source_scanner',
2235+
'target_scanner',
2236+
'source_factory',
2237+
'target_factory',
2238+
]:
2239+
try:
2240+
bkw[arg] = kw.pop(arg)
2241+
except KeyError:
2242+
pass
22512243

22522244
bld = SCons.Builder.Builder(**bkw)
22532245
return bld(self, target, source, **kw)
22542246

22552247
def Depends(self, target, dependency):
2256-
"""Explicity specify that 'target's depend on 'dependency'."""
2248+
"""Explicity specify that *target* depends on *dependency*."""
22572249
tlist = self.arg2nodes(target, self.fs.Entry)
22582250
dlist = self.arg2nodes(dependency, self.fs.Entry)
22592251
for t in tlist:
@@ -2281,7 +2273,7 @@ def PyPackageDir(self, modulename):
22812273
return self.fs.PyPackageDir(s)
22822274

22832275
def NoClean(self, *targets):
2284-
"""Tags a target so that it will not be cleaned by -c"""
2276+
"""Tag target(s) so that it will not be cleaned by -c."""
22852277
tlist = []
22862278
for t in targets:
22872279
tlist.extend(self.arg2nodes(t, self.fs.Entry))
@@ -2290,7 +2282,7 @@ def NoClean(self, *targets):
22902282
return tlist
22912283

22922284
def NoCache(self, *targets):
2293-
"""Tags a target so that it will not be cached"""
2285+
"""Tag target(s) so that it will not be cached."""
22942286
tlist = []
22952287
for t in targets:
22962288
tlist.extend(self.arg2nodes(t, self.fs.Entry))

SCons/Environment.xml

Lines changed: 56 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,15 +1125,16 @@ wx_env = env.Clone(parse_flags='!wx-config --cflags --cxxflags')
11251125
<builder name="Command">
11261126
<summary>
11271127
<para>
1128-
The &b-Command; "Builder" is actually
1129-
a function that looks like a Builder,
1130-
but takes a required third argument, which is the
1131-
action to take to construct the target
1132-
from the source, used for "one-off" builds
1133-
where a full builder is not needed.
1134-
Thus it does not follow the builder
1135-
calling rules described at the start of this section.
1136-
See instead the &f-link-Command; function description
1128+
There is actually no Builder named &Command;,
1129+
rather the term "Command Builder" refers to
1130+
a function which, on each call, creates and calls
1131+
an anonymous Builder.
1132+
This is useful for "one-off" builds
1133+
where a full Builder is not needed.
1134+
Since the anonymous Builder is never hooked
1135+
into the standard Builder framework,
1136+
an Action must always be specfied.
1137+
See the &f-link-Command; function description
11371138
for the calling syntax and details.
11381139
</para>
11391140
</summary>
@@ -1145,49 +1146,69 @@ for the calling syntax and details.
11451146
</arguments>
11461147
<summary>
11471148
<para>
1148-
Executes a specific <parameter>action</parameter>
1149-
(or list of actions)
1150-
to build a <parameter>target</parameter> file or files
1151-
from a <parameter>source</parameter> file or files.
1152-
This is more convenient
1153-
than defining a separate Builder object
1154-
for a single special-case build.
1149+
Creates an anonymous builder and calls it,
1150+
thus recording <parameter>action</parameter>
1151+
to build <parameter>target</parameter>
1152+
from <parameter>source</parameter>
1153+
into the dependency tree.
1154+
This can be more convenient for a single special-case build
1155+
than having to define and add a new named Builder.
11551156
</para>
11561157

11571158
<para>
11581159
The
1159-
&Command; function accepts
1160-
<parameter>source_scanner</parameter>,
1161-
<parameter>target_scanner</parameter>,
1162-
<parameter>source_factory</parameter>, and
1163-
<parameter>target_factory</parameter>
1164-
keyword arguments. These arguments can
1165-
be used to specify
1166-
a Scanner object
1167-
that will be used to apply a custom
1168-
scanner for a source or target.
1160+
&Command; function accepts the
1161+
<parameter>source_scanner</parameter> and
1162+
<parameter>target_scanner</parameter>
1163+
keyword arguments which are used to specify
1164+
custom scanners for the specified sources or targets.
1165+
The value must be a Scanner object.
11691166
For example, the global
11701167
<literal>DirScanner</literal>
11711168
object can be used
11721169
if any of the sources will be directories
11731170
that must be scanned on-disk for
11741171
changes to files that aren't
1175-
already specified in other Builder of function calls.
1176-
The <parameter>*_factory</parameter> arguments take a factory function that
1177-
&Command; will use to turn any sources or targets
1178-
specified as strings into SCons Nodes.
1172+
already specified in other Builder or function calls.
1173+
</para>
1174+
1175+
<para>
1176+
The
1177+
&Command; function also accepts the
1178+
<parameter>source_factory</parameter> and
1179+
<parameter>target_factory</parameter>
1180+
keyword arguments which are used to specify
1181+
factory functions to create &SCons; Nodes
1182+
from any sources or targets specified as strings.
1183+
If any sources or targets are already Node objects,
1184+
they are not further transformed even if
1185+
a factory is specified for them.
1186+
The default for each is the &Entry; factory.
1187+
</para>
1188+
1189+
<para>
1190+
These four arguments, if given, are used
1191+
in the creation of the Builder.
1192+
Other Builder-specific keyword arguments
1193+
are not recognized as such.
11791194
See the manpage section "Builder Objects"
11801195
for more information about how these
11811196
arguments work in a Builder.
11821197
</para>
11831198

11841199
<para>
1185-
Any other keyword arguments specified override any
1186-
same-named existing construction variables.
1200+
Any remaining keyword arguments are passed on to the
1201+
generated builder when it is called,
1202+
and behave as described in the manpage section "Builder Methods",
1203+
in short:
1204+
recognized arguments have their specified meanings,
1205+
while the rest are used to override
1206+
any same-named existing &consvars;
1207+
from the &consenv;.
11871208
</para>
11881209

11891210
<para>
1190-
An action can be an external command,
1211+
<parameter>action</parameter> can be an external command,
11911212
specified as a string,
11921213
or a callable &Python; object;
11931214
see the manpage section "Action Objects"
@@ -1649,7 +1670,7 @@ would supply a string as a directory name
16491670
to a Builder method or function.
16501671
Directory Nodes have attributes and methods
16511672
that are useful in many situations;
1652-
see manpage section "File and Directory Nodes"
1673+
see manpage section "Filesystem Nodes"
16531674
for more information.
16541675
</para>
16551676
</summary>
@@ -1849,7 +1870,7 @@ would supply a string as a file name
18491870
to a Builder method or function.
18501871
File Nodes have attributes and methods
18511872
that are useful in many situations;
1852-
see manpage section "File and Directory Nodes"
1873+
see manpage section "Filesystem Nodes"
18531874
for more information.
18541875
</para>
18551876
</summary>

doc/generated/builders.gen

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,16 @@ env.CFile(target='bar', source='bar.y')
3939
<term><function>Command</function>()</term>
4040
<term><replaceable>env</replaceable>.<methodname>Command</methodname>()</term>
4141
<listitem><para>
42-
The &b-Command; "Builder" is actually
43-
a function that looks like a Builder,
44-
but takes a required third argument, which is the
45-
action to take to construct the target
46-
from the source, used for "one-off" builds
47-
where a full builder is not needed.
48-
Thus it does not follow the builder
49-
calling rules described at the start of this section.
50-
See instead the &f-link-Command; function description
42+
There is actually no Builder named &Command;,
43+
rather the term "Command Builder" refers to
44+
a function which, on each call, creates and calls
45+
an anonymous Builder.
46+
This is useful for "one-off" builds
47+
where a full Builder is not needed.
48+
Since the anonymous Builder is never hooked
49+
into the standard Builder framework,
50+
an Action must always be specfied.
51+
See the &f-link-Command; function description
5152
for the calling syntax and details.
5253
</para>
5354
</listitem>

0 commit comments

Comments
 (0)