[ci skip] Add note that this change may break SetOption() + ninja usage with fix
[scons.git] / test / Configure / ConfigureDryRunError.py
blobae3b2ff1add91b685d497a1330706c885d7f3a1f
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.
27 """
28 Verify the ConfigureDryRunError.
29 """
31 import os
33 import TestSCons
35 from SCons.Util import get_current_hash_algorithm_used
37 _obj = TestSCons._obj
39 test = TestSCons.TestSCons()
41 lib = test.Configure_lib
43 NCR = test.NCR # non-cached rebuild
44 CR = test.CR # cached rebuild (up to date)
45 NCF = test.NCF # non-cached build failure
46 CF = test.CF # cached build failure
48 SConstruct_path = test.workpath('SConstruct')
50 test.write(SConstruct_path, """
52 import os
53 DefaultEnvironment(tools=[])
55 env = Environment()
56 env.AppendENVPath('PATH', os.environ['PATH'])
57 conf = Configure(env)
58 r1 = conf.CheckLib('%s') # will pass
59 r2 = conf.CheckLib('hopefullynolib') # will fail
60 env = conf.Finish()
61 if not (r1 and not r2):
62 Exit(1)
63 """ % lib)
65 expect = """
66 scons: *** Cannot create configure directory ".sconf_temp" within a dry-run.
67 """ + test.python_file_line(SConstruct_path, 8)
69 test.run(arguments='-n', status=2, stderr=expect)
71 test.must_not_exist('config.log')
72 test.subdir('.sconf_temp')
74 # depending on which default hash function we're using, we'd expect one
75 # of the following filenames. The filenames are generated by the conftest
76 # changes in #3543 : https://github.com/SCons/scons/pull/3543
77 # Note if the code generated for CheckLib(Configure_lib) changes, we need
78 # to recompute the hashes of the generated file - even though it won't
79 # even be built for this test.
80 possible_filenames = {
81 'md5': 'conftest_e492448966d6e04631c094ba6d6e8a32_0.c',
82 'sha1': 'conftest_f0a9e7fe48f48687797dbafb5d07071d35f86dd2_0.c',
83 'sha256': 'conftest_e856bf0bdb229b16823f193eee68254b885340d0b2f0277ff2eaca78aa0ba7aa_0.c',
85 test_filename = possible_filenames[get_current_hash_algorithm_used()]
87 conftest_0_c = os.path.join(".sconf_temp", test_filename)
88 SConstruct_file_line = test.python_file_line(SConstruct_path, 9)[:-1]
90 expect = """
91 scons: *** Cannot update configure test "%(conftest_0_c)s" within a dry-run.
92 %(SConstruct_file_line)s
93 """ % locals()
95 test.run(arguments='-n', status=2, stderr=expect)
97 test.run()
98 test.checkLogAndStdout(["Checking for C library %s... " % lib,
99 "Checking for C library hopefullynolib... "],
100 ["yes", "no"],
101 [[((".c", NCR), (_obj, NCR))],
102 [((".c", NCR), (_obj, NCF))]],
103 "config.log", ".sconf_temp", "SConstruct")
105 oldLog = test.read(test.workpath('config.log'), mode='r')
107 test.run(arguments='-n')
108 test.checkLogAndStdout(["Checking for C library %s... " % lib,
109 "Checking for C library hopefullynolib... "],
110 ["yes", "no"],
111 [[((".c", CR), (_obj, CR))],
112 [((".c", CR), (_obj, CF))]],
113 "config.log", ".sconf_temp", "SConstruct",
114 doCheckLog=False)
116 newLog = test.read(test.workpath('config.log'), mode='r')
117 if newLog != oldLog:
118 print("Unexpected update of log file within a dry run")
119 test.fail_test()
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: