Tool('msvc')(env)
.EE
+.IP PRINT_CMD_LINE_FUNC
+A Python function used to print the command lines as they are executed
+(assuming command printing is not disabled by the
+.B -q
+or
+.B -s
+options or their equivalents).
+The function should take four arguments:
+.IR s ,
+the command being executed (a string),
+.IR target ,
+the target being built (file node, list, or string name(s)),
+.IR source ,
+the source(s) used (file node, list, or string name(s)), and
+.IR env ,
+the environment being used.
+
+The function must do the printing itself. The default implementation,
+used if this variable is not set or is None, is:
+.ES
+def print_cmd_line(s, target, source, env):
+ sys.stdout.write(s + "\n")
+.EE
+
+Here's an example of a more interesting function:
+.ES
+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')
+.EE
+
+This just prints "Building <targetname> from <sourcename>..." instead
+of the actual commands.
+Such a function could also log the actual commands to a log file,
+for example.
+
.IP PROGPREFIX
The prefix used for executable file names.
- Add ParseConfig() support for the -framework GNU linker option.
+ - Add a PRINT_CMD_LINE_FUNC construction variable to allow people
+ to filter (or log) command-line output.
+
From Kevin Quick:
- Fix the Builder name returned from ListBuilders and other instances
def __cmp__(self, other):
return cmp(self.__dict__, other.__dict__)
+ def print_cmd_line(self, s, target, source, env):
+ sys.stdout.write(s + "\n")
+
def __call__(self, target, source, env,
errfunc=None,
presub=_null,
if show and self.strfunction:
s = self.strfunction(target, source, env)
if s:
- sys.stdout.write(s + '\n')
+ try:
+ get = env.get
+ except AttributeError:
+ print_func = self.print_cmd_line
+ else:
+ print_func = get('PRINT_CMD_LINE_FUNC')
+ if not print_func:
+ print_func = self.print_cmd_line
+ print_func(s, target, source, env)
if execute:
stat = self.execute(target, source, env)
if stat and errfunc:
self.d[item] = value
def has_key(self, item):
return self.d.has_key(item)
- def get(self, key, value):
+ def get(self, key, value=None):
return self.d.get(key, value)
def items(self):
return self.d.items()
assert a1 != a3
assert a2 != a3
+ def test_print_cmd_lines(self):
+ """Test the print_cmd_lines() method
+ """
+ save_stdout = sys.stdout
+
+ try:
+ def execfunc(target, source, env):
+ pass
+ a = SCons.Action.Action(execfunc)
+
+ sio = StringIO.StringIO()
+ sys.stdout = sio
+ a.print_cmd_line("foo bar", None, None, None)
+ s = sio.getvalue()
+ assert s == "foo bar\n", s
+
+ finally:
+ sys.stdout = save_stdout
+
def test___call__(self):
"""Test calling an Action
"""
assert result == 7, result
assert errfunc_result == [7], errfunc_result
+ result = []
+ def my_print_cmd_line(s, target, source, env, result=result):
+ result.append(s)
+ env['PRINT_CMD_LINE_FUNC'] = my_print_cmd_line
+ a("output", "input", env)
+ assert result == ['execfunc(["output"], ["input"])'], result
+
+
finally:
sys.stdout = save_stdout
SCons.Action.print_actions = save_print_actions
return self.d.has_key(item)
def keys(self):
return self.d.keys()
- def get(self, key, value):
+ def get(self, key, value=None):
return self.d.get(key, value)
def Override(self, overrides):
env = apply(Environment, (), self.d)
--- /dev/null
+#!/usr/bin/env python
+#
+# __COPYRIGHT__
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+"""
+Test the PRINT_CMD_LINE_FUNC construction variable.
+"""
+
+import sys
+import TestCmd
+import TestSCons
+
+test = TestSCons.TestSCons(match = TestCmd.match_re)
+
+
+test.write('SConstruct', r"""
+import sys
+def print_cmd_line(s, target, source, env):
+ sys.stdout.write("BUILDING %s from %s with %s\n"%
+ (str(target[0]), str(source[0]), s))
+
+e = Environment(PRINT_CMD_LINE_FUNC=print_cmd_line)
+e.Program(target = 'prog', source = 'prog.c')
+""")
+
+test.write('prog.c', r"""
+int main(int argc, char *argv[]) { return 0; }
+""")
+
+test.run(arguments = '-Q .', stdout = """\
+BUILDING prog.o from prog.c with .*
+BUILDING prog from prog.o with .*
+""")
+
+test.run(arguments = '-c .')
+
+# Just make sure it doesn't blow up when PRINT_CMD_LINE_FUNC
+# is explicity initialized to None.
+test.write('SConstruct', r"""
+e = Environment(PRINT_CMD_LINE_FUNC=None)
+e.Program(target = 'prog', source = 'prog.c')
+""")
+
+test.run(arguments = '-Q .')
+
+test.pass_test()