diff options
author | Steven Knight <knight@baldmt.com> | 2004-09-05 12:01:20 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2004-09-05 12:01:20 (GMT) |
commit | 1091ca56e75ed39820081d4cca289c241c7fbceb (patch) | |
tree | 143f770f6476c5398894e67deca44309283dfc67 /src | |
parent | 39ce0b2ef56813cd5abfbe9fac579ebd28b0f4b1 (diff) | |
download | SCons-1091ca56e75ed39820081d4cca289c241c7fbceb.zip SCons-1091ca56e75ed39820081d4cca289c241c7fbceb.tar.gz SCons-1091ca56e75ed39820081d4cca289c241c7fbceb.tar.bz2 |
Add a configurable function for command-line printing. (Gary Oberbrunner)
Diffstat (limited to 'src')
-rw-r--r-- | src/CHANGES.txt | 3 | ||||
-rw-r--r-- | src/engine/SCons/Action.py | 13 | ||||
-rw-r--r-- | src/engine/SCons/ActionTests.py | 29 | ||||
-rw-r--r-- | src/engine/SCons/BuilderTests.py | 2 |
4 files changed, 44 insertions, 3 deletions
diff --git a/src/CHANGES.txt b/src/CHANGES.txt index ad69907..eec33a5 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -38,6 +38,9 @@ RELEASE 0.97 - XXX - 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 diff --git a/src/engine/SCons/Action.py b/src/engine/SCons/Action.py index ec6a3b0..2cd23f4 100644 --- a/src/engine/SCons/Action.py +++ b/src/engine/SCons/Action.py @@ -218,6 +218,9 @@ class ActionBase: 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, @@ -238,7 +241,15 @@ class ActionBase: 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: diff --git a/src/engine/SCons/ActionTests.py b/src/engine/SCons/ActionTests.py index fa2bfe7..c6201e2 100644 --- a/src/engine/SCons/ActionTests.py +++ b/src/engine/SCons/ActionTests.py @@ -139,7 +139,7 @@ class Environment: 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() @@ -350,6 +350,25 @@ class ActionBaseTestCase(unittest.TestCase): 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 """ @@ -438,6 +457,14 @@ class ActionBaseTestCase(unittest.TestCase): 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 diff --git a/src/engine/SCons/BuilderTests.py b/src/engine/SCons/BuilderTests.py index bbff627..d7d7747 100644 --- a/src/engine/SCons/BuilderTests.py +++ b/src/engine/SCons/BuilderTests.py @@ -107,7 +107,7 @@ class Environment: 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) |