Skip to content

Commit 67bcf24

Browse files
committed
Handle --debug containing memoizer
The memoizer statistics have to be handled specially as they use conditional decorators, those have to be enabled before any of the decorated methods are read by Python. This worked if there was exactly "--debug=memoizer" on the commandline or in SCONSFLAGS, but not if it was in a multi-value option like "--debug=presub,memoizer". Handle the up-front-check a little more completely to fix this. Signed-off-by: Mats Wichmann <mats@linux.com>
1 parent 144af4a commit 67bcf24

File tree

4 files changed

+39
-29
lines changed

4 files changed

+39
-29
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
200200
attribute and to explain what's being done in the example.
201201
- Test framework reformatted using settings from pyproject.toml.
202202
Includes code embedded in docstrings.
203+
- Handle case of "memoizer" as one member of a comma-separated
204+
--debug string - this was previously missed.
203205

204206
From Adam Scott:
205207
- Changed Ninja's TEMPLATE rule pool to use `install_pool` instead of

RELEASE.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ FIXES
179179
- Fix Issue #2281, AddPreAction() & AddPostAction() were being ignored if no action
180180
was specified when the Alias was initially created.
181181

182+
- Handle case of "memoizer" as one member of a comma-separated
183+
--debug string - this was previously missed.
184+
182185
IMPROVEMENTS
183186
------------
184187

SCons/Script/__init__.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
start_time = time.time()
3636

3737
import collections
38+
import itertools
3839
import os
3940
from io import StringIO
4041

@@ -53,9 +54,17 @@
5354
# to not add the shims. So we use a special-case, up-front check for
5455
# the "--debug=memoizer" flag and enable Memoizer before we import any
5556
# of the other modules that use it.
56-
57-
_args = sys.argv + os.environ.get('SCONSFLAGS', '').split()
58-
if "--debug=memoizer" in _args:
57+
# Update: this breaks if the option isn't exactly "--debug=memoizer",
58+
# like if there is more than one debug option as a csv. Do a bit more work.
59+
60+
_args = sys.argv + os.environ.get("SCONSFLAGS", "").split()
61+
_args = (
62+
arg[len("--debug=") :].split(",")
63+
for arg in _args
64+
if arg.startswith("--debug=")
65+
)
66+
_args = list(itertools.chain.from_iterable(_args))
67+
if "memoizer" in _args:
5968
import SCons.Memoize
6069
import SCons.Warnings
6170
try:

test/option/debug-memoizer.py

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env python
22
#
3-
# __COPYRIGHT__
3+
# MIT License
4+
#
5+
# Copyright The SCons Foundation
46
#
57
# Permission is hereby granted, free of charge, to any person obtaining
68
# a copy of this software and associated documentation files (the
@@ -20,26 +22,21 @@
2022
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
2123
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2224
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23-
#
24-
25-
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
2625

27-
"""
28-
Test calling the --debug=memoizer option.
29-
"""
26+
"""Test calling the --debug=memoizer option."""
3027

3128
import os
3229

3330
import TestSCons
3431

35-
test = TestSCons.TestSCons(match = TestSCons.match_re_dotall)
36-
32+
test = TestSCons.TestSCons(match=TestSCons.match_re_dotall)
3733

3834
test.write('SConstruct', """
39-
DefaultEnvironment(tools=[])
4035
def cat(target, source, env):
4136
with open(str(target[0]), 'wb') as f, open(str(source[0]), 'rb') as infp:
4237
f.write(infp.read())
38+
39+
DefaultEnvironment(tools=[])
4340
env = Environment(tools=[], BUILDERS={'Cat':Builder(action=Action(cat))})
4441
env.Cat('file.out', 'file.in')
4542
""")
@@ -51,36 +48,35 @@ def cat(target, source, env):
5148
# names in the implementation, so if we change them, we'll have to
5249
# change this test...
5350
expect = [
54-
"Memoizer (memory cache) hits and misses",
55-
"Base.stat()",
51+
# "Memoizer (memory cache) hits and misses",
5652
"Dir.srcdir_list()",
53+
"File.stat()",
5754
"File.exists()",
5855
"Node._children_get()",
5956
]
6057

61-
62-
for args in ['-h --debug=memoizer', '--debug=memoizer']:
63-
test.run(arguments = args)
64-
test.must_contain_any_line(test.stdout(), expect)
65-
58+
test.run(arguments='--debug=memoizer')
59+
test.must_contain_any_line(test.stdout(), expect)
6660
test.must_match('file.out', "file.in\n")
67-
68-
69-
7061
test.unlink("file.out")
7162

63+
# make sure it also works if memoizer is not the only debug flag
64+
test.run(arguments='--debug=sconscript,memoizer')
65+
test.must_contain_any_line(test.stdout(), expect)
66+
test.must_match('file.out', "file.in\n")
67+
test.unlink("file.out")
7268

69+
# memoization should still report even in help mode
70+
test.run(arguments='-h --debug=memoizer')
71+
test.must_contain_any_line(test.stdout(), expect)
72+
test.must_not_exist("file.out")
7373

74+
# also try setting in SCONSFLAGS
7475
os.environ['SCONSFLAGS'] = '--debug=memoizer'
75-
76-
test.run(arguments = '')
77-
76+
test.run(arguments='.')
7877
test.must_contain_any_line(test.stdout(), expect)
79-
8078
test.must_match('file.out', "file.in\n")
8179

82-
83-
8480
test.pass_test()
8581

8682
# Local Variables:

0 commit comments

Comments
 (0)