summaryrefslogtreecommitdiffstats
path: root/test/Interactive/option-j.py
blob: 279fc51ca28375e4f60a6711f4c1a07b42beb9e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/env python
#
# __COPYRIGHT__
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"

"""
Verify that "build" command of --interactive mode can take a -j
option to build things in parallel.
"""

import TestSCons

test = TestSCons.TestSCons(combine=1)

test.write('SConstruct', """\
import os
import time
from SCons.Script import *
def cat(target, source, env):
    t = str(target[0])
    os.mkdir(t + '.started')
    fp = open(t, 'wb')
    for s in source:
        fp.write(open(str(s), 'rb').read())
    fp.close()
    os.mkdir(t + '.finished')

def must_be_finished(target, source, env, dir):
    if not os.path.exists(dir):
        msg = 'build failed, %s does not exist\\n' % dir
        sys.stderr.write(msg)
        return 1
    return cat(target, source, env)

def f1_a_out_must_be_finished(target, source, env):
    return must_be_finished(target, source, env, 'f1-a.out.finished')
def f3_a_out_must_be_finished(target, source, env):
    return must_be_finished(target, source, env, 'f3-a.out.finished')

def must_wait_for_f2_b_out(target, source, env):
    t = str(target[0])
    os.mkdir(t + '.started')
    f2_b_started = 'f2-b.out.started'
    while not os.path.exists(f2_b_started):
        time.sleep(1)
    fp = open(t, 'wb')
    for s in source:
        fp.write(open(str(s), 'rb').read())
    fp.close()
    os.mkdir(t + '.finished')

def _f2_a_out_must_not_be_finished(target, source, env):
    f2_a_started = 'f2-a.out.started'
    f2_a_finished = 'f2-a.out.finished'
    while not os.path.exists(f2_a_started):
        time.sleep(1)
    msg = 'f2_a_out_must_not_be_finished(["%s"], ["%s"])\\n' % (target[0], source[0])
    sys.stdout.write(msg)
    if os.path.exists(f2_a_finished):
        msg = 'build failed, %s exists\\n' % f2_a_finished
        sys.stderr.write(msg)
        return 1
    return cat(target, source, env)

f2_a_out_must_not_be_finished = Action(_f2_a_out_must_not_be_finished,
                                       strfunction = None)

Cat = Action(cat)
f1_a = Command('f1-a.out', 'f1-a.in', cat)
f1_b = Command('f1-b.out', 'f1-b.in', f1_a_out_must_be_finished)
f2_a = Command('f2-a.out', 'f2-a.in', must_wait_for_f2_b_out)
f2_b = Command('f2-b.out', 'f2-b.in', f2_a_out_must_not_be_finished)
f3_a = Command('f3-a.out', 'f3-a.in', cat)
f3_b = Command('f3-b.out', 'f3-b.in', f3_a_out_must_be_finished)
Command('f1.out', f1_a + f1_b, cat)
Command('f2.out', f2_a + f2_b, cat)
Command('f3.out', f3_a + f3_b, cat)
Command('1', [], Touch('$TARGET'))
Command('2', [], Touch('$TARGET'))
Command('3', [], Touch('$TARGET'))
""")

test.write('f1-a.in', "f1-a.in\n")
test.write('f1-b.in', "f1-b.in\n")
test.write('f2-a.in', "f2-a.in\n")
test.write('f2-b.in', "f2-b.in\n")
test.write('f3-a.in', "f3-a.in\n")
test.write('f3-b.in', "f3-b.in\n")



scons = test.start(arguments = '-Q --interactive')

scons.send("build f1.out\n")

scons.send("build 1\n")

test.wait_for(test.workpath('1'), popen=scons)

test.must_match(test.workpath('f1.out'), "f1-a.in\nf1-b.in\n")



scons.send("build -j2 f2.out\n")

scons.send("build 2\n")

test.wait_for(test.workpath('2'), popen=scons)

test.must_match(test.workpath('f2.out'), "f2-a.in\nf2-b.in\n")



scons.send("build f3.out\n")

scons.send("build 3\n")

test.wait_for(test.workpath('3'))

test.must_match(test.workpath('f3.out'), "f3-a.in\nf3-b.in\n")



expect_stdout = """\
scons>>> cat(["f1-a.out"], ["f1-a.in"])
f1_a_out_must_be_finished(["f1-b.out"], ["f1-b.in"])
cat(["f1.out"], ["f1-a.out", "f1-b.out"])
scons>>> Touch("1")
scons>>> must_wait_for_f2_b_out(["f2-a.out"], ["f2-a.in"])
f2_a_out_must_not_be_finished(["f2-b.out"], ["f2-b.in"])
cat(["f2.out"], ["f2-a.out", "f2-b.out"])
scons>>> Touch("2")
scons>>> cat(["f3-a.out"], ["f3-a.in"])
f3_a_out_must_be_finished(["f3-b.out"], ["f3-b.in"])
cat(["f3.out"], ["f3-a.out", "f3-b.out"])
scons>>> Touch("3")
scons>>> 
"""

test.finish(scons, stdout = expect_stdout)



test.pass_test()

# Local Variables:
# tab-width:4
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=4 shiftwidth=4: