Added fix for TeX includes with same name as subdirs.
[scons.git] / test / DSUFFIXES.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 """
28 Test the ability to scan additional filesuffixes added to $DSUFFIXES.
29 """
30
31 import TestSCons
32
33 _python_ = TestSCons._python_
34
35 test = TestSCons.TestSCons()
36
37 test.write('mydc.py', r"""
38 import sys
39 def do_file(outf, inf):
40     for line in open(inf, 'rb').readlines():
41         if line[:7] == 'import ':
42             do_file(outf, line[7:-2]+'.d')
43         else:
44             outf.write(line)
45 outf = open(sys.argv[1], 'wb')
46 for f in sys.argv[2:]:
47     do_file(outf, f)
48 sys.exit(0)
49 """)
50
51 test.write('SConstruct', """
52 # Force the 'dmd' tool to get added to the Environment, even if it's not
53 # installed, so we get its definition of variables to deal with turning
54 # '.d' suffix files into objects.
55 env = Environment()
56 Tool('dmd')(env)
57 # Now replace those suffixes with our fake-D things.
58 env.Replace(DPATH = ['.'],
59             DC = r'%(_python_)s mydc.py',
60             DFLAGS = [],
61             DCOM = '$DC $TARGET $SOURCES',
62             OBJSUFFIX = '.o')
63 env.Append(CPPSUFFIXES = ['.x'])
64 env.Object(target = 'test1', source = 'test1.d')
65 env.InstallAs('test1_d', 'test1.d')
66 env.InstallAs('test2_d', 'test2.d')
67 env.InstallAs('test3_d', 'test3.d')
68 """ % locals())
69
70 test.write('test1.d', """\
71 test1.d 1
72 import test2;
73 import test3;
74 """)
75
76 test.write('test2.d', """\
77 test2.d 1
78 import foo;
79 """)
80
81 test.write('test3.d', """\
82 test3.d 1
83 import foo;
84 """)
85
86 test.write('foo.d', "foo.d 1\n")
87
88 expect = test.wrap_stdout("""\
89 %(_python_)s mydc.py test1.o test1.d
90 Install file: "test1.d" as "test1_d"
91 Install file: "test2.d" as "test2_d"
92 Install file: "test3.d" as "test3_d"
93 """ % locals())
94
95 test.run(arguments='.', stdout=expect)
96
97 test.must_match('test1.o', """\
98 test1.d 1
99 test2.d 1
100 foo.d 1
101 test3.d 1
102 foo.d 1
103 """)
104
105 test.up_to_date(arguments='.')
106
107 test.write('foo.d', "foo.d 2\n")
108
109 expect = test.wrap_stdout("""\
110 %(_python_)s mydc.py test1.o test1.d
111 """ % locals())
112
113 test.run(arguments='.', stdout=expect)
114
115 test.must_match('test1.o', """\
116 test1.d 1
117 test2.d 1
118 foo.d 2
119 test3.d 1
120 foo.d 2
121 """)
122
123 test.up_to_date(arguments='.')
124
125 test.write('test3.d', """\
126 test3.d 2
127 import foo;
128 """)
129
130 expect = test.wrap_stdout("""\
131 %(_python_)s mydc.py test1.o test1.d
132 Install file: "test3.d" as "test3_d"
133 """ % locals())
134
135 test.run(arguments='.', stdout=expect)
136
137 test.must_match('test1.o', """\
138 test1.d 1
139 test2.d 1
140 foo.d 2
141 test3.d 2
142 foo.d 2
143 """)
144
145 test.up_to_date(arguments='.')
146
147 test.write('test2.d', """\
148 test2.d 2
149 import foo;
150 """)
151
152 expect = test.wrap_stdout("""\
153 %(_python_)s mydc.py test1.o test1.d
154 Install file: "test2.d" as "test2_d"
155 """ % locals())
156
157 test.run(arguments='.', stdout=expect)
158
159 test.must_match('test1.o', """\
160 test1.d 1
161 test2.d 2
162 foo.d 2
163 test3.d 2
164 foo.d 2
165 """)
166
167 test.up_to_date(arguments='.')
168
169 test.pass_test()
170
171 # Local Variables:
172 # tab-width:4
173 # indent-tabs-mode:nil
174 # End:
175 # vim: set expandtab tabstop=4 shiftwidth=4: