Skip to content

Commit

Permalink
bugfix: exclude targets (#888)
Browse files Browse the repository at this point in the history
  • Loading branch information
chen3feng committed Feb 25, 2021
1 parent 19d1f60 commit cd8bda5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/blade/build_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ def __init__(self,
def load_targets(self):
"""Load the targets."""
console.info('Loading BUILD files...')
excluded_targets = target_pattern.normalize_list(self.__options.exclude_targets.split(','),
self.__working_dir)
excluded_targets = target_pattern.normalize_str_list(self.__options.exclude_targets,
self.__working_dir, ',')
(self.__direct_targets,
self.__expanded_command_targets,
self.__build_targets) = load_targets(self.__load_targets, excluded_targets, self)
Expand Down Expand Up @@ -237,8 +237,8 @@ def _test(self):
"""Run tests."""
exclude_tests = []
if self.__options.exclude_tests:
exclude_tests = target_pattern.normalize_list(self.__options.exclude_tests.split(','),
self.__working_dir)
exclude_tests = target_pattern.normalize_str_list(self.__options.exclude_tests,
self.__working_dir, ',')
test_runner = TestRunner(
self.__options,
self.__target_database,
Expand Down
8 changes: 7 additions & 1 deletion src/blade/target_pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import os

from blade import console
from blade import util


def _split(target):
Expand Down Expand Up @@ -58,13 +59,18 @@ def normalize_list(targets, working_dir):
return [normalize(target, working_dir) for target in targets]


def normalize_str_list(targets, working_dir, sep):
"""Parse and normalize a target pattern list string. Any empty part is removed."""
return normalize_list(filter(bool, map(str.strip, targets.split(sep))), working_dir)


def match(target_id, pattern):
"""Check whether a atrget id match a target pattern"""
t_path, t_name = target_id.split(':')
p_path, p_name = pattern.split(':')

if p_name == '...':
return t_path == p_path or t_path.startswith(p_path) and t_path[len(p_path)] == os.sep
return util.path_under_dir(t_path, p_path)
if p_name == '*':
return t_path == p_path
return target_id == pattern
Expand Down

0 comments on commit cd8bda5

Please sign in to comment.