aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build
diff options
context:
space:
mode:
authorGravatar Michael Thvedt <mthvedt@google.com>2015-09-14 01:50:38 +0000
committerGravatar Kristina Chodorow <kchodorow@google.com>2015-09-14 15:39:31 +0000
commitc9e52201d11765638101e570664b09eaf1357cbd (patch)
tree6a27626229e955128f9e35b43bb12ec9fa9fbf9c /src/main/java/com/google/devtools/build
parent7f24022ce943c58dc4049b5206e39ab37d10f8ee (diff)
Rollforward of [], which was rolled back in []. Cleans up support for objc_proto_library with native proto_library.
-- MOS_MIGRATED_REVID=102962083
Diffstat (limited to 'src/main/java/com/google/devtools/build')
-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
3 files changed, 26 insertions, 5 deletions
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.