Fix spurious rebuilds/reinstalls of header files and circular dependencies with gener...
[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 env = Environment(DPATH = ['.'],
54                   DC = r'%s mydc.py',
55                   DFLAGS = [],
56                   DCOM = '$DC $TARGET $SOURCES',
57                   OBJSUFFIX = '.o')
58 env.Append(CPPSUFFIXES = ['.x'])
59 env.Object(target = 'test1', source = 'test1.d')
60 env.InstallAs('test1_d', 'test1.d')
61 env.InstallAs('test2_d', 'test2.d')
62 env.InstallAs('test3_d', 'test3.d')
63 """ % (python,))
64
65 test.write('test1.d', """\
66 test1.d 1
67 import test2;
68 import test3;
69 """)
70
71 test.write('test2.d', """\
72 test2.d 1
73 import foo;
74 """)
75
76 test.write('test3.d', """\
77 test3.d 1
78 import foo;
79 """)
80
81 test.write('foo.d', "foo.d 1\n")
82
83 test.run(arguments='.', stdout=test.wrap_stdout("""\
84 %s mydc.py test1.o test1.d
85 Install file: "test1.d" as "test1_d"
86 Install file: "test2.d" as "test2_d"
87 Install file: "test3.d" as "test3_d"
88 """ % (python,)))
89
90 test.must_match('test1.o', """\
91 test1.d 1
92 test2.d 1
93 foo.d 1
94 test3.d 1
95 foo.d 1
96 """)
97
98 test.up_to_date(arguments='.')
99
100 test.write('foo.d', "foo.d 2\n")
101
102 test.run(arguments='.', stdout=test.wrap_stdout("""\
103 %s mydc.py test1.o test1.d
104 """ % (python,)))
105
106 test.must_match('test1.o', """\
107 test1.d 1
108 test2.d 1
109 foo.d 2
110 test3.d 1
111 foo.d 2
112 """)
113
114 test.up_to_date(arguments='.')
115
116 test.write('test3.d', """\
117 test3.d 2
118 import foo;
119 """)
120
121 test.run(arguments='.', stdout=test.wrap_stdout("""\
122 %s mydc.py test1.o test1.d
123 Install file: "test3.d" as "test3_d"
124 """ % (python,)))
125
126 test.must_match('test1.o', """\
127 test1.d 1
128 test2.d 1
129 foo.d 2
130 test3.d 2
131 foo.d 2
132 """)
133
134 test.up_to_date(arguments='.')
135
136 test.write('test2.d', """\
137 test2.d 2
138 import foo;
139 """)
140
141 test.run(arguments='.', stdout=test.wrap_stdout("""\
142 %s mydc.py test1.o test1.d
143 Install file: "test2.d" as "test2_d"
144 """ % (python,)))
145
146 test.must_match('test1.o', """\
147 test1.d 1
148 test2.d 2
149 foo.d 2
150 test3.d 2
151 foo.d 2
152 """)
153
154 test.up_to_date(arguments='.')
155
156 test.pass_test()