Skip to content

Commit

Permalink
Invalidate tasks based on BinaryUtil.version.
Browse files Browse the repository at this point in the history
The assumption is that binaries are uniquely identified by their version
and name. This is at least true of pants-supported bintray binaries for
protoc and ragel.

Additionally invalidation is arranged for protoc plugins based on name.
This is not ideal - it allows for changing a plugin without chaging its
name - but its strictly better than not invalidating at all for changing
plugin lists.

Testing Done:
CI went green here:
  https://travis-ci.org/pantsbuild/pants/builds/72238973

Bugs closed: 1855

Reviewed at https://rbcommons.com/s/twitter/r/2516/
  • Loading branch information
jsirois committed Jul 23, 2015
1 parent b446929 commit 8a579f1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/python/pants/backend/codegen/tasks/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ python_library(
'src/python/pants/base:source_root',
'src/python/pants:binary_util',
'src/python/pants/util:dirutil',
'src/python/pants/util:memo',
],
)

Expand Down
24 changes: 15 additions & 9 deletions src/python/pants/backend/codegen/tasks/protobuf_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from pants.binary_util import BinaryUtil
from pants.fs.archive import ZIP
from pants.util.dirutil import safe_mkdir
from pants.util.memo import memoized_property


class ProtobufGen(SimpleCodegenTask):
Expand All @@ -36,17 +37,23 @@ def global_subsystems(cls):
@classmethod
def register_options(cls, register):
super(ProtobufGen, cls).register_options(register)
register('--version', advanced=True,

# The protoc version and the plugin names are used as proxies for the identity of the protoc
# executable environment here. Although version is an obvious proxy for the protoc binary
# itself, plugin names are less so and plugin authors must include a version in the name for
# proper invalidation of protobuf products in the face of plugin modification that affects
# plugin outputs.
register('--version', advanced=True, fingerprint=True,
help='Version of protoc. Used to create the default --javadeps and as part of '
'the path to lookup the tool with --pants-support-baseurls and '
'--pants-bootstrapdir. When changing this parameter you may also need to '
'update --javadeps.',
default='2.4.1')
# TODO(Eric Ayers) Mix the value of this option into the fingerprint
register('--plugins', advanced=True, action='append',
register('--plugins', advanced=True, fingerprint=True, action='append',
help='Names of protobuf plugins to invoke. Protoc will look for an executable '
'named protoc-gen-$NAME on PATH.',
default=[])

register('--extra_path', advanced=True, action='append',
help='Prepend this path onto PATH in the environment before executing protoc. '
'Intended to help protoc find its plugins.',
Expand Down Expand Up @@ -74,13 +81,12 @@ def __init__(self, *args, **kwargs):
self.plugins = self.get_options().plugins
self._extra_paths = self.get_options().extra_path

@memoized_property
def protobuf_binary(self):
binary_util = BinaryUtil.Factory.create()
self.protobuf_binary = binary_util.select_binary(self.get_options().supportdir,
self.get_options().version,
'protoc')

def invalidate_for_files(self):
return [self.protobuf_binary]
return binary_util.select_binary(self.get_options().supportdir,
self.get_options().version,
'protoc')

@property
def javadeps(self):
Expand Down
8 changes: 4 additions & 4 deletions src/python/pants/backend/codegen/tasks/ragel_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ def register_options(cls, register):
register('--supportdir', default='bin/ragel', advanced=True,
help='The path to find the ragel binary. Used as part of the path to lookup the'
'tool with --pants-support-baseurls and --pants_bootstrapdir.')
register('--version', default='6.9', advanced=True,

# We take the cautious approach here and assume a version bump will always correspond to
# changes in ragel codegen products.
register('--version', default='6.9', advanced=True, fingerprint=True,
help='The version of ragel to use. Used as part of the path to lookup the'
'tool with --pants-support-baseurls and --pants-bootstrapdir')

Expand All @@ -51,9 +54,6 @@ def ragel_binary(self):
def javadeps(self):
return OrderedSet()

def invalidate_for_files(self):
return [self.ragel_binary]

def is_gentarget(self, target):
return isinstance(target, JavaRagelLibrary)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ def test_ragel_gen(self):
task = self.create_task(self.context(target_roots=[target]))

task._ragel_binary = 'ragel'
task.invalidate_for_files = lambda: []
task._java_out = self.task_outdir

sources = [os.path.join(self.task_outdir, 'com/example/atoi/Parser.java')]
Expand Down

0 comments on commit 8a579f1

Please sign in to comment.