aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Carmi Grushko <carmi@google.com>2017-02-17 06:49:40 +0000
committerGravatar Dmitry Lomov <dslomov@google.com>2017-02-17 14:55:06 +0000
commit0fd73d6e3602003ae0e7e9ce6a25b27d73e30076 (patch)
tree0547ba510e475322ee512255a8d471ca5ad07fd0
parent8153cb80f4a4424640e694cb6ed4792dcc193171 (diff)
--proto_compiler points at @com_google_protobuf//:protoc
This allows proto_library to be used out of the box by adding a repository entry that points to the protobuf distro in one's WORKSPACE file. -- PiperOrigin-RevId: 147808147 MOS_MIGRATED_REVID=147808147
-rw-r--r--WORKSPACE6
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibraryRule.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/proto/ProtoConfiguration.java4
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/cpp/proto/CcProtoLibraryTest.java3
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibraryTest.java11
5 files changed, 17 insertions, 9 deletions
diff --git a/WORKSPACE b/WORKSPACE
index b5702db031..0eb938e7e5 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -57,6 +57,12 @@ docker_repository()
bind(name = "xcrunwrapper", actual = "@bazel_tools//tools/objc:xcrunwrapper")
new_local_repository(
+ name = "com_google_protobuf",
+ path = "./third_party/protobuf/3.0.0/",
+ build_file = "./third_party/protobuf/3.0.0/BUILD",
+)
+
+new_local_repository(
name = "com_google_protobuf_java",
path = "./third_party/protobuf/3.0.0/",
build_file = "./third_party/protobuf/3.0.0/com_google_protobuf_java.BUILD",
diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibraryRule.java b/src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibraryRule.java
index 77145fef11..9474c9401f 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibraryRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibraryRule.java
@@ -39,7 +39,7 @@ public final class BazelProtoLibraryRule implements RuleDefinition {
private static final Attribute.LateBoundLabel<BuildConfiguration> PROTO_COMPILER =
new Attribute.LateBoundLabel<BuildConfiguration>(
- "//third_party/protobuf:protoc", ProtoConfiguration.class) {
+ "@com_google_protobuf//:protoc", ProtoConfiguration.class) {
@Override
public Label resolve(Rule rule, AttributeMap attributes, BuildConfiguration configuration) {
Label label = configuration.getFragment(ProtoConfiguration.class).protoCompiler();
diff --git a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoConfiguration.java
index f2d6b80375..46be0f8345 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoConfiguration.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoConfiguration.java
@@ -65,8 +65,8 @@ public class ProtoConfiguration extends Fragment {
@Option(
name = "proto_compiler",
- defaultValue = "null",
- category = "version",
+ defaultValue = "@com_google_protobuf//:protoc",
+ category = "flags",
converter = BuildConfiguration.LabelConverter.class,
help = "The label of the proto-compiler."
)
diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/proto/CcProtoLibraryTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/proto/CcProtoLibraryTest.java
index 5951987a1d..6f5ee31a88 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/cpp/proto/CcProtoLibraryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/proto/CcProtoLibraryTest.java
@@ -34,10 +34,10 @@ import org.junit.runners.JUnit4;
public class CcProtoLibraryTest extends BuildViewTestCase {
@Before
public void setUp() throws Exception {
- scratch.file("third_party/protobuf/BUILD", "licenses(['notice'])", "exports_files(['protoc'])");
scratch.file(
"protobuf/BUILD",
"package(default_visibility=['//visibility:public'])",
+ "exports_files(['protoc'])",
"proto_lang_toolchain(",
" name = 'cc_toolchain',",
" command_line = '--cpp_out=$(OUT)',",
@@ -48,6 +48,7 @@ public class CcProtoLibraryTest extends BuildViewTestCase {
new String(FileSystemUtils.readContentAsLatin1(rootDirectory.getRelative("WORKSPACE")));
mockToolsConfig.overwrite(
"WORKSPACE",
+ "local_repository(name = 'com_google_protobuf', path = 'protobuf/')",
"local_repository(name = 'com_google_protobuf_cc', path = 'protobuf/')",
existingWorkspace);
invalidatePackages(); // A dash of magic to re-evaluate the WORKSPACE file.
diff --git a/src/test/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibraryTest.java b/src/test/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibraryTest.java
index 1133f24b8e..893e4f82ff 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibraryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibraryTest.java
@@ -34,7 +34,8 @@ public class BazelProtoLibraryTest extends BuildViewTestCase {
@Before
public void setUp() throws Exception {
- scratch.file("third_party/protobuf/BUILD", "licenses(['notice'])", "exports_files(['protoc'])");
+ useConfiguration("--proto_compiler=//proto:compiler");
+ scratch.file("proto/BUILD", "licenses(['notice'])", "exports_files(['compiler'])");
}
@Test
@@ -180,7 +181,7 @@ public class BazelProtoLibraryTest extends BuildViewTestCase {
@Test
public void testDescriptorSetOutput_strictDeps() throws Exception {
- useConfiguration("--strict_proto_deps=error");
+ useConfiguration("--proto_compiler=//proto:compiler", "--strict_proto_deps=error");
scratch.file(
"x/BUILD",
"proto_library(name='nodeps', srcs=['nodeps.proto'])",
@@ -210,7 +211,7 @@ public class BazelProtoLibraryTest extends BuildViewTestCase {
*/
@Test
public void testDescriptorSetOutput_strict_deps_multipleSrcs() throws Exception {
- useConfiguration("--strict_proto_deps=error");
+ useConfiguration("--proto_compiler=//proto:compiler", "--strict_proto_deps=error");
ConfiguredTarget target =
scratchConfiguredTarget(
"x", "foo", "proto_library(name='foo', srcs=['foo.proto', 'bar.proto'])");
@@ -223,7 +224,7 @@ public class BazelProtoLibraryTest extends BuildViewTestCase {
@Test
public void testDescriptorSetOutput_strictDeps_disabled() throws Exception {
- useConfiguration("--strict_proto_deps=off");
+ useConfiguration("--proto_compiler=//proto:compiler", "--strict_proto_deps=off");
scratch.file("x/BUILD", "proto_library(name='foo', srcs=['foo.proto'])");
for (String arg :
@@ -238,7 +239,7 @@ public class BazelProtoLibraryTest extends BuildViewTestCase {
*/
@Test
public void strictCanDependOnNonStrict() throws Exception {
- useConfiguration("--strict_proto_deps=strict");
+ useConfiguration("--proto_compiler=//proto:compiler", "--strict_proto_deps=strict");
scratch.file(
"x/BUILD",
"proto_library(name = 'foo', deps = [':bar'], strict_proto_deps=1)",