Skip to content

Commit

Permalink
Directly apply build ignore patterns.
Browse files Browse the repository at this point in the history
  • Loading branch information
stuhood committed Mar 16, 2018
1 parent 672a6e7 commit 0171aba
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 18 deletions.
1 change: 0 additions & 1 deletion src/python/pants/engine/BUILD
Expand Up @@ -79,7 +79,6 @@ python_library(
name='mapper',
sources=['mapper.py'],
dependencies=[
'3rdparty/python:pathspec',
':objects',
':parser',
'src/python/pants/build_graph',
Expand Down
12 changes: 2 additions & 10 deletions src/python/pants/engine/build_files.py
Expand Up @@ -75,10 +75,7 @@ def parse_address_family(address_mapper, path, build_files):
raise ResolveError('Directory "{}" does not contain build files.'.format(path))
address_maps = []
paths = (f.path for f in files_content)
ignored_paths = set(address_mapper.build_ignore_patterns.match_files(paths))
for filecontent_product in files_content:
if filecontent_product.path in ignored_paths:
continue
address_maps.append(AddressMap.parse(filecontent_product.path,
filecontent_product.content,
address_mapper.parser))
Expand Down Expand Up @@ -308,17 +305,12 @@ def include(address_families, predicate=None):
def filter_build_dirs(address_mapper, snapshot):
"""Given a Snapshot matching a build pattern, return parent directories as BuildDirs."""
dirnames = set(dirname(f.stat.path) for f in snapshot.files)
ignored_dirnames = address_mapper.build_ignore_patterns.match_files('{}/'.format(dirname) for dirname in dirnames)
ignored_dirnames = set(d.rstrip('/') for d in ignored_dirnames)
return BuildDirs(tuple(Dir(d) for d in dirnames if d not in ignored_dirnames))
return BuildDirs(tuple(Dir(d) for d in dirnames))


@rule(PathGlobs, [Select(AddressMapper), Select(Specs)])
def spec_to_globs(address_mapper, specs):
"""Given a Spec object, return a PathGlobs object for the build files that it matches.
TODO: We should apply address_mapper.build_ignore_patterns here to ignore paths earlier
than we would in `parse_address_family`.
"""
patterns = set()
for spec in specs.dependencies:
Expand All @@ -334,7 +326,7 @@ def spec_to_globs(address_mapper, specs):
for f in _recursive_dirname(spec.directory))
else:
raise ValueError('Unrecognized Spec type: {}'.format(spec))
return PathGlobs.create('', include=patterns, exclude=[])
return PathGlobs.create('', include=patterns, exclude=address_mapper.build_ignore_patterns)


def _recursive_dirname(f):
Expand Down
7 changes: 2 additions & 5 deletions src/python/pants/engine/mapper.py
Expand Up @@ -8,9 +8,6 @@
import re
from collections import OrderedDict

from pathspec import PathSpec
from pathspec.patterns.gitwildmatch import GitWildMatchPattern

from pants.build_graph.address import BuildFileAddress
from pants.engine.objects import Serializable
from pants.util.memo import memoized_property
Expand Down Expand Up @@ -184,8 +181,8 @@ def __init__(self,
:param list exclude_target_regexps: A list of regular expressions for excluding targets.
"""
self.parser = parser
self.build_patterns = build_patterns or (b'BUILD', b'BUILD.*')
self.build_ignore_patterns = PathSpec.from_lines(GitWildMatchPattern, build_ignore_patterns or [])
self.build_patterns = tuple(build_patterns or [b'BUILD', b'BUILD.*'])
self.build_ignore_patterns = tuple(build_ignore_patterns or [])
self._exclude_target_regexps = exclude_target_regexps or []
self.exclude_patterns = [re.compile(pattern) for pattern in self._exclude_target_regexps]
self.subproject_roots = subproject_roots or []
Expand Down
4 changes: 2 additions & 2 deletions src/python/pants/engine/scheduler.py
Expand Up @@ -20,8 +20,8 @@
from pants.engine.native import Function, TypeConstraint, TypeId
from pants.engine.nodes import Return, State, Throw
from pants.engine.rules import RuleIndex, SingletonRule, TaskRule
from pants.engine.selectors import (Select, SelectDependencies, SelectProjection,
SelectVariant, constraint_for)
from pants.engine.selectors import (Select, SelectDependencies, SelectProjection, SelectVariant,
constraint_for)
from pants.engine.struct import HasProducts, Variants
from pants.util.contextutil import temporary_file_path
from pants.util.objects import datatype
Expand Down

0 comments on commit 0171aba

Please sign in to comment.