Added fix for TeX includes with same name as subdirs.
[scons.git] / test / rebuild-generated.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 case for the bug report:
29 "[ 1088979 ] Unnecessary rebuild with generated header file"
30 (<http://sourceforge.net/tracker/index.php?func=detail&aid=1088979&group_id=30337&atid=398971>).
31
32 Unnecessary rebuild with generated header file
33 Scons rebuilds some nodes when invoked twice. The
34 trigger seems to be a generated C++ source file that
35 includes a header file that also is generated.
36
37 A tarball with a minimal test case is attached.
38 Transcript for reproducing:
39
40 cd /tmp
41 tar xzf scons_rebuild_debug.tar.gz
42 cd scons_rebuild_debug
43 scons target.o
44 scons target.o
45
46
47 Note that the bug is not triggered when scons is run
48 without arguments.
49
50 This may be a duplicate to bug 1019683.
51 """
52
53 import os
54 import sys
55 import TestSCons
56
57 test = TestSCons.TestSCons()
58
59 _obj = TestSCons._obj
60
61 if sys.platform == 'win32':
62     generator_name = 'generator.bat'
63     test.write(generator_name, '@echo #include "header.hh"')
64     kernel_action = "$SOURCES  > $TARGET"
65 else:
66     generator_name = 'generator.sh'
67     test.write(generator_name, 'echo \'#include "header.hh"\'')
68     kernel_action = "sh $SOURCES  > $TARGET"
69
70 test.write('SConstruct', """\
71
72 env = Environment()
73
74 kernelDefines = env.Command("header.hh",
75                             [],
76                             Touch("$TARGET"))
77
78 kernelImporterSource = env.Command(
79   "generated.cc", ["%s"],
80   "%s")
81
82 kernelImporter = env.Program(
83   kernelImporterSource + ["main.cc"])
84
85 kernelImports = env.Command(
86   "KernelImport.hh", kernelImporter,
87   ".%s$SOURCE > $TARGET")
88                                         
89 osLinuxModule = env.StaticObject(
90   ["target.cc"])
91 """ % (generator_name, kernel_action, os.sep))
92
93 test.write('main.cc', """\
94 int
95 main(int, char *[])
96 {
97     return (0);
98 }
99 """)
100
101 test.write('target.cc', """\
102 #if 0
103
104 #include "KernelImport.hh"
105
106 #endif
107 """)
108
109 test.run(arguments = 'target' + _obj)
110
111 expected_stdout = """\
112 scons: Reading SConscript files ...
113 scons: done reading SConscript files.
114 scons: Building targets ...
115 scons: `target%(_obj)s' is up to date.
116 scons: done building targets.
117 """ % locals()
118
119 test.run(arguments = 'target' + _obj, stdout=expected_stdout)
120
121 test.pass_test()
122
123 # Local Variables:
124 # tab-width:4
125 # indent-tabs-mode:nil
126 # End:
127 # vim: set expandtab tabstop=4 shiftwidth=4: