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 ')))
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):
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):
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):
# 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]
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):
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):
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
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