Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Fix 4282 file dir conflict stacktrace #4284

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions SCons/Node/FS.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,26 @@ def __str__(self):
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):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feels like a bit of overkill to define individual exceptions for this, but that's not a big deal.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DirWhereFile and FileWhereDir result in different fixes/issues.. removing a file to put a dir is easy, but not vice versa.
Or at least that was the thought.

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
Expand Down Expand Up @@ -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(),
Expand All @@ -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


Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions test/diskcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down