Move autogeneration of PATH-based variables from Environment initialization to variab...
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Tue, 11 Dec 2001 04:32:16 +0000 (04:32 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Tue, 11 Dec 2001 04:32:16 +0000 (04:32 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@138 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/engine/SCons/Builder.py
src/engine/SCons/BuilderTests.py
src/engine/SCons/Environment.py
src/engine/SCons/EnvironmentTests.py
src/engine/SCons/Util.py
src/engine/SCons/UtilTests.py

index 60aafb1051e84bc230b5e9abdde831f794f196bc..59d2affb2ec6685383a7db61c8d3865f1f18c9e3 100644 (file)
@@ -34,7 +34,7 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 import os
 import os.path
 import SCons.Node.FS
-from SCons.Util import PathList, scons_str2nodes, scons_subst, scons_subst_list
+from SCons.Util import PathList, scons_str2nodes, scons_subst, scons_subst_list, autogenerate
 import string
 import types
 from UserList import UserList
@@ -364,6 +364,9 @@ class ActionBase:
 
         dict.update(kw)
 
+        # Autogenerate necessary construction variables.
+        autogenerate(dict)
+
         return dict
 
 class CommandAction(ActionBase):
index fd55f03af24907cf9e87e3774647e75d556babe9..31135c01fef0d3543123abd8fd0e2c6a4ba224d8 100644 (file)
@@ -275,6 +275,18 @@ class BuilderTestCase(unittest.TestCase):
         contents = b3.get_contents()
         assert contents == "foo\177\036\000\177\037\000d\000\000Sbar", repr(contents)
 
+        b4 = SCons.Builder.Builder(action = "$_LIBFLAGS $_LIBDIRFLAGS $_INCFLAGS")
+        contents = b4.get_contents(LIBS = ['foo', 'bar'],
+                                   LIBLINKPREFIX = '-l',
+                                   LIBLINKSUFFIX = '',
+                                   LIBPATH = ['lib'],
+                                   LIBDIRPREFIX = '-L',
+                                   LIBDIRSUFFIX = '/',
+                                   CPPPATH = ['c', 'p'],
+                                   INCPREFIX = '-I',
+                                   INCSUFFIX = '')
+        assert contents == "-lfoo -lbar -Llib/ -Ic -Ip", contents
+
     def test_name(self):
        """Test Builder creation with a specified name
        """
index f85f72380edf6d312e78082b111c4a982a8bbb2a..b93a3dd2ecd65ee4afb48ac1b1a2eba4501c4748 100644 (file)
@@ -73,21 +73,6 @@ class Environment:
     Environment.
     """
 
-    # See the documentation for the __autogenerate() method
-    # for an explanation of this variable...
-    AUTO_GEN_VARS = ( ( '_LIBFLAGS',
-                        'LIBS',
-                        'LIBLINKPREFIX',
-                        'LIBLINKSUFFIX' ),
-                      ( '_LIBDIRFLAGS',
-                        'LIBPATH',
-                        'LIBDIRPREFIX',
-                        'LIBDIRSUFFIX' ),
-                      ( '_INCFLAGS',
-                        'CPPPATH',
-                        'INCPREFIX',
-                        'INCSUFFIX' ) )
-
     def __init__(self, **kw):
        import SCons.Defaults
        self._dict = copy.deepcopy(SCons.Defaults.ConstructionEnvironment)
@@ -96,7 +81,6 @@ class Environment:
         if kw.has_key('SCANNERS') and type(kw['SCANNERS']) != type([]):
                 kw['SCANNERS'] = [kw['SCANNERS']]
        self._dict.update(copy.deepcopy(kw))
-        self.__autogenerate()
 
        class BuilderWrapper:
            """Wrapper class that allows an environment to
@@ -126,48 +110,6 @@ class Environment:
         for s in self._dict['SCANNERS']:
             setattr(self, s.name, s)
 
-    def __autogenerate(self):
-        """Autogenerate the "interpolated" environment variables.
-        We read a static structure that tells us how.  AUTO_GEN_VARS
-        is a tuple of tuples.  Each inner tuple has four elements,
-        each strings referring to an environment variable, and describing
-        how to autogenerate a particular variable.  The elements are:
-
-        0 - The variable to generate
-        1 - The "source" variable, usually a list
-        2 - The "prefix" variable
-        3 - The "suffix" variable
-
-        The autogenerated variable is a list, consisting of every
-        element of the source list, or a single element if the source
-        is a string, with the prefix and suffix
-        concatenated."""
-
-        for strVarAuto, strSrc, strPref, strSuff, in self.AUTO_GEN_VARS:
-            if self._dict.has_key(strSrc):
-                src_var = self._dict[strSrc]
-                if type(src_var) is types.ListType or \
-                   isinstance(src_var, UserList):
-                    src_var = map(str, src_var)
-                else:
-                    src_var = [ str(src_var), ]
-            else:
-                src_var = []
-
-            try:
-                prefix = str(self._dict[strPref])
-            except KeyError:
-                prefix=''
-
-            try:
-                suffix = str(self._dict[strSuff])
-            except KeyError:
-                suffix =''
-
-            self._dict[strVarAuto] = map(lambda x, suff=suffix, pref=prefix: \
-                                         pref + os.path.normpath(str(x)) + suff,
-                                         src_var)
-
     def __cmp__(self, other):
        return cmp(self._dict, other._dict)
 
@@ -194,7 +136,6 @@ class Environment:
        construction variables and/or values.
        """
        self._dict.update(copy.deepcopy(kw))
-        self.__autogenerate()
 
     def        Depends(self, target, dependency):
        """Explicity specify that 'target's depend on 'dependency'."""
index 82b19bef268487f2de79575e7f7c08abb5b8d47b..af9ccb73bf50b4e9bad409577b432e662c1cf59b 100644 (file)
@@ -262,30 +262,7 @@ class EnvironmentTestCase(unittest.TestCase):
        str = env.subst("$AAA ${AAA}A ${AAA}B $BBB")
        assert str == "c c", str
 
-    def test_autogenerate(self):
-        """Test autogenerated environment variables."""
-        env = Environment(LIBS = [ 'foo', 'bar', 'baz' ],
-                          LIBLINKPREFIX = 'foo',
-                          LIBLINKSUFFIX = 'bar')
-        assert len(env.Dictionary('_LIBFLAGS')) == 3, env.Dictionary('_LIBFLAGS')
-        assert env.Dictionary('_LIBFLAGS')[0] == 'foofoobar', \
-               env.Dictionary('_LIBFLAGS')[0]
-        assert env.Dictionary('_LIBFLAGS')[1] == 'foobarbar', \
-               env.Dictionary('_LIBFLAGS')[1]
-        assert env.Dictionary('_LIBFLAGS')[2] == 'foobazbar', \
-               env.Dictionary('_LIBFLAGS')[2]
-
-        env = Environment(CPPPATH = [ 'foo', 'bar', 'baz' ],
-                          INCPREFIX = 'foo',
-                          INCSUFFIX = 'bar')
-        assert len(env.Dictionary('_INCFLAGS')) == 3, env.Dictionary('_INCFLAGS')
-        assert env.Dictionary('_INCFLAGS')[0] == 'foofoobar', \
-               env.Dictionary('_INCFLAGS')[0]
-        assert env.Dictionary('_INCFLAGS')[1] == 'foobarbar', \
-               env.Dictionary('_INCFLAGS')[1]
-        assert env.Dictionary('_INCFLAGS')[2] == 'foobazbar', \
-               env.Dictionary('_INCFLAGS')[2]
-        
+
 
 if __name__ == "__main__":
     suite = unittest.makeSuite(EnvironmentTestCase, 'test_')
index 9108f1465e3651ecd8e4b890a9be311d4b0cbd7a..b8286d1f4fe48432be2acd1fbb8c5de015dbfc64 100644 (file)
@@ -254,3 +254,62 @@ def find_files(filenames, paths,
                 pass
 
     return nodes
+
+
+
+# See the documentation for the __autogenerate() method
+# for an explanation of this variable...
+AUTO_GEN_VARS = ( ( '_LIBFLAGS',
+                    'LIBS',
+                    'LIBLINKPREFIX',
+                    'LIBLINKSUFFIX' ),
+                  ( '_LIBDIRFLAGS',
+                    'LIBPATH',
+                    'LIBDIRPREFIX',
+                    'LIBDIRSUFFIX' ),
+                  ( '_INCFLAGS',
+                    'CPPPATH',
+                    'INCPREFIX',
+                    'INCSUFFIX' ) )
+
+def autogenerate(dict):
+    """Autogenerate the "interpolated" environment variables.
+    We read a static structure that tells us how.  AUTO_GEN_VARS
+    is a tuple of tuples.  Each inner tuple has four elements,
+    each strings referring to an environment variable, and describing
+    how to autogenerate a particular variable.  The elements are:
+
+    0 - The variable to generate
+    1 - The "source" variable, usually a list
+    2 - The "prefix" variable
+    3 - The "suffix" variable
+
+    The autogenerated variable is a list, consisting of every
+    element of the source list, or a single element if the source
+    is a string, with the prefix and suffix
+    concatenated."""
+
+    for strVarAuto, strSrc, strPref, strSuff, in AUTO_GEN_VARS:
+        if dict.has_key(strSrc):
+            src_var = dict[strSrc]
+            if type(src_var) is types.ListType or \
+               isinstance(src_var, UserList):
+                src_var = map(str, src_var)
+            else:
+                src_var = [ str(src_var), ]
+        else:
+            src_var = []
+
+        try:
+            prefix = str(dict[strPref])
+        except KeyError:
+            prefix=''
+
+        try:
+            suffix = str(dict[strSuff])
+        except KeyError:
+            suffix =''
+
+        dict[strVarAuto] = map(lambda x, suff=suffix, pref=prefix: \
+                               pref + os.path.normpath(str(x)) + suff,
+                               src_var)
index 58e81b5fc676111534ae36bc7bfd281993bb39f6..7eadc9dcb551ab4f21aef39e7d2f6ff54110d0d3 100644 (file)
@@ -173,6 +173,32 @@ class UtilTestCase(unittest.TestCase):
         file_names = map(os.path.normpath, file_names)
         assert os.path.normpath('./foo') in file_names, file_names
         assert os.path.normpath('./bar/baz') in file_names, file_names
+
+    def test_autogenerate(dict):
+        """Test autogenerating variables in a dictionary."""
+        dict = {'LIBS'          : [ 'foo', 'bar', 'baz' ],
+                'LIBLINKPREFIX' : 'foo',
+                'LIBLINKSUFFIX' : 'bar'}
+        autogenerate(dict)
+        assert len(dict['_LIBFLAGS']) == 3, dict('_LIBFLAGS')
+        assert dict['_LIBFLAGS'][0] == 'foofoobar', \
+               dict['_LIBFLAGS'][0]
+        assert dict['_LIBFLAGS'][1] == 'foobarbar', \
+               dict['_LIBFLAGS'][1]
+        assert dict['_LIBFLAGS'][2] == 'foobazbar', \
+               dict['_LIBFLAGS'][2]
+
+        dict = {'CPPPATH'   : [ 'foo', 'bar', 'baz' ],
+                'INCPREFIX' : 'foo',
+                'INCSUFFIX' : 'bar'}
+        autogenerate(dict)
+        assert len(dict['_INCFLAGS']) == 3, dict('_INCFLAGS')
+        assert dict['_INCFLAGS'][0] == 'foofoobar', \
+               dict['_INCFLAGS'][0]
+        assert dict['_INCFLAGS'][1] == 'foobarbar', \
+               dict['_INCFLAGS'][1]
+        assert dict['_INCFLAGS'][2] == 'foobazbar', \
+               dict['_INCFLAGS'][2]
         
         
 if __name__ == "__main__":