From: stevenknight Date: Sat, 3 Apr 2004 06:23:15 +0000 (+0000) Subject: Make the new --debug=presub option work for LazyCommandGenerators. (Gary Oberbrunner) X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=88c3bf35fb387e52e24eb9dc59087d3dc8e34cd5;p=scons.git Make the new --debug=presub option work for LazyCommandGenerators. (Gary Oberbrunner) git-svn-id: http://scons.tigris.org/svn/scons/trunk@942 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/src/engine/SCons/Action.py b/src/engine/SCons/Action.py index c3ee84a2..f7024d34 100644 --- a/src/engine/SCons/Action.py +++ b/src/engine/SCons/Action.py @@ -198,11 +198,19 @@ class ActionBase: if print_actions: sys.stdout.write(s + '\n') - def presub(self, target): + def presub(self, target, env): if print_actions_presub: if not SCons.Util.is_List(target): target = [target] + # CommandGeneratorAction needs a real environment + # in order to return the proper string here, since + # it may call LazyCmdGenerator, which looks up a key + # in that env. So we temporarily remember the env here, + # and CommandGeneratorAction will use this env + # when it calls its __generate method. + self.presub_env = env lines = string.split(str(self), '\n') + self.presub_env = None # don't need this any more sys.stdout.write("Building %s with action(s):\n %s\n"% (string.join(map(lambda x: str(x), target), ' and '), string.join(lines, '\n '))) @@ -327,7 +335,7 @@ class CommandAction(ActionBase): return 0 def __call__(self, target, source, env): - self.presub(target) + self.presub(target, env) return self._execute(target, source, env) def get_contents(self, target, source, env, dict=None): @@ -369,7 +377,11 @@ class CommandGeneratorAction(ActionBase): return act.strfunction(target, rsources, env) def __str__(self): - act = self.__generate([], [], {}, 0) + try: + env = self.presub_env or {} + except AttributeError: + env = {} + act = self.__generate([], [], env, 0) return str(act) def _execute(self, target, source, env): @@ -384,7 +396,7 @@ class CommandGeneratorAction(ActionBase): source = [source] rsources = map(rfile, source) act = self.__generate(target, source, env, 0) - act.presub(target) + act.presub(target, env) return act._execute(target, source, env) def get_contents(self, target, source, env, dict=None): @@ -412,6 +424,9 @@ class LazyCmdGenerator: # The variable reference substitutes to nothing. return '' + def __str__(self): + return 'LazyCmdGenerator: %s'%str(self.var) + def _execute(self, target, source, env, for_signature): try: return env[self.var] @@ -472,7 +487,7 @@ class FunctionAction(ActionBase): return r def __call__(self, target, source, env): - self.presub(target) + self.presub(target, env) return self._execute(target, source, env) def get_contents(self, target, source, env, dict=None): @@ -523,7 +538,7 @@ class ListAction(ActionBase): return 0 def __call__(self, target, source, env): - self.presub(target) + self.presub(target, env) return self._execute(target, source, env) def get_contents(self, target, source, env, dict=None): diff --git a/src/engine/SCons/ActionTests.py b/src/engine/SCons/ActionTests.py index e81af0f0..5672dac5 100644 --- a/src/engine/SCons/ActionTests.py +++ b/src/engine/SCons/ActionTests.py @@ -291,10 +291,11 @@ class ActionBaseTestCase(unittest.TestCase): try: a = SCons.Action.Action("x") + env = Environment() sio = StringIO.StringIO() sys.stdout = sio - a.presub("xyzzy") + a.presub("xyzzy", env) s = sio.getvalue() assert s == "", s @@ -302,10 +303,58 @@ class ActionBaseTestCase(unittest.TestCase): sio = StringIO.StringIO() sys.stdout = sio - a.presub("foobar") + a.presub("foobar", env) s = sio.getvalue() assert s == "Building foobar with action(s):\n x\n", s + a = SCons.Action.Action(["y", "z"]) + + sio = StringIO.StringIO() + sys.stdout = sio + a.presub("foobar", env) + s = sio.getvalue() + assert s == "Building foobar with action(s):\n y\n z\n", s + + def func(): + pass + a = SCons.Action.Action(func) + + sio = StringIO.StringIO() + sys.stdout = sio + a.presub("foobar", env) + s = sio.getvalue() + assert s == "Building foobar with action(s):\n func(env, target, source)\n", s + + def gen(target, source, env, for_signature): + return 'generat' + env.get('GEN', 'or') + a = SCons.Action.Action(SCons.Action.CommandGenerator(gen)) + + sio = StringIO.StringIO() + sys.stdout = sio + a.presub("foobar", env) + s = sio.getvalue() + assert s == "Building foobar with action(s):\n generator\n", s + + sio = StringIO.StringIO() + sys.stdout = sio + a.presub("foobar", Environment(GEN = 'ed')) + s = sio.getvalue() + assert s == "Building foobar with action(s):\n generated\n", s + + a = SCons.Action.Action("$ACT") + + sio = StringIO.StringIO() + sys.stdout = sio + a.presub("foobar", env) + s = sio.getvalue() + assert s == "Building foobar with action(s):\n \n", s + + sio = StringIO.StringIO() + sys.stdout = sio + a.presub("foobar", Environment(ACT = 'expanded action')) + s = sio.getvalue() + assert s == "Building foobar with action(s):\n expanded action\n", s + finally: SCons.Action.print_actions_presub = save_print_actions_presub sys.stdout = save_stdout