Rollforward of [], which was rolled back in []. Cleans up support for objc_proto_library with native proto_library.

--
MOS_MIGRATED_REVID=102962083
diff --git a/examples/proto/BUILD b/examples/proto/BUILD
index 7ce5659..32e43e5 100644
--- a/examples/proto/BUILD
+++ b/examples/proto/BUILD
@@ -2,6 +2,12 @@
 
 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 db2590f..4057c25 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.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 @@
   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 @@
         .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 ff4903b..4052cef 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 @@
         ${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 b8e190c..2c4f9b4 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 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.