summaryrefslogtreecommitdiff
path: root/test/Scanner
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2010-05-16 19:51:12 +0000
committerSteven Knight <knight@baldmt.com>2010-05-16 19:51:12 +0000
commit3fd5c3bc9df9201ef8a7383bec62f0aa4c750e41 (patch)
treef52a489127bd6b4696c31157f58ed5bd91357b03 /test/Scanner
parent59f7f8bc7877962a7c8bca1a139eba2ddb02b987 (diff)
downloadscons-3fd5c3bc9df9201ef8a7383bec62f0aa4c750e41.tar.gz
Convert old-style classes in Scanner/*.py modules to new-style classes.
Ripple effect to fix monkey-patching in test/Scanner/generated.py.
Diffstat (limited to 'test/Scanner')
-rw-r--r--test/Scanner/generated.py47
1 files changed, 31 insertions, 16 deletions
diff --git a/test/Scanner/generated.py b/test/Scanner/generated.py
index 02120435..8b087321 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"))