Skip to content

Commit

Permalink
Handle --debug containing memoizer
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
mwichmann committed Feb 3, 2025
1 parent 144af4a commit 67bcf24
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 29 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
attribute and to explain what's being done in the example.
- Test framework reformatted using settings from pyproject.toml.
Includes code embedded in docstrings.
- Handle case of "memoizer" as one member of a comma-separated
--debug string - this was previously missed.

From Adam Scott:
- Changed Ninja's TEMPLATE rule pool to use `install_pool` instead of
Expand Down
3 changes: 3 additions & 0 deletions RELEASE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ FIXES
- Fix Issue #2281, AddPreAction() & AddPostAction() were being ignored if no action
was specified when the Alias was initially created.

- Handle case of "memoizer" as one member of a comma-separated
--debug string - this was previously missed.

IMPROVEMENTS
------------

Expand Down
15 changes: 12 additions & 3 deletions SCons/Script/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
start_time = time.time()

import collections
import itertools
import os
from io import StringIO

Expand All @@ -53,9 +54,17 @@
# to not add the shims. So we use a special-case, up-front check for
# the "--debug=memoizer" flag and enable Memoizer before we import any
# of the other modules that use it.

_args = sys.argv + os.environ.get('SCONSFLAGS', '').split()
if "--debug=memoizer" in _args:
# Update: this breaks if the option isn't exactly "--debug=memoizer",
# like if there is more than one debug option as a csv. Do a bit more work.

_args = sys.argv + os.environ.get("SCONSFLAGS", "").split()
_args = (
arg[len("--debug=") :].split(",")
for arg in _args
if arg.startswith("--debug=")
)
_args = list(itertools.chain.from_iterable(_args))
if "memoizer" in _args:
import SCons.Memoize
import SCons.Warnings
try:
Expand Down
48 changes: 22 additions & 26 deletions test/option/debug-memoizer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python
#
# __COPYRIGHT__
# MIT License
#
# Copyright The SCons Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
Expand All @@ -20,26 +22,21 @@
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"

"""
Test calling the --debug=memoizer option.
"""
"""Test calling the --debug=memoizer option."""

import os

import TestSCons

test = TestSCons.TestSCons(match = TestSCons.match_re_dotall)

test = TestSCons.TestSCons(match=TestSCons.match_re_dotall)

test.write('SConstruct', """
DefaultEnvironment(tools=[])
def cat(target, source, env):
with open(str(target[0]), 'wb') as f, open(str(source[0]), 'rb') as infp:
f.write(infp.read())
DefaultEnvironment(tools=[])
env = Environment(tools=[], BUILDERS={'Cat':Builder(action=Action(cat))})
env.Cat('file.out', 'file.in')
""")
Expand All @@ -51,36 +48,35 @@ def cat(target, source, env):
# names in the implementation, so if we change them, we'll have to
# change this test...
expect = [
"Memoizer (memory cache) hits and misses",
"Base.stat()",
# "Memoizer (memory cache) hits and misses",
"Dir.srcdir_list()",
"File.stat()",
"File.exists()",
"Node._children_get()",
]


for args in ['-h --debug=memoizer', '--debug=memoizer']:
test.run(arguments = args)
test.must_contain_any_line(test.stdout(), expect)

test.run(arguments='--debug=memoizer')
test.must_contain_any_line(test.stdout(), expect)
test.must_match('file.out', "file.in\n")



test.unlink("file.out")

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

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

# also try setting in SCONSFLAGS
os.environ['SCONSFLAGS'] = '--debug=memoizer'

test.run(arguments = '')

test.run(arguments='.')
test.must_contain_any_line(test.stdout(), expect)

test.must_match('file.out', "file.in\n")



test.pass_test()

# Local Variables:
Expand Down

0 comments on commit 67bcf24

Please sign in to comment.