Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 50 additions & 29 deletions SCons/Action.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,44 +130,65 @@ A Python function used to print the command lines as they are executed
or
<option>-s</option>
options or their equivalents).
The function should take four arguments:
The function must accept four arguments:
<varname>s</varname>,
the command being executed (a string),
<varname>target</varname>,
the target being built (file node, list, or string name(s)),
<varname>source</varname> and
<varname>env</varname>.
<varname>s</varname>
is a string showing the command being executed,
<varname>target</varname>,
is the target being built (file node, list, or string name(s)),
<varname>source</varname>,
the source(s) used (file node, list, or string name(s)), and
<varname>env</varname>,
the environment being used.
is the source(s) used (file node, list, or string name(s)),
and <varname>env</varname>
is the environment being used.
</para>

<para>
The function must do the printing itself. The default implementation,
used if this variable is not set or is None, is:
The function must do the printing itself.
The default implementation,
used if this variable is not set or is <constant>None</constant>,
is to just print the string, as in:
</para>
<example_commands>
def print_cmd_line(s, target, source, env):
sys.stdout.write(s + "\n")
sys.stdout.write(s + "\n")
</example_commands>

<para>
Here's an example of a more interesting function:
Here is an example of a more interesting function:
</para>

<example_commands>
def print_cmd_line(s, target, source, env):
sys.stdout.write("Building %s -> %s...\n" %
(' and '.join([str(x) for x in source]),
' and '.join([str(x) for x in target])))
env=Environment(PRINT_CMD_LINE_FUNC=print_cmd_line)
env.Program('foo', 'foo.c')
sys.stdout.write(
"Building %s -> %s...\n"
% (
' and '.join([str(x) for x in source]),
' and '.join([str(x) for x in target]),
)
)

env = Environment(PRINT_CMD_LINE_FUNC=print_cmd_line)
env.Program('foo', ['foo.c', 'bar.c'])
</example_commands>

<para>
This just prints "Building <varname>targetname</varname> from <varname>sourcename</varname>..." instead
of the actual commands.
Such a function could also log the actual commands to a log file,
for example.
This prints:
</para>

<screen>
...
scons: Building targets ...
Building bar.c -> bar.o...
Building foo.c -> foo.o...
Building foo.o and bar.o -> foo...
scons: done building targets.
</screen>

<para>
Another example could be a function that logs the actual commands to a file.
</para>
</summary>
</cvar>
Expand All @@ -176,26 +197,26 @@ for example.
<summary>
<para>
A command interpreter function that will be called to execute command line
strings. The function must expect the following arguments:
strings. The function must accept five arguments:
</para>

<example_commands>
def spawn(shell, escape, cmd, args, env):
</example_commands>

<para>
<varname>sh</varname>
is a string naming the shell program to use.
<varname>shell</varname>
is a string naming the shell program to use,
<varname>escape</varname>
is a function that can be called to escape shell special characters in
the command line.
the command line,
<varname>cmd</varname>
is the path to the command to be executed.
is the path to the command to be executed,
<varname>args</varname>
is the arguments to the command.
holds the arguments to the command and
<varname>env</varname>
is a dictionary of the environment variables
in which the command should be executed.
is a dictionary of environment variables
defining the execution environment in which the command should be executed.
</para>
</summary>
</cvar>
Expand All @@ -222,9 +243,9 @@ targets.
def custom_shell_env(env, target, source, shell_env):
"""customize shell_env if desired"""
if str(target[0]) == 'special_target':
shell_env['SPECIAL_VAR'] = env.subst('SOME_VAR', target=target, source=source)
shell_env['SPECIAL_VAR'] = env.subst('SOME_VAR', target=target, source=source)
return shell_env

env["SHELL_ENV_GENERATORS"] = [custom_shell_env]
</example_commands>

Expand Down
50 changes: 26 additions & 24 deletions SCons/Environment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1630,55 +1630,57 @@ See the manpage section "Construction Environments" for more details.

<scons_function name="Execute">
<arguments>
(action, [strfunction, varlist])
(action, [actionargs ...])
</arguments>
<summary>
<para>
Executes an Action object.
The specified
Executes an Action.
<parameter>action</parameter>
may be an Action object
(see manpage section "Action Objects"
for an explanation of behavior),
or it may be a command-line string,
list of commands,
or executable &Python; function,
each of which will be converted
each of which will first be converted
into an Action object
and then executed.
Any additional arguments to &f-Execute;
(<parameter>strfunction</parameter>, <parameter>varlist</parameter>)
are passed on to the &f-link-Action; factory function
which actually creates the Action object.
The exit value of the command
or return value of the &Python; function
will be returned.
which actually creates the Action object
(see the manpage section <link linkend="action_objects">Action Objects</link>
for a description). Example:
</para>

<example_commands>
Execute(Copy('file.out', 'file.in'))
</example_commands>

<para>&f-Execute; performs its action immediately,
as part of the SConscript-reading phase.
There are no sources or targets declared in an
&f-Execute; call, so any objects it manipulates
will not be tracked as part of the &SCons; dependency graph.
In the example above, neither
<filename>file.out</filename> nor
<filename>file.in</filename> will be tracked objects.
</para>

<para>
Note that
&f-Execute; returns the exit value of the command
or return value of the &Python; function.
&scons;
will print an error message if the executed
prints an error message if the executed
<parameter>action</parameter>
fails--that is,
exits with or returns a non-zero value.
&scons;
will
fails (exits with or returns a non-zero value),
however it does
<emphasis>not</emphasis>,
however,
automatically terminate the build
if the specified
<parameter>action</parameter>
fails.
automatically terminate the build for such a failure.
If you want the build to stop in response to a failed
&f-Execute;
call,
you must explicitly check for a non-zero return value:
</para>

<example_commands>
Execute(Copy('file.out', 'file.in'))

if Execute("mkdir sub/dir/ectory"):
# The mkdir failed, don't try to build.
Exit(1)
Expand Down
39 changes: 23 additions & 16 deletions doc/man/scons.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5904,7 +5904,7 @@ you need to create the action object using &f-Action;.
returns an appropriate object for the action
represented by the type of the
<parameter>action</parameter> argument
(the first positional parmeter):</para>
(the first positional parameter):</para>

<itemizedlist>
<listitem>
Expand Down Expand Up @@ -6034,42 +6034,49 @@ The following argument types are accepted:

<itemizedlist>
<listitem>
<para>If <parameter>output</parameter> is a string,
substitution is performed on the string before it is printed.
The string typically contains variables, notably
<para>If the second argument is a string,
or if the <parameter>cmdstr</parameter> keyword argument is supplied,
the string defines what is printed.
Substitution is performed on the string before it is printed.
The string typically contains substitutable variables, notably
<literal>$TARGET(S)</literal> and <literal>$SOURCE(S)</literal>,
or consists of just a single
variable, which is optionally defined somewhere else.
or consists of just a single variable
which is optionally defined somewhere else.
&SCons; itself heavily uses the latter variant.</para>
</listitem>

<listitem>
<para>If <parameter>output</parameter> is a function,
the function will be called to obtain a string
describing the action being executed.
<para>If the second argument is a function,
or if the <parameter>strfunction</parameter> keyword argument is supplied,
the function will be called to obtain the string
to be printed when the action is performed.
The function
must accept three keyword arguments:
<parameter>target</parameter>,
<parameter>source</parameter> and
<parameter>env</parameter>,
with the same interpretation as for a callable
<parameter>action</parameter> argument above.
The function is responsible for handling any required substitutions.
</para>
</listitem>

<listitem>
<para>If <parameter>output</parameter>is <constant>None</constant>,
<para>If the second argument is <constant>None</constant>,
or if <literal>cmdstr=None</literal> is supplied,
output is suppressed entirely.</para>
</listitem>
</itemizedlist>

<para>
Instead of using a positional argument,
the <parameter>cmdstr</parameter>
keyword argument may be used to specify the output string,
or the <parameter>strfunction</parameter> keyword argument
may be used to specify a function to return the output string.
<literal>cmdstr=None</literal> suppresses output entirely.
The <parameter>cmdstr</parameter> and
<parameter>strfunction</parameter>
keyword arguments may not both be supplied in a single call to &f-Action;
</para>

<para>
Printing of action strings is affected by the setting of
&cv-link-PRINT_CMD_LINE_FUNC;.
</para>

<para>Examples:</para>
Expand Down