Added fix for TeX includes with same name as subdirs.
[scons.git] / test / AlwaysBuild.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
26 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
27
28 import os
29
30 import TestSCons
31
32 test = TestSCons.TestSCons()
33
34 test.subdir('sub')
35
36 sub_f3_out = os.path.join('sub', 'f3.out')
37 _SUBDIR_f3_out = os.path.join('$SUBDIR', 'f3.out')
38
39 test.write('SConstruct', """\
40 def bfunc(target, source, env):
41     import shutil
42     shutil.copyfile('f2.in', str(target[0]))
43
44 B = Builder(action=bfunc)
45 env = Environment(BUILDERS = { 'B' : B }, SUBDIR='sub')
46 env.B('f1.out', source='f1.in')
47 AlwaysBuild('f1.out')
48
49 env.B(r'%(sub_f3_out)s', source='f3.in')
50 env.AlwaysBuild(r'%(_SUBDIR_f3_out)s')
51
52 env.Alias('clean1', [], Delete('clean1-target'))
53 env.AlwaysBuild('clean1')
54 c2 = env.Alias('clean2', [], [Delete('clean2-t1'), Delete('clean2-t2')])
55 env.AlwaysBuild(c2)
56
57 def dir_build(target, source, env):
58     open('dir_build.txt', 'ab').write('dir_build()\\n')
59 env.Command(Dir('dir'), None, dir_build)
60 env.AlwaysBuild('dir')
61 """ % locals())
62
63 test.write('f1.in', "f1.in\n")
64 test.write('f2.in', "1")
65 test.write('f3.in', "f3.in\n")
66
67 test.subdir('dir')
68
69 test.run(arguments = ".")
70 test.must_match('f1.out', '1')
71 test.must_match(['sub', 'f3.out'], '1')
72 test.must_match('dir_build.txt', "dir_build()\n")
73
74 test.write('f2.in', "2")
75
76 test.run(arguments = ".")
77 test.must_match('f1.out', '2')
78 test.must_match(['sub', 'f3.out'], '2')
79 test.must_match('dir_build.txt', "dir_build()\ndir_build()\n")
80
81 test.run(arguments = 'clean1', stdout=test.wrap_stdout("""\
82 Delete("clean1-target")
83 """))
84
85 test.run(arguments = 'clean2', stdout=test.wrap_stdout("""\
86 Delete("clean2-t1")
87 Delete("clean2-t2")
88 """))
89
90 test.not_up_to_date(arguments = 'dir')
91
92 test.must_match('dir_build.txt', "dir_build()\ndir_build()\ndir_build()\n")
93
94 test.pass_test()
95
96 # Local Variables:
97 # tab-width:4
98 # indent-tabs-mode:nil
99 # End:
100 # vim: set expandtab tabstop=4 shiftwidth=4: