Merged revisions 2647-2719 via svnmerge from
[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 string
39
40 import TestSCons
41
42 test = TestSCons.TestSCons()
43
44 test.subdir('dir1')
45 test.subdir('dir2')
46
47 test.write('SConstruct', """\
48 opts = Options()
49 opts.AddOptions(
50     BoolOption('view_all_dependencies', 'View all dependencies', True),
51     BoolOption('duplicate', 'Duplicate sources to variant dir', True)
52 )
53
54 env = Environment(options=opts)
55 Export('env')
56
57 SConscript(dirs='.', variant_dir='build', duplicate=env['duplicate'])
58 """ % locals())
59
60
61 test.write('SConscript', """\
62 Import('env')
63
64 if env['view_all_dependencies']:
65     SConscript(dirs='dir1')
66
67 SConscript(dirs='dir2')
68 """ % locals())
69
70 test.write('dir1/SConscript', """\
71 Import('env')
72
73 env.Command('x.cpp', '', Touch('$TARGET'))
74
75 env.Object(env.File('x.cpp'))
76 """ % locals())
77
78 test.write('dir2/SConscript', """\
79 Import('env')
80
81 env.Object(env.File('#/build/dir1/x.cpp'))
82 """ % locals())
83
84 test.must_not_exist('build/dir1/x.cpp')
85
86
87 ############################################################
88 #
89 # Test without duplication
90 #
91
92 # Build everything first.
93 test.run(arguments = 'duplicate=False view_all_dependencies=True .')
94 test.must_exist('build/dir1/x.cpp')
95 test.fail_test(string.find(test.stdout(), "`.' is up to date.") != -1)
96
97 # Double check that targets are not rebuilt.
98 test.run(arguments = 'duplicate=False view_all_dependencies=True .')
99 test.must_exist('build/dir1/x.cpp')
100 test.fail_test(string.find(test.stdout(), "`.' is up to date.") == -1)
101
102 # Clean-up only the object file
103 test.run(arguments = 'duplicate=False view_all_dependencies=False -c .')
104 test.must_exist('build/dir1/x.cpp')
105
106 # Rebuild the only object file without seeing all the dependencies.
107 test.run(arguments = 'duplicate=False view_all_dependencies=False .')
108 test.must_exist('build/dir1/x.cpp')
109 test.fail_test(string.find(test.stdout(), "`.' is up to date.") != -1)
110
111 # Double check that targets are not rebuilt without and with all the
112 # dependencies.
113 test.run(arguments = 'duplicate=False view_all_dependencies=False .')
114 test.must_exist('build/dir1/x.cpp')
115 test.fail_test(string.find(test.stdout(), "`.' is up to date.") == -1)
116
117 test.run(arguments = 'duplicate=False view_all_dependencies=True .')
118 test.must_exist('build/dir1/x.cpp')
119 test.fail_test(string.find(test.stdout(), "`.' is up to date.") == -1)
120
121 # Clean-up everything.
122 test.run(arguments = 'duplicate=False view_all_dependencies=True -c .')
123 test.must_not_exist('build/dir1/x.cpp')
124
125
126 ############################################################
127 #
128 # Test with duplication
129 #
130 # FIXME: This can not work for now because there is no way that SCons
131 # can differentiate between a source that no longer exists and a file
132 # that has a builder that scons does not know about because scons has
133 # not parsed all the SConscript of a given project.
134 #
135
136 # # Build everything first.
137 # test.run(arguments = 'duplicate=True view_all_dependencies=True .')
138 # test.must_exist('build/dir1/x.cpp')
139 # test.fail_test(string.find(test.stdout(), "`.' is up to date.") != -1)
140
141 # # Double check that targets are not rebuilt.
142 # test.run(arguments = 'duplicate=True view_all_dependencies=True .')
143 # test.must_exist('build/dir1/x.cpp')
144 # test.fail_test(string.find(test.stdout(), "`.' is up to date.") == -1)
145
146 # # Clean-up only the object file
147 # test.run(arguments = 'duplicate=True view_all_dependencies=False -c .')
148 # test.must_exist('build/dir1/x.cpp')
149
150 # # Rebuild the only object file without seeing all the dependencies.
151 # test.run(arguments = 'duplicate=True view_all_dependencies=False .')
152 # test.must_exist('build/dir1/x.cpp')
153 # test.fail_test(string.find(test.stdout(), "`.' is up to date.") != -1)
154
155 # # Double check that targets are not rebuilt without and with all the
156 # # dependencies.
157 # test.run(arguments = 'duplicate=True view_all_dependencies=False .')
158 # test.must_exist('build/dir1/x.cpp')
159 # test.fail_test(string.find(test.stdout(), "`.' is up to date.") == -1)
160
161 # test.run(arguments = 'duplicate=True view_all_dependencies=True .')
162 # test.must_exist('build/dir1/x.cpp')
163 # test.fail_test(string.find(test.stdout(), "`.' is up to date.") == -1)
164
165 # # Clean-up everything.
166 # test.run(arguments = 'duplicate=True view_all_dependencies=True -c .')
167 # test.must_not_exist('build/dir1/x.cpp')
168
169
170 test.pass_test()