Skip to content

Commit

Permalink
Ensure no duplicate scope registrations, and move legacy/v1 implement…
Browse files Browse the repository at this point in the history
…ations of tasks to a subscope.
  • Loading branch information
stuhood committed Dec 18, 2018
1 parent a2c978b commit b5c99a6
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/python/pants/backend/project_info/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ def register_goals():

task(name='depmap', action=Depmap).install()
task(name='dependencies', action=Dependencies).install()
task(name='filedeps', action=FileDeps).install('filedeps')
task(name='legacy', action=FileDeps).install('filedeps')
12 changes: 3 additions & 9 deletions src/python/pants/backend/project_info/tasks/filedeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,15 @@
from pants.backend.jvm.targets.jvm_app import JvmApp
from pants.backend.jvm.targets.scala_library import ScalaLibrary
from pants.base.build_environment import get_buildroot
from pants.rules.core import filedeps as filedeps_rules
from pants.task.console_task import ConsoleTask


class FileDeps(ConsoleTask):
"""List all source and BUILD files a target transitively depends on.
Files are listed with absolute paths and any BUILD files implied in the transitive closure of
targets are also included.
"""

@classmethod
def register_options(cls, register):
super(FileDeps, cls).register_options(register)
register('--globs', type=bool,
help='Instead of outputting filenames, output globs (ignoring excludes)')
def subsystem_dependencies(cls):
return super(FileDeps, cls).subsystem_dependencies() + (filedeps_rules.Filedeps,)

def _full_path(self, path):
return os.path.join(get_buildroot(), path)
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/core_tasks/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def register_goals():
task(name='compile-prep-command', action=RunCompilePrepCommand).install('compile', first=True)

# Stub for other goals to schedule 'test'. See noop_exec_task.py for why this is useful.
task(name='test', action=NoopTest).install('test')
task(name='legacy', action=NoopTest).install('test')

# Workspace information.
task(name='roots', action=ListRoots).install()
Expand Down
8 changes: 8 additions & 0 deletions src/python/pants/engine/goal.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ def options_scope(cls):
raise AssertionError('{} must have a `Goal.name` defined.'.format(cls.__name__))
return cls.name

@classmethod
def subsystem_dependencies_iter(cls):
# NB: `Goal` quacks like a `SubsystemClientMixin` in order to allow v1 `Tasks` to depend on
# v2 Goals for backwards compatibility purposes. But v2 Goals should _not_ have subsystem
# dependencies: instead, the @rules participating (transitively) in a Goal should directly
# declare Subsystem deps.
return iter([])

def __init__(self, scope, scoped_options):
# NB: This constructor is shaped to meet the contract of `Optionable(Factory).signature`.
super(Goal, self).__init__()
Expand Down
13 changes: 10 additions & 3 deletions src/python/pants/option/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ class Options(object):
class FrozenOptionsError(Exception):
"""Options are frozen and can't be mutated."""

class DuplicateScopeError(Exception):
"""More than one registration occurred for the same scope."""

@classmethod
def complete_scopes(cls, scope_infos):
"""Expand a set of scopes to include all enclosing scopes.
Expand All @@ -88,13 +91,17 @@ def complete_scopes(cls, scope_infos):
Also adds any deprecated scopes.
"""
ret = {GlobalOptionsRegistrar.get_scope_info()}
original_scopes = set()
original_scopes = dict()
for si in scope_infos:
ret.add(si)
original_scopes.add(si.scope)
if si.scope in original_scopes:
raise cls.DuplicateScopeError('Scope `{}` claimed by {}, was also claimed by {}.'.format(
si.scope, si, original_scopes[si.scope]
))
original_scopes[si.scope] = si
if si.deprecated_scope:
ret.add(ScopeInfo(si.deprecated_scope, si.category, si.optionable_cls))
original_scopes.add(si.deprecated_scope)
original_scopes[si.deprecated_scope] = si

# TODO: Once scope name validation is enforced (so there can be no dots in scope name
# components) we can replace this line with `for si in scope_infos:`, because it will
Expand Down
6 changes: 6 additions & 0 deletions src/python/pants/rules/core/filedeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ class Filedeps(Goal):

name = 'filedeps'

@classmethod
def register_options(cls, register):
super(Filedeps, cls).register_options(register)
register('--globs', type=bool,
help='Instead of outputting filenames, output globs (ignoring excludes)')


@console_rule(Filedeps, [Select(Console), Select(TransitiveHydratedTargets)])
def file_deps(console, transitive_hydrated_targets):
Expand Down

0 comments on commit b5c99a6

Please sign in to comment.