Stop the hard coding of the index 0 to refer to the SkyframeFilesetManifestAction.
Since we're not dropping actions anymore, this should be a safe approach now.

RELNOTES: None
PiperOrigin-RevId: 212855688
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ActionInputMapHelper.java b/src/main/java/com/google/devtools/build/lib/skyframe/ActionInputMapHelper.java
index abc7208..bbfb9e2 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ActionInputMapHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ActionInputMapHelper.java
@@ -16,11 +16,15 @@
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
+import com.google.devtools.build.lib.actions.ActionAnalysisMetadata;
 import com.google.devtools.build.lib.actions.ActionInputMap;
+import com.google.devtools.build.lib.actions.ActionLookupValue;
 import com.google.devtools.build.lib.actions.ActionLookupValue.ActionLookupKey;
 import com.google.devtools.build.lib.actions.Artifact;
 import com.google.devtools.build.lib.actions.FileArtifactValue;
 import com.google.devtools.build.lib.actions.FilesetOutputSymlink;
+import com.google.devtools.build.lib.analysis.actions.SymlinkAction;
 import com.google.devtools.build.lib.util.Pair;
 import com.google.devtools.build.skyframe.SkyFunction.Environment;
 import com.google.devtools.build.skyframe.SkyKey;
@@ -88,17 +92,31 @@
       Artifact actionInput) throws InterruptedException {
     Preconditions.checkState(actionInput.isFileset(), actionInput);
     ActionLookupKey filesetActionLookupKey = (ActionLookupKey) actionInput.getArtifactOwner();
-    // Index 0 for the Fileset ConfiguredTarget indicates the SkyframeFilesetManifestAction where
-    // we compute the fileset's outputSymlinks.
-    SkyKey filesetActionKey = ActionExecutionValue.key(filesetActionLookupKey, 0);
+
+    ActionLookupValue filesetActionLookupValue =
+        (ActionLookupValue) env.getValue(filesetActionLookupKey);
+
+    ActionAnalysisMetadata generatingAction =
+        filesetActionLookupValue.getGeneratingActionDangerousReadJavadoc(actionInput);
+    int filesetManifestActionIndex;
+
+    if (generatingAction instanceof SymlinkAction) {
+      Artifact outputManifest = Iterables.getOnlyElement(generatingAction.getInputs());
+      ActionAnalysisMetadata symlinkTreeAction =
+          filesetActionLookupValue.getGeneratingActionDangerousReadJavadoc(outputManifest);
+      Artifact inputManifest = Iterables.getOnlyElement(symlinkTreeAction.getInputs());
+      filesetManifestActionIndex = filesetActionLookupValue.getGeneratingActionIndex(inputManifest);
+    } else {
+      filesetManifestActionIndex = filesetActionLookupValue.getGeneratingActionIndex(actionInput);
+    }
+
+    SkyKey filesetActionKey =
+        ActionExecutionValue.key(filesetActionLookupKey, filesetManifestActionIndex);
     ActionExecutionValue filesetValue = (ActionExecutionValue) env.getValue(filesetActionKey);
     if (filesetValue == null) {
       // At this point skyframe does not guarantee that the filesetValue will be ready, since
       // the current action does not directly depend on the outputs of the
       // SkyframeFilesetManifestAction whose ActionExecutionValue (filesetValue) is needed here.
-      // TODO(kush): Get rid of this hack by making the outputSymlinks available in the Fileset
-      // artifact, which this action depends on, so its value will be guaranteed to be present.
-      // Also, unify handling of Fileset with Artifact expansion.
       return null;
     }
     return filesetValue.getOutputSymlinks();