diff options
author | Steven Knight <knight@baldmt.com> | 2010-05-16 19:51:12 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2010-05-16 19:51:12 (GMT) |
commit | e2c9bab6e3921aa9a96bdbbea4853fd000638f07 (patch) | |
tree | f52a489127bd6b4696c31157f58ed5bd91357b03 /test | |
parent | 31d33033b32826914dd32fde0e52a7edf8d8720b (diff) | |
download | SCons-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.
Diffstat (limited to 'test')
-rw-r--r-- | test/Scanner/generated.py | 47 |
1 files changed, 31 insertions, 16 deletions
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")) |