Merge pull request #4584 from siegria/fix_piped_spawn_encoding
[scons.git] / test / rebuild-generated.py
blob1b4292f878548b7b9d3da85e457f9652991d2455
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 (<https://sourceforge.net/tracker/index.php?func=detail&aid=1088979&group_id=30337&atid=398971>).
30 (historical - dead link)
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.
37 A tarball with a minimal test case is attached.
38 Transcript for reproducing:
40 cd /tmp
41 tar xzf scons_rebuild_debug.tar.gz
42 cd scons_rebuild_debug
43 scons target.o
44 scons target.o
47 Note that the bug is not triggered when scons is run
48 without arguments.
50 This may be a duplicate to bug 1019683.
51 """
53 import os
54 import sys
55 import sysconfig
57 import TestSCons
59 test = TestSCons.TestSCons()
61 _obj = TestSCons._obj
63 if sys.platform == 'win32' and not sysconfig.get_platform() in ("mingw",):
65 generator_name = 'generator.bat'
66 test.write(generator_name, '@echo #include "header.hh"')
67 kernel_action = "$SOURCES > $TARGET"
68 else:
69 generator_name = 'generator.sh'
70 test.write(generator_name, 'echo \'#include "header.hh"\'')
71 kernel_action = "sh $SOURCES > $TARGET"
73 if sysconfig.get_platform() in ("mingw",):
74 # mingw Python uses a sep of '/', when Command fires, that will not work.
75 # use its altsep instead, that is the standard Windows separator.
76 sep = os.altsep
77 else:
78 sep = os.sep
81 test.write('SConstruct', """\
82 env = Environment()
84 kernelDefines = env.Command("header.hh", "header.hh.in", Copy('$TARGET', '$SOURCE'))
85 kernelImporterSource = env.Command("generated.cc", ["%s"], "%s")
86 kernelImporter = env.Program(kernelImporterSource + ["main.cc"])
87 kernelImports = env.Command("KernelImport.hh", kernelImporter, r".%s$SOURCE > $TARGET")
88 osLinuxModule = env.StaticObject(["target.cc"])
89 """ % (generator_name, kernel_action, sep))
91 test.write('main.cc', """\
92 int
93 main(int, char *[])
95 return (0);
97 """)
99 test.write('target.cc', """\
100 #if 0
102 #include "KernelImport.hh"
104 #endif
105 """)
107 test.write("header.hh.in", "#define HEADER_HH 1\n")
109 test.run(arguments = 'target' + _obj)
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()
119 test.run(arguments = 'target' + _obj, stdout=expected_stdout)
121 test.pass_test()
123 # Local Variables:
124 # tab-width:4
125 # indent-tabs-mode:nil
126 # End:
127 # vim: set expandtab tabstop=4 shiftwidth=4: