8 # Copyright (c) 2001 Steven Knight
10 # Permission is hereby granted, free of charge, to any person obtaining
11 # a copy of this software and associated documentation files (the
12 # "Software"), to deal in the Software without restriction, including
13 # without limitation the rights to use, copy, modify, merge, publish,
14 # distribute, sublicense, and/or sell copies of the Software, and to
15 # permit persons to whom the Software is furnished to do so, subject to
16 # the following conditions:
18 # The above copyright notice and this permission notice shall be included
19 # in all copies or substantial portions of the Software.
21 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
22 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
23 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
43 """Base class for Builders, objects that create output
44 nodes (files) from input nodes (files).
47 def __init__(self, name = None,
51 node_factory = SCons.Node.FS.default_fs.File):
53 self.action = Action(action)
54 self.insuffix = input_suffix
55 self.outsuffix = output_suffix
56 self.node_factory = node_factory
57 if not self.insuffix is None and self.insuffix[0] != '.':
58 self.insuffix = '.' + self.insuffix
59 if not self.outsuffix is None and self.outsuffix[0] != '.':
60 self.outsuffix = '.' + self.outsuffix
62 def __cmp__(self, other):
63 return cmp(self.__dict__, other.__dict__)
65 def __call__(self, env, target = None, source = None):
66 tlist = SCons.Util.scons_str2nodes(target)
67 slist = SCons.Util.scons_str2nodes(source)
78 def execute(self, **kw):
79 """Execute a builder's action to create an output object.
81 return apply(self.action.execute, (), kw)
91 """A factory for action objects."""
92 if type(act) == types.StringType:
93 l = string.split(act, "\n")
97 return FunctionAction(act)
98 elif type(act) == types.StringType:
99 return CommandAction(act)
100 elif type(act) == types.ListType:
101 return ListAction(act)
106 """Base class for actions that create output objects.
108 We currently expect Actions will only be accessible through
109 Builder objects, so they don't yet merit their own module."""
110 def __cmp__(self, other):
111 return cmp(self.__dict__, other.__dict__)
113 def show(self, string):
116 class CommandAction(ActionBase):
117 """Class for command-execution actions."""
118 def __init__(self, string):
119 self.command = string
121 def execute(self, **kw):
122 cmd = self.command % kw
130 args = string.split(cmd)
134 import SCons.Defaults
135 ENV = SCons.Defaults.ENV
136 os.execvpe(args[0], args, ENV)
139 pid, stat = os.waitpid(pid, 0)
145 class FunctionAction(ActionBase):
146 """Class for Python function actions."""
147 def __init__(self, function):
148 self.function = function
150 def execute(self, **kw):
152 # XXX: WHAT SHOULD WE PRINT HERE?
154 return self.function(kw)
156 class ListAction(ActionBase):
157 """Class for lists of other actions."""
158 def __init__(self, list):
159 self.list = map(lambda x: Action(x), list)
161 def execute(self, **kw):
163 r = apply(l.execute, (), kw)