[ci skip] update generated files
[scons.git] / test / Mkdir.py
blob367c8349522fadd722dc82f32713213a24d50e8b
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.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
27 """
28 Verify that the Mkdir() Action works.
29 """
31 import os.path
33 import TestSCons
35 test = TestSCons.TestSCons()
37 test.subdir('work1', 'work2', 'work3')
39 test.write(['work1', 'SConstruct'], """
40 Execute(Mkdir('d1'))
41 Execute(Mkdir(Dir('#d1-Dir')))
42 def cat(env, source, target):
43 target = str(target[0])
44 with open(target, "wb") as f:
45 for src in source:
46 with open(str(src), "rb") as ifp:
47 f.write(ifp.read())
48 Cat = Action(cat)
49 env = Environment()
50 env.Command('f2.out', 'f2.in', [Cat, Mkdir("d3")])
51 env = Environment(DIR = 'd4')
52 env.Command('f5.out', 'f5.in', [Mkdir("$DIR"), Cat])
53 env.Command('f6.out', 'f6.in', [Cat,
54 Mkdir("Mkdir-$SOURCE"),
55 Mkdir("$TARGET-Mkdir")])
56 # Make sure that a user-defined Mkdir builder on a directory
57 # doesn't get executed twice if it has to get called to create
58 # directory for another target.
59 env.Command(Dir('hello'), None, [Mkdir('$TARGET')])
60 env.Command('hello/world', None, [Touch('$TARGET')])
62 # Make sure Mkdir works with a list of arguments
63 Execute(Mkdir(['d7', Dir('d8')]))
64 """)
66 test.write(['work1', 'f2.in'], "f2.in\n")
67 test.write(['work1', 'f5.in'], "f5.in\n")
68 test.write(['work1', 'f6.in'], "f6.in\n")
70 expect = test.wrap_stdout(read_str = """\
71 Mkdir("d1")
72 Mkdir("d1-Dir")
73 Mkdir(["d7", "d8"])
74 """,
75 build_str = """\
76 cat(["f2.out"], ["f2.in"])
77 Mkdir("d3")
78 Mkdir("d4")
79 cat(["f5.out"], ["f5.in"])
80 cat(["f6.out"], ["f6.in"])
81 Mkdir("Mkdir-f6.in")
82 Mkdir("f6.out-Mkdir")
83 Mkdir("hello")
84 Touch("%s")
85 """ % (os.path.join('hello', 'world')))
86 test.run(chdir = 'work1', options = '-n', arguments = '.', stdout = expect)
88 test.must_not_exist(['work1', 'd1'])
89 test.must_not_exist(['work1', 'd1-Dir'])
90 test.must_not_exist(['work1', 'f2.out'])
91 test.must_not_exist(['work1', 'd3'])
92 test.must_not_exist(['work1', 'd4'])
93 test.must_not_exist(['work1', 'f5.out'])
94 test.must_not_exist(['work1', 'f6.out'])
95 test.must_not_exist(['work1', 'Mkdir-f6.in'])
96 test.must_not_exist(['work1', 'f6.out-Mkdir'])
97 test.must_not_exist(['work1', 'd7'])
98 test.must_not_exist(['work1', 'd8'])
100 test.run(chdir = 'work1')
102 test.must_exist(['work1', 'd1'])
103 test.must_exist(['work1', 'd1-Dir'])
104 test.must_match(['work1', 'f2.out'], "f2.in\n")
105 test.must_exist(['work1', 'd3'])
106 test.must_exist(['work1', 'd4'])
107 test.must_match(['work1', 'f5.out'], "f5.in\n")
108 test.must_exist(['work1', 'f6.out'])
109 test.must_exist(['work1', 'Mkdir-f6.in'])
110 test.must_exist(['work1', 'f6.out-Mkdir'])
111 test.must_exist(['work1', 'hello'])
112 test.must_exist(['work1', 'hello/world'])
113 test.must_exist(['work1', 'd7'])
114 test.must_exist(['work1', 'd8'])
116 test.write(['work1', 'd1', 'file'], "d1/file\n")
117 test.write(['work1', 'd3', 'file'], "d3/file\n")
118 test.write(['work1', 'Mkdir-f6.in', 'file'], "Mkdir-f6.in/file\n")
119 test.write(['work1', 'f6.out-Mkdir', 'file'], "f6.out-Mkdir/file\n")
120 test.write(['work1', 'hello', 'file'], "hello/file\n")
125 test.write(['work2', 'SConstruct'], """\
126 import os
127 def catdir(env, source, target):
128 target = str(target[0])
129 with open(target, "wb") as outfp:
130 for src in source:
131 s = str(src)
132 for f in sorted(os.listdir(s)):
133 f = os.path.join(s, f)
134 if os.path.isfile(f):
135 with open(f, "rb") as infp:
136 outfp.write(infp.read())
137 CatDir = Builder(action = catdir)
138 env = Environment(BUILDERS = {'CatDir' : CatDir})
139 env.Command(Dir('hello'), None, [Mkdir('$TARGET')])
140 env.Command('hello/file1.out', 'file1.in', [Copy('$TARGET', '$SOURCE')])
141 env.Command('hello/file2.out', 'file2.in', [Copy('$TARGET', '$SOURCE')])
142 env.CatDir('output', Dir('hello'))
143 """)
145 test.write(['work2', 'file1.in'], "work2/file1.in\n")
146 test.write(['work2', 'file2.in'], "work2/file2.in\n")
148 test.run(chdir = 'work2', arguments = 'hello/file2.out output')
150 test.must_match(['work2', 'output'], "work2/file1.in\nwork2/file2.in\n")
153 #----------------------------------------
154 # Regression test for bug #1249
156 test.subdir(['work3', 'sub1'], ['work3', 'sub1', 'sub11'])
158 test.write(['work3', 'SConstruct'], """\
159 #/SConstruct ------------------------------------------
160 import os
161 env = Environment(ENV = os.environ)
162 VariantDir('build', 'sub1', duplicate=0)
163 base = '#build/sub1'
164 Export('env base')
165 SConscript('sub1/SConscript', exports='env')
166 """)
168 test.write(['work3', 'sub1', 'SConscript'], """\
169 #/sub1/SConscript ----------------------------------
170 Import ('env base')
171 test1 = base + '/test1'
172 Export ('env test1')
173 env.Command(Dir(test1), '', Mkdir('$TARGET'))
174 SConscript('sub11/SConscript')
175 """)
177 test.write(['work3', 'sub1', 'sub11', 'SConscript'], """\
178 #/sub1/sub11/SConscript-------------------------
179 Import('env test1')
180 test11 = test1 + '/test11'
181 print('test11 = ' + test11)
182 env.Command(Dir(test11), '', Mkdir('$TARGET'))
183 """)
185 test.run(chdir = 'work3', arguments = '')
187 test.pass_test()
189 # Local Variables:
190 # tab-width:4
191 # indent-tabs-mode:nil
192 # End:
193 # vim: set expandtab tabstop=4 shiftwidth=4: