Expose __init__.py filenames to Skylark

This is important for packaging Python code in a way which is compatible
with the way Bazel builds its standard runfiles directory.

Refs #671

--
Change-Id: Ica2adab481cfecabb84b608cd952b0cae5a8653c
Reviewed-on: https://bazel-review.googlesource.com/#/c/2900/
MOS_MIGRATED_REVID=119945845
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java b/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java
index 95efeb3..5c14ec2 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java
@@ -46,6 +46,7 @@
 import java.util.Map.Entry;
 import java.util.Objects;
 import java.util.Set;
+import java.util.TreeSet;
 
 import javax.annotation.Nullable;
 
@@ -77,6 +78,22 @@
         }
       };
 
+  private static final Function<Artifact, PathFragment> GET_ROOT_RELATIVE_PATH =
+      new Function<Artifact, PathFragment>() {
+        @Override
+        public PathFragment apply(Artifact input) {
+          return input.getRootRelativePath();
+        }
+      };
+
+  private static final Function<PathFragment, String> PATH_FRAGMENT_TO_STRING =
+      new Function<PathFragment, String>() {
+        @Override
+        public String apply(PathFragment input) {
+          return input.toString();
+        }
+      };
+
   /**
    * An entry in the runfiles map.
    *
@@ -319,6 +336,20 @@
     return symlinks;
   }
 
+  @SkylarkCallable(
+    name = "empty_filenames",
+    doc = "Returns names of empty files to create.",
+    structField = true
+  )
+  public NestedSet<String> getEmptyFilenames() {
+    Set<PathFragment> manifest = new TreeSet();
+    Iterables.addAll(
+        manifest, Iterables.transform(getArtifacts().toCollection(), GET_ROOT_RELATIVE_PATH));
+    return NestedSetBuilder.wrap(
+        Order.STABLE_ORDER,
+        Iterables.transform(emptyFilesSupplier.getExtraPaths(manifest), PATH_FRAGMENT_TO_STRING));
+  }
+
   /**
    * Returns the symlinks as a map from path fragment to artifact.
    *