Updates and slight refactor in fix
[scons.git] / test / no-global-dependencies.py
blob541a645ec0dab8d22fc9a3b1bd67b57419da1a79
1 #!/usr/bin/env python
3 # MIT License
5 # Copyright The SCons Foundation
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 """
27 Test that files are correctly located in the variant directory even when
28 Scons does not have a global view of all targets.
30 Sometimes, it might be interesting to not tell scons about every
31 targets. For example, one might not read in all the SConscipts of a
32 hierarchical build for a particular invocation of scons. This would be
33 done to speed-up a partial rebuild when the developer knows that only
34 a subset of the targets need to be rebuilt.
35 """
37 import TestSCons
39 test = TestSCons.TestSCons()
41 test.subdir('dir1')
42 test.subdir('dir2')
44 test.write('SConstruct', """\
45 opts = Variables()
46 opts.AddVariables(
47 BoolVariable('view_all_dependencies', 'View all dependencies', True),
48 BoolVariable('duplicate', 'Duplicate sources to variant dir', True)
51 _ = DefaultEnvironment(tools=[])
52 env = Environment(options=opts)
53 Export('env')
55 SConscript(dirs='.', variant_dir='build', duplicate=env['duplicate'])
56 """)
59 test.write('SConscript', """\
60 Import('env')
62 if env['view_all_dependencies']:
63 SConscript(dirs='dir1')
65 SConscript(dirs='dir2')
66 """)
68 test.write('dir1/SConscript', """\
69 Import('env')
71 env.Command('x.cpp', '', Touch('$TARGET'))
73 env.Object(env.File('x.cpp'))
74 """)
76 test.write('dir2/SConscript', """\
77 Import('env')
79 env.Object(env.File('#/build/dir1/x.cpp'))
80 """)
82 test.must_not_exist('build/dir1/x.cpp')
85 ############################################################
87 # Test without duplication
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."])
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."])
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')
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."])
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."])
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."])
119 # Clean-up everything.
120 test.run(arguments='duplicate=False view_all_dependencies=True -c .')
121 test.must_not_exist('build/dir1/x.cpp')
124 ############################################################
126 # Test with duplication
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.
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."])
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."])
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')
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."])
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."])
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."])
163 # # Clean-up everything.
164 # test.run(arguments='duplicate=True view_all_dependencies=True -c .')
165 # test.must_not_exist('build/dir1/x.cpp')
168 test.pass_test()
170 # Local Variables:
171 # tab-width:4
172 # indent-tabs-mode:nil
173 # End:
174 # vim: set expandtab tabstop=4 shiftwidth=4: