Skip to content

Commit

Permalink
Make requirements on codegen products optional. (pantsbuild#6357)
Browse files Browse the repository at this point in the history
We declare product requirements in various places to force
codegen to run before, e.g., dependency resolution.

However currently these requirements are mandatory, so
deregistering all codegen backends will cause the round engine
to find no producers of these products, and fail.

This commit changes these requirements to optional, so
that if there are no codegen backends, we don't attempt
to depend on their products.

Also, minor unrelated documentation nits that weren't worth a 
separate pull request.
  • Loading branch information
benjyw authored Aug 17, 2018
1 parent b0a2469 commit f4ab07c
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/python/pants/backend/jvm/tasks/coursier_resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,8 +661,10 @@ def product_types(cls):
@classmethod
def prepare(cls, options, round_manager):
super(CoursierResolve, cls).prepare(options, round_manager)
round_manager.require_data('java')
round_manager.require_data('scala')
# Codegen may inject extra resolvable deps, so make sure we have a product dependency
# on relevant codegen tasks, if any.
round_manager.optional_data('java')
round_manager.optional_data('scala')

@classmethod
def register_options(cls, register):
Expand Down
6 changes: 4 additions & 2 deletions src/python/pants/backend/jvm/tasks/ivy_resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ def product_types(cls):
@classmethod
def prepare(cls, options, round_manager):
super(IvyResolve, cls).prepare(options, round_manager)
round_manager.require_data('java')
round_manager.require_data('scala')
# Codegen may inject extra resolvable deps, so make sure we have a product dependency
# on relevant codegen tasks, if any.
round_manager.optional_data('java')
round_manager.optional_data('scala')

def __init__(self, *args, **kwargs):
super(IvyResolve, self).__init__(*args, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/backend/python/tasks/gather_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def product_types(cls):
@classmethod
def prepare(cls, options, round_manager):
round_manager.require_data(PythonInterpreter)
round_manager.require_data('python') # For codegen.
round_manager.optional_data('python') # For codegen.

def execute(self):
targets = self._collect_source_targets()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ def cache_target_dirs(self):

@classmethod
def prepare(cls, options, round_manager):
# See comment below for why we don't use the GatherSources.PYTHON_SOURCES product.
round_manager.require_data(PythonInterpreter)
round_manager.require_data('python') # For codegen.
round_manager.optional_data('python') # For codegen.
round_manager.optional_product(PythonRequirementLibrary) # For local dists.

@staticmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def _python_native_code_settings(self):
def prepare(cls, options, round_manager):
round_manager.require_data(PythonInterpreter)
round_manager.optional_product(PythonRequirementLibrary) # For local dists.
# Codegen may inject extra resolvable deps, so make sure we have a product dependency
# on relevant codegen tasks, if any.
round_manager.optional_data('python')

def resolve_requirements(self, interpreter, req_libs):
"""Requirements resolution for PEX files.
Expand Down
2 changes: 2 additions & 0 deletions src/python/pants/goal/run_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ def initialize(self):
raise AssertionError('RunTracker.initialize must not be called multiple times.')

# Initialize the run.

# Select a globally unique ID for the run, that sorts by time.
millis = int((self._run_timestamp * 1000) % 1000)
run_id = 'pants_run_{}_{}_{}'.format(
time.strftime('%Y_%m_%d_%H_%M_%S', time.localtime(self._run_timestamp)),
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/task/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ def check_artifact_cache(self, vts):
def do_check_artifact_cache(self, vts, post_process_cached_vts=None):
"""Checks the artifact cache for the specified list of VersionedTargetSets.
Returns a pair (cached, uncached) of VersionedTargets that were
Returns a tuple (cached, uncached, uncached_causes) of VersionedTargets that were
satisfied/unsatisfied from the cache.
"""
if not vts:
Expand Down

0 comments on commit f4ab07c

Please sign in to comment.