summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2004-04-03 06:23:15 (GMT)
committerSteven Knight <knight@baldmt.com>2004-04-03 06:23:15 (GMT)
commit30d6dfd79594a041ebbeaf8e77ca8407488f202e (patch)
tree80c8e99d84d5ff5c1fbbc02a3b1538cd6e87d5bd
parenta4262fb3471ddc34f8fe3a7f6589b66ed98bfb4e (diff)
downloadSCons-30d6dfd79594a041ebbeaf8e77ca8407488f202e.zip
SCons-30d6dfd79594a041ebbeaf8e77ca8407488f202e.tar.gz
SCons-30d6dfd79594a041ebbeaf8e77ca8407488f202e.tar.bz2
Make the new --debug=presub option work for LazyCommandGenerators. (Gary Oberbrunner)
-rw-r--r--src/engine/SCons/Action.py27
-rw-r--r--src/engine/SCons/ActionTests.py53
2 files changed, 72 insertions, 8 deletions
diff --git a/src/engine/SCons/Action.py b/src/engine/SCons/Action.py
index c3ee84a..f7024d3 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 e81af0f..5672dac 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