From daeabac2fe8e3339fcac65b58b925269381d8ed4 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Tue, 20 Dec 2022 11:23:46 -0800 Subject: [PATCH 1/3] Switched DiskChecker()'s methods to expect an exception rather than a format string. Created FileWhereDirectoryExpectedError and DirWhereFileExpectedError exceptions which are children of TypeError (The previous exception raised when there was a mismatch. --- SCons/Node/FS.py | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/SCons/Node/FS.py b/SCons/Node/FS.py index 67e1ff6083..9a9892724f 100644 --- a/SCons/Node/FS.py +++ b/SCons/Node/FS.py @@ -92,6 +92,26 @@ def __str__(self): repr(entry.name), repr(self.attribute)) + +class FileWhereDirectoryExpectedError(TypeError): + def __init__(self, node_path): + super().__init__() + self.node_path = node_path + + def __str__(self): + fmt = "File %s found where directory expected." + return fmt % self.node_path + + +class DirWhereFileExpectedError(TypeError): + def __init__(self, node_path): + super().__init__() + self.node_path = node_path + + def __str__(self): + fmt = "Directory %s found where file expected." + return fmt % self.node_path + # The max_drift value: by default, use a cached signature value for # any file that's been untouched for more than two days. default_max_drift = 2*24*60*60 @@ -406,7 +426,7 @@ def enable(self, disk_check_type_list): self.func = self.ignore_check_function -def do_diskcheck_match(node, predicate, errorfmt): +def do_diskcheck_match(node, predicate, error_exception): result = predicate() try: # If calling the predicate() cached a None value from stat(), @@ -420,10 +440,10 @@ def do_diskcheck_match(node, predicate, errorfmt): except (AttributeError, KeyError): pass if result: - raise TypeError(errorfmt % node.get_abspath()) + raise error_exception(node.get_abspath()) -def ignore_diskcheck_match(node, predicate, errorfmt): +def ignore_diskcheck_match(node, predicate, error_exception): pass @@ -1650,8 +1670,7 @@ def _morph(self): self.get_executor().set_action_list(l) def diskcheck_match(self): - diskcheck_match(self, self.isfile, - "File %s found where directory expected.") + diskcheck_match(self, self.isfile, FileWhereDirectoryExpectedError) def __clearRepositoryCache(self, duplicate=None): """Called when we change the repository(ies) for a directory. @@ -2450,6 +2469,7 @@ def _lookup_abs(self, p, klass, create=True): # created matches whatever is out there in the real world. result.diskcheck_match() + self._lookupDict[k] = result dir_node.entries[_my_normcase(file_name)] = result dir_node.implicit = None @@ -2681,8 +2701,7 @@ class File(Base): hash_chunksize = 65536 def diskcheck_match(self): - diskcheck_match(self, self.isdir, - "Directory %s found where file expected.") + diskcheck_match(self, self.isdir, DirWhereFileExpectedError) def __init__(self, name, directory, fs): if SCons.Debug.track_instances: logInstanceCreation(self, 'Node.FS.File') From d998edf4194903c2f21a27f785d3947582b43b99 Mon Sep 17 00:00:00 2001 From: William Deegan Date: Tue, 20 Dec 2022 11:32:22 -0800 Subject: [PATCH 2/3] changed new exceptions to be children of BuildError exception --- SCons/Node/FS.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SCons/Node/FS.py b/SCons/Node/FS.py index 9a9892724f..f7ad60c45a 100644 --- a/SCons/Node/FS.py +++ b/SCons/Node/FS.py @@ -93,7 +93,7 @@ def __str__(self): repr(self.attribute)) -class FileWhereDirectoryExpectedError(TypeError): +class FileWhereDirectoryExpectedError(SCons.Errors.BuildError): def __init__(self, node_path): super().__init__() self.node_path = node_path @@ -103,7 +103,7 @@ def __str__(self): return fmt % self.node_path -class DirWhereFileExpectedError(TypeError): +class DirWhereFileExpectedError(SCons.Errors.BuildError): def __init__(self, node_path): super().__init__() self.node_path = node_path From 40dedc113bba005709736af29ece977a5657d44c Mon Sep 17 00:00:00 2001 From: William Deegan Date: Tue, 20 Dec 2022 11:43:01 -0800 Subject: [PATCH 3/3] Fix test/diskcheck by comparing expected output against stdout instead of previously stderr --- test/diskcheck.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/diskcheck.py b/test/diskcheck.py index c07dc6b344..9f59088598 100644 --- a/test/diskcheck.py +++ b/test/diskcheck.py @@ -48,10 +48,10 @@ """) test.run(status=2, stderr=None) -test.must_contain_all_lines(test.stderr(), ["found where file expected"]) +test.must_contain_all_lines(test.stdout(), ["found where file expected"]) test.run(arguments='--diskcheck=match', status=2, stderr=None) -test.must_contain_all_lines(test.stderr(), ["found where file expected"]) +test.must_contain_all_lines(test.stdout(), ["found where file expected"]) # Test that setting --diskcheck to none via command line also works. test.run(arguments='--diskcheck=none')