Added fix for TeX includes with same name as subdirs.
[scons.git] / test / srcchange.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 changing the C source files based on an always-executed revision
29 extraction and substitution.
30
31 This makes sure we evaluate the content of intermediate files as
32 expected.  We used to configure this explicitly using
33 TargetSignatures('content') but we now rely on the default behavior
34 being the equivalent of Decider('content').
35 """
36
37 import os.path
38
39 import TestSCons
40
41 _python_ = TestSCons._python_
42
43 test = TestSCons.TestSCons()
44
45 test.write('getrevision', """
46 #!/usr/bin/env python
47 print open('revnum.in','rb').read().strip()
48 """)
49
50 test.write('SConstruct', """
51 import re
52
53 def subrevision(target, source ,env):
54     orig = target[0].get_text_contents()
55     new = re.sub('\$REV.*?\$',
56                  '$REV: %%s$'%%source[0].get_text_contents().strip(),
57                  target[0].get_text_contents())
58     outf = open(str(target[0]),'wb')
59     outf.write(new)
60     outf.close()
61
62 SubRevision = Action(subrevision)
63
64 env=Environment()
65 content_env=env.Clone()
66 content_env.Command('revision.in', [], '%(_python_)s getrevision > $TARGET')
67 content_env.AlwaysBuild('revision.in')
68 env.Precious('main.c')
69 env.Command('main.c', 'revision.in', SubRevision)
70 exe = env.Program('main.c')
71 env.Default(exe)
72 """ % locals())
73
74 test.write('main.c', """\
75 #include <stdio.h>
76 #include <stdlib.h>
77 #include <stdio.h>
78 int
79 main(int argc, char *argv[])
80 {
81     printf("Revision $REV$\\n");
82     exit (0);
83 }
84 """)
85
86 test.write('revnum.in', '3.2\n')
87
88 prog = 'main' + TestSCons._exe
89
90 light_build=test.wrap_stdout("""\
91 %(_python_)s getrevision > revision.in
92 """ % locals())
93
94 test.run(arguments='.')
95 test.must_exist(prog)
96 test.run(program=test.workpath(prog), stdout='Revision $REV: 3.2$\n')
97
98 test.run(arguments='.', stdout=light_build)
99 test.must_exist(prog)
100
101 test.run(arguments='.', stdout=light_build)
102 test.must_exist(prog)
103
104 test.write('revnum.in', '3.3\n')
105
106 test.run(arguments='.')
107 test.must_exist(prog)
108 test.run(program=test.workpath(prog), stdout='Revision $REV: 3.3$\n')
109
110 test.pass_test()
111
112 # Local Variables:
113 # tab-width:4
114 # indent-tabs-mode:nil
115 # End:
116 # vim: set expandtab tabstop=4 shiftwidth=4: