aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--examples/proto/BUILD6
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibrary.java24
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibraryRule.java1
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/proto/BazelProtoLibraryRule.java6
4 files changed, 32 insertions, 5 deletions
diff --git a/examples/proto/BUILD b/examples/proto/BUILD
index 7ce5659ea6..32e43e5831 100644
--- a/examples/proto/BUILD
+++ b/examples/proto/BUILD
@@ -2,6 +2,12 @@ package(default_visibility = ["//visibility:public"])
load("/tools/build_rules/genproto", "proto_java_library")
+proto_library(
+ name = "proto_smoke_test",
+ srcs = ["test.proto"],
+)
+
+# proto_java_library is a quick and dirty rule to help Bazel compile itself.
proto_java_library(
name = "test_proto",
src = "test.proto",
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibrary.java
index db2590f4d9..4057c25d50 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibrary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibrary.java
@@ -26,6 +26,7 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.analysis.ConfiguredTarget;
+import com.google.devtools.build.lib.analysis.PrerequisiteArtifacts;
import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
@@ -58,16 +59,19 @@ public class ObjcProtoLibrary implements RuleConfiguredTargetFactory {
static final String NO_PROTOS_ERROR =
"no protos to compile - a non-empty deps attribute is required";
+ @VisibleForTesting
+ static final String FILES_DEPRECATED_WARNING =
+ "Using files and filegroups in objc_proto_library is deprecated";
+
@Override
public ConfiguredTarget create(final RuleContext ruleContext) throws InterruptedException {
Artifact compileProtos = ruleContext.getPrerequisiteArtifact(
ObjcProtoLibraryRule.COMPILE_PROTOS_ATTR, Mode.HOST);
Optional<Artifact> optionsFile = Optional.fromNullable(
ruleContext.getPrerequisiteArtifact(ObjcProtoLibraryRule.OPTIONS_FILE_ATTR, Mode.HOST));
+
NestedSet<Artifact> protos = NestedSetBuilder.<Artifact>stableOrder()
- .addAll(ruleContext.getPrerequisiteArtifacts("deps", Mode.TARGET)
- .filter(FileType.of(".proto"))
- .list())
+ .addAll(maybeGetProtoFiles(ruleContext))
.addTransitive(maybeGetProtoSources(ruleContext))
.build();
@@ -207,6 +211,20 @@ public class ObjcProtoLibrary implements RuleConfiguredTargetFactory {
.build();
}
+ /**
+ * Get .proto files added to the deps attribute. This is for backwards compatibility,
+ * and emits a warning.
+ */
+ private ImmutableList<Artifact> maybeGetProtoFiles(RuleContext ruleContext) {
+ PrerequisiteArtifacts prerequisiteArtifacts =
+ ruleContext.getPrerequisiteArtifacts("deps", Mode.TARGET);
+ ImmutableList<Artifact> protoFiles = prerequisiteArtifacts.filter(FileType.of(".proto")).list();
+ if (!protoFiles.isEmpty()) {
+ ruleContext.attributeWarning("deps", FILES_DEPRECATED_WARNING);
+ }
+ return protoFiles;
+ }
+
private NestedSet<Artifact> maybeGetProtoSources(RuleContext ruleContext) {
NestedSetBuilder<Artifact> artifacts = new NestedSetBuilder<>(Order.STABLE_ORDER);
Iterable<ProtoSourcesProvider> providers =
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibraryRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibraryRule.java
index ff4903b082..4052cef8c9 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibraryRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProtoLibraryRule.java
@@ -53,6 +53,7 @@ public class ObjcProtoLibraryRule implements RuleDefinition {
${SYNOPSIS}
<!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
.override(attr("deps", LABEL_LIST)
+ // Support for files in deps is for backwards compatibility.
.allowedRuleClasses("proto_library", "filegroup")
.legacyAllowAnyFileType())
/* <!-- #BLAZE_RULE(objc_proto_library).ATTRIBUTE(options_file) -->
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 b8e190c1f3..2c4f9b4239 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
@@ -33,11 +33,13 @@ public final class BazelProtoLibraryRule implements RuleDefinition {
public RuleClass build(Builder builder, final RuleDefinitionEnvironment env) {
return builder
+ // This rule works, but does nothing, in open-source Bazel, due to the
+ // lack of protoc support. Users can theoretically write their own Skylark rules,
+ // but these are still 'experimental' according to the documentation.
.setUndocumented()
.setOutputToGenfiles()
/* <!-- #BLAZE_RULE(proto_library).ATTRIBUTE(deps) -->
- The list of other <code>proto_library</code>
- rules that the target depends upon.
+ The list of other <code>proto_library</code> rules that the target depends upon.
${SYNOPSIS}
A <code>proto_library</code> may only depend on other
<code>proto_library</code> targets.