[ci skip] update generated files
[scons.git] / test / Repository / SConscript.py
blob72e2d27bc561feaf871cc60dbba48dbd382fe6ad
1 #!/usr/bin/env python
3 # MIT License
5 # Copyright The SCons Foundation
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 """
27 Test how we handle SConscript calls when using a Repository.
28 """
30 import sys
31 from TestSCons import TestSCons
33 test = TestSCons()
35 test.subdir('work',
36 ['work', 'src'],
37 'rep1',
38 ['rep1', 'src'],
39 'rep2',
40 ['rep2', 'build'],
41 ['rep2', 'src'],
42 ['rep2', 'src', 'sub'])
44 workpath_rep1 = test.workpath('rep1')
45 workpath_rep2 = test.workpath('rep2')
47 test.write(['work', 'SConstruct'], """
48 Repository(r'%s')
49 SConscript('src/SConscript')
50 """ % workpath_rep1)
52 test.write(['rep1', 'src', 'SConscript'], """\
53 def cat(env, source, target):
54 target = str(target[0])
55 with open(target, "w") as ofp:
56 for src in source:
57 with open(str(src), "r") as ifp:
58 ofp.write(ifp.read())
60 env = Environment(BUILDERS={'Cat':Builder(action=cat)})
61 env.Cat(target = 'foo', source = ['aaa.in', 'bbb.in', 'ccc.in'])
62 """)
64 test.write(['rep1', 'src', 'aaa.in'], "rep1/src/aaa.in\n")
65 test.write(['rep1', 'src', 'bbb.in'], "rep1/src/bbb.in\n")
66 test.write(['rep1', 'src', 'ccc.in'], "rep1/src/ccc.in\n")
68 # Make the rep1 non-writable,
69 # so we'll detect if we try to write into it accidentally.
70 test.writable('rep1', 0)
72 test.run(chdir = 'work', arguments = ".")
74 test.must_match(['work', 'src', 'foo'], """\
75 rep1/src/aaa.in
76 rep1/src/bbb.in
77 rep1/src/ccc.in
78 """, mode='r')
80 test.up_to_date(chdir = 'work', arguments = ".")
83 test.write(['rep2', 'build', 'SConstruct'], """
84 env = Environment(REPOSITORY = r'%s')
85 env.Repository('$REPOSITORY')
86 SConscript('src/SConscript')
87 """ % workpath_rep2)
89 test.write(['rep2', 'src', 'SConscript'], """\
90 def cat(env, source, target):
91 target = str(target[0])
92 with open(target, "w") as ofp:
93 for src in source:
94 with open(str(src), "r") as ifp:
95 ofp.write(ifp.read())
97 env = Environment(BUILDERS={'Cat':Builder(action=cat)})
98 env.Cat(target = 'foo', source = ['aaa.in', 'bbb.in', 'ccc.in'])
99 SConscript('sub/SConscript')
100 """)
102 test.write(['rep2', 'src', 'sub', 'SConscript'], """\
103 """)
105 test.write(['rep2', 'src', 'aaa.in'], "rep2/src/aaa.in\n")
106 test.write(['rep2', 'src', 'bbb.in'], "rep2/src/bbb.in\n")
107 test.write(['rep2', 'src', 'ccc.in'], "rep2/src/ccc.in\n")
109 test.run(chdir = 'rep2/build', arguments = ".")
111 test.must_match(['rep2', 'build', 'src', 'foo'], """\
112 rep2/src/aaa.in
113 rep2/src/bbb.in
114 rep2/src/ccc.in
115 """, mode='r')
118 test.pass_test()
120 # Local Variables:
121 # tab-width:4
122 # indent-tabs-mode:nil
123 # End:
124 # vim: set expandtab tabstop=4 shiftwidth=4: