Pass a path to ActionExecutedEvent that is resolved via ActionExecutionContext.

If the output artifact is backed by a different file system then we need to use that file system later.

RELNOTES: None
PiperOrigin-RevId: 206981369
diff --git a/src/main/java/com/google/devtools/build/lib/actions/ActionExecutedEvent.java b/src/main/java/com/google/devtools/build/lib/actions/ActionExecutedEvent.java
index f903503..9c03813 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/ActionExecutedEvent.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/ActionExecutedEvent.java
@@ -41,6 +41,7 @@
 
   private final Action action;
   private final ActionExecutionException exception;
+  private final Path primaryOutput;
   private final Path stdout;
   private final Path stderr;
   private final ErrorTiming timing;
@@ -48,11 +49,13 @@
   public ActionExecutedEvent(
       Action action,
       ActionExecutionException exception,
+      Path primaryOutput,
       Path stdout,
       Path stderr,
       ErrorTiming timing) {
     this.action = action;
     this.exception = exception;
+    this.primaryOutput = primaryOutput;
     this.stdout = stdout;
     this.stderr = stderr;
     this.timing = timing;
@@ -90,10 +93,10 @@
   @Override
   public BuildEventId getEventId() {
     if (action.getOwner() == null) {
-      return BuildEventId.actionCompleted(action.getPrimaryOutput().getPath());
+      return BuildEventId.actionCompleted(primaryOutput);
     } else {
       return BuildEventId.actionCompleted(
-          action.getPrimaryOutput().getPath(),
+          primaryOutput,
           action.getOwner().getLabel(),
           action.getOwner().getConfigurationChecksum());
     }
@@ -127,7 +130,7 @@
       localFiles.add(new LocalFile(stderr, LocalFileType.STDERR));
     }
     if (exception == null) {
-      localFiles.add(new LocalFile(action.getPrimaryOutput().getPath(), LocalFileType.OUTPUT));
+      localFiles.add(new LocalFile(primaryOutput, LocalFileType.OUTPUT));
     }
     return localFiles.build();
   }
@@ -168,7 +171,7 @@
       actionBuilder.setConfiguration(configuration.getEventId().asStreamProto().getConfiguration());
     }
     if (exception == null) {
-      String uri = pathConverter.apply(action.getPrimaryOutput().getPath());
+      String uri = pathConverter.apply(primaryOutput);
       if (uri != null) {
         actionBuilder.setPrimaryOutput(
             BuildEventStreamProtos.File.newBuilder().setUri(uri).build());
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeActionExecutor.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeActionExecutor.java
index 98b5c3c..215e7f0 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeActionExecutor.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeActionExecutor.java
@@ -677,8 +677,9 @@
     } catch (ActionExecutionException e) {
       throw processAndThrow(
           env.getListener(),
-          e,
+          actionExecutionContext,
           action,
+          e,
           actionExecutionContext.getFileOutErr(),
           ErrorTiming.BEFORE_EXECUTION);
     }
@@ -766,7 +767,7 @@
         Preconditions.checkState(actionExecutionContext.getMetadataHandler() == metadataHandler,
             "%s %s", actionExecutionContext.getMetadataHandler(), metadataHandler);
         prepareScheduleExecuteAndCompleteAction(
-            eventHandler, action, actionExecutionContext, actionStartTime, actionLookupData);
+            eventHandler, actionExecutionContext, action, actionStartTime, actionLookupData);
         Preconditions.checkState(
             actionExecutionContext.getOutputSymlinks() == null
                 || action instanceof SkyframeAwareAction,
@@ -890,8 +891,8 @@
    */
   private void prepareScheduleExecuteAndCompleteAction(
       ExtendedEventHandler eventHandler,
-      Action action,
       ActionExecutionContext context,
+      Action action,
       long actionStartTime,
       ActionLookupData actionLookupData)
       throws ActionExecutionException, InterruptedException {
@@ -924,6 +925,7 @@
       boolean outputDumped = executeActionTask(eventHandler, action, context);
       completeAction(
           eventHandler,
+          context,
           action,
           context.getMetadataHandler(),
           context.getFileOutErr(),
@@ -936,12 +938,14 @@
 
   private ActionExecutionException processAndThrow(
       ExtendedEventHandler eventHandler,
-      ActionExecutionException e,
+      ActionExecutionContext actionExecutionContext,
       Action action,
+      ActionExecutionException e,
       FileOutErr outErrBuffer,
       ErrorTiming errorTiming)
-          throws ActionExecutionException {
-    reportActionExecution(eventHandler, action, e, outErrBuffer, errorTiming);
+      throws ActionExecutionException {
+    reportActionExecution(
+        eventHandler, actionExecutionContext, action, e, outErrBuffer, errorTiming);
     boolean reported = reportErrorIfNotAbortingMode(e, outErrBuffer);
 
     ActionExecutionException toThrow = e;
@@ -1005,17 +1009,25 @@
       }
       // Defer reporting action success until outputs are checked
     } catch (ActionExecutionException e) {
-      throw processAndThrow(eventHandler, e, action, outErrBuffer, ErrorTiming.AFTER_EXECUTION);
+      throw processAndThrow(
+          eventHandler,
+          actionExecutionContext,
+          action,
+          e,
+          outErrBuffer,
+          ErrorTiming.AFTER_EXECUTION);
     }
     return false;
   }
 
   private void completeAction(
       ExtendedEventHandler eventHandler,
+      ActionExecutionContext actionExecutionContext,
       Action action,
       MetadataHandler metadataHandler,
       FileOutErr fileOutErr,
-      boolean outputAlreadyDumped) throws ActionExecutionException {
+      boolean outputAlreadyDumped)
+      throws ActionExecutionException {
     try {
       Preconditions.checkState(action.inputsDiscovered(),
           "Action %s successfully executed, but inputs still not known", action);
@@ -1035,16 +1047,23 @@
         }
       }
 
-      reportActionExecution(eventHandler, action, null, fileOutErr, ErrorTiming.NO_ERROR);
+      reportActionExecution(
+          eventHandler, actionExecutionContext, action, null, fileOutErr, ErrorTiming.NO_ERROR);
     } catch (ActionExecutionException actionException) {
       // Success in execution but failure in completion.
       reportActionExecution(
-          eventHandler, action, actionException, fileOutErr, ErrorTiming.AFTER_EXECUTION);
+          eventHandler,
+          actionExecutionContext,
+          action,
+          actionException,
+          fileOutErr,
+          ErrorTiming.AFTER_EXECUTION);
       throw actionException;
     } catch (IllegalStateException exception) {
       // More serious internal error, but failure still reported.
       reportActionExecution(
           eventHandler,
+          actionExecutionContext,
           action,
           new ActionExecutionException(exception, action, true),
           fileOutErr,
@@ -1220,6 +1239,7 @@
 
   private void reportActionExecution(
       ExtendedEventHandler eventHandler,
+      ActionExecutionContext actionExecutionContext,
       Action action,
       ActionExecutionException exception,
       FileOutErr outErr,
@@ -1233,7 +1253,14 @@
     if (outErr.hasRecordedStderr()) {
       stderr = outErr.getErrorPath();
     }
-    eventHandler.post(new ActionExecutedEvent(action, exception, stdout, stderr, errorTiming));
+    eventHandler.post(
+        new ActionExecutedEvent(
+            action,
+            exception,
+            actionExecutionContext.getInputPath(action.getPrimaryOutput()),
+            stdout,
+            stderr,
+            errorTiming));
   }
 
   /**
diff --git a/src/test/java/com/google/devtools/build/lib/buildeventservice/BazelBuildEventServiceModuleTest.java b/src/test/java/com/google/devtools/build/lib/buildeventservice/BazelBuildEventServiceModuleTest.java
index cda7069..8657132 100644
--- a/src/test/java/com/google/devtools/build/lib/buildeventservice/BazelBuildEventServiceModuleTest.java
+++ b/src/test/java/com/google/devtools/build/lib/buildeventservice/BazelBuildEventServiceModuleTest.java
@@ -62,6 +62,7 @@
       new ActionExecutedEvent(
           new ActionsTestUtil.NullAction(),
           /* exception= */ null,
+          ActionsTestUtil.DUMMY_ARTIFACT.getPath(),
           /* stdout= */ null,
           /* stderr= */ null,
           ErrorTiming.NO_ERROR);
diff --git a/src/test/java/com/google/devtools/build/lib/runtime/BuildEventStreamerTest.java b/src/test/java/com/google/devtools/build/lib/runtime/BuildEventStreamerTest.java
index d50717d..7d7bbc4 100644
--- a/src/test/java/com/google/devtools/build/lib/runtime/BuildEventStreamerTest.java
+++ b/src/test/java/com/google/devtools/build/lib/runtime/BuildEventStreamerTest.java
@@ -87,6 +87,7 @@
       new ActionExecutedEvent(
           new ActionsTestUtil.NullAction(),
           /* exception= */ null,
+          ActionsTestUtil.DUMMY_ARTIFACT.getPath(),
           /* stdout= */ null,
           /* stderr= */ null,
           ErrorTiming.NO_ERROR);
@@ -912,6 +913,7 @@
         new ActionExecutedEvent(
             new ActionsTestUtil.NullAction(),
             new ActionExecutionException("Exception", /* action= */ null, /* catastrophe= */ false),
+            ActionsTestUtil.DUMMY_ARTIFACT.getPath(),
             /* stdout= */ null,
             /* stderr= */ null,
             ErrorTiming.BEFORE_EXECUTION);
@@ -941,6 +943,7 @@
         new ActionExecutedEvent(
             new ActionsTestUtil.NullAction(),
             new ActionExecutionException("Exception", /* action= */ null, /* catastrophe= */ false),
+            ActionsTestUtil.DUMMY_ARTIFACT.getPath(),
             /* stdout= */ null,
             /* stderr= */ null,
             ErrorTiming.BEFORE_EXECUTION);