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