From: stevenknight Date: Tue, 11 Dec 2001 15:39:53 +0000 (+0000) Subject: Rework implicit dependency scanning for relative CPPPATH values. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=aaf7416da497d7e11d062487de2ea6cf50333921;p=scons.git Rework implicit dependency scanning for relative CPPPATH values. git-svn-id: http://scons.tigris.org/svn/scons/trunk@144 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/src/engine/SCons/Builder.py b/src/engine/SCons/Builder.py index 59d2affb..a5784059 100644 --- a/src/engine/SCons/Builder.py +++ b/src/engine/SCons/Builder.py @@ -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 diff --git a/src/engine/SCons/BuilderTests.py b/src/engine/SCons/BuilderTests.py index 31135c01..d563bb61 100644 --- a/src/engine/SCons/BuilderTests.py +++ b/src/engine/SCons/BuilderTests.py @@ -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 diff --git a/src/engine/SCons/Node/NodeTests.py b/src/engine/SCons/Node/NodeTests.py index 46cfad45..9dec623c 100644 --- a/src/engine/SCons/Node/NodeTests.py +++ b/src/engine/SCons/Node/NodeTests.py @@ -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: diff --git a/src/engine/SCons/Node/__init__.py b/src/engine/SCons/Node/__init__.py index 8ee98e73..17bf539c 100644 --- a/src/engine/SCons/Node/__init__.py +++ b/src/engine/SCons/Node/__init__.py @@ -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): diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index b8286d1f..b2850c09 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -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) diff --git a/src/engine/SCons/UtilTests.py b/src/engine/SCons/UtilTests.py index 7eadc9dc..adcd5862 100644 --- a/src/engine/SCons/UtilTests.py +++ b/src/engine/SCons/UtilTests.py @@ -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] diff --git a/test/CPPPATH.py b/test/CPPPATH.py index 30b0c226..52fbbfb8 100644 --- a/test/CPPPATH.py +++ b/test/CPPPATH.py @@ -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 +""") + +test.write('include/bar.h', +r""" +#define BAR_STRING "include/bar.h 1\n" +""") + +test.write('subdir/prog.c', +r"""#include #include -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)