updated copyright and added csv results output to bench.py
[scons.git] / test / Configure / implicit-cache.py
blob2cf74d17ea7fc527476cb46499abf628115e4c6c
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.
24 """
25 Verify that use of --implicit-cache with the Python Value Nodes
26 used by the Configure subsystem generate the same .sconsign file
27 and don't cause it to grow without limit.
29 This was reported as issue 2033 in the tigris.org bug tracker, by the
30 Ardour project. Prior to 0.98.4, the Value implementation would actually
31 return the repr() of its value as the str(). This was done because
32 it made saving a Value in a file and reading it back in kind of work,
33 because a print a string Value into a file (for example) would in fact
34 put quotes around it and be assignable in that file.
36 The problem is that this would get stored in a .sconsign file as its
37 repr(), with the specific problem being that Values with embedded newlines
38 would get stored as strings containing backslash+n digraphs *and* the
39 quotes at beginning and end of the string::
41 '\n#include <math.h>\n\n': {<.sconsign info>}
43 Then, when we read that back in from the .sconsign file, we would store
44 that repr() as a string Value itself, escaping the backslashes and
45 including the quotes, so when we stored it the second time it would end
46 up looking like:
48 "'\\n#include <math.h>\\n\\n'": {<.sconsign info>}
50 Every time that we would read this value and store it again (because
51 something else changed in the .sconf_temp directory), the string would
52 get longer and longer until it blew out the users's memory.
53 """
55 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
57 import TestSConsign
58 from SCons.Util import get_hash_format, get_current_hash_algorithm_used
60 test = TestSConsign.TestSConsign()
62 test.write('SConstruct', """
63 env = Environment(CPPPATH=['.'])
64 conf = Configure(env)
65 conf.CheckHeader( 'math.h' )
66 if ARGUMENTS.get('USE_FOO'):
67 conf.CheckHeader( 'foo.h' )
68 env = conf.Finish()
69 """)
71 test.write('foo.h', "#define FOO 1\n")
73 # First run: Have the configure subsystem only look for math.h, and
74 # squirrel away the .sconsign info for the conftest_0.c file that's
75 # generated from the Python Value Node that we're using for our test.
77 test.run(arguments = '.')
79 # depending on which default hash function we're using, we'd expect one of the following filenames.
80 # The filenames are generated by the conftest changes in #3543 : https://github.com/SCons/scons/pull/3543/files
81 # this test is different than the other tests, as the database name is used here.
82 # when the database defaults to md5, that's a different name than when the user selects md5 directly.
83 possible_filenames = {
84 'default': "conftest_5a3fa36d51dd2a28d521d6cc0e2e1d04_0.c",
85 'md5': "conftest_5a3fa36d51dd2a28d521d6cc0e2e1d04_0.c",
86 'sha1': "conftest_80e5b88f2c7427a92f0e6c7184f144f874f10e60_0.c",
87 'sha256': "conftest_ba8270c26647ad00993cd7777f4c5d3751018372b97d16eb993563bea051c3df_0.c"
89 # user left algorithm default, it defaulted to md5, with the special database name
90 if get_hash_format() is None and get_current_hash_algorithm_used() == 'md5':
91 test_filename = possible_filenames['default']
92 # either user selected something (like explicitly setting md5) or algorithm defaulted to something else.
93 # SCons can default to something else if it detects the hashlib doesn't support it, example md5 in FIPS
94 # mode prior to Python 3.9
95 else:
96 test_filename = possible_filenames[get_current_hash_algorithm_used()]
98 database_name=test.get_sconsignname() + ".dblite"
100 test.run_sconsign('-d .sconf_temp -e {} --raw {}'.format(test_filename, database_name))
101 old_sconsign_dblite = test.stdout()
103 # Second run: Have the configure subsystem also look for foo.h, so
104 # that there's a change in the .sconf_temp directory that will cause its
105 # .sconsign information to get rewritten from disk. Squirrel away the
106 # .sconsign info for the conftest_0.c file. The now-fixed bug would show
107 # up because the entry would change with the additional string-escaping
108 # described above. The now-correct behavior is that the re-stored value
109 # for conftest_0.c doesn't change.
111 test.run(arguments = '--implicit-cache USE_FOO=1 .')
113 test.run_sconsign('-d .sconf_temp -e {} --raw {}'.format(test_filename, database_name))
114 new_sconsign_dblite = test.stdout()
116 if old_sconsign_dblite != new_sconsign_dblite:
117 print("{} did not match:".format(database_name))
118 print("FIRST RUN ==========")
119 print(old_sconsign_dblite)
120 print("SECOND RUN ==========")
121 print(new_sconsign_dblite)
122 test.fail_test()
124 test.pass_test()
126 # Local Variables:
127 # tab-width:4
128 # indent-tabs-mode:nil
129 # End:
130 # vim: set expandtab tabstop=4 shiftwidth=4: