From 8ded7e2d688da06366496840b390ef1f1cf3dadb Mon Sep 17 00:00:00 2001 From: stevenknight Date: Wed, 22 Sep 2004 00:08:28 +0000 Subject: [PATCH] Fix inconsistency in Builder handling of src_suffix and extensions. (Kevin Quick) git-svn-id: http://scons.tigris.org/svn/scons/trunk@1094 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- src/CHANGES.txt | 3 ++ src/engine/SCons/Builder.py | 48 +++++++++++++++++--------------- src/engine/SCons/BuilderTests.py | 27 ++++++++++++++++++ 3 files changed, 56 insertions(+), 22 deletions(-) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 71c03dc0..cb61513c 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -137,6 +137,9 @@ RELEASE 0.97 - XXX - Better test infrastructure for -c output. + - Fix handling of src_suffix values that aren't extensions (don't + begin with a '.'). + From Christoph Wiedemann: - Add an Environment.SetDefault() method that only sets values if diff --git a/src/engine/SCons/Builder.py b/src/engine/SCons/Builder.py index c1c7b495..7a96aedd 100644 --- a/src/engine/SCons/Builder.py +++ b/src/engine/SCons/Builder.py @@ -467,7 +467,15 @@ class BuilderBase: 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): @@ -503,7 +511,8 @@ class BuilderBase: 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) @@ -708,27 +717,22 @@ class MultiStepBuilder(BuilderBase): 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): diff --git a/src/engine/SCons/BuilderTests.py b/src/engine/SCons/BuilderTests.py index 9c5b3e51..53a56284 100644 --- a/src/engine/SCons/BuilderTests.py +++ b/src/engine/SCons/BuilderTests.py @@ -484,6 +484,33 @@ class BuilderTestCase(unittest.TestCase): 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 -- 2.26.2