Expose FilesToRun provider to Skylark.

It is now possible to get the main executable of *_binary rules with
target.files_to_run.executable.

--
Change-Id: I4a81f216bdd237fc5b0e7dbd7d0a312558f3cf2c
Reviewed-on: https://bazel-review.googlesource.com/#/c/1760/
MOS_MIGRATED_REVID=101675365
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/FilesToRunProvider.java b/src/main/java/com/google/devtools/build/lib/analysis/FilesToRunProvider.java
index 216a782..2875934 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/FilesToRunProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/FilesToRunProvider.java
@@ -20,6 +20,8 @@
 import com.google.devtools.build.lib.actions.RunfilesSupplier;
 import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
 import com.google.devtools.build.lib.syntax.Label;
+import com.google.devtools.build.lib.syntax.SkylarkCallable;
+import com.google.devtools.build.lib.syntax.SkylarkModule;
 
 import javax.annotation.Nullable;
 
@@ -27,7 +29,10 @@
  * Returns information about executables produced by a target and the files needed to run it.
  */
 @Immutable
+@SkylarkModule(name = "FilesToRunProvider", doc = "")
 public final class FilesToRunProvider implements TransitiveInfoProvider {
+  /** The name of the field in Skylark used to access this class. */
+  public static final String SKYLARK_NAME = "files_to_run";
 
   private final Label label;
   private final ImmutableList<Artifact> filesToRun;
@@ -75,7 +80,14 @@
   /**
    * Returns the Executable or null if it does not exist.
    */
-  @Nullable public Artifact getExecutable() {
+  @SkylarkCallable(
+    name = "executable",
+    doc = "The main executable or None if it does not exist",
+    structField = true,
+    allowReturnNones = true
+  )
+  @Nullable
+  public Artifact getExecutable() {
     return executable;
   }
 
@@ -83,7 +95,14 @@
    * Returns the RunfilesManifest or null if it does not exist. It is a shortcut to
    * getRunfilesSupport().getRunfilesManifest().
    */
-  @Nullable public Artifact getRunfilesManifest() {
+  @SkylarkCallable(
+    name = "runfiles_manifest",
+    doc = "The runfiles manifest or None if it does not exist",
+    structField = true,
+    allowReturnNones = true
+  )
+  @Nullable
+  public Artifact getRunfilesManifest() {
     return runfilesSupport != null ? runfilesSupport.getRunfilesManifest() : null;
   }