Make a Clean() environment method. Add global functions for AlwaysBuild(), Command...
[scons.git] / test / Ignore.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
29 import TestSCons
30
31 python = TestSCons.python
32
33 test = TestSCons.TestSCons()
34
35 test.subdir('subdir')
36
37 test.write('build.py', r"""
38 import sys
39 contents = open(sys.argv[2], 'rb').read() + open(sys.argv[3], 'rb').read()
40 file = open(sys.argv[1], 'wb')
41 for arg in sys.argv[2:]:
42     file.write(open(arg, 'rb').read())
43 file.close()
44 """)
45
46 test.write('SConstruct', """\
47 Foo = Builder(action = r"%s build.py $TARGET $SOURCES")
48 Bar = Builder(action = r"%s build.py $TARGET $SOURCES")
49 env = Environment(BUILDERS = { 'Foo' : Foo, 'Bar' : Bar }, SUBDIR='subdir')
50 env.Foo(target = 'f1.out', source = ['f1a.in', 'f1b.in'])
51 Ignore(target = 'f1.out', dependency = 'f1b.in')
52 SConscript('subdir/SConscript', "env")
53 env.Foo(target = 'subdir/f3.out', source = ['subdir/f3a.in', 'subdir/f3b.in'])
54 env.Ignore(target = r'%s', dependency = r'%s')
55 """ % (python,
56        python,
57        os.path.join('$SUBDIR', 'f3.out'),
58        os.path.join('$SUBDIR', 'f3b.in')))
59
60 test.write(['subdir', 'SConscript'], """
61 Import("env")
62 env.Bar(target = 'f2.out', source = ['f2a.in', 'f2b.in'])
63 env.Ignore('f2.out', 'f2a.in')
64 """)
65
66 test.write('f1a.in', "f1a.in\n")
67 test.write('f1b.in', "f1b.in\n")
68
69 test.write(['subdir', 'f2a.in'], "subdir/f2a.in\n")
70 test.write(['subdir', 'f2b.in'], "subdir/f2b.in\n")
71
72 test.write(['subdir', 'f3a.in'], "subdir/f3a.in\n")
73 test.write(['subdir', 'f3b.in'], "subdir/f3b.in\n")
74
75 test.run(arguments = '.')
76
77 test.fail_test(test.read('f1.out') != "f1a.in\nf1b.in\n")
78 test.fail_test(test.read(['subdir', 'f2.out']) !=
79                "subdir/f2a.in\nsubdir/f2b.in\n")
80 test.fail_test(test.read(['subdir', 'f3.out']) !=
81                "subdir/f3a.in\nsubdir/f3b.in\n")
82
83 test.up_to_date(arguments = '.')
84
85 test.write('f1b.in', "f1b.in 2\n")
86 test.write(['subdir', 'f2a.in'], "subdir/f2a.in 2\n")
87 test.write(['subdir', 'f3b.in'], "subdir/f3b.in 2\n")
88
89 test.up_to_date(arguments = '.')
90
91 test.fail_test(test.read('f1.out') != "f1a.in\nf1b.in\n")
92 test.fail_test(test.read(['subdir', 'f2.out']) !=
93                "subdir/f2a.in\nsubdir/f2b.in\n")
94 test.fail_test(test.read(['subdir', 'f3.out']) !=
95                "subdir/f3a.in\nsubdir/f3b.in\n")
96
97 test.write('f1a.in', "f1a.in 2\n")
98 test.write(['subdir', 'f2b.in'], "subdir/f2b.in 2\n")
99 test.write(['subdir', 'f3a.in'], "subdir/f3a.in 2\n")
100
101 test.run(arguments = '.')
102
103 test.fail_test(test.read('f1.out') != "f1a.in 2\nf1b.in 2\n")
104 test.fail_test(test.read(['subdir', 'f2.out']) !=
105                "subdir/f2a.in 2\nsubdir/f2b.in 2\n")
106 test.fail_test(test.read(['subdir', 'f3.out']) !=
107                "subdir/f3a.in 2\nsubdir/f3b.in 2\n")
108
109 test.up_to_date(arguments = '.')
110
111 test.pass_test()