Migrate Actions provider to skylarkbuildapi

RELNOTES: None.
PiperOrigin-RevId: 201367075
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/ActionsProvider.java b/src/main/java/com/google/devtools/build/lib/analysis/ActionsProvider.java
index 105dbd8..4e887e4 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/ActionsProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/ActionsProvider.java
@@ -17,9 +17,10 @@
 import com.google.devtools.build.lib.actions.ActionAnalysisMetadata;
 import com.google.devtools.build.lib.actions.Artifact;
 import com.google.devtools.build.lib.events.Location;
+import com.google.devtools.build.lib.packages.BuiltinProvider;
 import com.google.devtools.build.lib.packages.Info;
-import com.google.devtools.build.lib.packages.NativeProvider;
 import com.google.devtools.build.lib.packages.SkylarkInfo;
+import com.google.devtools.build.lib.skylarkbuildapi.ActionsInfoProviderApi;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -27,11 +28,14 @@
  * This provides a view over the actions that were created during the analysis of a rule
  * (not including actions for its transitive dependencies).
  */
-public final class ActionsProvider {
+public final class ActionsProvider extends BuiltinProvider<Info> implements ActionsInfoProviderApi {
 
-  /** The Actions provider type itself. */
-  public static final NativeProvider<Info> SKYLARK_CONSTRUCTOR =
-      new NativeProvider<Info>(Info.class, "Actions") {};
+  /** The ActionsProvider singleton instance. */
+  public static final ActionsProvider INSTANCE = new ActionsProvider();
+
+  public ActionsProvider() {
+    super("Actions", Info.class);
+  }
 
   /** Factory method for creating instances of the Actions provider. */
   public static Info create(Iterable<ActionAnalysisMetadata> actions) {
@@ -46,6 +50,6 @@
       }
     }
     ImmutableMap<String, Object> fields = ImmutableMap.<String, Object>of("by_file", map);
-    return SkylarkInfo.createSchemaless(SKYLARK_CONSTRUCTOR, fields, Location.BUILTIN);
+    return SkylarkInfo.createSchemaless(INSTANCE, fields, Location.BUILTIN);
   }
 }
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkModules.java b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkModules.java
index 3770c51..9f50d75 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkModules.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkModules.java
@@ -15,6 +15,7 @@
 package com.google.devtools.build.lib.analysis.skylark;
 
 import com.google.common.collect.ImmutableMap;
+import com.google.devtools.build.lib.analysis.ActionsProvider;
 import com.google.devtools.build.lib.analysis.OutputGroupInfo;
 import com.google.devtools.build.lib.packages.SkylarkNativeModule;
 import com.google.devtools.build.lib.packages.StructProvider;
@@ -38,7 +39,8 @@
           SkylarkNativeModule.class,
           SkylarkRuleClassFunctions.class,
           StructProvider.STRUCT,
-          OutputGroupInfo.SKYLARK_CONSTRUCTOR);
+          OutputGroupInfo.SKYLARK_CONSTRUCTOR,
+          ActionsProvider.INSTANCE);
 
   /**
    * Adds bindings for skylark built-ins and non-rules-specific globals of the build API to
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleClassFunctions.java b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleClassFunctions.java
index ff3ff32..4108824 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleClassFunctions.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleClassFunctions.java
@@ -33,7 +33,6 @@
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import com.google.devtools.build.lib.actions.Artifact;
-import com.google.devtools.build.lib.analysis.ActionsProvider;
 import com.google.devtools.build.lib.analysis.BaseRuleClasses;
 import com.google.devtools.build.lib.analysis.DefaultInfo;
 import com.google.devtools.build.lib.analysis.TemplateVariableInfo;
@@ -257,28 +256,6 @@
   )
   private static final NativeProvider<?> defaultInfo = DefaultInfo.PROVIDER;
 
-  // TODO(bazel-team): Move to a "testing" namespace module. Normally we'd pass an objectType
-  // to @SkylarkSignature to do this, but that doesn't work here because we're exposing an already-
-  // configured BaseFunction, rather than defining a new BuiltinFunction. This should wait for
-  // better support from the Skylark/Java interface, or perhaps support for first-class modules.
-  @SkylarkSignature(
-    name = "Actions",
-    returnType = SkylarkProvider.class,
-    doc =
-        "<i>(Note: This is a provider type. Don't instantiate it yourself; use it to retrieve a "
-            + "provider object from a <a href=\"Target.html\">Target</a>.)</i>"
-            + "<br/><br/>"
-            + "Provides access to the <a href=\"Action.html\">actions</a> generated by a rule. "
-            + "There is one field, <code>by_file</code>, which is a dictionary from an output "
-            + "of the rule to its corresponding generating action. "
-            + "<br/><br/>"
-            + "This is designed for testing rules, and should not be accessed outside "
-            + "of test logic. This provider is only available for targets generated by rules"
-            + " that have <a href=\"globals.html#rule._skylark_testable\">_skylark_testable</a> "
-            + "set to <code>True</code>."
-  )
-  private static final NativeProvider<?> actions = ActionsProvider.SKYLARK_CONSTRUCTOR;
-
   @Override
   public Provider provider(String doc, Object fields, Location location) throws EvalException {
     Iterable<String> fieldNames = null;
diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/ActionsInfoProviderApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/ActionsInfoProviderApi.java
new file mode 100644
index 0000000..333fa78
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/ActionsInfoProviderApi.java
@@ -0,0 +1,37 @@
+// Copyright 2018 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.lib.skylarkbuildapi;
+
+import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
+import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
+
+/**
+ * Provider for structs containing actions created during the analysis of a rule.
+ */
+@SkylarkModule(name = "Actions",
+    doc = "<i>(Note: This is a provider type. Don't instantiate it yourself; use it to retrieve a "
+        + "provider object from a <a href=\"Target.html\">Target</a>.)</i>"
+        + "<br/><br/>"
+        + "Provides access to the <a href=\"Action.html\">actions</a> generated by a rule. "
+        + "There is one field, <code>by_file</code>, which is a dictionary from an output "
+        + "of the rule to its corresponding generating action. "
+        + "<br/><br/>"
+        + "This is designed for testing rules, and should not be accessed outside "
+        + "of test logic. This provider is only available for targets generated by rules "
+        + "that have <a href=\"globals.html#rule._skylark_testable\">_skylark_testable</a> "
+        + "set to <code>True</code>.",
+    category = SkylarkModuleCategory.PROVIDER)
+// TODO(cparsons): Deprecate and remove this API.
+public interface ActionsInfoProviderApi extends ProviderApi {}
diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/TopLevelBootstrap.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/TopLevelBootstrap.java
index b64d50c..ed0ffec 100644
--- a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/TopLevelBootstrap.java
+++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/TopLevelBootstrap.java
@@ -29,6 +29,7 @@
   private final Class<? extends SkylarkRuleFunctionsApi<?>> skylarkRuleFunctionsApi;
   private final StructApi.StructProviderApi structProvider;
   private final OutputGroupInfoApiProvider outputGroupInfoProvider;
+  private final ActionsInfoProviderApi actionsInfoProviderApi;
 
   public TopLevelBootstrap(
       Class<? extends SkylarkBuildApiGlobals> skylarkBuildApiGlobals,
@@ -37,7 +38,8 @@
       Class<? extends SkylarkNativeModuleApi> skylarkNativeModuleApi,
       Class<? extends SkylarkRuleFunctionsApi<?>> skylarkRuleFunctionsApi,
       StructApi.StructProviderApi structProvider,
-      OutputGroupInfoApiProvider outputGroupInfoProvider) {
+      OutputGroupInfoApiProvider outputGroupInfoProvider,
+      ActionsInfoProviderApi actionsInfoProviderApi) {
     this.skylarkAttrApi = skylarkAttrApi;
     this.skylarkBuildApiGlobals = skylarkBuildApiGlobals;
     this.skylarkCommandLineApi = skylarkCommandLineApi;
@@ -45,6 +47,7 @@
     this.skylarkRuleFunctionsApi = skylarkRuleFunctionsApi;
     this.structProvider = structProvider;
     this.outputGroupInfoProvider = outputGroupInfoProvider;
+    this.actionsInfoProviderApi = actionsInfoProviderApi;
   }
 
   @Override
@@ -56,5 +59,6 @@
     Runtime.setupModuleGlobals(builder, skylarkRuleFunctionsApi);
     builder.put("struct", structProvider);
     builder.put("OutputGroupInfo", outputGroupInfoProvider);
+    builder.put("Actions", actionsInfoProviderApi);
   }
 }