or return value of the Python function
will be returned.
+Note that
+.B scons
+will print an error message if the executed
+.I action
+fails--that is,
+exits with or returns a non-zero value.
+.B scons
+will
+.I not ,
+however,
+automatically terminate the build
+if the specified
+.I action
+fails.
+If you want the build to stop in response to a failed
+.BR Execute ()
+call,
+you must explicitly check for a non-zero return value:
+
+.ES
+Execute(Copy('file.out', 'file.in'))
+
+if Execute("mkdir sub/dir/ectory"):
+ # The mkdir failed, don't try to build.
+ Exit(1)
+.EE
+
'\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
.TP
.RI Exit([ value ])
You can also execute an &Action; returned by a factory
(or actually, any &Action;)
at the time the &SConscript; file is read
- by wrapping it up in the &Execute; function.
+ by using the &Execute; function.
For example, if we need to make sure that
a directory exists before we build any targets,
-
</para>
<scons_example name="Execute">
</para>
+ <para>
+
+ The &Execute; function returns the exit status
+ or return value of the underlying action being executed.
+ It will also print an error message if the action
+ fails and returns a non-zero value.
+ &SCons; will <emphasis>not</emphasis>, however,
+ actually stop the build if the action fails.
+ If you want the build to stop
+ in response to a failure in an action called by &Execute;,
+ you must do so by explicitly
+ checking the return value
+ and calling the &Exit; function
+ (or a Python equivalent):
+
+ </para>
+
+ <sconstruct>
+ if Execute(Mkdir('__ROOT__/tmp/my_temp_directory')):
+ # A problem occurred while making the temp directory.
+ Exit(1)
+ </sconstruct>
+
</section>
You can also execute an &Action; returned by a factory
(or actually, any &Action;)
at the time the &SConscript; file is read
- by wrapping it up in the &Execute; function.
+ by using the &Execute; function.
For example, if we need to make sure that
a directory exists before we build any targets,
-
</para>
<programlisting>
</para>
+ <para>
+
+ The &Execute; function returns the exit status
+ or return value of the underlying action being executed.
+ It will also print an error message if the action
+ fails and returns a non-zero value.
+ &SCons; will <emphasis>not</emphasis>, however,
+ actually stop the build if the action fails.
+ If you want the build to stop
+ in response to a failure in an action called by &Execute;,
+ you must do so by explicitly
+ checking the return value
+ and calling the &Exit; function
+ (or a Python equivalent):
+
+ </para>
+
+ <programlisting>
+ if Execute(Mkdir('/tmp/my_temp_directory')):
+ # A problem occurred while making the temp directory.
+ Exit(1)
+ </programlisting>
+
</section>
- Document the GetLaunchDir() function in the User's Guide.
+ - Have the env.Execute() method print an error message if the
+ executed command fails.
+
From Greg Noel:
- Handle yacc/bison on newer Mac OS X versions creating file.hpp,
action = apply(self.Action, (action,) + args, kw)
result = action([], [], self)
if isinstance(result, SCons.Errors.BuildError):
+ errstr = result.errstr
+ if result.filename:
+ errstr = result.filename + ': ' + errstr
+ import sys
+ sys.stderr.write("scons: *** %s\n" % errstr)
return result.status
else:
return result
Execute(Action(lambda target, source, env: shutil.copy('j.in', 'j.out')))
env.Execute(lambda target, source, env: shutil.copy('k.in', 'k.out'))
env.Execute(Action(lambda target, source, env: shutil.copy('l.in', 'l.out')))
+
+Execute(Copy('m.out', 'm.in'))
+Execute(Copy('nonexistent.out', 'nonexistent.in'))
""" % locals())
test.write('a.in', "a.in\n")
test.write('j.in', "j.in\n")
test.write('k.in', "k.in\n")
test.write('l.in', "l.in\n")
+test.write('m.in', "m.in\n")
+
+expect = """\
+scons: *** Error 1
+scons: *** Error 2
+scons: *** nonexistent.in: No such file or directory
+"""
-test.run(arguments = '.')
+test.run(arguments = '.', stderr=expect)
-test.fail_test(test.read('a.out') != "a.in\n")
-test.fail_test(test.read('b.out') != "b.in\n")
-test.fail_test(test.read('c.out') != "c.in\n")
-test.fail_test(test.read('d.out') != "d.in\n")
-test.fail_test(test.read('e.out') != "e.in\n")
-test.fail_test(test.read('f.out') != "f.in\n")
-test.fail_test(test.read('g.out') != "g.in\n")
-test.fail_test(test.read('h.out') != "h.in\n")
-test.fail_test(test.read('i.out') != "i.in\n")
-test.fail_test(test.read('j.out') != "j.in\n")
-test.fail_test(test.read('k.out') != "k.in\n")
-test.fail_test(test.read('l.out') != "l.in\n")
+test.must_match('a.out', "a.in\n")
+test.must_match('b.out', "b.in\n")
+test.must_match('c.out', "c.in\n")
+test.must_match('d.out', "d.in\n")
+test.must_match('e.out', "e.in\n")
+test.must_match('f.out', "f.in\n")
+test.must_match('g.out', "g.in\n")
+test.must_match('h.out', "h.in\n")
+test.must_match('i.out', "i.in\n")
+test.must_match('j.out', "j.in\n")
+test.must_match('k.out', "k.in\n")
+test.must_match('l.out', "l.in\n")
+test.must_match('m.out', "m.in\n")
test.pass_test()