diff options
author | Steven Knight <knight@baldmt.com> | 2002-03-08 06:01:39 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2002-03-08 06:01:39 (GMT) |
commit | bd1384bd791e94dd5191f50d92850e857a987d08 (patch) | |
tree | 7349dc7549b054db7f64250233718c2bbc7cce03 /src | |
parent | 232ea1169c24b803d0c90e3cdb277e356b2eb087 (diff) | |
download | SCons-bd1384bd791e94dd5191f50d92850e857a987d08.zip SCons-bd1384bd791e94dd5191f50d92850e857a987d08.tar.gz SCons-bd1384bd791e94dd5191f50d92850e857a987d08.tar.bz2 |
Changes to the CommandGenerator functionality. (Charles Crain)
Diffstat (limited to 'src')
-rw-r--r-- | src/engine/SCons/Action.py | 25 | ||||
-rw-r--r-- | src/engine/SCons/ActionTests.py | 18 | ||||
-rw-r--r-- | src/engine/SCons/Script/SConscript.py | 1 |
3 files changed, 37 insertions, 7 deletions
diff --git a/src/engine/SCons/Action.py b/src/engine/SCons/Action.py index 7bee082..26595d6 100644 --- a/src/engine/SCons/Action.py +++ b/src/engine/SCons/Action.py @@ -163,6 +163,10 @@ def SetCommandHandler(func): global spawn spawn = func +def GetCommandHandler(): + global spawn + return spawn + class CommandGenerator: """ Wrappes a command generator function so the Action() factory @@ -264,8 +268,8 @@ class CommandAction(ActionBase): self.command = string def execute(self, **kw): - import SCons.Util dict = apply(self.subst_dict, (), kw) + import SCons.Util cmd_list = SCons.Util.scons_subst_list(self.command, dict, {}, _rm) for cmd_line in cmd_list: if len(cmd_line): @@ -324,10 +328,23 @@ class CommandGeneratorAction(ActionBase): if kw.has_key("target") and not SCons.Util.is_List(kw["target"]): kw["target"] = [kw["target"]] - cmd_list = apply(self.generator, (), kw) + gen_list = apply(self.generator, (), kw) + gen_list = map(lambda x: map(str, x), gen_list) - cmd_list = map(lambda x: map(str, x), cmd_list) - for cmd_line in cmd_list: + # Do environment variable substitution on returned command list + dict = apply(self.subst_dict, (), kw) + cmd_list = [ ] + for gen_line in gen_list: + cmd_list.append([]) + curr_line = cmd_list[-1] + for gen_arg in gen_line: + arg_list = SCons.Util.scons_subst_list(gen_arg, dict, {}) + curr_line.extend(arg_list[0]) + if(len(arg_list) > 1): + cmd_list.extend(arg_list[1:]) + curr_line = cmd_list[-1] + + for cmd_line in filter(lambda x: x, cmd_list): if print_actions: self.show(cmd_line) if execute_actions: diff --git a/src/engine/SCons/ActionTests.py b/src/engine/SCons/ActionTests.py index 461da6e..592fa82 100644 --- a/src/engine/SCons/ActionTests.py +++ b/src/engine/SCons/ActionTests.py @@ -156,14 +156,26 @@ class CommandGeneratorActionTestCase(unittest.TestCase): """Test executing a command generator Action """ - def f(dummy, self=self): + def f(dummy, env, self=self): self.dummy = dummy - return [[""]] + return [["$FOO"]] + def ch(cmd, args, env, self=self): + self.cmd.append(cmd) + self.args.append(args) a = SCons.Action.CommandGeneratorAction(f) self.dummy = 0 - a.execute(dummy=1) + old_hdl = SCons.Action.GetCommandHandler() + self.cmd = [] + self.args = [] + try: + SCons.Action.SetCommandHandler(ch) + a.execute(dummy=1, env={ 'FOO' : 'foo baz\nbar ack' }) + finally: + SCons.Action.SetCommandHandler(old_hdl) assert self.dummy == 1 + assert self.cmd == [ 'foo', 'bar'], self.cmd + assert self.args == [ [ 'foo', 'baz' ], [ 'bar', 'ack' ] ], self.args del self.dummy def test_get_contents(self): diff --git a/src/engine/SCons/Script/SConscript.py b/src/engine/SCons/Script/SConscript.py index 7210bed..d50f521 100644 --- a/src/engine/SCons/Script/SConscript.py +++ b/src/engine/SCons/Script/SConscript.py @@ -189,4 +189,5 @@ def BuildDefaultGlobals(): globals['Scanner'] = SCons.Scanner.Base globals['SConscript'] = SConscript globals['SetCommandHandler'] = SCons.Action.SetCommandHandler + globals['GetCommandHandler'] = SCons.Action.GetCommandHandler return globals |