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

Make "changed" tasks work with deleted files #4546

Merged

Conversation

JieGhost
Copy link
Contributor

@JieGhost JieGhost commented May 3, 2017

Problem

#4529

There are 2 kinds of "changed" tasks in pants currently. Neither of them output correct result if a file is deleted.

  1. "./pants changed" tasks. They used to have the correct output, but after Fix Go source excludes; Cleanup old filespec matching #4350 , the logic of file matching in SpecSourceMapper was changed. We used to do a regular expression matching to check if the modified file is owned by a target. Now we check if a modified file is in a target's source file set. For a deleted file, it will not be in any target's source file set, thus no target will be considered as the owner of the deleted file, giving incorrect result.
  2. "./pants --changed-XXX list". This uses EngineSourceMapper which implements similar logic as above. It never works on deleted files.

Solution

I restored the removed file matching logic (using regular expression). In both SpecSourceMapper and EngineSourceMapper, first check if a file exists. It it exists, then check if it's in target's file set. If not, then it is a deleted file, and use re matching logic on it. Fixes #4529

@JieGhost JieGhost requested review from stuhood, wisechengyi and kwlzn May 3, 2017 19:20

def glob_to_regex(pattern):
"""Given a glob pattern, return an equivalent regex expression.
:param string glob: The glob pattern. "**" matches 0 or more dirs recursively.
Copy link
Member

Choose a reason for hiding this comment

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

this should already be provided by the pathspec 3rdparty dep?

see: cpburnz/python-pathspec#11

Copy link
Contributor Author

Choose a reason for hiding this comment

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

glob syntax used in file matching is not equivalent to gitignore syntax. For example, "src" in gitignore will match everything inside "src", but in glob syntax, it should only match "src".

Copy link
Member

@stuhood stuhood left a comment

Choose a reason for hiding this comment

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

Thanks Yujie.

@@ -48,20 +49,27 @@ def _unique_dirs_for_sources(self, sources):
def target_addresses_for_source(self, source):
return list(self.iter_target_addresses_for_sources([source]))

def _iter_owned_files_from_hydrated_target(self, legacy_target):
def _match_source(self, source, fileset):
if os.path.exists(source):
Copy link
Member

Choose a reason for hiding this comment

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

Rather than always checking whether it exists, maybe first check whether it is in the fileset... if it is, then it's definitely owned, and that's cheaper than a syscall. If it's not in the fileset, can use matches_filespec.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

else:
return matches_filespec(source, fileset.filespec)

def _own_source(self, source, legacy_target):
"""Given a `HydratedTarget` instance, yield all files owned by the target."""
Copy link
Member

Choose a reason for hiding this comment

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

Comment out of date. I think this method is probably _owns_source since it returns a boolean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@JieGhost JieGhost merged commit 0510f02 into pantsbuild:master May 4, 2017
@JieGhost JieGhost deleted the yujieproject/changed_on_delete_files branch May 4, 2017 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants