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__"
28 Verify that the Mkdir() Action works.
35 test = TestSCons.TestSCons()
37 test.subdir('work1', 'work2')
39 test.write(['work1', 'SConstruct'], """
41 Execute(Mkdir(Dir('#d1-Dir')))
42 def cat(env, source, target):
43 target = str(target[0])
44 source = map(str, source)
45 f = open(target, "wb")
47 f.write(open(src, "rb").read())
51 env.Command('f2.out', 'f2.in', [Cat, Mkdir("d3")])
52 env = Environment(DIR = 'd4')
53 env.Command('f5.out', 'f5.in', [Mkdir("$DIR"), Cat])
54 env.Command('f6.out', 'f6.in', [Cat,
55 Mkdir("Mkdir-$SOURCE"),
56 Mkdir("$TARGET-Mkdir")])
57 # Make sure that a user-defined Mkdir builder on a directory
58 # doesn't get executed twice if it has to get called to create
59 # directory for another target.
60 env.Command(Dir('hello'), None, [Mkdir('$TARGET')])
61 env.Command('hello/world', None, [Touch('$TARGET')])
63 # Make sure Mkdir works with a list of arguments
64 Execute(Mkdir(['d7', Dir('d8')]))
67 test.write(['work1', 'f2.in'], "f2.in\n")
68 test.write(['work1', 'f5.in'], "f5.in\n")
69 test.write(['work1', 'f6.in'], "f6.in\n")
71 expect = test.wrap_stdout(read_str = """\
77 cat(["f2.out"], ["f2.in"])
80 cat(["f5.out"], ["f5.in"])
81 cat(["f6.out"], ["f6.in"])
86 """ % (os.path.join('hello', 'world')))
87 test.run(chdir = 'work1', options = '-n', arguments = '.', stdout = expect)
89 test.must_not_exist(['work1', 'd1'])
90 test.must_not_exist(['work1', 'd1-Dir'])
91 test.must_not_exist(['work1', 'f2.out'])
92 test.must_not_exist(['work1', 'd3'])
93 test.must_not_exist(['work1', 'd4'])
94 test.must_not_exist(['work1', 'f5.out'])
95 test.must_not_exist(['work1', 'f6.out'])
96 test.must_not_exist(['work1', 'Mkdir-f6.in'])
97 test.must_not_exist(['work1', 'f6.out-Mkdir'])
98 test.must_not_exist(['work1', 'd7'])
99 test.must_not_exist(['work1', 'd8'])
101 test.run(chdir = 'work1')
103 test.must_exist(['work1', 'd1'])
104 test.must_exist(['work1', 'd1-Dir'])
105 test.must_match(['work1', 'f2.out'], "f2.in\n")
106 test.must_exist(['work1', 'd3'])
107 test.must_exist(['work1', 'd4'])
108 test.must_match(['work1', 'f5.out'], "f5.in\n")
109 test.must_exist(['work1', 'f6.out'])
110 test.must_exist(['work1', 'Mkdir-f6.in'])
111 test.must_exist(['work1', 'f6.out-Mkdir'])
112 test.must_exist(['work1', 'hello'])
113 test.must_exist(['work1', 'hello/world'])
114 test.must_exist(['work1', 'd7'])
115 test.must_exist(['work1', 'd8'])
117 test.write(['work1', 'd1', 'file'], "d1/file\n")
118 test.write(['work1', 'd3', 'file'], "d3/file\n")
119 test.write(['work1', 'Mkdir-f6.in', 'file'], "Mkdir-f6.in/file\n")
120 test.write(['work1', 'f6.out-Mkdir', 'file'], "f6.out-Mkdir/file\n")
121 test.write(['work1', 'hello', 'file'], "hello/file\n")
126 test.write(['work2', 'SConstruct'], """\
128 def catdir(env, source, target):
129 target = str(target[0])
130 source = map(str, source)
131 outfp = open(target, "wb")
136 f = os.path.join(src, f)
137 if os.path.isfile(f):
138 outfp.write(open(f, "rb").read())
140 CatDir = Builder(action = catdir)
141 env = Environment(BUILDERS = {'CatDir' : CatDir})
142 env.Command(Dir('hello'), None, [Mkdir('$TARGET')])
143 env.Command('hello/file1.out', 'file1.in', [Copy('$TARGET', '$SOURCE')])
144 env.Command('hello/file2.out', 'file2.in', [Copy('$TARGET', '$SOURCE')])
145 env.CatDir('output', Dir('hello'))
148 test.write(['work2', 'file1.in'], "work2/file1.in\n")
149 test.write(['work2', 'file2.in'], "work2/file2.in\n")
151 test.run(chdir = 'work2', arguments = 'hello/file2.out output')
153 test.must_match(['work2', 'output'], "work2/file1.in\nwork2/file2.in\n")