Updates to PR 4374 from mwichmann to correct config file hash changes
[scons.git] / test / rebuild-generated.py
blob91b4e1e7c3b4a4182759fd94daf3d6fca4df4b53
1 #!/usr/bin/env python
3 # MIT License
5 # Copyright The SCons Foundation
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 """
27 Test case for the bug report:
28 "[ 1088979 ] Unnecessary rebuild with generated header file"
29 (<http://sourceforge.net/tracker/index.php?func=detail&aid=1088979&group_id=30337&atid=398971>).
31 Unnecessary rebuild with generated header file
32 Scons rebuilds some nodes when invoked twice. The
33 trigger seems to be a generated C++ source file that
34 includes a header file that also is generated.
36 A tarball with a minimal test case is attached.
37 Transcript for reproducing:
39 cd /tmp
40 tar xzf scons_rebuild_debug.tar.gz
41 cd scons_rebuild_debug
42 scons target.o
43 scons target.o
46 Note that the bug is not triggered when scons is run
47 without arguments.
49 This may be a duplicate to bug 1019683.
50 """
52 import os
53 import sys
54 import sysconfig
56 import TestSCons
58 test = TestSCons.TestSCons()
60 _obj = TestSCons._obj
62 if sys.platform == 'win32' and not sysconfig.get_platform() in ("mingw",):
64 generator_name = 'generator.bat'
65 test.write(generator_name, '@echo #include "header.hh"')
66 kernel_action = "$SOURCES > $TARGET"
67 else:
68 generator_name = 'generator.sh'
69 test.write(generator_name, 'echo \'#include "header.hh"\'')
70 kernel_action = "sh $SOURCES > $TARGET"
72 if sysconfig.get_platform() in ("mingw",):
73 # mingw Python uses a sep of '/', when Command fires, that will not work.
74 # use its altsep instead, that is the standard Windows separator.
75 sep = os.altsep
76 else:
77 sep = os.sep
80 test.write('SConstruct', """\
81 env = Environment()
83 kernelDefines = env.Command("header.hh", "header.hh.in", Copy('$TARGET', '$SOURCE'))
84 kernelImporterSource = env.Command("generated.cc", ["%s"], "%s")
85 kernelImporter = env.Program(kernelImporterSource + ["main.cc"])
86 kernelImports = env.Command("KernelImport.hh", kernelImporter, r".%s$SOURCE > $TARGET")
87 osLinuxModule = env.StaticObject(["target.cc"])
88 """ % (generator_name, kernel_action, sep))
90 test.write('main.cc', """\
91 int
92 main(int, char *[])
94 return (0);
96 """)
98 test.write('target.cc', """\
99 #if 0
101 #include "KernelImport.hh"
103 #endif
104 """)
106 test.write("header.hh.in", "#define HEADER_HH 1\n")
108 test.run(arguments = 'target' + _obj)
110 expected_stdout = """\
111 scons: Reading SConscript files ...
112 scons: done reading SConscript files.
113 scons: Building targets ...
114 scons: `target%(_obj)s' is up to date.
115 scons: done building targets.
116 """ % locals()
118 test.run(arguments = 'target' + _obj, stdout=expected_stdout)
120 test.pass_test()
122 # Local Variables:
123 # tab-width:4
124 # indent-tabs-mode:nil
125 # End:
126 # vim: set expandtab tabstop=4 shiftwidth=4: