From b3e5676bc771819d96bd2190961917ba1b9f8dfe Mon Sep 17 00:00:00 2001 From: stevenknight Date: Mon, 5 Aug 2002 04:05:13 +0000 Subject: [PATCH] Add a decent error message for corrupted .sconsign files (Bug 579666). (Anthony Roach) git-svn-id: http://scons.tigris.org/svn/scons/trunk@428 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- src/CHANGES.txt | 2 ++ src/engine/SCons/Script/__init__.py | 1 + src/engine/SCons/Sig/__init__.py | 12 ++++++++--- src/engine/SCons/Warnings.py | 3 +++ test/sconsign.py | 32 ++++++++++++++++++++++++++++- 5 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 30f8eb95..6e24752d 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -20,6 +20,8 @@ RELEASE 0.09 - - Make -U be case insensitive on Win32 systems. + - Issue a warning and continue when finding a corrupt .sconsign file. + RELEASE 0.08 - Mon, 15 Jul 2002 12:08:51 -0500 diff --git a/src/engine/SCons/Script/__init__.py b/src/engine/SCons/Script/__init__.py index a00c7347..bce17ba8 100644 --- a/src/engine/SCons/Script/__init__.py +++ b/src/engine/SCons/Script/__init__.py @@ -865,6 +865,7 @@ def _main(): # Enable deprecated warnings by default. SCons.Warnings._warningOut = _scons_internal_warning SCons.Warnings.enableWarningClass(SCons.Warnings.DeprecatedWarning) + SCons.Warnings.enableWarningClass(SCons.Warnings.CorruptSConsignWarning) try: cmd_opts, t = getopt.getopt(string.split(os.environ['SCONSFLAGS']), diff --git a/src/engine/SCons/Sig/__init__.py b/src/engine/SCons/Sig/__init__.py index 7739aad7..b6a5c25f 100644 --- a/src/engine/SCons/Sig/__init__.py +++ b/src/engine/SCons/Sig/__init__.py @@ -34,6 +34,7 @@ import os.path import string import SCons.Node import time +import SCons.Warnings #XXX Get rid of the global array so this becomes re-entrant. sig_files = [] @@ -131,9 +132,14 @@ class SConsignFile: pass else: for line in file.readlines(): - filename, rest = map(string.strip, string.split(line, ":", 1)) - self.entries[filename] = SConsignEntry(self.module, rest) - + try: + filename, rest = map(string.strip, string.split(line, ":", 1)) + self.entries[filename] = SConsignEntry(self.module, rest) + except ValueError: + SCons.Warnings.warn(SCons.Warnings.CorruptSConsignWarning, + "Ignoring corrupt .sconsign file: %s"%self.sconsign) + self.entries = {} + global sig_files sig_files.append(self) diff --git a/src/engine/SCons/Warnings.py b/src/engine/SCons/Warnings.py index 5ba3aec3..bf18ba5a 100644 --- a/src/engine/SCons/Warnings.py +++ b/src/engine/SCons/Warnings.py @@ -44,6 +44,9 @@ class DeprecatedWarning(Warning): class DependencyWarning(Warning): pass +class CorruptSConsignWarning(Warning): + pass + _warningAsException = 0 # The below is a list of 2-tuples. The first element is a class object. diff --git a/test/sconsign.py b/test/sconsign.py index 76fa355f..57906af4 100644 --- a/test/sconsign.py +++ b/test/sconsign.py @@ -26,8 +26,9 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os import TestSCons +import TestCmd -test = TestSCons.TestSCons() +test = TestSCons.TestSCons(match = TestCmd.match_re) test.subdir('sub1', 'sub2', 'sub3') @@ -70,4 +71,33 @@ test.fail_test(test.read(sub2__sconsign) == "") os.chmod(sub1__sconsign, 0666) +test.write('SConstruct', """ +def build1(target, source, env): + print '%s->%s'%(str(source[0]), str(target[0])) + open(str(target[0]), 'wb').write(open(str(source[0]), 'rb').read()) + return None + +B1 = Builder(action = build1) +env = Environment(BUILDERS = { 'B1' : B1}) +env.B1(target = 'sub1/foo.out', source = 'foo.in') +""") + +stderr = ''' +SCons warning: Ignoring corrupt .sconsign file: sub1..sconsign +.* +''' + +stdout = '''foo.in->sub1.foo.out +''' + +test.write(sub1__sconsign, 'garbage') +test.run(arguments = '.', stderr=stderr, stdout=stdout) + +test.write(sub1__sconsign, 'not:a:sconsign:file') +test.run(arguments = '.', stderr=stderr, stdout=stdout) + +test.write(sub1__sconsign, '\0\0\0\0\0\0\0\0\0\0\0\0\0\0') +test.run(arguments = '.', stderr=stderr, stdout=stdout) + + test.pass_test() -- 2.26.2