Merged revisions 1582-1665 via svnmerge from
[scons.git] / test / CPPSUFFIXES.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 $CPPSUFFIXES.
29 """
30
31 import TestSCons
32
33 _python_ = TestSCons._python_
34
35 test = TestSCons.TestSCons()
36
37 test.write('mycc.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[:10] == '#include <':
43             do_file(outf, line[10:-2])
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 env = Environment(CPPPATH = ['.'],
54                   CC = r'%(_python_)s mycc.py',
55                   CCFLAGS = [],
56                   CCCOM = '$CC $TARGET $SOURCES',
57                   OBJSUFFIX = '.o')
58 env.Append(CPPSUFFIXES = ['.x'])
59 env.Object(target = 'test1', source = 'test1.c')
60 env.InstallAs('test1_c', 'test1.c')
61 env.InstallAs('test1_h', 'test1.h')
62 env.InstallAs('test1_x', 'test1.x')
63 """ % locals())
64
65 test.write('test1.c', """\
66 test1.c 1
67 #include <test1.h>
68 #include <test1.x>
69 """)
70
71 test.write('test1.h', """\
72 test1.h 1
73 #include <foo.h>
74 """)
75
76 test.write('test1.x', """\
77 test1.x 1
78 #include <foo.h>
79 """)
80
81 test.write('foo.h', "foo.h 1\n")
82
83 expect = test.wrap_stdout("""\
84 %(_python_)s mycc.py test1.o test1.c
85 Install file: "test1.c" as "test1_c"
86 Install file: "test1.h" as "test1_h"
87 Install file: "test1.x" as "test1_x"
88 """ % locals())
89
90 test.run(arguments='.', stdout=expect)
91
92 test.must_match('test1.o', """\
93 test1.c 1
94 test1.h 1
95 foo.h 1
96 test1.x 1
97 foo.h 1
98 """)
99
100 test.up_to_date(arguments='.')
101
102 test.write('foo.h', "foo.h 2\n")
103
104 expect = test.wrap_stdout("""\
105 %(_python_)s mycc.py test1.o test1.c
106 """ % locals())
107
108 test.run(arguments='.', stdout=expect)
109
110 test.must_match('test1.o', """\
111 test1.c 1
112 test1.h 1
113 foo.h 2
114 test1.x 1
115 foo.h 2
116 """)
117
118 test.up_to_date(arguments='.')
119
120 test.write('test1.x', """\
121 test1.x 2
122 #include <foo.h>
123 """)
124
125 expect = test.wrap_stdout("""\
126 %(_python_)s mycc.py test1.o test1.c
127 Install file: "test1.x" as "test1_x"
128 """ % locals())
129
130 test.run(arguments='.', stdout=expect)
131
132 test.must_match('test1.o', """\
133 test1.c 1
134 test1.h 1
135 foo.h 2
136 test1.x 2
137 foo.h 2
138 """)
139
140 test.up_to_date(arguments='.')
141
142 test.write('test1.h', """\
143 test1.h 2
144 #include <foo.h>
145 """)
146
147 expect = test.wrap_stdout("""\
148 %(_python_)s mycc.py test1.o test1.c
149 Install file: "test1.h" as "test1_h"
150 """ % locals())
151
152 test.run(arguments='.', stdout=expect)
153
154 test.must_match('test1.o', """\
155 test1.c 1
156 test1.h 2
157 foo.h 2
158 test1.x 2
159 foo.h 2
160 """)
161
162 test.up_to_date(arguments='.')
163
164 test.pass_test()