Fix inconsistency in Builder handling of src_suffix and extensions. (Kevin Quick)
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Wed, 22 Sep 2004 00:08:28 +0000 (00:08 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Wed, 22 Sep 2004 00:08:28 +0000 (00:08 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@1094 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/CHANGES.txt
src/engine/SCons/Builder.py
src/engine/SCons/BuilderTests.py

index 71c03dc0fc84392d8c23bfd7ded3308e544abc20..cb61513c542651ab48c1ebc743fce4eaa9dce96c 100644 (file)
@@ -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
index c1c7b495a6cd3b1b6608c0ec959ad23614e54d2c..7a96aeddb336cd27ffc04c728f677c9f42867a31 100644 (file)
@@ -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):
index 9c5b3e518f908eeb7c6a8f38608ba208474a3e8a..53a5628401a87939cfd621b800955c6266fa3639 100644 (file)
@@ -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