5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
31 if sys.platform == 'win32':
37 subdir_prog = os.path.join('subdir', 'prog' + _exe)
38 variant_prog = os.path.join('variant', 'prog' + _exe)
40 args = prog + ' ' + subdir_prog + ' ' + variant_prog
42 test = TestSCons.TestSCons()
44 test.subdir('include', 'subdir', ['subdir', 'include'], 'inc2')
46 test.write('SConstruct', """
47 env = Environment(CPPPATH = ['$FOO'],
49 obj = env.Object(target='foobar/prog', source='subdir/prog.c')
50 env.Program(target='prog', source=obj)
51 SConscript('subdir/SConscript', "env")
53 BuildDir('variant', 'subdir', 0)
54 include = Dir('include')
55 env = Environment(CPPPATH=[include])
56 SConscript('variant/SConscript', "env")
59 test.write(['subdir', 'SConscript'],
62 env.Program(target='prog', source='prog.c')
65 test.write(['include', 'foo.h'],
67 #define FOO_STRING "include/foo.h 1\n"
71 test.write(['include', 'bar.h'],
73 #define BAR_STRING "include/bar.h 1\n"
76 test.write(['subdir', 'prog.c'],
82 main(int argc, char *argv[])
85 printf("subdir/prog.c\n");
92 test.write(['subdir', 'include', 'foo.h'],
94 #define FOO_STRING "subdir/include/foo.h 1\n"
98 test.write(['subdir', 'include', 'bar.h'],
100 #define BAR_STRING "subdir/include/bar.h 1\n"
105 test.run(arguments = args)
107 test.run(program = test.workpath(prog),
108 stdout = "subdir/prog.c\ninclude/foo.h 1\ninclude/bar.h 1\n")
110 test.run(program = test.workpath(subdir_prog),
111 stdout = "subdir/prog.c\nsubdir/include/foo.h 1\nsubdir/include/bar.h 1\n")
113 test.run(program = test.workpath(variant_prog),
114 stdout = "subdir/prog.c\ninclude/foo.h 1\ninclude/bar.h 1\n")
116 # Make sure we didn't duplicate the source file in the variant subdirectory.
117 test.fail_test(os.path.exists(test.workpath('variant', 'prog.c')))
119 test.up_to_date(arguments = args)
121 test.write(['include', 'foo.h'],
123 #define FOO_STRING "include/foo.h 2\n"
127 test.run(arguments = args)
129 test.run(program = test.workpath(prog),
130 stdout = "subdir/prog.c\ninclude/foo.h 2\ninclude/bar.h 1\n")
132 test.run(program = test.workpath(subdir_prog),
133 stdout = "subdir/prog.c\nsubdir/include/foo.h 1\nsubdir/include/bar.h 1\n")
135 test.run(program = test.workpath(variant_prog),
136 stdout = "subdir/prog.c\ninclude/foo.h 2\ninclude/bar.h 1\n")
138 # Make sure we didn't duplicate the source file in the variant subdirectory.
139 test.fail_test(os.path.exists(test.workpath('variant', 'prog.c')))
141 test.up_to_date(arguments = args)
144 test.write(['include', 'bar.h'],
146 #define BAR_STRING "include/bar.h 2\n"
149 test.run(arguments = args)
151 test.run(program = test.workpath(prog),
152 stdout = "subdir/prog.c\ninclude/foo.h 2\ninclude/bar.h 2\n")
154 test.run(program = test.workpath(subdir_prog),
155 stdout = "subdir/prog.c\nsubdir/include/foo.h 1\nsubdir/include/bar.h 1\n")
157 test.run(program = test.workpath(variant_prog),
158 stdout = "subdir/prog.c\ninclude/foo.h 2\ninclude/bar.h 2\n")
160 # Make sure we didn't duplicate the source file in the variant subdirectory.
161 test.fail_test(os.path.exists(test.workpath('variant', 'prog.c')))
163 test.up_to_date(arguments = args)
165 # Change CPPPATH and make sure we don't rebuild because of it.
166 test.write('SConstruct', """
167 env = Environment(CPPPATH = Split('inc2 include'))
168 obj = env.Object(target='foobar/prog', source='subdir/prog.c')
169 env.Program(target='prog', source=obj)
170 SConscript('subdir/SConscript', "env")
172 BuildDir('variant', 'subdir', 0)
173 include = Dir('include')
174 env = Environment(CPPPATH=['inc2', include])
175 SConscript('variant/SConscript', "env")
178 test.up_to_date(arguments = args)
181 test.write(['inc2', 'foo.h'],
183 #define FOO_STRING "inc2/foo.h 1\n"
187 test.run(arguments = args)
189 test.run(program = test.workpath(prog),
190 stdout = "subdir/prog.c\ninc2/foo.h 1\ninclude/bar.h 2\n")
192 test.run(program = test.workpath(subdir_prog),
193 stdout = "subdir/prog.c\nsubdir/include/foo.h 1\nsubdir/include/bar.h 1\n")
195 test.run(program = test.workpath(variant_prog),
196 stdout = "subdir/prog.c\ninclude/foo.h 2\ninclude/bar.h 2\n")
198 test.up_to_date(arguments = args)
200 # Check that a null-string CPPPATH doesn't blow up.
201 test.write('SConstruct', """
202 env = Environment(CPPPATH = '')
203 env.Library('foo', source = '')
206 test.run(arguments = '.')