diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/engine/SCons/Environment.py | 21 | ||||
-rw-r--r-- | src/engine/SCons/EnvironmentTests.py | 87 |
2 files changed, 83 insertions, 25 deletions
diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py index 2144a7f..c312f31 100644 --- a/src/engine/SCons/Environment.py +++ b/src/engine/SCons/Environment.py @@ -300,6 +300,9 @@ class Base: except KeyError: self._dict[key] = BuilderDict(kwbd, self) self._dict[key].update(value) + elif key == 'SCANNERS': + self._dict[key] = value + self.scanner_map_delete() else: if not SCons.Util.is_valid_construction_var(key): raise SCons.Errors.UserError, "Illegal construction variable `%s'" % key @@ -407,6 +410,19 @@ class Base: except KeyError: return None + def scanner_map_delete(self, kw=None): + """Delete the cached scanner map (if we need to). + """ + if not kw is None: + try: + kw['SCANNERS'] + except KeyError: + return + try: + del self.scanner_map + except AttributeError: + pass + def subst(self, string, raw=0, target=None, source=None, dict=None, conv=None): """Recursively interpolates construction variables from the Environment into the specified string, returning the expanded @@ -546,6 +562,7 @@ class Base: # value to it (if there's a value to append). if val: add_to_orig(val) + self.scanner_map_delete(kw) def AppendENVPath(self, name, newpath, envname = 'ENV', sep = os.pathsep): """Append path elements to the path 'name' in the 'ENV' @@ -590,6 +607,7 @@ class Base: self._dict[key] = dk + val else: self._dict[key] = self._dict[key] + val + self.scanner_map_delete(kw) def Copy(self, tools=None, toolpath=[], **kw): """Return a copy of a construction Environment. The @@ -779,6 +797,7 @@ class Base: if orig: add_to_val(orig) self._dict[key] = val + self.scanner_map_delete(kw) def PrependENVPath(self, name, newpath, envname = 'ENV', sep = os.pathsep): """Prepend path elements to the path 'name' in the 'ENV' @@ -823,6 +842,7 @@ class Base: self._dict[key] = val + dk else: self._dict[key] = val + dk + self.scanner_map_delete(kw) def Replace(self, **kw): """Replace existing construction variables in an Environment @@ -836,6 +856,7 @@ class Base: pass kw = copy_non_reserved_keywords(kw) self._dict.update(our_deepcopy(kw)) + self.scanner_map_delete(kw) def ReplaceIxes(self, path, old_prefix, old_suffix, new_prefix, new_suffix): """ diff --git a/src/engine/SCons/EnvironmentTests.py b/src/engine/SCons/EnvironmentTests.py index 3447e7b..0995a05 100644 --- a/src/engine/SCons/EnvironmentTests.py +++ b/src/engine/SCons/EnvironmentTests.py @@ -108,10 +108,17 @@ class Scanner: self.skeys = skeys def __call__(self, filename): + global scanned_it scanned_it[filename] = 1 def __cmp__(self, other): - return cmp(self.__dict__, other.__dict__) + try: + return cmp(self.__dict__, other.__dict__) + except AttributeError: + return 1 + + def get_skeys(self, env): + return self.skeys @@ -538,43 +545,73 @@ class EnvironmentTestCase(unittest.TestCase): assert built_it['out2'] def test_Scanners(self): - """Test Scanner execution through different environments + """Test setting SCANNERS in various ways One environment is initialized with a single Scanner object, one with a list of a single Scanner object, and one with a list of two Scanner objects. """ -# global scanned_it -# -# s1 = Scanner(name = 'scanner1', skeys = [".c", ".cc"]) -# s2 = Scanner(name = 'scanner2', skeys = [".m4"]) -# -# scanned_it = {} -# env1 = Environment(SCANNERS = s1) + global scanned_it + + s1 = Scanner(name = 'scanner1', skeys = [".c", ".cc"]) + s2 = Scanner(name = 'scanner2', skeys = [".m4"]) + s3 = Scanner(name = 'scanner3', skeys = [".m4", ".m5"]) + +# XXX Tests for scanner execution through different environments, +# XXX if we ever want to do that some day +# scanned_it = {} +# env1 = Environment(SCANNERS = s1) # env1.scanner1(filename = 'out1') -# assert scanned_it['out1'] +# assert scanned_it['out1'] # -# scanned_it = {} -# env2 = Environment(SCANNERS = [s1]) +# scanned_it = {} +# env2 = Environment(SCANNERS = [s1]) # env1.scanner1(filename = 'out1') -# assert scanned_it['out1'] +# assert scanned_it['out1'] # -# scanned_it = {} +# scanned_it = {} # env3 = Environment() -# env3.Replace(SCANNERS = [s1, s2]) +# env3.Replace(SCANNERS = [s1]) # env3.scanner1(filename = 'out1') # env3.scanner2(filename = 'out2') # env3.scanner1(filename = 'out3') -# assert scanned_it['out1'] -# assert scanned_it['out2'] -# assert scanned_it['out3'] -# -# s = env3.get_scanner(".c") -# assert s == s1, s -# s = env3.get_scanner(skey=".m4") -# assert s == s2, s -# s = env3.get_scanner(".cxx") -# assert s == None, s +# assert scanned_it['out1'] +# assert scanned_it['out2'] +# assert scanned_it['out3'] + + suffixes = [".c", ".cc", ".cxx", ".m4", ".m5"] + + env = Environment(SCANNERS = []) + s = map(env.get_scanner, suffixes) + assert s == [None, None, None, None, None], s + + env.Replace(SCANNERS = [s1]) + s = map(env.get_scanner, suffixes) + assert s == [s1, s1, None, None, None], s + + env.Append(SCANNERS = [s2]) + s = map(env.get_scanner, suffixes) + assert s == [s1, s1, None, s2, None], s + + env.AppendUnique(SCANNERS = [s3]) + s = map(env.get_scanner, suffixes) + assert s == [s1, s1, None, s2, s3], s + + env = env.Copy(SCANNERS = [s2]) + s = map(env.get_scanner, suffixes) + assert s == [None, None, None, s2, None], s + + env['SCANNERS'] = [s1] + s = map(env.get_scanner, suffixes) + assert s == [s1, s1, None, None, None], s + + env.PrependUnique(SCANNERS = [s2, s1]) + s = map(env.get_scanner, suffixes) + assert s == [s1, s1, None, s2, None], s + + env.Prepend(SCANNERS = [s3]) + s = map(env.get_scanner, suffixes) + assert s == [s1, s1, None, s3, s3], s def test_ENV(self): """Test setting the external ENV in Environments |