Rework implicit dependency scanning for relative CPPPATH values.
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Tue, 11 Dec 2001 15:39:53 +0000 (15:39 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Tue, 11 Dec 2001 15:39:53 +0000 (15:39 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@144 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/engine/SCons/Builder.py
src/engine/SCons/BuilderTests.py
src/engine/SCons/Node/NodeTests.py
src/engine/SCons/Node/__init__.py
src/engine/SCons/Util.py
src/engine/SCons/UtilTests.py
test/CPPPATH.py

index 59d2affb2ec6685383a7db61c8d3865f1f18c9e3..a5784059576a8dd6204723eda3de22c3d2d927e0 100644 (file)
@@ -180,6 +180,7 @@ class BuilderBase:
                                 self.node_factory)
 
        for t in tlist:
+            t.cwd = SCons.Node.FS.default_fs.cwd       # XXX
            t.builder_set(self)
            t.env_set(env)
            t.add_source(slist)
@@ -347,14 +348,26 @@ class ActionBase:
             dict.update(kw['env'])
             del kw['env']
 
+        try:
+            cwd = kw['dir']
+        except:
+            cwd = None
+        else:
+            del kw['dir']
+
         if kw.has_key('target'):
             t = kw['target']
             del kw['target']
-            if not type(t) is types.ListType:
+            if not type(t) is types.ListType and not isinstance(t, UserList):
                 t = [t]
+            try:
+                cwd = t[0].cwd
+            except AttributeError:
+                pass
             dict['TARGETS'] = PathList(map(os.path.normpath, map(str, t)))
-           if dict['TARGETS']:
+            if dict['TARGETS']:
                 dict['TARGET'] = dict['TARGETS'][0]
+
         if kw.has_key('source'):
             s = kw['source']
             del kw['source']
@@ -365,7 +378,7 @@ class ActionBase:
         dict.update(kw)
 
         # Autogenerate necessary construction variables.
-        autogenerate(dict)
+        autogenerate(dict, dir = cwd)
 
         return dict
 
index 31135c01fef0d3543123abd8fd0e2c6a4ba224d8..d563bb6161a9f5aed93a3ecbb4edf6e893887d64 100644 (file)
@@ -276,16 +276,27 @@ class BuilderTestCase(unittest.TestCase):
         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
+        kw = {'LIBS'          : ['l1', 'l2'],
+              'LIBLINKPREFIX' : '-l',
+              'LIBLINKSUFFIX' : '',
+              'LIBPATH'       : ['lib'],
+              'LIBDIRPREFIX'  : '-L',
+              'LIBDIRSUFFIX'  : '/',
+              'CPPPATH'       : ['c', 'p'],
+              'INCPREFIX'     : '-I',
+              'INCSUFFIX'     : ''}
+
+        contents = apply(b4.get_contents, (), kw)
+        assert contents == "-ll1 -ll2 -Llib/ -Ic -Ip", contents
+
+        # SCons.Node.FS has been imported by our import of
+        # SCons.Node.Builder.  It's kind of bogus that we don't
+        # import this ourselves before using it this way, but it's
+        # maybe a little cleaner than tying these tests directly
+        # to the other module via a direct import.
+        kw['dir'] = SCons.Node.FS.default_fs.Dir('d')
+        contents = apply(b4.get_contents, (), kw)
+        assert contents == "-ld/l1 -ld/l2 -Ld/lib/ -Id/c -Id/p", contents
 
     def test_name(self):
        """Test Builder creation with a specified name
index 46cfad457b365603bfc5278fcb2ec33128988814..9dec623c00c5011c0e35dc0215f620e21a074496 100644 (file)
@@ -44,7 +44,7 @@ class Builder:
         built_target = kw['target']
         built_source = kw['source']
         return 0
-    def get_contents(self, env):
+    def get_contents(self, env, dir):
         return 7
 
 class FailBuilder:
index 8ee98e737b99163a74865b29c6aeee376e42ea3e..17bf539c12136789cfb2cf553c0f48a1ef1ad2f7 100644 (file)
@@ -95,7 +95,11 @@ class Node:
                 self.node = node
             def get_contents(self):
                 env = self.node.env.Dictionary()
-                return self.node.builder.get_contents(env = env)
+                try:
+                    dir = self.node.cwd
+                except AttributeError:
+                    dir = None
+                return self.node.builder.get_contents(env = env, dir = dir)
         return Adapter(self)
 
     def scanner_set(self, scanner):
index b8286d1f4fe48432be2acd1fbb8c5de015dbfc64..b2850c09ab34157d08f3c7539dddee636278d4bd 100644 (file)
@@ -257,8 +257,6 @@ def find_files(filenames, paths,
 
 
 
-# See the documentation for the __autogenerate() method
-# for an explanation of this variable...
 AUTO_GEN_VARS = ( ( '_LIBFLAGS',
                     'LIBS',
                     'LIBLINKPREFIX',
@@ -272,7 +270,7 @@ AUTO_GEN_VARS = ( ( '_LIBFLAGS',
                     'INCPREFIX',
                     'INCSUFFIX' ) )
 
-def autogenerate(dict):
+def autogenerate(dict, fs = SCons.Node.FS.default_fs, dir = None):
     """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,
@@ -290,15 +288,16 @@ def autogenerate(dict):
     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 = []
+        if not dict.has_key(strSrc):
+            dict[strVarAuto] = ''
+            continue
+                
+        src = dict[strSrc]
+        if not type(src) is types.ListType and not isinstance(src, UserList):
+            src = [ src ]
+        src = map(lambda x, fs=fs, d=dir: \
+                  fs.Dir(str(x), directory = d).path,
+                  src)
 
         try:
             prefix = str(dict[strPref])
@@ -312,4 +311,4 @@ def autogenerate(dict):
 
         dict[strVarAuto] = map(lambda x, suff=suffix, pref=prefix: \
                                pref + os.path.normpath(str(x)) + suff,
-                               src_var)
+                               src)
index 7eadc9dcb551ab4f21aef39e7d2f6ff54110d0d3..adcd58628b6ce96673345fe37ff0a9a562cebbc8 100644 (file)
@@ -191,13 +191,13 @@ class UtilTestCase(unittest.TestCase):
         dict = {'CPPPATH'   : [ 'foo', 'bar', 'baz' ],
                 'INCPREFIX' : 'foo',
                 'INCSUFFIX' : 'bar'}
-        autogenerate(dict)
+        autogenerate(dict, dir = SCons.Node.FS.default_fs.Dir('/xx'))
         assert len(dict['_INCFLAGS']) == 3, dict('_INCFLAGS')
-        assert dict['_INCFLAGS'][0] == 'foofoobar', \
+        assert dict['_INCFLAGS'][0] == 'foo/xx/foobar', \
                dict['_INCFLAGS'][0]
-        assert dict['_INCFLAGS'][1] == 'foobarbar', \
+        assert dict['_INCFLAGS'][1] == 'foo/xx/barbar', \
                dict['_INCFLAGS'][1]
-        assert dict['_INCFLAGS'][2] == 'foobazbar', \
+        assert dict['_INCFLAGS'][2] == 'foo/xx/bazbar', \
                dict['_INCFLAGS'][2]
         
         
index 30b0c226c66102864596af7cbb643b86a3e4b867..52fbbfb8159888e5a5359ea06e3d68adac261361 100644 (file)
@@ -24,6 +24,7 @@
 
 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
+import os
 import sys
 import TestSCons
 
@@ -33,70 +34,108 @@ else:
     _exe = ''
 
 prog = 'prog' + _exe
+subdir_prog = os.path.join('subdir', 'prog' + _exe)
+
+args = prog + ' ' + subdir_prog
 
 test = TestSCons.TestSCons()
 
-test.write('foo.c',
-"""#include "foo.h"
+test.subdir('include', 'subdir', ['subdir', 'include'])
+
+test.write('SConstruct', """
+env = Environment(CPPPATH = ['include'])
+obj = env.Object(target='prog', source='subdir/prog.c')
+env.Program(target='prog', source=obj)
+SConscript('subdir/SConscript')
+""")
+
+test.write(['subdir', 'SConscript'], """
+env.Program(target='prog', source='prog.c')
+""")
+
+test.write('include/foo.h',
+r"""
+#define        FOO_STRING "include/foo.h 1\n"
+#include <bar.h>
+""")
+
+test.write('include/bar.h',
+r"""
+#define BAR_STRING "include/bar.h 1\n"
+""")
+
+test.write('subdir/prog.c',
+r"""#include <foo.h>
 #include <stdio.h>
 
-int main(void)
+int
+main(int argc, char *argv[])
 {
+    argv[argc++] = "--";
+    printf("subdir/prog.c\n");
     printf(FOO_STRING);
     printf(BAR_STRING);
     return 0;
 }
 """)
 
-test.subdir('include')
-
-test.write('include/foo.h',
+test.write('subdir/include/foo.h',
 r"""
-#define        FOO_STRING "foo.h 1\n"
+#define        FOO_STRING "subdir/include/foo.h 1\n"
 #include "bar.h"
 """)
 
-test.write('include/bar.h',
+test.write('subdir/include/bar.h',
 r"""
-#define BAR_STRING "bar.h 1\n"
+#define BAR_STRING "subdir/include/bar.h 1\n"
 """)
 
-test.write('SConstruct', """
-env = Environment(CPPPATH = ['include'])
-env.Program(target='prog', source='foo.c')
-""")
 
-test.run(arguments = prog)
+
+test.run(arguments = args, stderr = None)
 
 test.run(program = test.workpath(prog),
-         stdout = "foo.h 1\nbar.h 1\n")
+         stdout = "subdir/prog.c\ninclude/foo.h 1\ninclude/bar.h 1\n")
+
+test.run(program = test.workpath(subdir_prog),
+         stdout = "subdir/prog.c\nsubdir/include/foo.h 1\nsubdir/include/bar.h 1\n")
+
+test.up_to_date(arguments = args)
+
 
-test.up_to_date(arguments = prog)
 
 test.unlink('include/foo.h')
 test.write('include/foo.h',
 r"""
-#define        FOO_STRING "foo.h 2\n"
+#define        FOO_STRING "include/foo.h 2\n"
 #include "bar.h"
 """)
 
-test.run(arguments = prog)
+test.run(arguments = args)
 
 test.run(program = test.workpath(prog),
-         stdout = "foo.h 2\nbar.h 1\n")
+         stdout = "subdir/prog.c\ninclude/foo.h 2\ninclude/bar.h 1\n")
+
+test.run(program = test.workpath(subdir_prog),
+         stdout = "subdir/prog.c\nsubdir/include/foo.h 1\nsubdir/include/bar.h 1\n")
+
+test.up_to_date(arguments = args)
+
 
-test.up_to_date(arguments = prog)
 
 test.unlink('include/bar.h')
 test.write('include/bar.h',
 r"""
-#define BAR_STRING "bar.h 2\n"
+#define BAR_STRING "include/bar.h 2\n"
 """)
 
 test.run(arguments = prog)
 
 test.run(program = test.workpath(prog),
-         stdout = "foo.h 2\nbar.h 2\n")
+         stdout = "subdir/prog.c\ninclude/foo.h 2\ninclude/bar.h 2\n")
+
+test.run(program = test.workpath(subdir_prog),
+         stdout = "subdir/prog.c\nsubdir/include/foo.h 1\nsubdir/include/bar.h 1\n")
 
 test.up_to_date(arguments = prog)