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

Remove SelectDependencies. #5800

Merged
Merged
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
18 changes: 12 additions & 6 deletions src/python/pants/engine/build_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
unicode_literals, with_statement)

import collections
import functools
from os.path import dirname, join

import six
Expand All @@ -20,7 +21,7 @@
from pants.engine.mapper import AddressFamily, AddressMap, AddressMapper, ResolveError
from pants.engine.objects import Locatable, SerializableFactory, Validatable
from pants.engine.rules import RootRule, SingletonRule, TaskRule, rule
from pants.engine.selectors import Get, Select, SelectDependencies
from pants.engine.selectors import Get, Select
from pants.engine.struct import Struct
from pants.util.dirutil import fast_relpath_optional
from pants.util.objects import TypeConstraintError, datatype
Expand Down Expand Up @@ -130,12 +131,13 @@ def collect_dependencies(item):
filter(lambda build_address: build_address == address, addresses)[0], struct, dependencies)


def hydrate_struct(address_mapper, unhydrated_struct, dependencies):
def hydrate_struct(symbol_table_constraint, address_mapper, unhydrated_struct):
"""Hydrates a Struct from an UnhydratedStruct and its satisfied embedded addressable deps.

Note that this relies on the guarantee that DependenciesNode provides dependencies in the
order they were requested.
"""
dependencies = yield [Get(symbol_table_constraint, Address, a) for a in unhydrated_struct.dependencies]
address = unhydrated_struct.address
struct = unhydrated_struct.struct

Expand Down Expand Up @@ -176,7 +178,7 @@ def consume_dependencies(item, args=None):
hydrated_args[key] = maybe_consume(key, value)
return _hydrate(type(item), address.spec_path, **hydrated_args)

return consume_dependencies(struct, args={'address': address})
yield consume_dependencies(struct, args={'address': address})


def _hydrate(item_type, spec_path, **kwargs):
Expand Down Expand Up @@ -316,16 +318,20 @@ def create_graph_rules(address_mapper, symbol_table):
:param symbol_table: A SymbolTable instance to provide symbols for Address lookups.
"""
symbol_table_constraint = symbol_table.constraint()

partial_hydrate_struct = functools.partial(hydrate_struct, symbol_table_constraint)
partial_hydrate_struct.__name__ = 'hydrate_struct'

return [
# A singleton to provide the AddressMapper.
SingletonRule(AddressMapper, address_mapper),
# Support for resolving Structs from Addresses.
TaskRule(
symbol_table_constraint,
[Select(AddressMapper),
Select(UnhydratedStruct),
SelectDependencies(symbol_table_constraint, UnhydratedStruct, field_types=(Address,))],
hydrate_struct
Select(UnhydratedStruct)],
partial_hydrate_struct,
input_gets=[Get(symbol_table_constraint, Address)],
),
resolve_unhydrated_struct,
# BUILD file parsing.
Expand Down
23 changes: 14 additions & 9 deletions src/python/pants/engine/legacy/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from pants.engine.fs import PathGlobs, Snapshot
from pants.engine.legacy.structs import BundleAdaptor, BundlesField, SourcesField, TargetAdaptor
from pants.engine.rules import TaskRule, rule
from pants.engine.selectors import Get, Select, SelectDependencies
from pants.engine.selectors import Get, Select
from pants.source.wrapped_globs import EagerFilesetWithSpec, FilesetRelPathWrapper
from pants.util.dirutil import fast_relpath
from pants.util.objects import Collection, datatype
Expand Down Expand Up @@ -342,13 +342,17 @@ class HydratedField(datatype(['name', 'value'])):
"""A wrapper for a fully constructed replacement kwarg for a HydratedTarget."""


def hydrate_target(target_adaptor, hydrated_fields):
def hydrate_target(target_adaptor):
"""Construct a HydratedTarget from a TargetAdaptor and hydrated versions of its adapted fields."""
# Hydrate the fields of the adaptor and re-construct it.
hydrated_fields = yield [(Get(HydratedField, BundlesField, fa)
if type(fa) is BundlesField
else Get(HydratedField, SourcesField, fa))
for fa in target_adaptor.field_adaptors]
kwargs = target_adaptor.kwargs()
for field in hydrated_fields:
kwargs[field.name] = field.value
return HydratedTarget(target_adaptor.address,
yield HydratedTarget(target_adaptor.address,
TargetAdaptor(**kwargs),
tuple(target_adaptor.dependencies))

Expand Down Expand Up @@ -405,18 +409,19 @@ def hydrate_bundles(bundles_field):
def create_legacy_graph_tasks(symbol_table):
"""Create tasks to recursively parse the legacy graph."""
symbol_table_constraint = symbol_table.constraint()

return [
transitive_hydrated_targets,
transitive_hydrated_target,
hydrated_targets,
TaskRule(
HydratedTarget,
[Select(symbol_table_constraint),
SelectDependencies(HydratedField,
symbol_table_constraint,
'field_adaptors',
field_types=(SourcesField, BundlesField,))],
hydrate_target
[Select(symbol_table_constraint)],
hydrate_target,
input_gets=[
Get(HydratedField, SourcesField),
Get(HydratedField, BundlesField),
]
),
hydrate_sources,
hydrate_bundles,
Expand Down
1 change: 0 additions & 1 deletion src/python/pants/engine/native.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@
void tasks_add_get(Tasks*, TypeConstraint, TypeId);
void tasks_add_select(Tasks*, TypeConstraint);
void tasks_add_select_variant(Tasks*, TypeConstraint, Buffer);
void tasks_add_select_dependencies(Tasks*, TypeConstraint, TypeConstraint, Buffer, TypeIdBuffer);
void tasks_task_end(Tasks*);
void tasks_singleton_add(Tasks*, Value, TypeConstraint);
void tasks_destroy(Tasks*);
Expand Down
9 changes: 4 additions & 5 deletions src/python/pants/engine/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class RuleIndex(datatype(['rules', 'roots'])):

@classmethod
def create(cls, rule_entries):
"""Creates a NodeBuilder with tasks indexed by their output type."""
"""Creates a RuleIndex with tasks indexed by their output type."""
# NB make tasks ordered so that gen ordering is deterministic.
serializable_rules = OrderedDict()
serializable_roots = set()
Expand All @@ -175,11 +175,10 @@ def add_rule(rule):
if isinstance(rule, RootRule):
serializable_roots.add(rule.output_constraint)
return
# TODO: The heterogenity here has some confusing implications here:
# see https://github.com/pantsbuild/pants/issues/4005
# TODO: Ensure that interior types work by indexing on the list of types in
# the constraint. This heterogenity has some confusing implications:
# see https://github.com/pantsbuild/pants/issues/4005
for kind in rule.output_constraint.types:
# NB Ensure that interior types from SelectDependencies work by
# indexing on the list of types in the constraint.
add_task(kind, rule)
add_task(rule.output_constraint, rule)

Expand Down
8 changes: 1 addition & 7 deletions src/python/pants/engine/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
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, SelectVariant, constraint_for
from pants.engine.selectors import Select, SelectVariant, constraint_for
from pants.engine.struct import HasProducts, Variants
from pants.util.contextutil import temporary_file_path
from pants.util.objects import SubclassesOf, datatype
Expand Down Expand Up @@ -221,12 +221,6 @@ def _register_task(self, output_constraint, rule):
self._native.lib.tasks_add_select_variant(self._tasks,
product_constraint,
key_buf)
elif selector_type is SelectDependencies:
self._native.lib.tasks_add_select_dependencies(self._tasks,
product_constraint,
self._to_constraint(selector.dep_product),
self._to_utf8_buf(selector.field),
self._to_ids_buf(selector.field_types))
else:
raise ValueError('Unrecognized Selector type: {}'.format(selector))
for get in rule.input_gets:
Expand Down
43 changes: 0 additions & 43 deletions src/python/pants/engine/selectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,46 +130,3 @@ def __repr__(self):
return '{}({}, {})'.format(type(self).__name__,
type_or_constraint_repr(self.product),
repr(self.variant_key))


class SelectDependencies(datatype(['product', 'dep_product', 'field', 'field_types']),
Selector):
"""Selects a product for each of the dependencies of a product for the Subject.

The dependencies declared on `dep_product` (in the optional `field` parameter, which defaults
to 'dependencies' when not specified) will be provided to the requesting task in the
order they were declared.

Field types are used to statically declare the types expected to be contained by the
`dep_product`.
"""

DEFAULT_FIELD = 'dependencies'

optional = False

def __new__(cls, product, dep_product, field=DEFAULT_FIELD, field_types=tuple()):
return super(SelectDependencies, cls).__new__(cls, product, dep_product, field, field_types)

@property
def input_product_selector(self):
return Select(self.dep_product)

@property
def projected_product_selector(self):
return Select(self.product)

def __repr__(self):
if self.field_types:
field_types_portion = ', field_types=({},)'.format(', '.join(f.__name__ for f in self.field_types))
else:
field_types_portion = ''
if self.field is not self.DEFAULT_FIELD:
field_name_portion = ', {}'.format(repr(self.field))
else:
field_name_portion = ''
return '{}({}, {}{}{})'.format(type(self).__name__,
type_or_constraint_repr(self.product),
type_or_constraint_repr(self.dep_product),
field_name_portion,
field_types_portion)
3 changes: 0 additions & 3 deletions src/rust/engine/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ impl Variants {

pub type Id = u64;

// The name of a field.
pub type Field = String;

// The type of a python object (which itself has a type, but which is not represented
// by a Key, because that would result in a infinitely recursive structure.)
#[repr(C)]
Expand Down
18 changes: 0 additions & 18 deletions src/rust/engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,24 +381,6 @@ pub extern "C" fn tasks_add_select_variant(
})
}

#[no_mangle]
pub extern "C" fn tasks_add_select_dependencies(
tasks_ptr: *mut Tasks,
product: TypeConstraint,
dep_product: TypeConstraint,
field: Buffer,
field_types: TypeIdBuffer,
) {
with_tasks(tasks_ptr, |tasks| {
tasks.add_select_dependencies(
product,
dep_product,
field.to_string().expect("field to be a string"),
field_types.to_vec(),
);
})
}

#[no_mangle]
pub extern "C" fn tasks_task_end(tasks_ptr: *mut Tasks) {
with_tasks(tasks_ptr, |tasks| {
Expand Down
Loading