diff options
author | Steven Knight <knight@baldmt.com> | 2002-01-09 01:15:41 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2002-01-09 01:15:41 (GMT) |
commit | 5daa14bb00b2c45dfd9d9587ca27687e64c542ed (patch) | |
tree | d3ca26807ab1fbbe311b2bcea297e95fcdbfe167 /src/engine/SCons/Builder.py | |
parent | 5e8c9967abc27764f333927804f5e7e4ebedffce (diff) | |
download | SCons-5daa14bb00b2c45dfd9d9587ca27687e64c542ed.zip SCons-5daa14bb00b2c45dfd9d9587ca27687e64c542ed.tar.gz SCons-5daa14bb00b2c45dfd9d9587ca27687e64c542ed.tar.bz2 |
Split Action objects into their own module.
Diffstat (limited to 'src/engine/SCons/Builder.py')
-rw-r--r-- | src/engine/SCons/Builder.py | 251 |
1 files changed, 2 insertions, 249 deletions
diff --git a/src/engine/SCons/Builder.py b/src/engine/SCons/Builder.py index 796af0a..59e8834 100644 --- a/src/engine/SCons/Builder.py +++ b/src/engine/SCons/Builder.py @@ -31,85 +31,14 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" -import os import os.path import string -import sys -import types from Errors import UserError +import SCons.Action import SCons.Node.FS import SCons.Util -exitvalmap = { - 2 : 127, - 13 : 126, -} - -if os.name == 'posix': - - def spawn(cmd, args, env): - pid = os.fork() - if not pid: - # Child process. - exitval = 127 - try: - os.execvpe(cmd, args, env) - except OSError, e: - exitval = exitvalmap[e[0]] - sys.stderr.write("scons: %s: %s\n" % (cmd, e[1])) - os._exit(exitval) - else: - # Parent process. - pid, stat = os.waitpid(pid, 0) - ret = stat >> 8 - return ret - -elif os.name == 'nt': - - def pathsearch(cmd, env): - # In order to deal with the fact that 1.5.2 doesn't have - # os.spawnvpe(), roll our own PATH search. - if os.path.isabs(cmd): - if not os.path.exists(cmd): - exts = env['PATHEXT'] - if not SCons.Util.is_List(exts): - exts = string.split(exts, os.pathsep) - for e in exts: - f = cmd + e - if os.path.exists(f): - return f - else: - path = env['PATH'] - if not SCons.Util.is_List(path): - path = string.split(path, os.pathsep) - exts = env['PATHEXT'] - if not SCons.Util.is_List(exts): - exts = string.split(exts, os.pathsep) - pairs = [] - for dir in path: - for e in exts: - pairs.append((dir, e)) - for dir, ext in pairs: - f = os.path.join(dir, cmd) - if not ext is None: - f = f + ext - if os.path.exists(f): - return f - return cmd - - def spawn(cmd, args, env): - try: - try: - ret = os.spawnvpe(os.P_WAIT, cmd, args, env) - except AttributeError: - cmd = pathsearch(cmd, env) - ret = os.spawnve(os.P_WAIT, cmd, args, env) - except OSError, e: - ret = exitvalmap[e[0]] - sys.stderr.write("scons: %s: %s\n" % (cmd, e[1])) - return ret - def Builder(**kw): @@ -136,7 +65,7 @@ class BuilderBase: node_factory = SCons.Node.FS.default_fs.File, scanner = None): self.name = name - self.action = Action(action) + self.action = SCons.Action.Action(action) self.prefix = prefix self.suffix = suffix @@ -336,179 +265,3 @@ class CompositeBuilder(BuilderBase): return reduce(lambda x, y: x + y, map(lambda b: b.src_suffixes(), self.builder_dict.values())) - -print_actions = 1; -execute_actions = 1; - -def Action(act): - """A factory for action objects.""" - if callable(act): - return FunctionAction(act) - elif SCons.Util.is_String(act): - return CommandAction(act) - elif SCons.Util.is_List(act): - return ListAction(act) - else: - return None - -class ActionBase: - """Base class for actions that create output objects. - - We currently expect Actions will only be accessible through - Builder objects, so they don't yet merit their own module.""" - def __cmp__(self, other): - return cmp(self.__dict__, other.__dict__) - - def show(self, string): - print string - - def subst_dict(self, **kw): - """Create a dictionary for substitution of construction - variables. - - This translates the following special arguments: - - env - the construction environment itself, - the values of which (CC, CCFLAGS, etc.) - are copied straight into the dictionary - - target - the target (object or array of objects), - used to generate the TARGET and TARGETS - construction variables - - source - the source (object or array of objects), - used to generate the SOURCES construction - variable - - Any other keyword arguments are copied into the - dictionary.""" - - dict = {} - if kw.has_key('env'): - dict.update(kw['env']) - del kw['env'] - - try: - cwd = kw['dir'] - except: - cwd = None - else: - del kw['dir'] - - if kw.has_key('target'): - t = kw['target'] - del kw['target'] - if not SCons.Util.is_List(t): - t = [t] - try: - cwd = t[0].cwd - except AttributeError: - pass - dict['TARGETS'] = SCons.Util.PathList(map(os.path.normpath, map(str, t))) - if dict['TARGETS']: - dict['TARGET'] = dict['TARGETS'][0] - - if kw.has_key('source'): - s = kw['source'] - del kw['source'] - if not SCons.Util.is_List(s): - s = [s] - dict['SOURCES'] = SCons.Util.PathList(map(os.path.normpath, map(str, s))) - - dict.update(kw) - - # Autogenerate necessary construction variables. - SCons.Util.autogenerate(dict, dir = cwd) - - return dict - -class CommandAction(ActionBase): - """Class for command-execution actions.""" - def __init__(self, string): - self.command = string - - def execute(self, **kw): - import SCons.Util - dict = apply(self.subst_dict, (), kw) - cmd_list = SCons.Util.scons_subst_list(self.command, dict, {}) - for cmd_line in cmd_list: - if len(cmd_line): - if print_actions: - self.show(string.join(cmd_line)) - if execute_actions: - try: - ENV = kw['env']['ENV'] - except: - import SCons.Defaults - ENV = SCons.Defaults.ConstructionEnvironment['ENV'] - ret = spawn(cmd_line[0], cmd_line, ENV) - if ret: - return ret - return 0 - - def get_contents(self, **kw): - """Return the signature contents of this action's command line. - - For signature purposes, it doesn't matter what targets or - sources we use, so long as we use the same ones every time - so the signature stays the same. We supply an array of two - of each to allow for distinction between TARGET and TARGETS. - """ - kw['target'] = ['__t1__', '__t2__'] - kw['source'] = ['__s1__', '__s2__'] - dict = apply(self.subst_dict, (), kw) - return SCons.Util.scons_subst(self.command, dict, {}) - -class FunctionAction(ActionBase): - """Class for Python function actions.""" - def __init__(self, function): - self.function = function - - def execute(self, **kw): - # if print_actions: - # XXX: WHAT SHOULD WE PRINT HERE? - if execute_actions: - if kw.has_key('target'): - if SCons.Util.is_List(kw['target']): - kw['target'] = map(str, kw['target']) - else: - kw['target'] = str(kw['target']) - if kw.has_key('source'): - kw['source'] = map(str, kw['source']) - return apply(self.function, (), kw) - - def get_contents(self, **kw): - """Return the signature contents of this callable action. - - By providing direct access to the code object of the - function, Python makes this extremely easy. Hooray! - """ - #XXX DOES NOT ACCOUNT FOR CHANGES IN ENVIRONMENT VARIABLES - #THE FUNCTION MAY USE - try: - # "self.function" is a function. - code = self.function.func_code.co_code - except: - # "self.function" is a callable object. - code = self.function.__call__.im_func.func_code.co_code - return str(code) - -class ListAction(ActionBase): - """Class for lists of other actions.""" - def __init__(self, list): - self.list = map(lambda x: Action(x), list) - - def execute(self, **kw): - for l in self.list: - r = apply(l.execute, (), kw) - if r != 0: - return r - return 0 - - def get_contents(self, **kw): - """Return the signature contents of this action list. - - Simple concatenation of the signatures of the elements. - """ - - return reduce(lambda x, y: x + str(y.get_contents()), self.list, "") |