diff --git a/SCons/Node/FS.py b/SCons/Node/FS.py index 694ff9f87..5d3d21d7d 100644 --- a/SCons/Node/FS.py +++ b/SCons/Node/FS.py @@ -93,6 +93,26 @@ def __str__(self) -> str: repr(entry.name), repr(self.attribute)) + +class FileWhereDirectoryExpectedError(SCons.Errors.BuildError): + 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(SCons.Errors.BuildError): + 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 @@ -418,7 +438,7 @@ def enable(self, disk_check_type_list) -> None: 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(), @@ -432,7 +452,7 @@ 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) -> None: @@ -1674,9 +1694,9 @@ def _morph(self) -> None: l.insert(0, a) self.get_executor().set_action_list(l) - def diskcheck_match(self) -> None: - diskcheck_match(self, self.isfile, - "File %s found where directory expected.") + def diskcheck_match(self)-> None: + diskcheck_match(self, self.isfile, FileWhereDirectoryExpectedError) + def __clearRepositoryCache(self, duplicate=None) -> None: """Called when we change the repository(ies) for a directory. @@ -2474,6 +2494,7 @@ def _lookup_abs(self, p, klass, create: bool=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 @@ -2675,8 +2696,7 @@ class File(Base): hash_chunksize = 65536 def diskcheck_match(self) -> None: - diskcheck_match(self, self.isdir, - "Directory %s found where file expected.") + diskcheck_match(self, self.isdir, DirWhereFileExpectedError) def __init__(self, name, directory, fs) -> None: if SCons.Debug.track_instances: logInstanceCreation(self, 'Node.FS.File') diff --git a/test/diskcheck.py b/test/diskcheck.py index c07dc6b34..9f5908859 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')