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

Merge subjects and variants into Params, and remove Noop #6170

Merged
merged 13 commits into from
Sep 20, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from pants.backend.native.config.environment import Assembler, Linker
from pants.binaries.binary_tool import NativeTool
from pants.engine.rules import RootRule, rule
from pants.engine.rules import rule
from pants.engine.selectors import Select


Expand Down Expand Up @@ -49,5 +49,4 @@ def create_binutils_rules():
return [
get_as,
get_ld,
RootRule(Binutils),
]
3 changes: 1 addition & 2 deletions src/python/pants/backend/native/subsystems/binaries/gcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pants.backend.native.config.environment import CCompiler, CppCompiler, Platform
from pants.backend.native.subsystems.utils.archive_file_mapper import ArchiveFileMapper
from pants.binaries.binary_tool import NativeTool
from pants.engine.rules import RootRule, rule
from pants.engine.rules import rule
from pants.engine.selectors import Select
from pants.util.memo import memoized_method, memoized_property

Expand Down Expand Up @@ -108,5 +108,4 @@ def create_gcc_rules():
return [
get_gcc,
get_gplusplus,
RootRule(GCC),
]
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import os

from pants.backend.native.config.environment import Assembler, CCompiler, CppCompiler, Linker
from pants.engine.rules import RootRule, rule
from pants.engine.rules import rule
from pants.engine.selectors import Select
from pants.subsystem.subsystem import Subsystem
from pants.util.dirutil import is_readable_dir
Expand Down Expand Up @@ -196,5 +196,4 @@ def create_xcode_cli_tools_rules():
get_ld,
get_clang,
get_clang_plusplus,
RootRule(XCodeCLITools),
]
1 change: 0 additions & 1 deletion src/python/pants/engine/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,4 @@ def create_fs_rules():
return [
RootRule(DirectoryDigest),
RootRule(PathGlobs),
RootRule(Snapshot),
]
7 changes: 0 additions & 7 deletions src/python/pants/engine/native.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@
void tasks_task_begin(Tasks*, Function, TypeConstraint);
void tasks_add_get(Tasks*, TypeConstraint, TypeId);
void tasks_add_select(Tasks*, TypeConstraint);
void tasks_add_select_variant(Tasks*, TypeConstraint, Buffer);
void tasks_task_end(Tasks*);
void tasks_singleton_add(Tasks*, Handle, TypeConstraint);
void tasks_destroy(Tasks*);
Expand All @@ -197,8 +196,6 @@
TypeConstraint,
TypeConstraint,
TypeConstraint,
TypeConstraint,
TypeConstraint,
TypeId,
TypeId,
Buffer,
Expand Down Expand Up @@ -802,9 +799,7 @@ def new_scheduler(self,
construct_file,
construct_link,
construct_process_result,
constraint_has_products,
constraint_address,
constraint_variants,
constraint_path_globs,
constraint_directory_digest,
constraint_snapshot,
Expand Down Expand Up @@ -836,8 +831,6 @@ def tc(constraint):
func(construct_process_result),
# TypeConstraints.
tc(constraint_address),
tc(constraint_has_products),
tc(constraint_variants),
tc(constraint_path_globs),
tc(constraint_directory_digest),
tc(constraint_snapshot),
Expand Down
11 changes: 0 additions & 11 deletions src/python/pants/engine/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,6 @@ class Rule(AbstractClass):
def output_constraint(self):
"""An output Constraint type for the rule."""

@abstractproperty
def input_selectors(self):
"""Collection of input selectors."""


class TaskRule(datatype(['output_constraint', 'input_selectors', 'input_gets', 'func']), Rule):
"""A Rule that runs a task function when all of its input selectors are satisfied.
Expand Down Expand Up @@ -191,10 +187,6 @@ def __new__(cls, output_type, value):
# Create.
return super(SingletonRule, cls).__new__(cls, constraint, value)

@property
def input_selectors(self):
return tuple()

def __repr__(self):
return '{}({}, {})'.format(type(self).__name__, type_or_constraint_repr(self.output_constraint), self.value)

Expand All @@ -207,9 +199,6 @@ class RootRule(datatype(['output_constraint']), Rule):
of an execution.
"""

def input_selectors(self):
return []


class RuleIndex(datatype(['rules', 'roots'])):
"""Holds an index of Tasks and Singletons used to instantiate Nodes."""
Expand Down
21 changes: 5 additions & 16 deletions src/python/pants/engine/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
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, SelectVariant, constraint_for
from pants.engine.struct import HasProducts, Variants
from pants.engine.selectors import Select, constraint_for
from pants.util.contextutil import temporary_file_path
from pants.util.dirutil import check_no_overlapping_paths
from pants.util.objects import Collection, SubclassesOf, datatype
from pants.util.objects import Collection, datatype
from pants.util.strutil import pluralize


Expand Down Expand Up @@ -103,9 +102,6 @@ def __init__(
self._native = native
self.include_trace_on_error = include_trace_on_error

# TODO: The only (?) case where we use inheritance rather than exact type unions.
has_products_constraint = SubclassesOf(HasProducts)

# Validate and register all provided and intrinsic tasks.
rule_index = RuleIndex.create(list(rules))
self._root_subject_types = sorted(rule_index.roots, key=repr)
Expand All @@ -132,9 +128,7 @@ def __init__(
construct_file=File,
construct_link=Link,
construct_process_result=FallibleExecuteProcessResult,
constraint_has_products=has_products_constraint,
constraint_address=constraint_for(Address),
constraint_variants=constraint_for(Variants),
constraint_path_globs=constraint_for(PathGlobs),
constraint_directory_digest=constraint_for(DirectoryDigest),
constraint_snapshot=constraint_for(Snapshot),
Expand Down Expand Up @@ -230,18 +224,13 @@ def _register_singleton(self, output_constraint, rule):

def _register_task(self, output_constraint, rule):
"""Register the given TaskRule with the native scheduler."""
func = rule.func
self._native.lib.tasks_task_begin(self._tasks, Function(self._to_key(func)), output_constraint)
func = Function(self._to_key(rule.func))
self._native.lib.tasks_task_begin(self._tasks, func, output_constraint)
for selector in rule.input_selectors:
selector_type = type(selector)
product_constraint = self._to_constraint(selector.product)
if selector_type is Select:
self._native.lib.tasks_add_select(self._tasks, product_constraint)
elif selector_type is SelectVariant:
key_buf = self._to_utf8_buf(selector.variant_key)
self._native.lib.tasks_add_select_variant(self._tasks,
product_constraint,
key_buf)
else:
raise ValueError('Unrecognized Selector type: {}'.format(selector))
for get in rule.input_gets:
Expand Down Expand Up @@ -325,7 +314,7 @@ def _run_and_return_roots(self, session, execution_request):
for raw_root in self._native.unpack(raw_roots.nodes_ptr, raw_roots.nodes_len):
if raw_root.state_tag is 1:
state = Return(self._from_value(raw_root.state_value))
elif raw_root.state_tag in (2, 3, 4):
elif raw_root.state_tag in (2, 3):
state = Throw(self._from_value(raw_root.state_value))
else:
raise ValueError(
Expand Down
22 changes: 0 additions & 22 deletions src/python/pants/engine/selectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
from abc import abstractproperty
from builtins import str

import six

from pants.util.meta import AbstractClass
from pants.util.objects import Exactly, datatype

Expand Down Expand Up @@ -110,23 +108,3 @@ def __repr__(self):
return '{}({}{})'.format(type(self).__name__,
type_or_constraint_repr(self.product),
', optional=True' if self.optional else '')


class SelectVariant(datatype(['product', 'variant_key']), Selector):
"""Selects the matching Product and variant name for the Subject provided to the constructor.

For example: a SelectVariant with a variant_key of "thrift" and a product of type ApacheThrift
will only match when a consumer passes a variant value for "thrift" that matches the name of an
ApacheThrift value.
"""
optional = False

def __new__(cls, product, variant_key):
if not isinstance(variant_key, six.string_types):
raise ValueError('Expected variant_key to be a string, but was {!r}'.format(variant_key))
return super(SelectVariant, cls).__new__(cls, product, variant_key)

def __repr__(self):
return '{}({}, {})'.format(type(self).__name__,
type_or_constraint_repr(self.product),
repr(self.variant_key))
27 changes: 0 additions & 27 deletions src/python/pants/engine/struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@

from __future__ import absolute_import, division, print_function, unicode_literals

from abc import abstractproperty
from collections import MutableMapping, MutableSequence

from future.utils import binary_type, text_type

from pants.engine.addressable import addressable, addressable_list
from pants.engine.objects import Serializable, SerializableFactory, Validatable, ValidationError
from pants.util.meta import AbstractClass
from pants.util.objects import SubclassesOf, SuperclassesOf


Expand Down Expand Up @@ -307,28 +305,3 @@ def dependencies(self):

:rtype: list
"""


class HasProducts(AbstractClass):
"""A mixin for a class that has a collection of products which it would like to expose."""

@abstractproperty
def products(self):
"""Returns a collection of products held by this class."""


class Variants(Struct):
"""A struct that holds default variant values.

Variants are key-value pairs representing uniquely identifying parameters for a Node.

Default variants are usually configured on a Target to be used whenever they are
not specified by a caller.
"""

def __init__(self, default=None, **kwargs):
"""
:param dict default: A dict of default variant values.
"""
# TODO: enforce the type of variants using the Addressable framework.
super(Variants, self).__init__(default=default, **kwargs)
4 changes: 3 additions & 1 deletion src/rust/engine/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/rust/engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ fs = { path = "fs" }
futures = "^0.1.16"
graph = { path = "graph" }
hashing = { path = "hashing" }
lazy_static = "1"
itertools = "0.7.2"
lazy_static = "0.2.2"
log = "0.4"
process_execution = { path = "process_execution" }
resettable = { path = "resettable" }
smallvec = "0.6"
tokio = "0.1"
tempfile = "3"
Loading