Support Java when using Repository and SConscriptChdir(0). (Charles Crain)
[scons.git] / test / Repository / option-c.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 import os.path
28 import sys
29 import TestSCons
30
31 test = TestSCons.TestSCons()
32
33 test.subdir('repository', ['repository', 'subdir'], 'work')
34
35 repository_aaa_in = test.workpath('repository', 'aaa.in')
36 repository_aaa_mid = test.workpath('repository', 'aaa.mid')
37 repository_aaa_out = test.workpath('repository', 'aaa.out')
38 repository_bbb_in = test.workpath('repository', 'bbb.in')
39 repository_bbb_mid = test.workpath('repository', 'bbb.mid')
40 repository_bbb_out = test.workpath('repository', 'bbb.out')
41 repository_subdir_ccc_in = test.workpath('repository', 'subdir', 'ccc.in')
42 repository_subdir_ccc_mid = test.workpath('repository', 'subdir', 'ccc.mid')
43 repository_subdir_ccc_out = test.workpath('repository', 'subdir', 'ccc.out')
44 repository_subdir_ddd_in = test.workpath('repository', 'subdir', 'ddd.in')
45 repository_subdir_ddd_mid = test.workpath('repository', 'subdir', 'ddd.mid')
46 repository_subdir_ddd_out = test.workpath('repository', 'subdir', 'ddd.out')
47
48 work_aaa_in = test.workpath('work', 'aaa.in')
49 work_aaa_mid = test.workpath('work', 'aaa.mid')
50 work_aaa_out = test.workpath('work', 'aaa.out')
51 work_bbb_in = test.workpath('work', 'bbb.in')
52 work_bbb_mid = test.workpath('work', 'bbb.mid')
53 work_bbb_out = test.workpath('work', 'bbb.out')
54 work_subdir_ccc_in = test.workpath('work', 'subdir', 'ccc.in')
55 work_subdir_ccc_mid = test.workpath('work', 'subdir', 'ccc.mid')
56 work_subdir_ccc_out = test.workpath('work', 'subdir', 'ccc.out')
57 work_subdir_ddd_in = test.workpath('work', 'subdir', 'ddd.in')
58 work_subdir_ddd_mid = test.workpath('work', 'subdir', 'ddd.mid')
59 work_subdir_ddd_out = test.workpath('work', 'subdir', 'ddd.out')
60
61 opts = "-Y " + test.workpath('repository')
62
63 #
64 test.write(['repository', 'SConstruct'], r"""
65 def copy(env, source, target):
66     source = str(source[0])
67     target = str(target[0])
68     print 'copy() < %s > %s' % (source, target)
69     open(target, "wb").write(open(source, "rb").read())
70
71 Build = Builder(action=copy)
72 env = Environment(BUILDERS={'Build':Build})
73 env.Build('aaa.mid', 'aaa.in')
74 env.Build('aaa.out', 'aaa.mid')
75 env.Build('bbb.mid', 'bbb.in')
76 env.Build('bbb.out', 'bbb.mid')
77 SConscript('subdir/SConscript', "env")
78 """)
79
80 test.write(['repository', 'subdir', 'SConscript'], r"""
81 Import("env")
82 env.Build('ccc.mid', 'ccc.in')
83 env.Build('ccc.out', 'ccc.mid')
84 env.Build('ddd.mid', 'ddd.in')
85 env.Build('ddd.out', 'ddd.mid')
86 """)
87
88 test.write(repository_aaa_in, "repository/aaa.in\n")
89 test.write(repository_bbb_in, "repository/bbb.in\n")
90
91 test.write(repository_subdir_ccc_in, "repository/subdir/ccc.in\n")
92 test.write(repository_subdir_ddd_in, "repository/subdir/ddd.in\n")
93
94 # Make the entire repository non-writable, so we'll detect
95 # if we try to write into it accidentally.
96 test.writable('repository', 0)
97
98 # Build in the work subdirectory first, so that it really
99 # builds all of the target files locally instead of possibly
100 # copying them from the Repository.
101 test.run(chdir = 'work', options = opts, arguments = '.')
102
103 test.fail_test(test.read(work_aaa_mid) != "repository/aaa.in\n")
104 test.fail_test(test.read(work_aaa_out) != "repository/aaa.in\n")
105 test.fail_test(test.read(work_bbb_mid) != "repository/bbb.in\n")
106 test.fail_test(test.read(work_bbb_out) != "repository/bbb.in\n")
107 test.fail_test(test.read(work_subdir_ccc_mid) != "repository/subdir/ccc.in\n")
108 test.fail_test(test.read(work_subdir_ccc_out) != "repository/subdir/ccc.in\n")
109 test.fail_test(test.read(work_subdir_ddd_mid) != "repository/subdir/ddd.in\n")
110 test.fail_test(test.read(work_subdir_ddd_out) != "repository/subdir/ddd.in\n")
111
112 test.up_to_date(chdir = 'work', options = opts, arguments = '.')
113
114 # Make the repository writable, so we can build in it.
115 test.writable('repository', 1)
116
117 # Now build everything in the repository.
118 test.run(chdir = 'repository', options = opts, arguments = '.')
119
120 test.fail_test(test.read(repository_aaa_mid) != "repository/aaa.in\n")
121 test.fail_test(test.read(repository_aaa_out) != "repository/aaa.in\n")
122 test.fail_test(test.read(repository_bbb_mid) != "repository/bbb.in\n")
123 test.fail_test(test.read(repository_bbb_out) != "repository/bbb.in\n")
124 test.fail_test(test.read(repository_subdir_ccc_mid) != "repository/subdir/ccc.in\n")
125 test.fail_test(test.read(repository_subdir_ccc_out) != "repository/subdir/ccc.in\n")
126 test.fail_test(test.read(repository_subdir_ddd_mid) != "repository/subdir/ddd.in\n")
127 test.fail_test(test.read(repository_subdir_ddd_out) != "repository/subdir/ddd.in\n")
128
129 test.up_to_date(chdir = 'repository', options = opts, arguments = '.')
130
131 # Make the entire repository non-writable again, so we'll detect
132 # if we try to write into it accidentally.
133 test.writable('repository', 0)
134
135 #
136 test.run(chdir = 'work', options = opts + ' -c', arguments = 'bbb.mid bbb.out')
137
138 test.fail_test(test.read(work_aaa_mid) != "repository/aaa.in\n")
139 test.fail_test(test.read(work_aaa_out) != "repository/aaa.in\n")
140 test.fail_test(os.path.exists(work_bbb_mid))
141 test.fail_test(os.path.exists(work_bbb_out))
142 test.fail_test(test.read(work_subdir_ccc_mid) != "repository/subdir/ccc.in\n")
143 test.fail_test(test.read(work_subdir_ccc_out) != "repository/subdir/ccc.in\n")
144 test.fail_test(test.read(work_subdir_ddd_mid) != "repository/subdir/ddd.in\n")
145 test.fail_test(test.read(work_subdir_ddd_out) != "repository/subdir/ddd.in\n")
146
147 #
148 test.run(chdir = 'work', options = opts + ' -c', arguments = 'subdir')
149
150 test.fail_test(test.read(work_aaa_mid) != "repository/aaa.in\n")
151 test.fail_test(test.read(work_aaa_out) != "repository/aaa.in\n")
152 test.fail_test(os.path.exists(work_bbb_mid))
153 test.fail_test(os.path.exists(work_bbb_out))
154 test.fail_test(os.path.exists(work_subdir_ccc_mid))
155 test.fail_test(os.path.exists(work_subdir_ccc_out))
156 test.fail_test(os.path.exists(work_subdir_ddd_mid))
157 test.fail_test(os.path.exists(work_subdir_ddd_out))
158
159 #
160 test.run(chdir = 'work', options = opts + ' -c', arguments = '.')
161
162 test.fail_test(os.path.exists(work_aaa_mid))
163 test.fail_test(os.path.exists(work_aaa_out))
164 test.fail_test(os.path.exists(work_bbb_mid))
165 test.fail_test(os.path.exists(work_bbb_out))
166 test.fail_test(os.path.exists(work_subdir_ccc_mid))
167 test.fail_test(os.path.exists(work_subdir_ccc_out))
168 test.fail_test(os.path.exists(work_subdir_ddd_mid))
169 test.fail_test(os.path.exists(work_subdir_ddd_out))
170
171 # Double-check that nothing in the repository got deleted.
172 test.fail_test(test.read(repository_aaa_mid) != "repository/aaa.in\n")
173 test.fail_test(test.read(repository_aaa_out) != "repository/aaa.in\n")
174 test.fail_test(test.read(repository_bbb_mid) != "repository/bbb.in\n")
175 test.fail_test(test.read(repository_bbb_out) != "repository/bbb.in\n")
176 test.fail_test(test.read(repository_subdir_ccc_mid) != "repository/subdir/ccc.in\n")
177 test.fail_test(test.read(repository_subdir_ccc_out) != "repository/subdir/ccc.in\n")
178 test.fail_test(test.read(repository_subdir_ddd_mid) != "repository/subdir/ddd.in\n")
179 test.fail_test(test.read(repository_subdir_ddd_out) != "repository/subdir/ddd.in\n")
180
181 #
182 test.pass_test()