def __cmp__(self, other):
return cmp(self.__dict__, other.__dict__)
- def splitext(self, path):
+ def splitext(self, path, env=None):
+ if not env:
+ env = self.env
+ if env:
+ matchsuf = filter(lambda S,path=path: path[-len(S):] == S,
+ self.src_suffixes(env))
+ if matchsuf:
+ suf = max(map(None, map(len, matchsuf), matchsuf))[1]
+ return [path[:-len(suf)], path[-len(suf):]]
return SCons.Util.splitext(path)
def _create_nodes(self, env, overwarn, target = None, source = None):
t_from_s = slist[0].target_from_source
except AttributeError:
raise UserError("Do not know how to create a target from source `%s'" % slist[0])
- tlist = [ t_from_s(pre, suf, self.splitext) ]
+ splitext = lambda S,self=self,env=env: self.splitext(S,env)
+ tlist = [ t_from_s(pre, suf, splitext) ]
else:
target = _adjustixes(target, pre, suf)
tlist = env.arg2nodes(target, self.target_factory)
src_suffixes = self.src_suffixes(env)
for snode in slist:
- try:
- get_suffix = snode.get_suffix
- except AttributeError:
- ext = self.splitext(str(snode))
- else:
- ext = get_suffix()
- try:
- subsidiary_builder = sdict[ext]
- except KeyError:
+ for srcsuf in src_suffixes:
+ if str(snode)[-len(srcsuf):] == srcsuf and sdict.has_key(srcsuf):
+ tgt = sdict[srcsuf]._execute(env, None, snode, overwarn)
+ # If the subsidiary Builder returned more than one target,
+ # then filter out any sources that this Builder isn't
+ # capable of building.
+ if len(tgt) > 1:
+ tgt = filter(lambda x, self=self, suf=src_suffixes, e=env:
+ self.splitext(SCons.Util.to_String(x),e)[1] in suf,
+ tgt)
+ final_sources.extend(tgt)
+ snode = None
+ break
+ if snode:
final_sources.append(snode)
- else:
- tgt = subsidiary_builder._execute(env, None, snode, overwarn)
- # If the subsidiary Builder returned more than one target,
- # then filter out any sources that this Builder isn't
- # capable of building.
- if len(tgt) > 1:
- tgt = filter(lambda x, self=self, suf=src_suffixes:
- self.splitext(SCons.Util.to_String(x))[1] in suf,
- tgt)
- final_sources.extend(tgt)
-
+
return BuilderBase._execute(self, env, target, final_sources, overwarn)
def get_src_builders(self, env):
b5 = SCons.Builder.Builder(action = { '.y' : ''})
assert b5.src_suffixes(env) == ['.y'], b5.src_suffixes(env)
+ def test_srcsuffix_nonext(self):
+ "Test target generation from non-extension source suffixes"
+ env = Environment()
+ b6 = SCons.Builder.Builder(action = '',
+ src_suffix='_src.a',
+ suffix='.b')
+ tgt = b6(env, source='foo_src.a')
+ assert str(tgt[0]) == 'foo.b', str(tgt[0])
+
+ b7 = SCons.Builder.Builder(action = '',
+ src_suffix='_source.a',
+ suffix='_obj.b')
+ b8 = SCons.Builder.Builder(action = '',
+ src_builder=b7,
+ suffix='.c')
+ tgt = b8(env, source='foo_source.a')
+ assert str(tgt[0]) == 'foo_obj.c', str(tgt[0])
+ src = SCons.Node.FS.default_fs.File('foo_source.a')
+ tgt = b8(env, source=src)
+ assert str(tgt[0]) == 'foo_obj.c', str(tgt[0])
+
+ b9 = SCons.Builder.Builder(action={'_src.a' : 'srcaction'},
+ suffix='.c')
+ b9.add_action('_altsrc.b', 'altaction')
+ tgt = b9(env, source='foo_altsrc.b')
+ assert str(tgt[0]) == 'foo.c', str(tgt[0])
+
def test_suffix(self):
"""Test Builder creation with a specified target suffix