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.
27 1) that we don't build files when we use the -n, --no-exec,
28 --just-print, --dry-run, and --recon options;
29 2) that we don't remove built files when -n is used in
31 3) that files installed by the Install() method don't get
32 installed when -n is used;
33 4) that source files don't get duplicated in a VariantDir
35 5) that Configure calls don't build any files. If a file
36 needs to be built (i.e. is not up-to-date), a ConfigureError
40 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
50 _python_ = TestSCons._python_
52 test = TestSCons.TestSCons()
54 test.subdir('build', 'src')
56 test.write('build.py', r"""
58 file = open(sys.argv[1], 'wb')
59 file.write("build.py: %s\n" % sys.argv[1])
63 test.write('SConstruct', """
64 MyBuild = Builder(action = r'%(_python_)s build.py $TARGETS')
65 env = Environment(BUILDERS = { 'MyBuild' : MyBuild })
67 env.MyBuild(target = 'f1.out', source = 'f1.in')
68 env.MyBuild(target = 'f2.out', source = 'f2.in')
69 env.Install('install', 'f3.in')
70 VariantDir('build', 'src', duplicate=1)
71 SConscript('build/SConscript', "env")
74 test.write(['src', 'SConscript'], """
76 env.MyBuild(target = 'f4.out', source = 'f4.in')
79 test.write('f1.in', "f1.in\n")
80 test.write('f2.in', "f2.in\n")
81 test.write('f3.in', "f3.in\n")
82 test.write(['src', 'f4.in'], "src/f4.in\n")
84 args = 'f1.out f2.out'
85 expect = test.wrap_stdout("""\
86 %(_python_)s build.py f1.out
87 %(_python_)s build.py f2.out
90 test.run(arguments = args, stdout = expect)
91 test.fail_test(not os.path.exists(test.workpath('f1.out')))
92 test.fail_test(not os.path.exists(test.workpath('f2.out')))
97 test.run(arguments = '-n ' + args, stdout = expect)
98 test.fail_test(os.path.exists(test.workpath('f1.out')))
99 test.fail_test(os.path.exists(test.workpath('f2.out')))
101 test.run(arguments = '--no-exec ' + args, stdout = expect)
102 test.fail_test(os.path.exists(test.workpath('f1.out')))
103 test.fail_test(os.path.exists(test.workpath('f2.out')))
105 test.run(arguments = '--just-print ' + args, stdout = expect)
106 test.fail_test(os.path.exists(test.workpath('f1.out')))
107 test.fail_test(os.path.exists(test.workpath('f2.out')))
109 test.run(arguments = '--dry-run ' + args, stdout = expect)
110 test.fail_test(os.path.exists(test.workpath('f1.out')))
111 test.fail_test(os.path.exists(test.workpath('f2.out')))
113 test.run(arguments = '--recon ' + args, stdout = expect)
114 test.fail_test(os.path.exists(test.workpath('f1.out')))
115 test.fail_test(os.path.exists(test.workpath('f2.out')))
117 test.run(arguments = args)
118 test.fail_test(not os.path.exists(test.workpath('f1.out')))
120 # Test that SCons does not write a modified .sconsign when -n is used.
121 expect = test.wrap_stdout("""\
122 %(_python_)s build.py f1.out
124 test.unlink('.sconsign.dblite')
125 test.write('f1.out', "X1.out\n")
126 test.run(arguments = '-n f1.out', stdout = expect)
127 test.run(arguments = '-n f1.out', stdout = expect)
129 expect = test.wrap_stdout("Removed f1.out\nRemoved f2.out\n", cleaning=1)
131 test.run(arguments = '-n -c ' + args, stdout = expect)
133 test.run(arguments = '-c -n ' + args, stdout = expect)
135 test.fail_test(not os.path.exists(test.workpath('f1.out')))
136 test.fail_test(not os.path.exists(test.workpath('f2.out')))
139 install_f3_in = os.path.join('install', 'f3.in')
140 expect = test.wrap_stdout('Install file: "f3.in" as "%s"\n' % install_f3_in)
142 test.run(arguments = '-n install', stdout = expect)
143 test.fail_test(os.path.exists(test.workpath('install', 'f3.in')))
145 test.run(arguments = 'install', stdout = expect)
146 test.fail_test(not os.path.exists(test.workpath('install', 'f3.in')))
148 test.write('f3.in', "f3.in again\n")
150 test.run(arguments = '-n install', stdout = expect)
151 test.fail_test(not os.path.exists(test.workpath('install', 'f3.in')))
153 # Make sure duplicate source files in a VariantDir aren't created
154 # when the -n option is used.
156 # First, make sure none of the previous non-dryrun invocations caused
157 # the build directory to be populated. Processing of the
158 # src/SConscript (actually build/SConscript) will reference f4.in as a
159 # source, causing a Node object to be built for "build/f4.in".
160 # Creating the node won't cause "build/f4.in" to be created from
161 # "src/f4.in", but that *is* a side-effect of calling the exists()
162 # method on that node, which may happen via other processing.
163 # Therefore add this conditional removal to ensure a clean setting
164 # before running this test.
166 if os.path.exists(test.workpath('build', 'f4.in')):
167 test.unlink(test.workpath('build', 'f4.in'))
169 test.run(arguments = '-n build')
170 test.fail_test(os.path.exists(test.workpath('build', 'f4.in')))
172 # test Configure-calls in conjunction with -n
173 test.subdir('configure')
174 test.match_func = TestCmd.match_re_dotall
175 test.write('configure/SConstruct',
176 """def CustomTest(context):
177 def userAction(target,source,env):
179 shutil.copyfile( str(source[0]), str(target[0]))
180 def strAction(target,source,env):
181 return "cp " + str(source[0]) + " " + str(target[0])
182 context.Message("Executing Custom Test ... " )
183 (ok, msg) = context.TryAction(Action(userAction,strAction),
184 "Hello World", ".in")
189 conf = Configure( env,
190 custom_tests={'CustomTest':CustomTest},
191 conf_dir="config.test",
192 log_file="config.log" )
193 if not conf.CustomTest():
198 # test that conf_dir isn't created and an error is raised
200 scons: \*\*\* Cannot create configure directory "config\.test" within a dry-run\.
201 File \S+, line \S+, in \S+
203 test.run(arguments="-n",stderr=stderr,status=2,
204 chdir=test.workpath("configure"))
205 test.fail_test(os.path.exists(test.workpath("configure", "config.test")))
206 test.fail_test(os.path.exists(test.workpath("configure", "config.log")))
208 # test that targets are not built, if conf_dir exists.
209 # verify that .cache and config.log are not created.
210 # an error should be raised
212 scons: \*\*\* Cannot update configure test "%s" within a dry-run\.
213 File \S+, line \S+, in \S+
214 """ % re.escape(os.path.join("config.test", "conftest_0.in"))
215 test.subdir(['configure','config.test'])
216 test.run(arguments="-n",stderr=stderr,status=2,
217 chdir=test.workpath("configure"))
218 test.fail_test(os.path.exists(test.workpath("configure", "config.test",
220 test.fail_test(os.path.exists(test.workpath("configure", "config.test",
222 test.fail_test(os.path.exists(test.workpath("configure", "config.test",
224 test.fail_test(os.path.exists(test.workpath("configure", "config.log")))
226 # test that no error is raised, if all targets are up-to-date. In this
227 # case .cache and config.log shouldn't be created
228 stdout=test.wrap_stdout(build_str="scons: `.' is up to date.\n",
229 read_str=r"""Executing Custom Test ... \(cached\) yes
231 test.run(status=0,chdir=test.workpath("configure"))
232 log1_mtime = os.path.getmtime(test.workpath("configure","config.log"))
233 test.run(stdout=stdout,arguments="-n",status=0,
234 chdir=test.workpath("configure"))
235 log2_mtime = os.path.getmtime(test.workpath("configure","config.log"))
236 test.fail_test( log1_mtime != log2_mtime )