Skip to content
This repository has been archived by the owner on Dec 10, 2020. It is now read-only.

Commit

Permalink
Fixed errors in how arguments are passed to wire_gen.
Browse files Browse the repository at this point in the history
Arguments such as 'roots' and 'enum_options' are expected to
be comma-delimited when multiple arguments exist, not added by repeated
specifications of the --roots or --enum_options flags.

Testing Done:
Wire_integration tests (including new test for --roots) pass.

CI went green here: https://travis-ci.org/pantsbuild/pants/builds/66615227

Bugs closed: 1664

Reviewed at https://rbcommons.com/s/twitter/r/2354/
  • Loading branch information
gmalmquist authored and jsirois committed Jun 13, 2015
1 parent 37b41b7 commit 29b44b8
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 11 deletions.
12 changes: 12 additions & 0 deletions examples/src/java/org/pantsbuild/example/wire/roots/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

jvm_binary(name='roots',
basename='wire-roots-example',
dependencies=[
'examples/src/wire/org/pantsbuild/example/roots',
],
source='WireRootsExample.java',
main='org.pantsbuild.example.wire.roots.WireRootsExample',
)

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2015 Pants project contributors (see CONTRIBUTORS.md).
// Licensed under the Apache License, Version 2.0 (see LICENSE).

package org.pantsbuild.example.wire.roots;

class WireRootsExample {

public static void main(String[] args) {
}
}
16 changes: 16 additions & 0 deletions examples/src/wire/org/pantsbuild/example/roots/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

java_wire_library(name='roots',
sources=[
'foo.proto',
'bar.proto',
'foobar.proto',
],
dependencies=[],
roots = [
'org.pantsbuild.example.roots.Bar',
'org.pantsbuild.example.roots.Foobar',
'org.pantsbuild.example.roots.Fooboo',
],
)
9 changes: 9 additions & 0 deletions examples/src/wire/org/pantsbuild/example/roots/bar.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright 2015 Pants project contributors (see CONTRIBUTORS.md).
// Licensed under the Apache License, Version 2.0 (see LICENSE).

package org.pantsbuild.example.roots;

message Bar {
optional string param1 = 1;
optional string param2 = 2;
}
9 changes: 9 additions & 0 deletions examples/src/wire/org/pantsbuild/example/roots/foo.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright 2015 Pants project contributors (see CONTRIBUTORS.md).
// Licensed under the Apache License, Version 2.0 (see LICENSE).

package org.pantsbuild.example.roots;

message Foo {
optional string param1 = 1;
optional string param2 = 2;
}
20 changes: 20 additions & 0 deletions examples/src/wire/org/pantsbuild/example/roots/foobar.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2015 Pants project contributors (see CONTRIBUTORS.md).
// Licensed under the Apache License, Version 2.0 (see LICENSE).

package org.pantsbuild.example.roots;

message Foobar {
optional string param = 1;
}

message Barfoo {
optional string param = 1;
}

message Fooboo {
optional string param = 1;
}

message Farbar {
required string param = 1;
}
7 changes: 0 additions & 7 deletions src/python/pants/backend/codegen/targets/java_wire_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
unicode_literals, with_statement)

import logging
from textwrap import dedent

from pants.backend.jvm.targets.exportable_jvm_library import ExportableJvmLibrary
from pants.base.payload import Payload
Expand Down Expand Up @@ -50,12 +49,6 @@ def __init__(self,

if service_writer_options:
logger.warn('The service_writer_options flag is ignored.')
if roots:
logger.warn(dedent('''
It is known that passing in roots may not work as intended. Pants tries to predict what
files Wire will generate then does a verification to see if all of those files were
generated. With the roots flag set, it may be the case that not all predicted files will
be generated and the verification will fail.'''))

super(JavaWireLibrary, self).__init__(payload=payload, **kwargs)
self.add_labels('codegen')
8 changes: 4 additions & 4 deletions src/python/pants/backend/codegen/tasks/wire_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ def execute_codegen(self, targets):
if registry_class:
args.append('--registry_class={0}'.format(registry_class))

for root in target.payload.roots:
args.append('--roots={0}'.format(root))
if target.payload.roots:
args.append('--roots={0}'.format(','.join(target.payload.roots)))

for enum_option in target.payload.enum_options:
args.append('--enum_options={0}'.format(enum_option))
if target.payload.enum_options:
args.append('--enum_options={0}'.format(','.join(target.payload.enum_options)))

args.append('--proto_path={0}'.format(os.path.join(get_buildroot(),
SourceRoot.find(target))))
Expand Down
21 changes: 21 additions & 0 deletions tests/python/pants_test/tasks/test_wire_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import subprocess

from pants.base.build_environment import get_buildroot
from pants.util.contextutil import open_zip
from pants_test.pants_run_integration_test import PantsRunIntegrationTest


Expand Down Expand Up @@ -76,3 +77,23 @@ def test_bundle_wire_dependent_targets(self):
self.assertIn('Compound{name=Water, primary_element=Element{symbol=O, name=Oxygen, '
'atomic_number=8}, secondary_element=Element{symbol=H, name=Hydrogen, '
'atomic_number=1}}', java_out)

def test_compile_wire_roots(self):
pants_run = self.run_pants(['bundle', '--deployjar',
'examples/src/java/org/pantsbuild/example/wire/roots'])
self.assert_success(pants_run)
out_path = os.path.join(get_buildroot(), 'dist', 'wire-roots-example.jar')
with open_zip(out_path) as zipfile:
jar_entries = zipfile.namelist()

def is_relevant(entry):
return (entry.startswith('org/pantsbuild/example/roots/') and entry.endswith('.class')
and '$' not in entry)

expected_classes = {
'org/pantsbuild/example/roots/Bar.class',
'org/pantsbuild/example/roots/Foobar.class',
'org/pantsbuild/example/roots/Fooboo.class',
}
received_classes = {entry for entry in jar_entries if is_relevant(entry)}
self.assertEqual(expected_classes, received_classes)

0 comments on commit 29b44b8

Please sign in to comment.