added release.txt blurb. Fixed spelling typo in Defaults.xml
[scons.git] / test / srcchange.py
blobe72d923a2210ffcabb4b28ba1b5af02caa645bd5
1 #!/usr/bin/env python
3 # __COPYRIGHT__
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:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
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.
24 """
25 Test changing the C source files based on an always-executed revision
26 extraction and substitution.
28 This makes sure we evaluate the content of intermediate files as
29 expected. This relies on the default behavior being the equivalent
30 of Decider('content').
31 """
33 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
36 import TestSCons
38 _python_ = TestSCons._python_
40 test = TestSCons.TestSCons()
42 test.write('getrevision', r"""
43 with open('revnum.in', 'r') as f:
44 print(f.read().strip(), end='')
45 """)
47 test.write('SConstruct', r"""
48 import re
50 def subrevision(target, source ,env):
51 orig = target[0].get_text_contents()
52 new = re.sub(r'\$REV.*?\$',
53 '$REV: %%s$'%%source[0].get_text_contents().strip(),
54 target[0].get_text_contents())
55 with open(str(target[0]),'w') as outf:
56 outf.write(new)
58 SubRevision = Action(subrevision)
60 env=Environment()
61 content_env=env.Clone()
62 content_env.Command('revision.in', [], r'%(_python_)s getrevision > $TARGET')
63 content_env.AlwaysBuild('revision.in')
64 env.Precious('main.c')
65 env.Command('main.c', 'revision.in', SubRevision)
66 exe = env.Program('main.c')
67 env.Default(exe)
68 """ % locals())
70 test.write('main.c', r"""
71 #include <stdio.h>
72 #include <stdlib.h>
73 #include <stdio.h>
74 int
75 main(int argc, char *argv[])
77 printf("Revision $REV$\n");
78 exit (0);
81 """, mode='w')
83 test.write('revnum.in', '3.2\n')
85 program_name = 'main' + TestSCons._exe
87 light_build = test.wrap_stdout("""\
88 %(_python_)s getrevision > revision.in
89 """ % locals())
91 test.run(arguments='.')
92 test.must_exist(program_name)
93 test.run(program=test.workpath(program_name), stdout='Revision $REV: 3.2$\n')
95 test.run(arguments='.', stdout=light_build)
96 test.must_exist(program_name)
98 test.run(arguments='.', stdout=light_build)
99 test.must_exist(program_name)
101 test.write('revnum.in', '3.3\n', mode='w')
103 test.run(arguments='.')
104 test.must_exist(program_name)
105 test.run(program=test.workpath(program_name), stdout='Revision $REV: 3.3$\n')
107 test.pass_test()
109 # Local Variables:
110 # tab-width:4
111 # indent-tabs-mode:nil
112 # End:
113 # vim: set expandtab tabstop=4 shiftwidth=4: