From 67bcf240aa066dac269aea402566c21f4641822e Mon Sep 17 00:00:00 2001 From: Mats Wichmann Date: Mon, 3 Feb 2025 10:07:42 -0700 Subject: 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 --- CHANGES.txt | 2 ++ RELEASE.txt | 3 +++ SCons/Script/__init__.py | 15 +++++++++++--- test/option/debug-memoizer.py | 48 ++++++++++++++++++++----------------------- 4 files changed, 39 insertions(+), 29 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 97f7be2..acc087a 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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 diff --git a/RELEASE.txt b/RELEASE.txt index 1b823b9..54b4800 100644 --- a/RELEASE.txt +++ b/RELEASE.txt @@ -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 ------------ diff --git a/SCons/Script/__init__.py b/SCons/Script/__init__.py index 2083e4f..0243a9c 100644 --- a/SCons/Script/__init__.py +++ b/SCons/Script/__init__.py @@ -35,6 +35,7 @@ import time start_time = time.time() import collections +import itertools import os from io import StringIO @@ -53,9 +54,17 @@ import sys # 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: diff --git a/test/option/debug-memoizer.py b/test/option/debug-memoizer.py index 01af561..2425eaa 100644 --- a/test/option/debug-memoizer.py +++ b/test/option/debug-memoizer.py @@ -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 @@ -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') """) @@ -51,36 +48,35 @@ test.write('file.in', "file.in\n") # 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: -- cgit v0.12