Issue 2505: fix use of pre-compiled headers when the source .cpp
[scons.git] / test / Dir / source.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 This test tests directories as source files.  The correct behavior is that
29 any file under a directory acts like a source file of that directory.
30 In other words, if a build has a directory as a source file, any
31 change in any file under that directory should trigger a rebuild.
32 """
33
34 import TestSCons
35
36
37 test = TestSCons.TestSCons()
38
39 test.subdir('tstamp', [ 'tstamp', 'subdir' ],
40             'content', [ 'content', 'subdir' ],
41             'cmd-tstamp', [ 'cmd-tstamp', 'subdir' ],
42             'cmd-content', [ 'cmd-content', 'subdir' ])
43
44 test.write('SConstruct', """\
45 def writeTarget(target, source, env):
46     f=open(str(target[0]), 'wb')
47     f.write("stuff\\n")
48     f.close()
49     return 0
50
51 test_bld_dir = Builder(action=writeTarget,
52                        source_factory=Dir,
53                        source_scanner=DirScanner)
54 test_bld_file = Builder(action=writeTarget)
55 env = Environment()
56 env['BUILDERS']['TestDir'] = test_bld_dir
57 env['BUILDERS']['TestFile'] = test_bld_file
58
59 env_tstamp = env.Clone()
60 env_tstamp.Decider('timestamp-newer')
61 env_tstamp.TestFile(source='junk.txt', target='tstamp/junk.out')
62 env_tstamp.TestDir(source='tstamp', target='tstamp.out')
63 env_tstamp.Command('cmd-tstamp-noscan.out', 'cmd-tstamp', writeTarget)
64 env_tstamp.Command('cmd-tstamp.out', 'cmd-tstamp', writeTarget,
65                  source_scanner=DirScanner)
66
67 env_content = env.Clone()
68 env_content.Decider('content')
69 env_content.TestFile(source='junk.txt', target='content/junk.out')
70 env_content.TestDir(source='content', target='content.out')
71 env_content.Command('cmd-content-noscan.out', 'cmd-content', writeTarget)
72 env_content.Command('cmd-content.out', 'cmd-content', writeTarget,
73                  source_scanner=DirScanner)
74 """)
75
76 test.write([ 'tstamp', 'foo.txt' ], 'foo.txt 1\n')
77 test.write([ 'tstamp', '#hash.txt' ], 'hash.txt 1\n')
78 test.write([ 'tstamp', 'subdir', 'bar.txt'], 'bar.txt 1\n')
79 test.write([ 'tstamp', 'subdir', '#hash.txt'], 'hash.txt 1\n')
80 test.write([ 'content', 'foo.txt' ], 'foo.txt 1\n')
81 test.write([ 'content', '#hash.txt' ], 'hash.txt 1\n')
82 test.write([ 'content', 'subdir', 'bar.txt' ], 'bar.txt 1\n')
83 test.write([ 'content', 'subdir', '#hash.txt' ], 'hash.txt 1\n')
84 test.write([ 'cmd-tstamp', 'foo.txt' ], 'foo.txt 1\n')
85 test.write([ 'cmd-tstamp', '#hash.txt' ], 'hash.txt 1\n')
86 test.write([ 'cmd-tstamp', 'subdir', 'bar.txt' ], 'bar.txt 1\n')
87 test.write([ 'cmd-tstamp', 'subdir', '#hash.txt' ], 'hash.txt 1\n')
88 test.write([ 'cmd-content', 'foo.txt' ], 'foo.txt 1\n')
89 test.write([ 'cmd-content', '#hash.txt' ], '#hash.txt 1\n')
90 test.write([ 'cmd-content', 'subdir', 'bar.txt' ], 'bar.txt 1\n')
91 test.write([ 'cmd-content', 'subdir', '#hash.txt' ], 'hash.txt 1\n')
92 test.write('junk.txt', 'junk.txt\n')
93
94 test.run(arguments=".", stderr=None)
95 test.must_match('tstamp.out', 'stuff\n')
96 test.must_match('content.out', 'stuff\n')
97 test.must_match('cmd-tstamp.out', 'stuff\n')
98 test.must_match('cmd-content.out', 'stuff\n')
99 test.must_match('cmd-tstamp-noscan.out', 'stuff\n')
100 test.must_match('cmd-content-noscan.out', 'stuff\n')
101
102 test.up_to_date(arguments='tstamp.out')
103 test.up_to_date(arguments='content.out')
104 test.up_to_date(arguments='cmd-tstamp.out')
105 test.up_to_date(arguments='cmd-content.out')
106 test.up_to_date(arguments='cmd-tstamp-noscan.out')
107 test.up_to_date(arguments='cmd-content-noscan.out')
108
109 test.write([ 'tstamp', 'foo.txt' ], 'foo.txt 2\n')
110 test.not_up_to_date(arguments='tstamp.out')
111
112 test.write([ 'tstamp', 'new.txt' ], 'new.txt\n')
113 test.not_up_to_date(arguments='tstamp.out')
114
115 test.write([ 'content', 'foo.txt' ], 'foo.txt 2\n')
116 test.not_up_to_date(arguments='content.out')
117
118 test.write([ 'content', 'new.txt' ], 'new.txt\n')
119 test.not_up_to_date(arguments='content.out')
120
121 test.write([ 'cmd-tstamp', 'foo.txt' ], 'foo.txt 2\n')
122 test.not_up_to_date(arguments='cmd-tstamp.out')
123 test.up_to_date(arguments='cmd-tstamp-noscan.out')
124
125 test.write([ 'cmd-tstamp', 'new.txt' ], 'new.txt\n')
126 test.not_up_to_date(arguments='cmd-tstamp.out')
127 test.up_to_date(arguments='cmd-tstamp-noscan.out')
128
129 test.write([ 'cmd-content', 'foo.txt' ], 'foo.txt 2\n')
130 test.not_up_to_date(arguments='cmd-content.out')
131 test.up_to_date(arguments='cmd-content-noscan.out')
132
133 test.write([ 'cmd-content', 'new.txt' ], 'new.txt\n')
134 test.not_up_to_date(arguments='cmd-content.out')
135 test.up_to_date(arguments='cmd-content-noscan.out')
136
137 test.write([ 'tstamp', 'subdir', 'bar.txt' ], 'bar.txt 2\n')
138 test.not_up_to_date(arguments='tstamp.out')
139
140 test.write([ 'tstamp', 'subdir', 'new.txt' ], 'new.txt\n')
141 test.not_up_to_date(arguments='tstamp.out')
142
143 test.write([ 'content', 'subdir', 'bar.txt' ], 'bar.txt 2\n')
144 test.not_up_to_date(arguments='content.out')
145
146 test.write([ 'content', 'subdir', 'new.txt' ], 'new.txt\n')
147 test.not_up_to_date(arguments='content.out')
148
149 test.write([ 'cmd-tstamp', 'subdir', 'bar.txt' ], 'bar.txt 2\n')
150 test.not_up_to_date(arguments='cmd-tstamp.out')
151 test.up_to_date(arguments='cmd-tstamp-noscan.out')
152
153 test.write([ 'cmd-tstamp', 'subdir', 'new.txt' ], 'new.txt\n')
154 test.not_up_to_date(arguments='cmd-tstamp.out')
155 test.up_to_date(arguments='cmd-tstamp-noscan.out')
156
157 test.write([ 'cmd-content', 'subdir', 'bar.txt' ], 'bar.txt 2\n')
158 test.not_up_to_date(arguments='cmd-content.out')
159 test.up_to_date(arguments='cmd-content-noscan.out')
160
161 test.write([ 'cmd-content', 'subdir', 'new.txt' ], 'new.txt\n')
162 test.not_up_to_date(arguments='cmd-content.out')
163 test.up_to_date(arguments='cmd-content-noscan.out')
164
165 test.write('junk.txt', 'junk.txt 2\n')
166 test.not_up_to_date(arguments='tstamp.out')
167 test.not_up_to_date(arguments='content.out')
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: