-
-
Notifications
You must be signed in to change notification settings - Fork 626
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make "changed" tasks work with deleted files (#4546)
### 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 #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
- Loading branch information
Showing
8 changed files
with
246 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# coding=utf-8 | ||
# Copyright 2017 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import (absolute_import, division, generators, nested_scopes, print_function, | ||
unicode_literals, with_statement) | ||
|
||
import re | ||
|
||
|
||
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. | ||
"*" only matches patterns in a single dir. | ||
:returns: A regex string that matches same paths as the input glob does. | ||
""" | ||
out = ['^'] | ||
components = pattern.strip('/').replace('.', '[.]').replace('$','[$]').split('/') | ||
doublestar = False | ||
for component in components: | ||
if len(out) == 1: | ||
if pattern.startswith('/'): | ||
out.append('/') | ||
else: | ||
if not doublestar: | ||
out.append('/') | ||
|
||
if '**' in component: | ||
if component != '**': | ||
raise ValueError('Invalid usage of "**", use "*" instead.') | ||
|
||
if not doublestar: | ||
out.append('(([^/]+/)*)') | ||
doublestar = True | ||
else: | ||
out.append(component.replace('*', '[^/]*')) | ||
doublestar = False | ||
|
||
if doublestar: | ||
out.append('[^/]*') | ||
|
||
out.append('$') | ||
|
||
return ''.join(out) | ||
|
||
|
||
def globs_matches(path, patterns): | ||
return any(re.match(glob_to_regex(pattern), path) for pattern in patterns) | ||
|
||
|
||
def matches_filespec(path, spec): | ||
if spec is None: | ||
return False | ||
if not globs_matches(path, spec.get('globs', [])): | ||
return False | ||
for spec in spec.get('exclude', []): | ||
if matches_filespec(path, spec): | ||
return False | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.