summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2010-05-16 19:51:12 (GMT)
committerSteven Knight <knight@baldmt.com>2010-05-16 19:51:12 (GMT)
commite2c9bab6e3921aa9a96bdbbea4853fd000638f07 (patch)
treef52a489127bd6b4696c31157f58ed5bd91357b03
parent31d33033b32826914dd32fde0e52a7edf8d8720b (diff)
downloadSCons-e2c9bab6e3921aa9a96bdbbea4853fd000638f07.zip
SCons-e2c9bab6e3921aa9a96bdbbea4853fd000638f07.tar.gz
SCons-e2c9bab6e3921aa9a96bdbbea4853fd000638f07.tar.bz2
Convert old-style classes in Scanner/*.py modules to new-style classes.
Ripple effect to fix monkey-patching in test/Scanner/generated.py.
-rw-r--r--src/engine/SCons/Scanner/C.py2
-rw-r--r--src/engine/SCons/Scanner/__init__.py6
-rw-r--r--test/Scanner/generated.py47
3 files changed, 35 insertions, 20 deletions
diff --git a/src/engine/SCons/Scanner/C.py b/src/engine/SCons/Scanner/C.py
index fd8d2f2..3311a09 100644
--- a/src/engine/SCons/Scanner/C.py
+++ b/src/engine/SCons/Scanner/C.py
@@ -81,7 +81,7 @@ def dictify_CPPDEFINES(env):
return {cppdefines : None}
return cppdefines
-class SConsCPPScannerWrapper:
+class SConsCPPScannerWrapper(object):
"""
The SCons wrapper around a cpp.py scanner.
diff --git a/src/engine/SCons/Scanner/__init__.py b/src/engine/SCons/Scanner/__init__.py
index dcee1f1..562a361 100644
--- a/src/engine/SCons/Scanner/__init__.py
+++ b/src/engine/SCons/Scanner/__init__.py
@@ -35,7 +35,7 @@ import SCons.Node.FS
import SCons.Util
-class _Null:
+class _Null(object):
pass
# This is used instead of None as a default argument value so None can be
@@ -61,7 +61,7 @@ def Scanner(function, *args, **kw):
-class FindPathDirs:
+class FindPathDirs(object):
"""A class to bind a specific *PATH variable name to a function that
will return all of the *path directories."""
def __init__(self, variable):
@@ -79,7 +79,7 @@ class FindPathDirs:
-class Base:
+class Base(object):
"""
The base class for dependency scanners. This implements
straightforward, single-pass scanning of a single file.
diff --git a/test/Scanner/generated.py b/test/Scanner/generated.py
index 0212043..8b08732 100644
--- a/test/Scanner/generated.py
+++ b/test/Scanner/generated.py
@@ -307,22 +307,37 @@ def write_out(file, dict):
f.write(file + ": " + str(dict[k]) + "\\n")
f.close()
-orig_function = CScan.__call__
-
-def MyCScan(node, paths, cwd, orig_function=orig_function):
- deps = orig_function(node, paths, cwd)
-
- global Scanned
- n = str(node)
- try:
- Scanned[n] = Scanned[n] + 1
- except KeyError:
- Scanned[n] = 1
- write_out(r'%s', Scanned)
-
- return deps
-
-CScan.__call__ = MyCScan
+# A hand-coded new-style class proxy to wrap the underlying C Scanner
+# with a method that counts the calls.
+#
+# This is more complicated than it used to be with old-style classes
+# because the .__*__() methods in new-style classes are not looked
+# up on the instance, but resolve to the actual wrapped class methods,
+# so we have to handle those directly.
+class CScannerCounter(object):
+ def __init__(self, original_CScanner, *args, **kw):
+ self.original_CScanner = original_CScanner
+ def __cmp__(self, *args, **kw):
+ return self.original_CScanner.__cmp__(*args, **kw)
+ def __hash__(self, *args, **kw):
+ return self.original_CScanner.__hash__(*args, **kw)
+ def __str__(self, *args, **kw):
+ return self.original_CScanner.__str__(*args, **kw)
+ def __getattr__(self, *args, **kw):
+ return self.original_CScanner.__getattribute__(*args, **kw)
+ def __call__(self, node, *args, **kw):
+ global Scanned
+ n = str(node)
+ try:
+ Scanned[n] = Scanned[n] + 1
+ except KeyError:
+ Scanned[n] = 1
+ write_out(r'%s', Scanned)
+ return self.original_CScanner(node, *args, **kw)
+
+import SCons.Tool
+MyCScanner = CScannerCounter(SCons.Script.CScanner)
+SCons.Tool.SourceFileScanner.add_scanner('.c', MyCScanner)
env = Environment(CPPPATH = ".")
l = env.StaticLibrary("g", Split("libg_1.c libg_2.c libg_3.c"))