fa07a8804efceea7f60496be48f33d18a8aa7b1b
[scons.git] / test / DirSource.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 sys
35 import TestSCons
36
37
38 test = TestSCons.TestSCons()
39
40 test.subdir('bsig', [ 'bsig', 'subdir' ],
41             'csig', [ 'csig', 'subdir' ],
42             'cmd-bsig', [ 'cmd-bsig', 'subdir' ],
43             'cmd-csig', [ 'cmd-csig', 'subdir' ])
44
45 test.write('SConstruct', """\
46 def writeTarget(target, source, env):
47     f=open(str(target[0]), 'wb')
48     f.write("stuff\\n")
49     f.close()
50     return 0
51
52 test_bld_dir = Builder(action=writeTarget,
53                        source_factory=Dir,
54                        source_scanner=DirScanner)
55 test_bld_file = Builder(action=writeTarget)
56 env = Environment()
57 env['BUILDERS']['TestDir'] = test_bld_dir
58 env['BUILDERS']['TestFile'] = test_bld_file
59
60 env_bsig = env.Clone()
61 env_bsig.TargetSignatures('build')
62 env_bsig.TestFile(source='junk.txt', target='bsig/junk.out')
63 env_bsig.TestDir(source='bsig', target='bsig.out')
64 env_bsig.Command('cmd-bsig-noscan.out', 'cmd-bsig', writeTarget)
65 env_bsig.Command('cmd-bsig.out', 'cmd-bsig', writeTarget,
66                  source_scanner=DirScanner)
67
68 env_csig = env.Clone()
69 env_csig.TargetSignatures('content')
70 env_csig.TestFile(source='junk.txt', target='csig/junk.out')
71 env_csig.TestDir(source='csig', target='csig.out')
72 env_csig.Command('cmd-csig-noscan.out', 'cmd-csig', writeTarget)
73 env_csig.Command('cmd-csig.out', 'cmd-csig', writeTarget,
74                  source_scanner=DirScanner)
75 """)
76
77 test.write([ 'bsig', 'foo.txt' ], 'foo.txt 1\n')
78 test.write([ 'bsig', '#hash.txt' ], 'hash.txt 1\n')
79 test.write([ 'bsig', 'subdir', 'bar.txt'], 'bar.txt 1\n')
80 test.write([ 'bsig', 'subdir', '#hash.txt'], 'hash.txt 1\n')
81 test.write([ 'csig', 'foo.txt' ], 'foo.txt 1\n')
82 test.write([ 'csig', '#hash.txt' ], 'hash.txt 1\n')
83 test.write([ 'csig', 'subdir', 'bar.txt' ], 'bar.txt 1\n')
84 test.write([ 'csig', 'subdir', '#hash.txt' ], 'hash.txt 1\n')
85 test.write([ 'cmd-bsig', 'foo.txt' ], 'foo.txt 1\n')
86 test.write([ 'cmd-bsig', '#hash.txt' ], 'hash.txt 1\n')
87 test.write([ 'cmd-bsig', 'subdir', 'bar.txt' ], 'bar.txt 1\n')
88 test.write([ 'cmd-bsig', 'subdir', '#hash.txt' ], 'hash.txt 1\n')
89 test.write([ 'cmd-csig', 'foo.txt' ], 'foo.txt 1\n')
90 test.write([ 'cmd-csig', '#hash.txt' ], '#hash.txt 1\n')
91 test.write([ 'cmd-csig', 'subdir', 'bar.txt' ], 'bar.txt 1\n')
92 test.write([ 'cmd-csig', 'subdir', '#hash.txt' ], 'hash.txt 1\n')
93 test.write('junk.txt', 'junk.txt\n')
94
95 test.run(arguments=".", stderr=None)
96 test.must_match('bsig.out', 'stuff\n')
97 test.must_match('csig.out', 'stuff\n')
98 test.must_match('cmd-bsig.out', 'stuff\n')
99 test.must_match('cmd-csig.out', 'stuff\n')
100 test.must_match('cmd-bsig-noscan.out', 'stuff\n')
101 test.must_match('cmd-csig-noscan.out', 'stuff\n')
102
103 test.up_to_date(arguments='bsig.out')
104 test.up_to_date(arguments='csig.out')
105 test.up_to_date(arguments='cmd-bsig.out')
106 test.up_to_date(arguments='cmd-csig.out')
107 test.up_to_date(arguments='cmd-bsig-noscan.out')
108 test.up_to_date(arguments='cmd-csig-noscan.out')
109
110 test.write([ 'bsig', 'foo.txt' ], 'foo.txt 2\n')
111 test.not_up_to_date(arguments='bsig.out')
112
113 test.write([ 'bsig', 'new.txt' ], 'new.txt\n')
114 test.not_up_to_date(arguments='bsig.out')
115
116 test.write([ 'csig', 'foo.txt' ], 'foo.txt 2\n')
117 test.not_up_to_date(arguments='csig.out')
118
119 test.write([ 'csig', 'new.txt' ], 'new.txt\n')
120 test.not_up_to_date(arguments='csig.out')
121
122 test.write([ 'cmd-bsig', 'foo.txt' ], 'foo.txt 2\n')
123 test.not_up_to_date(arguments='cmd-bsig.out')
124 test.up_to_date(arguments='cmd-bsig-noscan.out')
125
126 test.write([ 'cmd-bsig', 'new.txt' ], 'new.txt\n')
127 test.not_up_to_date(arguments='cmd-bsig.out')
128 test.up_to_date(arguments='cmd-bsig-noscan.out')
129
130 test.write([ 'cmd-csig', 'foo.txt' ], 'foo.txt 2\n')
131 test.not_up_to_date(arguments='cmd-csig.out')
132 test.up_to_date(arguments='cmd-csig-noscan.out')
133
134 test.write([ 'cmd-csig', 'new.txt' ], 'new.txt\n')
135 test.not_up_to_date(arguments='cmd-csig.out')
136 test.up_to_date(arguments='cmd-csig-noscan.out')
137
138 test.write([ 'bsig', 'subdir', 'bar.txt' ], 'bar.txt 2\n')
139 test.not_up_to_date(arguments='bsig.out')
140
141 test.write([ 'bsig', 'subdir', 'new.txt' ], 'new.txt\n')
142 test.not_up_to_date(arguments='bsig.out')
143
144 test.write([ 'csig', 'subdir', 'bar.txt' ], 'bar.txt 2\n')
145 test.not_up_to_date(arguments='csig.out')
146
147 test.write([ 'csig', 'subdir', 'new.txt' ], 'new.txt\n')
148 test.not_up_to_date(arguments='csig.out')
149
150 test.write([ 'cmd-bsig', 'subdir', 'bar.txt' ], 'bar.txt 2\n')
151 test.not_up_to_date(arguments='cmd-bsig.out')
152 test.up_to_date(arguments='cmd-bsig-noscan.out')
153
154 test.write([ 'cmd-bsig', 'subdir', 'new.txt' ], 'new.txt\n')
155 test.not_up_to_date(arguments='cmd-bsig.out')
156 test.up_to_date(arguments='cmd-bsig-noscan.out')
157
158 test.write([ 'cmd-csig', 'subdir', 'bar.txt' ], 'bar.txt 2\n')
159 test.not_up_to_date(arguments='cmd-csig.out')
160 test.up_to_date(arguments='cmd-csig-noscan.out')
161
162 test.write([ 'cmd-csig', 'subdir', 'new.txt' ], 'new.txt\n')
163 test.not_up_to_date(arguments='cmd-csig.out')
164 test.up_to_date(arguments='cmd-csig-noscan.out')
165
166 test.write('junk.txt', 'junk.txt 2\n')
167 test.not_up_to_date(arguments='bsig.out')
168 # XXX For some reason, 'csig' is still reported as up to date.
169 # XXX Comment out this test until someone can look at it.
170 #test.not_up_to_date(arguments='csig.out')
171
172 test.pass_test()