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 def cat(env, source, target):
42 target = str(target[0])
43 source = map(str, source)
44 f = open(target, "wb")
46 f.write(open(src, "rb").read())
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')])
63 test.write(['work1', 'f2.in'], "f2.in\n")
64 test.write(['work1', 'f5.in'], "f5.in\n")
65 test.write(['work1', 'f6.in'], "f6.in\n")
67 expect = test.wrap_stdout(read_str = 'Mkdir("d1")\n',
69 cat(["f2.out"], ["f2.in"])
72 cat(["f5.out"], ["f5.in"])
73 cat(["f6.out"], ["f6.in"])
78 """ % (os.path.join('hello', 'world')))
79 test.run(chdir = 'work1', options = '-n', arguments = '.', stdout = expect)
81 test.must_not_exist(['work1', 'd1'])
82 test.must_not_exist(['work1', 'f2.out'])
83 test.must_not_exist(['work1', 'd3'])
84 test.must_not_exist(['work1', 'd4'])
85 test.must_not_exist(['work1', 'f5.out'])
86 test.must_not_exist(['work1', 'f6.out'])
87 test.must_not_exist(['work1', 'Mkdir-f6.in'])
88 test.must_not_exist(['work1', 'f6.out-Mkdir'])
90 test.run(chdir = 'work1')
92 test.must_exist(['work1', 'd1'])
93 test.must_match(['work1', 'f2.out'], "f2.in\n")
94 test.must_exist(['work1', 'd3'])
95 test.must_exist(['work1', 'd4'])
96 test.must_match(['work1', 'f5.out'], "f5.in\n")
97 test.must_exist(['work1', 'f6.out'])
98 test.must_exist(['work1', 'Mkdir-f6.in'])
99 test.must_exist(['work1', 'f6.out-Mkdir'])
100 test.must_exist(['work1', 'hello'])
101 test.must_exist(['work1', 'hello/world'])
103 test.write(['work1', 'd1', 'file'], "d1/file\n")
104 test.write(['work1', 'd3', 'file'], "d3/file\n")
105 test.write(['work1', 'Mkdir-f6.in', 'file'], "Mkdir-f6.in/file\n")
106 test.write(['work1', 'f6.out-Mkdir', 'file'], "f6.out-Mkdir/file\n")
107 test.write(['work1', 'hello', 'file'], "hello/file\n")
112 test.write(['work2', 'SConstruct'], """\
114 def catdir(env, source, target):
115 target = str(target[0])
116 source = map(str, source)
117 outfp = open(target, "wb")
122 f = os.path.join(src, f)
123 if os.path.isfile(f):
124 outfp.write(open(f, "rb").read())
126 CatDir = Builder(action = catdir)
127 env = Environment(BUILDERS = {'CatDir' : CatDir})
128 env.Command(Dir('hello'), None, [Mkdir('$TARGET')])
129 env.Command('hello/file1.out', 'file1.in', [Copy('$TARGET', '$SOURCE')])
130 env.Command('hello/file2.out', 'file2.in', [Copy('$TARGET', '$SOURCE')])
131 env.CatDir('output', Dir('hello'))
134 test.write(['work2', 'file1.in'], "work2/file1.in\n")
135 test.write(['work2', 'file2.in'], "work2/file2.in\n")
137 test.run(chdir = 'work2', arguments = 'hello/file2.out output')
139 test.must_match(['work2', 'output'], "work2/file1.in\nwork2/file2.in\n")