Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle --debug containing memoizer #4677

Merged
merged 1 commit into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one commented out because it prints even if the memoizer failed to initialize, since the actual heading/print-when-done is handled by the normal option processing, not the special up-front processing. Since the match requires "at least one of" it would still match and obscure the failure in the combined-debug-option case.

"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
Loading