diff options
author | Steven Knight <knight@baldmt.com> | 2005-02-01 12:02:12 +0000 |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2005-02-01 12:02:12 +0000 |
commit | ef79870bf32839c16d2e46e971388663f5cc2352 (patch) | |
tree | 9db62ee7c1d6eb561b0ae64f0c4e93d21f19ab5e /src/engine/SCons/Action.py | |
parent | 09599aef30df7b9abedd8311187b10efd3f57c7d (diff) | |
download | scons-ef79870bf32839c16d2e46e971388663f5cc2352.tar.gz |
Reduce the number of actions created by caching generated LazyActions.
Diffstat (limited to 'src/engine/SCons/Action.py')
-rw-r--r-- | src/engine/SCons/Action.py | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/src/engine/SCons/Action.py b/src/engine/SCons/Action.py index a3b62eb9..fa8f1d25 100644 --- a/src/engine/SCons/Action.py +++ b/src/engine/SCons/Action.py @@ -232,7 +232,7 @@ class ActionBase: def presub_lines(self, env): # CommandGeneratorAction needs a real environment # in order to return the proper string here, since - # it may call LazyCmdGenerator, which looks up a key + # it may call LazyAction, 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. @@ -482,9 +482,9 @@ class CommandGeneratorAction(ActionBase): """ return self._generate(target, source, env, 1).get_contents(target, source, env) -# Ooh, polymorphism -- pretty scary, eh, kids? -# -# A LazyCmdAction is a kind of hybrid generator and command action for + + +# A LazyAction is a kind of hybrid generator and command action for # strings of the form "$VAR". These strings normally expand to other # strings (think "$CCCOM" to "$CC -c -o $TARGET $SOURCE"), but we also # want to be able to replace them with functions in the construction @@ -498,10 +498,13 @@ class CommandGeneratorAction(ActionBase): # the corresponding CommandAction method to do the heavy lifting. # If not, then we call the same-named CommandGeneratorAction method. # The CommandGeneratorAction methods work by using the overridden -# _generate() method, uses our own way of handling "generation" of an -# action based on what's in the construction variable. +# _generate() method, that is, our own way of handling "generation" of +# an action based on what's in the construction variable. class LazyAction(CommandGeneratorAction, CommandAction): + + __metaclass__ = SCons.Memoize.Memoized_Metaclass + def __init__(self, var, *args, **kw): if __debug__: logInstanceCreation(self) apply(CommandAction.__init__, (self, '$'+var)+args, kw) @@ -514,13 +517,17 @@ class LazyAction(CommandGeneratorAction, CommandAction): return CommandAction return CommandGeneratorAction - def _generate(self, target, source, env, for_signature): + def _generate_cache(self, env): + """__cacheable__""" c = env.get(self.var, '') gen_cmd = apply(Action, (c,), self.gen_kw) if not gen_cmd: raise SCons.Errors.UserError("$%s value %s cannot be used to create an Action." % (self.var, repr(c))) return gen_cmd + def _generate(self, target, source, env, for_signature): + return self._generate_cache(env) + def __call__(self, target, source, env, *args, **kw): args = (self, target, source, env) + args c = self.get_parent_class(env) @@ -530,6 +537,15 @@ class LazyAction(CommandGeneratorAction, CommandAction): c = self.get_parent_class(env) return c.get_contents(self, target, source, env) +if not SCons.Memoize.has_metaclass: + _Base = LazyAction + class LazyAction(SCons.Memoize.Memoizer, _Base): + def __init__(self, *args, **kw): + SCons.Memoize.Memoizer.__init__(self) + apply(_Base.__init__, (self,)+args, kw) + + + class FunctionAction(_ActionAction): """Class for Python function actions.""" |