Thread Artifact path resolution through template expansion.

PiperOrigin-RevId: 211527631
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/actions/LocalTemplateExpansionStrategy.java b/src/main/java/com/google/devtools/build/lib/analysis/actions/LocalTemplateExpansionStrategy.java
index 4abee91..6a6f544 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/actions/LocalTemplateExpansionStrategy.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/actions/LocalTemplateExpansionStrategy.java
@@ -16,6 +16,7 @@
 
 import com.google.common.collect.ImmutableList;
 import com.google.devtools.build.lib.actions.ActionExecutionContext;
+import com.google.devtools.build.lib.actions.ArtifactPathResolver;
 import com.google.devtools.build.lib.actions.EnvironmentalExecException;
 import com.google.devtools.build.lib.actions.ExecException;
 import com.google.devtools.build.lib.actions.ExecutionStrategy;
@@ -42,7 +43,7 @@
       TemplateExpansionAction action, ActionExecutionContext ctx)
       throws ExecException, InterruptedException {
     try {
-      final String expandedTemplate = getExpandedTemplateUnsafe(action);
+      final String expandedTemplate = getExpandedTemplateUnsafe(action, ctx.getPathResolver());
       DeterministicWriter deterministicWriter =
           new DeterministicWriter() {
             @Override
@@ -64,9 +65,10 @@
    * TODO(b/110418949): Stop public access to this method as it's unhealthy to evaluate the
    * action result without the action being executed.
    */
-  public String getExpandedTemplateUnsafe(TemplateExpansionAction action) throws IOException {
+  public String getExpandedTemplateUnsafe(TemplateExpansionAction action,
+      ArtifactPathResolver resolver) throws IOException {
     String templateString;
-    templateString = action.getTemplate().getContent();
+    templateString = action.getTemplate().getContent(resolver);
     for (Substitution entry : action.getSubstitutions()) {
       templateString =
           StringUtilities.replaceAllLiteral(templateString, entry.getKey(), entry.getValue());
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/actions/Template.java b/src/main/java/com/google/devtools/build/lib/analysis/actions/Template.java
index 4cd870b..68aacdd 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/actions/Template.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/actions/Template.java
@@ -15,6 +15,7 @@
 package com.google.devtools.build.lib.analysis.actions;
 
 import com.google.devtools.build.lib.actions.Artifact;
+import com.google.devtools.build.lib.actions.ArtifactPathResolver;
 import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
 import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
 import com.google.devtools.build.lib.util.ResourceFileLoader;
@@ -35,7 +36,7 @@
   private Template() {}
 
   /** Returns the text content of the template. */
-  protected abstract String getContent() throws IOException;
+  protected abstract String getContent(ArtifactPathResolver resolver) throws IOException;
 
   @Nullable
   public Artifact getTemplateArtifact() {
@@ -62,7 +63,7 @@
     }
 
     @Override
-    protected String getContent() throws IOException {
+    protected String getContent(ArtifactPathResolver resolver) throws IOException {
       throw new IOException(
           "failed to load resource file '" + templateName + "' due to I/O error: " + e.getMessage(),
           e);
@@ -86,7 +87,7 @@
     }
 
     @Override
-    protected String getContent() {
+    protected String getContent(ArtifactPathResolver resolver) {
       return templateText;
     }
 
@@ -108,8 +109,8 @@
     }
 
     @Override
-    protected String getContent() throws IOException {
-      Path templatePath = templateArtifact.getPath();
+    protected String getContent(ArtifactPathResolver resolver) throws IOException {
+      Path templatePath = resolver.toPath(templateArtifact);
       try {
         return FileSystemUtils.readContent(templatePath, DEFAULT_CHARSET);
       } catch (IOException e) {
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/actions/TemplateExpansionAction.java b/src/main/java/com/google/devtools/build/lib/analysis/actions/TemplateExpansionAction.java
index 9b38031..137b6ab 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/actions/TemplateExpansionAction.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/actions/TemplateExpansionAction.java
@@ -25,6 +25,7 @@
 import com.google.devtools.build.lib.actions.ActionOwner;
 import com.google.devtools.build.lib.actions.ActionResult;
 import com.google.devtools.build.lib.actions.Artifact;
+import com.google.devtools.build.lib.actions.ArtifactPathResolver;
 import com.google.devtools.build.lib.actions.ExecException;
 import com.google.devtools.build.lib.cmdline.Label;
 import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
@@ -114,7 +115,8 @@
 
   @VisibleForTesting
   public String getFileContents() throws IOException {
-    return LocalTemplateExpansionStrategy.INSTANCE.getExpandedTemplateUnsafe(this);
+    return LocalTemplateExpansionStrategy.INSTANCE.getExpandedTemplateUnsafe(this,
+        ArtifactPathResolver.IDENTITY);
   }
 
   @Override