Updates to PR 4374 from mwichmann to correct config file hash changes
[scons.git] / test / Configure / option--config.py
blob3fd0691df77b5db434415ba2b33a35fa901bae51
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.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
27 """
28 Verify use of the --config=<auto|force|cache> option.
29 """
31 import os.path
33 from TestSCons import TestSCons, ConfigCheckInfo, _obj
34 from TestCmd import IS_WINDOWS
35 from SCons.Util import get_current_hash_algorithm_used
37 test = TestSCons()
39 test.subdir('include')
41 NCR = test.NCR # non-cached rebuild
42 CR = test.CR # cached rebuild (up to date)
43 NCF = test.NCF # non-cached build failure
44 CF = test.CF # cached build failure
46 # as this test is somewhat complicated, skip it if the library doesn't support md5
47 # as the default hashing algorithm.
48 if get_current_hash_algorithm_used() != 'md5':
49 test.skip_test('Skipping test as could not continue without the hash algorithm set to md5!')
51 SConstruct_path = test.workpath('SConstruct')
53 test.write(SConstruct_path, """
54 env = Environment(CPPPATH='#/include')
55 import os
56 env.AppendENVPath('PATH', os.environ['PATH'])
57 conf = Configure(env)
58 conf.CheckCHeader('non_system_header0.h')
59 conf.CheckCHeader('non_system_header1.h')
60 env = conf.Finish()
61 """)
63 test.write(['include', 'non_system_header0.h'], """
64 /* A header */
65 """)
67 conftest_0_c_hash = 'cda36b76729ffb03bf36a48d13b2d98d'
68 conftest_1_c_hash = 'acc476a565a3f6d5d67ddc21f187d062'
70 if IS_WINDOWS:
71 conftest_0_obj_suffix = '_213c72f9eb682c6f27f2eb78ed8bd57a'+_obj
72 conftest_1_obj_suffix = '_7c505229a64dccfea6e7cfdffe76bd2a'+_obj
73 else:
74 conftest_0_obj_suffix = '_9b191e4c46e9d6ba17c8cd4d730900cf'+_obj
75 conftest_1_obj_suffix = '_b9da1a844a8707269188b28a62c0d83e'+_obj
77 conftest_0_base = os.path.join(".sconf_temp", "conftest_%s_0%%s"%conftest_0_c_hash)
78 conftest_0_c = conftest_0_base%'.c'
79 conftest_1_base = os.path.join(".sconf_temp", "conftest_%s_0%%s"%conftest_1_c_hash)
81 SConstruct_file_line = test.python_file_line(SConstruct_path, 6)[:-1]
83 expect = """
84 scons: *** "%(conftest_0_c)s" is not yet built and cache is forced.
85 %(SConstruct_file_line)s
86 """ % locals()
88 test.run(arguments='--config=cache', status=2, stderr=expect)
90 test.run(arguments='--config=auto')
91 test.checkConfigureLogAndStdout(checks=[
92 ConfigCheckInfo("Checking for C header file non_system_header0.h... ",
93 'yes',
94 [((".c", NCR),
95 (_obj, NCR))],
96 conftest_0_base
98 ConfigCheckInfo("Checking for C header file non_system_header1.h... ",
99 'no',
100 [((".c", NCR),
101 (_obj, NCF))],
102 conftest_1_base)]
105 test.run(arguments='--config=auto')
106 test.checkConfigureLogAndStdout(checks=[
107 ConfigCheckInfo("Checking for C header file non_system_header0.h... ",
108 'yes',
109 [((".c", CR),
110 (conftest_0_obj_suffix, CR))],
111 conftest_0_base,
113 ConfigCheckInfo("Checking for C header file non_system_header1.h... ",
114 'no',
115 [((".c", CR),
116 (conftest_1_obj_suffix, CF))],
117 conftest_1_base)]
121 test.run(arguments='--config=force')
122 test.checkConfigureLogAndStdout(checks=[
123 ConfigCheckInfo("Checking for C header file non_system_header0.h... ",
124 'yes',
125 [((".c", NCR),
126 (conftest_0_obj_suffix, NCR))],
127 conftest_0_base,
129 ConfigCheckInfo("Checking for C header file non_system_header1.h... ",
130 'no',
131 [((".c", NCR),
132 (conftest_1_obj_suffix, NCF))],
133 conftest_1_base)]
137 test.run(arguments='--config=cache')
138 test.checkConfigureLogAndStdout(checks=[
139 ConfigCheckInfo("Checking for C header file non_system_header0.h... ",
140 'yes',
141 [((".c", CR),
142 (conftest_0_obj_suffix, CR))],
143 conftest_0_base,
145 ConfigCheckInfo("Checking for C header file non_system_header1.h... ",
146 'no',
147 [((".c", CR),
148 (conftest_1_obj_suffix, CF))],
149 conftest_1_base)]
153 test.write(['include', 'non_system_header1.h'], """
154 /* Another header */
155 """)
156 test.unlink(['include', 'non_system_header0.h'])
158 test.run(arguments='--config=cache')
160 test.checkConfigureLogAndStdout(checks=[
161 ConfigCheckInfo("Checking for C header file non_system_header0.h... ",
162 'yes',
163 [((".c", CR),
164 (conftest_0_obj_suffix, CR))],
165 conftest_0_base,
167 ConfigCheckInfo("Checking for C header file non_system_header1.h... ",
168 'no',
169 [((".c", CR),
170 (conftest_1_obj_suffix, CF))],
171 conftest_1_base)]
174 test.run(arguments='--config=auto')
175 test.checkConfigureLogAndStdout(checks=[
176 ConfigCheckInfo("Checking for C header file non_system_header0.h... ",
177 'no',
178 [((".c", CR),
179 (conftest_0_obj_suffix, NCF))],
180 conftest_0_base,
182 ConfigCheckInfo("Checking for C header file non_system_header1.h... ",
183 'yes',
184 [((".c", CR),
185 (conftest_1_obj_suffix, NCR))],
186 conftest_1_base)]
189 test.file_fixture('test_main.c')
191 # Check the combination of --config=force and Decider('MD5-timestamp')
192 SConstruct_path = test.workpath('SConstruct')
193 test.write(SConstruct_path, """
194 env = Environment()
195 env.Decider('MD5-timestamp')
196 conf = Configure(env)
197 conf.TryLink('int main(){return 0;}','.c')
198 env = conf.Finish()
199 env.Program('test_main.c')
200 """)
201 test.run(arguments='--config=force')
202 # On second run the sconsign is loaded and decider doesn't just indicate need to rebuild
203 test.run(arguments='--config=force')
204 test.must_not_contain(test.workpath('config.log'), "TypeError: 'NoneType' object is not callable", mode='r')
206 # Now check to check that test_main.c didn't rebuild on second run above.
207 # This fixes an issue where --config=force overwrites the Environments decider and is not reset when
208 # the configure context is done.
209 # https://github.com/SCons/scons/issues/3303
210 test.fail_test('test_main.o' in test.stdout())
212 test.pass_test()
214 # Local Variables:
215 # tab-width:4
216 # indent-tabs-mode:nil
217 # End:
218 # vim: set expandtab tabstop=4 shiftwidth=4: