[ci skip] Add note that this change may break SetOption() + ninja usage with fix
[scons.git] / test / Interactive / option-j.py
blob356a06749abbb4891986763db04b9c519572613f
1 #!/usr/bin/env python
3 # __COPYRIGHT__
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.
24 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
26 """
27 Verify that "build" command of --interactive mode can take a -j
28 option to build things in parallel.
29 """
31 import TestSCons
33 test = TestSCons.TestSCons(combine=1)
35 test.write('SConstruct', """\
36 import os
37 import time
38 from SCons.Script import *
39 def cat(target, source, env):
40 t = str(target[0])
41 os.mkdir(t + '.started')
42 with open(t, 'wb') as ofp:
43 for s in source:
44 with open(str(s), 'rb') as ifp:
45 ofp.write(ifp.read())
46 os.mkdir(t + '.finished')
48 def must_be_finished(target, source, env, dir):
49 if not os.path.exists(dir):
50 msg = 'build failed, %s does not exist\\n' % dir
51 sys.stderr.write(msg)
52 return 1
53 return cat(target, source, env)
55 def f1_a_out_must_be_finished(target, source, env):
56 return must_be_finished(target, source, env, 'f1-a.out.finished')
57 def f3_a_out_must_be_finished(target, source, env):
58 return must_be_finished(target, source, env, 'f3-a.out.finished')
60 def must_wait_for_f2_b_out(target, source, env):
61 t = str(target[0])
62 os.mkdir(t + '.started')
63 f2_b_started = 'f2-b.out.started'
64 while not os.path.exists(f2_b_started):
65 time.sleep(1)
66 with open(t, 'wb') as ofp:
67 for s in source:
68 with open(str(s), 'rb') as ifp:
69 ofp.write(ifp.read())
70 os.mkdir(t + '.finished')
72 def _f2_a_out_must_not_be_finished(target, source, env):
73 f2_a_started = 'f2-a.out.started'
74 f2_a_finished = 'f2-a.out.finished'
75 while not os.path.exists(f2_a_started):
76 time.sleep(1)
77 msg = 'f2_a_out_must_not_be_finished(["%s"], ["%s"])\\n' % (target[0], source[0])
78 sys.stdout.write(msg)
79 if os.path.exists(f2_a_finished):
80 msg = 'build failed, %s exists\\n' % f2_a_finished
81 sys.stderr.write(msg)
82 return 1
83 return cat(target, source, env)
85 f2_a_out_must_not_be_finished = Action(_f2_a_out_must_not_be_finished,
86 strfunction = None)
88 Cat = Action(cat)
89 f1_a = Command('f1-a.out', 'f1-a.in', cat)
90 f1_b = Command('f1-b.out', 'f1-b.in', f1_a_out_must_be_finished)
91 f2_a = Command('f2-a.out', 'f2-a.in', must_wait_for_f2_b_out)
92 f2_b = Command('f2-b.out', 'f2-b.in', f2_a_out_must_not_be_finished)
93 f3_a = Command('f3-a.out', 'f3-a.in', cat)
94 f3_b = Command('f3-b.out', 'f3-b.in', f3_a_out_must_be_finished)
95 Command('f1.out', f1_a + f1_b, cat)
96 Command('f2.out', f2_a + f2_b, cat)
97 Command('f3.out', f3_a + f3_b, cat)
98 Command('1', [], Touch('$TARGET'))
99 Command('2', [], Touch('$TARGET'))
100 Command('3', [], Touch('$TARGET'))
101 """)
103 test.write('f1-a.in', "f1-a.in\n")
104 test.write('f1-b.in', "f1-b.in\n")
105 test.write('f2-a.in', "f2-a.in\n")
106 test.write('f2-b.in', "f2-b.in\n")
107 test.write('f3-a.in', "f3-a.in\n")
108 test.write('f3-b.in', "f3-b.in\n")
112 scons = test.start(arguments = '-Q --interactive')
114 scons.send("build f1.out\n")
116 scons.send("build 1\n")
118 test.wait_for(test.workpath('1'), popen=scons)
120 test.must_match(test.workpath('f1.out'), "f1-a.in\nf1-b.in\n")
124 scons.send("build -j2 f2.out\n")
126 scons.send("build 2\n")
128 test.wait_for(test.workpath('2'), popen=scons)
130 test.must_match(test.workpath('f2.out'), "f2-a.in\nf2-b.in\n")
134 scons.send("build f3.out\n")
136 scons.send("build 3\n")
138 test.wait_for(test.workpath('3'))
140 test.must_match(test.workpath('f3.out'), "f3-a.in\nf3-b.in\n")
144 expect_stdout = """\
145 scons>>> cat(["f1-a.out"], ["f1-a.in"])
146 f1_a_out_must_be_finished(["f1-b.out"], ["f1-b.in"])
147 cat(["f1.out"], ["f1-a.out", "f1-b.out"])
148 scons>>> Touch("1")
149 scons>>> must_wait_for_f2_b_out(["f2-a.out"], ["f2-a.in"])
150 f2_a_out_must_not_be_finished(["f2-b.out"], ["f2-b.in"])
151 cat(["f2.out"], ["f2-a.out", "f2-b.out"])
152 scons>>> Touch("2")
153 scons>>> cat(["f3-a.out"], ["f3-a.in"])
154 f3_a_out_must_be_finished(["f3-b.out"], ["f3-b.in"])
155 cat(["f3.out"], ["f3-a.out", "f3-b.out"])
156 scons>>> Touch("3")
157 scons>>>
160 test.finish(scons, stdout = expect_stdout)
164 test.pass_test()
166 # Local Variables:
167 # tab-width:4
168 # indent-tabs-mode:nil
169 # End:
170 # vim: set expandtab tabstop=4 shiftwidth=4: