From ad257d2483736b6e9461a26a62048ac05dafe3b6 Mon Sep 17 00:00:00 2001 From: Steven Knight Date: Sat, 25 Sep 2004 14:13:21 +0000 Subject: Add a --debug=findlibs option. (Gary Oberbrunner) --- doc/man/scons.1 | 7 ++ src/CHANGES.txt | 3 + src/engine/SCons/Node/FS.py | 9 +- src/engine/SCons/Node/FSTests.py | 23 ++++ src/engine/SCons/Scanner/Prog.py | 5 +- src/engine/SCons/Script/__init__.py | 4 +- test/option/debug-findlibs.py | 205 ++++++++++++++++++++++++++++++++++++ 7 files changed, 252 insertions(+), 4 deletions(-) create mode 100644 test/option/debug-findlibs.py diff --git a/doc/man/scons.1 b/doc/man/scons.1 index dda0ce2..5601f98 100644 --- a/doc/man/scons.1 +++ b/doc/man/scons.1 @@ -520,6 +520,13 @@ Print the dependency tree after each top-level target is built. This prints out only derived files. .TP +--debug=findlibs +Instruct the scanner that searches for libraries +to print a message about each potential library +name it is searching for, +and about the actual libraries it finds. + +.TP --debug=includes Print the include tree after each top-level target is built. This is generally used to find out what files are included by the sources diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 7379368..aa9a71e 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -100,6 +100,9 @@ RELEASE 0.97 - XXX - Print an internal Python stack trace in response to an otherwise unexplained error when --debug=stacktrace is specified. + - Add a --debug=findlibs option to print what's happening when + the scanner is searching for libraries. + From Chris Pawling: - Have the linkloc tool use $MSVS_VERSION to select the Microsoft diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py index be4770f..5cdece1 100644 --- a/src/engine/SCons/Node/FS.py +++ b/src/engine/SCons/Node/FS.py @@ -1834,8 +1834,7 @@ class File(Base): default_fs = FS() - -def find_file(filename, paths, node_factory = default_fs.File): +def find_file(filename, paths, node_factory=default_fs.File, verbose=None): """ find_file(str, [Dir()]) -> [nodes] @@ -1850,8 +1849,12 @@ def find_file(filename, paths, node_factory = default_fs.File): Only the first file found is returned, and none is returned if no file is found. """ + if verbose and not SCons.Util.is_String(verbose): + verbose = "find_file" retval = None for dir in paths: + if verbose: + sys.stdout.write(" %s: looking for '%s' in '%s' ...\n" % (verbose, filename, dir)) try: node = node_factory(filename, dir) # Return true if the node exists or is a derived node. @@ -1859,6 +1862,8 @@ def find_file(filename, paths, node_factory = default_fs.File): node.is_pseudo_derived() or \ (isinstance(node, SCons.Node.FS.Base) and node.exists()): retval = node + if verbose: + sys.stdout.write(" %s: ... FOUND '%s' in '%s'\n" % (verbose, filename, dir)) break except TypeError: # If we find a directory instead of a file, we don't care diff --git a/src/engine/SCons/Node/FSTests.py b/src/engine/SCons/Node/FSTests.py index 6bee431..4501cf1 100644 --- a/src/engine/SCons/Node/FSTests.py +++ b/src/engine/SCons/Node/FSTests.py @@ -1368,6 +1368,29 @@ class find_fileTestCase(unittest.TestCase): assert os.path.normpath('./bar/baz') in file_names, file_names assert os.path.normpath('./pseudo') in file_names, file_names + import StringIO + save_sys_stdout = sys.stdout + + try: + sio = StringIO.StringIO() + sys.stdout = sio + SCons.Node.FS.find_file('foo', paths, fs.File, verbose="xyz") + expect = " xyz: looking for 'foo' in '.' ...\n" + \ + " xyz: ... FOUND 'foo' in '.'\n" + c = sio.getvalue() + assert c == expect, c + + sio = StringIO.StringIO() + sys.stdout = sio + SCons.Node.FS.find_file('baz', paths, fs.File, verbose=1) + expect = " find_file: looking for 'baz' in '.' ...\n" + \ + " find_file: looking for 'baz' in 'bar' ...\n" + \ + " find_file: ... FOUND 'baz' in 'bar'\n" + c = sio.getvalue() + assert c == expect, c + finally: + sys.stdout = save_sys_stdout + class StringDirTestCase(unittest.TestCase): def runTest(self): """Test using a string as the second argument of diff --git a/src/engine/SCons/Scanner/Prog.py b/src/engine/SCons/Scanner/Prog.py index 78b7233..fa36cad 100644 --- a/src/engine/SCons/Scanner/Prog.py +++ b/src/engine/SCons/Scanner/Prog.py @@ -30,6 +30,9 @@ import SCons.Node.FS import SCons.Scanner import SCons.Util +# global, set by --debug=findlibs +print_find_libs = None + def ProgScan(fs = SCons.Node.FS.default_fs, **kw): """Return a prototype Scanner instance for scanning executable files for static-lib dependencies""" @@ -85,7 +88,7 @@ def scan(node, env, libpath = (), fs = SCons.Node.FS.default_fs): lib = env.subst(lib) for pref, suf in pairs: l = adjustixes(lib, pref, suf) - l = find_file(l, libpath, fs.File) + l = find_file(l, libpath, fs.File, verbose=print_find_libs) if l: result.append(l) else: diff --git a/src/engine/SCons/Script/__init__.py b/src/engine/SCons/Script/__init__.py index 4832b02..c40f27e 100644 --- a/src/engine/SCons/Script/__init__.py +++ b/src/engine/SCons/Script/__init__.py @@ -420,6 +420,8 @@ def _set_globals(options): print_dtree = 1 elif options.debug == "explain": print_explanations = 1 + elif options.debug == "findlibs": + SCons.Scanner.Prog.print_find_libs = "findlibs" elif options.debug == "includes": print_includes = 1 elif options.debug == "memory": @@ -526,7 +528,7 @@ class OptParser(OptionParser): help="Search up directory tree for SConstruct, " "build all Default() targets.") - debug_options = ["count", "dtree", "explain", + debug_options = ["count", "dtree", "explain", "findlibs", "includes", "memory", "objects", "pdb", "presub", "stacktrace", "time", "tree"] diff --git a/test/option/debug-findlibs.py b/test/option/debug-findlibs.py new file mode 100644 index 0000000..4827ab0 --- /dev/null +++ b/test/option/debug-findlibs.py @@ -0,0 +1,205 @@ +#!/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 TestSCons +import sys +import string +import re +import time + +test = TestSCons.TestSCons() + +test.subdir('sub1', 'sub2') + +test.write('cat.py', """\ +import sys +ofp = open(sys.argv[1], "w") +for ifp in map(open, sys.argv[2:]): + ofp.write(ifp.read()) +ofp.close() +""") + +test.write('SConstruct', """\ +env = Environment(OBJSUFFIX = '.ooo', PROGSUFFIX = '.xxx', + LIBPATH = ['sub1', 'sub2', '.'], + LIBS = ['iii', 'jjj', 'kkk', 'lll', 'mmm'], + LIBPREFIXES = ['a-', 'b-', 'c-'], + LIBSUFFIXES = ['.aaa', '.bbb', '.ccc'], + LINKCOM = '%(python)s cat.py $TARGET $SOURCES') +env.Program('foo', 'a.ooo',) +""" % {'python' : TestSCons.python}) + +test.write('a.ooo', "a.ooo\n") + +test.write('a-iii.aaa', "a-iii.aaa\n") +test.write(['sub1', 'b-jjj.bbb'], "b-jjj.bbb\n") +test.write(['sub2', 'c-kkk.ccc'], "c-kkk.ccc\n") +test.write('a-lll.ccc', "a-lll.ccc\n") + +test.run(arguments = "--debug=findlibs foo.xxx", + stdout = test.wrap_stdout("""\ + findlibs: looking for 'a-iii.aaa' in 'sub1' ... + findlibs: looking for 'a-iii.aaa' in 'sub2' ... + findlibs: looking for 'a-iii.aaa' in '.' ... + findlibs: ... FOUND 'a-iii.aaa' in '.' + findlibs: looking for 'b-iii.aaa' in 'sub1' ... + findlibs: looking for 'b-iii.aaa' in 'sub2' ... + findlibs: looking for 'b-iii.aaa' in '.' ... + findlibs: looking for 'c-iii.aaa' in 'sub1' ... + findlibs: looking for 'c-iii.aaa' in 'sub2' ... + findlibs: looking for 'c-iii.aaa' in '.' ... + findlibs: looking for 'a-iii.bbb' in 'sub1' ... + findlibs: looking for 'a-iii.bbb' in 'sub2' ... + findlibs: looking for 'a-iii.bbb' in '.' ... + findlibs: looking for 'b-iii.bbb' in 'sub1' ... + findlibs: looking for 'b-iii.bbb' in 'sub2' ... + findlibs: looking for 'b-iii.bbb' in '.' ... + findlibs: looking for 'c-iii.bbb' in 'sub1' ... + findlibs: looking for 'c-iii.bbb' in 'sub2' ... + findlibs: looking for 'c-iii.bbb' in '.' ... + findlibs: looking for 'a-iii.ccc' in 'sub1' ... + findlibs: looking for 'a-iii.ccc' in 'sub2' ... + findlibs: looking for 'a-iii.ccc' in '.' ... + findlibs: looking for 'b-iii.ccc' in 'sub1' ... + findlibs: looking for 'b-iii.ccc' in 'sub2' ... + findlibs: looking for 'b-iii.ccc' in '.' ... + findlibs: looking for 'c-iii.ccc' in 'sub1' ... + findlibs: looking for 'c-iii.ccc' in 'sub2' ... + findlibs: looking for 'c-iii.ccc' in '.' ... + findlibs: looking for 'a-jjj.aaa' in 'sub1' ... + findlibs: looking for 'a-jjj.aaa' in 'sub2' ... + findlibs: looking for 'a-jjj.aaa' in '.' ... + findlibs: looking for 'b-jjj.aaa' in 'sub1' ... + findlibs: looking for 'b-jjj.aaa' in 'sub2' ... + findlibs: looking for 'b-jjj.aaa' in '.' ... + findlibs: looking for 'c-jjj.aaa' in 'sub1' ... + findlibs: looking for 'c-jjj.aaa' in 'sub2' ... + findlibs: looking for 'c-jjj.aaa' in '.' ... + findlibs: looking for 'a-jjj.bbb' in 'sub1' ... + findlibs: looking for 'a-jjj.bbb' in 'sub2' ... + findlibs: looking for 'a-jjj.bbb' in '.' ... + findlibs: looking for 'b-jjj.bbb' in 'sub1' ... + findlibs: ... FOUND 'b-jjj.bbb' in 'sub1' + findlibs: looking for 'c-jjj.bbb' in 'sub1' ... + findlibs: looking for 'c-jjj.bbb' in 'sub2' ... + findlibs: looking for 'c-jjj.bbb' in '.' ... + findlibs: looking for 'a-jjj.ccc' in 'sub1' ... + findlibs: looking for 'a-jjj.ccc' in 'sub2' ... + findlibs: looking for 'a-jjj.ccc' in '.' ... + findlibs: looking for 'b-jjj.ccc' in 'sub1' ... + findlibs: looking for 'b-jjj.ccc' in 'sub2' ... + findlibs: looking for 'b-jjj.ccc' in '.' ... + findlibs: looking for 'c-jjj.ccc' in 'sub1' ... + findlibs: looking for 'c-jjj.ccc' in 'sub2' ... + findlibs: looking for 'c-jjj.ccc' in '.' ... + findlibs: looking for 'a-kkk.aaa' in 'sub1' ... + findlibs: looking for 'a-kkk.aaa' in 'sub2' ... + findlibs: looking for 'a-kkk.aaa' in '.' ... + findlibs: looking for 'b-kkk.aaa' in 'sub1' ... + findlibs: looking for 'b-kkk.aaa' in 'sub2' ... + findlibs: looking for 'b-kkk.aaa' in '.' ... + findlibs: looking for 'c-kkk.aaa' in 'sub1' ... + findlibs: looking for 'c-kkk.aaa' in 'sub2' ... + findlibs: looking for 'c-kkk.aaa' in '.' ... + findlibs: looking for 'a-kkk.bbb' in 'sub1' ... + findlibs: looking for 'a-kkk.bbb' in 'sub2' ... + findlibs: looking for 'a-kkk.bbb' in '.' ... + findlibs: looking for 'b-kkk.bbb' in 'sub1' ... + findlibs: looking for 'b-kkk.bbb' in 'sub2' ... + findlibs: looking for 'b-kkk.bbb' in '.' ... + findlibs: looking for 'c-kkk.bbb' in 'sub1' ... + findlibs: looking for 'c-kkk.bbb' in 'sub2' ... + findlibs: looking for 'c-kkk.bbb' in '.' ... + findlibs: looking for 'a-kkk.ccc' in 'sub1' ... + findlibs: looking for 'a-kkk.ccc' in 'sub2' ... + findlibs: looking for 'a-kkk.ccc' in '.' ... + findlibs: looking for 'b-kkk.ccc' in 'sub1' ... + findlibs: looking for 'b-kkk.ccc' in 'sub2' ... + findlibs: looking for 'b-kkk.ccc' in '.' ... + findlibs: looking for 'c-kkk.ccc' in 'sub1' ... + findlibs: looking for 'c-kkk.ccc' in 'sub2' ... + findlibs: ... FOUND 'c-kkk.ccc' in 'sub2' + findlibs: looking for 'a-lll.aaa' in 'sub1' ... + findlibs: looking for 'a-lll.aaa' in 'sub2' ... + findlibs: looking for 'a-lll.aaa' in '.' ... + findlibs: looking for 'b-lll.aaa' in 'sub1' ... + findlibs: looking for 'b-lll.aaa' in 'sub2' ... + findlibs: looking for 'b-lll.aaa' in '.' ... + findlibs: looking for 'c-lll.aaa' in 'sub1' ... + findlibs: looking for 'c-lll.aaa' in 'sub2' ... + findlibs: looking for 'c-lll.aaa' in '.' ... + findlibs: looking for 'a-lll.bbb' in 'sub1' ... + findlibs: looking for 'a-lll.bbb' in 'sub2' ... + findlibs: looking for 'a-lll.bbb' in '.' ... + findlibs: looking for 'b-lll.bbb' in 'sub1' ... + findlibs: looking for 'b-lll.bbb' in 'sub2' ... + findlibs: looking for 'b-lll.bbb' in '.' ... + findlibs: looking for 'c-lll.bbb' in 'sub1' ... + findlibs: looking for 'c-lll.bbb' in 'sub2' ... + findlibs: looking for 'c-lll.bbb' in '.' ... + findlibs: looking for 'a-lll.ccc' in 'sub1' ... + findlibs: looking for 'a-lll.ccc' in 'sub2' ... + findlibs: looking for 'a-lll.ccc' in '.' ... + findlibs: ... FOUND 'a-lll.ccc' in '.' + findlibs: looking for 'b-lll.ccc' in 'sub1' ... + findlibs: looking for 'b-lll.ccc' in 'sub2' ... + findlibs: looking for 'b-lll.ccc' in '.' ... + findlibs: looking for 'c-lll.ccc' in 'sub1' ... + findlibs: looking for 'c-lll.ccc' in 'sub2' ... + findlibs: looking for 'c-lll.ccc' in '.' ... + findlibs: looking for 'a-mmm.aaa' in 'sub1' ... + findlibs: looking for 'a-mmm.aaa' in 'sub2' ... + findlibs: looking for 'a-mmm.aaa' in '.' ... + findlibs: looking for 'b-mmm.aaa' in 'sub1' ... + findlibs: looking for 'b-mmm.aaa' in 'sub2' ... + findlibs: looking for 'b-mmm.aaa' in '.' ... + findlibs: looking for 'c-mmm.aaa' in 'sub1' ... + findlibs: looking for 'c-mmm.aaa' in 'sub2' ... + findlibs: looking for 'c-mmm.aaa' in '.' ... + findlibs: looking for 'a-mmm.bbb' in 'sub1' ... + findlibs: looking for 'a-mmm.bbb' in 'sub2' ... + findlibs: looking for 'a-mmm.bbb' in '.' ... + findlibs: looking for 'b-mmm.bbb' in 'sub1' ... + findlibs: looking for 'b-mmm.bbb' in 'sub2' ... + findlibs: looking for 'b-mmm.bbb' in '.' ... + findlibs: looking for 'c-mmm.bbb' in 'sub1' ... + findlibs: looking for 'c-mmm.bbb' in 'sub2' ... + findlibs: looking for 'c-mmm.bbb' in '.' ... + findlibs: looking for 'a-mmm.ccc' in 'sub1' ... + findlibs: looking for 'a-mmm.ccc' in 'sub2' ... + findlibs: looking for 'a-mmm.ccc' in '.' ... + findlibs: looking for 'b-mmm.ccc' in 'sub1' ... + findlibs: looking for 'b-mmm.ccc' in 'sub2' ... + findlibs: looking for 'b-mmm.ccc' in '.' ... + findlibs: looking for 'c-mmm.ccc' in 'sub1' ... + findlibs: looking for 'c-mmm.ccc' in 'sub2' ... + findlibs: looking for 'c-mmm.ccc' in '.' ... +%(python)s cat.py foo.xxx a.ooo +""" % {'python' : TestSCons.python})) + +test.must_match('foo.xxx', "a.ooo\n") + +test.pass_test() -- cgit v0.12