From d1c2fed3f0085253a40a179a39f9f837769f5dfa Mon Sep 17 00:00:00 2001 From: StenGruener <69786685+StenGruener@users.noreply.github.com> Date: Sat, 28 Oct 2023 18:02:04 +0000 Subject: adding unit test, --debug flag, comments in changes.txt --- CHANGES.txt | 3 ++ SCons/Debug.py | 3 ++ SCons/Script/Main.py | 2 ++ SCons/Script/SConsOptions.py | 2 +- SCons/Script/SConscript.py | 4 +-- test/SConscript/SConscriptTrace.py | 58 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 test/SConscript/SConscriptTrace.py diff --git a/CHANGES.txt b/CHANGES.txt index 9076faa..c362989 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -8,6 +8,9 @@ NOTE: The 4.0.0 Release of SCons dropped Python 2.7 Support NOTE: 4.3.0 now requires Python 3.6.0 and above. Python 3.5.x is no longer supported RELEASE VERSION/DATE TO BE FILLED IN LATER + From Sten GrĂ¼ner + - The --debug flag has a 'sconscript-trace' option allowint to trace + files included via SConscript call. From Max Bachmann: - Add missing directories to searched paths for mingw installs diff --git a/SCons/Debug.py b/SCons/Debug.py index 615eb4f..9397fde 100644 --- a/SCons/Debug.py +++ b/SCons/Debug.py @@ -41,6 +41,9 @@ import inspect track_instances = False # List of currently tracked classes tracked_classes = {} +# Global variable that gets set to 'True' by the Main script +# when SConscript call tracing should be enabled. +sconscript_trace = False def logInstanceCreation(instance, name=None) -> None: if name is None: diff --git a/SCons/Script/Main.py b/SCons/Script/Main.py index 9735df2..d218803 100644 --- a/SCons/Script/Main.py +++ b/SCons/Script/Main.py @@ -725,6 +725,8 @@ def _set_debug_values(options) -> None: SCons.Node.print_duplicate = True if "json" in debug_values: ENABLE_JSON = True + if "sconscript-trace" in debug_values: + SCons.Debug.sconscript_trace = True def _create_path(plist): path = '.' diff --git a/SCons/Script/SConsOptions.py b/SCons/Script/SConsOptions.py index e799716..1d40f5c 100644 --- a/SCons/Script/SConsOptions.py +++ b/SCons/Script/SConsOptions.py @@ -752,7 +752,7 @@ def Parser(version): debug_options = ["count", "duplicate", "explain", "findlibs", "includes", "memoizer", "memory", "objects", "pdb", "prepare", "presub", "stacktrace", - "time", "action-timestamps", "json"] + "time", "action-timestamps", "json", "sconscript-trace"] def opt_debug(option, opt, value__, parser, debug_options=debug_options, diff --git a/SCons/Script/SConscript.py b/SCons/Script/SConscript.py index d87c782..860b3e7 100644 --- a/SCons/Script/SConscript.py +++ b/SCons/Script/SConscript.py @@ -274,10 +274,10 @@ def _SConscript(fs, *files, **kw): scriptdata = _file_.read() scriptname = _file_.name _file_.close() - if "SCONS_CALL_TRACING" in os.environ: + if SCons.Debug.sconscript_trace: print("scons-entering>"+str(scriptname)) exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals) - if "SCONS_CALL_TRACING" in os.environ: + if SCons.Debug.sconscript_trace: print("scons-exiting>"+str(scriptname)) except SConscriptReturn: pass diff --git a/test/SConscript/SConscriptTrace.py b/test/SConscript/SConscriptTrace.py new file mode 100644 index 0000000..c432362 --- /dev/null +++ b/test/SConscript/SConscriptTrace.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# 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__" + +import os +import TestSCons + +test = TestSCons.TestSCons() + + +test.write('SConstruct', """\ +print("SConstruct") +""") + +wpath = test.workpath() + +test.run(arguments = ".") +unexpect = [ + 'scons-entering>%s%sSConstruct'%(wpath, os.sep), + 'scons-exiting>%s%sSConstruct'%(wpath, os.sep) +] +test.must_not_contain_any_line(test.stdout(), unexpect) + +test.run(arguments = "--debug=sconscript-trace .") +expect = [ + 'scons-entering>%s%sSConstruct'%(wpath, os.sep), + 'scons-exiting>%s%sSConstruct'%(wpath, os.sep) +] +test.must_contain_all_lines(test.stdout(), expect) +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: -- cgit v0.12