Added fix for TeX includes with same name as subdirs.
[scons.git] / test / no-global-dependencies.py
1 #!/usr/bin/env python
2 #
3 # __COPYRIGHT__
4 #
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:
12 #
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
15 #
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.
23 #
24
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
26
27 """
28 Test that files are correctly located in the variant directory even when
29 Scons does not have a global view of all targets.
30
31 Sometimes, it might be interesting to not tell scons about every
32 targets. For example, one might not read in all the SConscipts of a
33 hierarchical build for a particular invocation of scons. This would be
34 done to speed-up a partial rebuild when the developer knows that only
35 a subset of the targets need to be rebuilt.
36 """
37
38 import TestSCons
39
40 test = TestSCons.TestSCons()
41
42 test.subdir('dir1')
43 test.subdir('dir2')
44
45 test.write('SConstruct', """\
46 opts = Variables()
47 opts.AddVariables(
48     BoolVariable('view_all_dependencies', 'View all dependencies', True),
49     BoolVariable('duplicate', 'Duplicate sources to variant dir', True)
50 )
51
52 env = Environment(options=opts)
53 Export('env')
54
55 SConscript(dirs='.', variant_dir='build', duplicate=env['duplicate'])
56 """ % locals())
57
58
59 test.write('SConscript', """\
60 Import('env')
61
62 if env['view_all_dependencies']:
63     SConscript(dirs='dir1')
64
65 SConscript(dirs='dir2')
66 """ % locals())
67
68 test.write('dir1/SConscript', """\
69 Import('env')
70
71 env.Command('x.cpp', '', Touch('$TARGET'))
72
73 env.Object(env.File('x.cpp'))
74 """ % locals())
75
76 test.write('dir2/SConscript', """\
77 Import('env')
78
79 env.Object(env.File('#/build/dir1/x.cpp'))
80 """ % locals())
81
82 test.must_not_exist('build/dir1/x.cpp')
83
84
85 ############################################################
86 #
87 # Test without duplication
88 #
89
90 # Build everything first.
91 test.run(arguments = 'duplicate=False view_all_dependencies=True .')
92 test.must_exist('build/dir1/x.cpp')
93 test.must_not_contain_any_line(test.stdout(), ["`.' is up to date."])
94
95 # Double check that targets are not rebuilt.
96 test.run(arguments = 'duplicate=False view_all_dependencies=True .')
97 test.must_exist('build/dir1/x.cpp')
98 test.must_contain_all_lines(test.stdout(), ["`.' is up to date."])
99
100 # Clean-up only the object file
101 test.run(arguments = 'duplicate=False view_all_dependencies=False -c .')
102 test.must_exist('build/dir1/x.cpp')
103
104 # Rebuild the only object file without seeing all the dependencies.
105 test.run(arguments = 'duplicate=False view_all_dependencies=False .')
106 test.must_exist('build/dir1/x.cpp')
107 test.must_not_contain_any_line(test.stdout(), ["`.' is up to date."])
108
109 # Double check that targets are not rebuilt without and with all the
110 # dependencies.
111 test.run(arguments = 'duplicate=False view_all_dependencies=False .')
112 test.must_exist('build/dir1/x.cpp')
113 test.must_contain_all_lines(test.stdout(), ["`.' is up to date."])
114
115 test.run(arguments = 'duplicate=False view_all_dependencies=True .')
116 test.must_exist('build/dir1/x.cpp')
117 test.must_contain_all_lines(test.stdout(), ["`.' is up to date."])
118
119 # Clean-up everything.
120 test.run(arguments = 'duplicate=False view_all_dependencies=True -c .')
121 test.must_not_exist('build/dir1/x.cpp')
122
123
124 ############################################################
125 #
126 # Test with duplication
127 #
128 # FIXME: This can not work for now because there is no way that SCons
129 # can differentiate between a source that no longer exists and a file
130 # that has a builder that scons does not know about because scons has
131 # not parsed all the SConscript of a given project.
132 #
133
134 # # Build everything first.
135 # test.run(arguments = 'duplicate=True view_all_dependencies=True .')
136 # test.must_exist('build/dir1/x.cpp')
137 # test.must_not_contain_any_line(test.stdout(), ["`.' is up to date."])
138
139 # # Double check that targets are not rebuilt.
140 # test.run(arguments = 'duplicate=True view_all_dependencies=True .')
141 # test.must_exist('build/dir1/x.cpp')
142 # test.must_contain_all_lines(test.stdout(), ["`.' is up to date."])
143
144 # # Clean-up only the object file
145 # test.run(arguments = 'duplicate=True view_all_dependencies=False -c .')
146 # test.must_exist('build/dir1/x.cpp')
147
148 # # Rebuild the only object file without seeing all the dependencies.
149 # test.run(arguments = 'duplicate=True view_all_dependencies=False .')
150 # test.must_exist('build/dir1/x.cpp')
151 # test.must_not_contain_any_line(test.stdout(), ["`.' is up to date."])
152
153 # # Double check that targets are not rebuilt without and with all the
154 # # dependencies.
155 # test.run(arguments = 'duplicate=True view_all_dependencies=False .')
156 # test.must_exist('build/dir1/x.cpp')
157 # test.must_contain_all_lines(test.stdout(), ["`.' is up to date."])
158
159 # test.run(arguments = 'duplicate=True view_all_dependencies=True .')
160 # test.must_exist('build/dir1/x.cpp')
161 # test.must_contain_all_lines(test.stdout(), ["`.' is up to date."])
162
163 # # Clean-up everything.
164 # test.run(arguments = 'duplicate=True view_all_dependencies=True -c .')
165 # test.must_not_exist('build/dir1/x.cpp')
166
167
168 test.pass_test()
169
170 # Local Variables:
171 # tab-width:4
172 # indent-tabs-mode:nil
173 # End:
174 # vim: set expandtab tabstop=4 shiftwidth=4: