Use an ArtifactPathResolver to read the header list during header thinning. PiperOrigin-RevId: 211687222
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/HeaderThinning.java b/src/main/java/com/google/devtools/build/lib/rules/objc/HeaderThinning.java index 940974f..d4e2ad0 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/HeaderThinning.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/HeaderThinning.java
@@ -14,9 +14,11 @@ package com.google.devtools.build.lib.rules.objc; +import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; import com.google.devtools.build.lib.actions.ActionExecutionContext; import com.google.devtools.build.lib.actions.Artifact; +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.UserExecException; @@ -80,7 +82,10 @@ if (headersListFile == null) { return null; } - return findRequiredHeaderInputs(action.getSourceFile(), headersListFile, getAllowedInputsMap()); + return findRequiredHeaderInputs(action.getSourceFile(), headersListFile, getAllowedInputsMap(), + actionExecutionContext == null + ? ArtifactPathResolver.IDENTITY + : actionExecutionContext.getPathResolver()); } /** @@ -89,17 +94,20 @@ * @param sourceFile the source that requires these headers * @param headersListFile .headers_list file output from header_scanner tool to be read * @param inputArtifactsMap map of PathFragment to Artifact of possible headers + * @param pathResolver used to read the headersListFile * @return collection of header artifacts that are required for {@code action} to compile * @throws ExecException on environmental (IO) or user errors */ - public static Iterable<Artifact> findRequiredHeaderInputs( - Artifact sourceFile, Artifact headersListFile, Map<PathFragment, Artifact> inputArtifactsMap) + @VisibleForTesting + static Iterable<Artifact> findRequiredHeaderInputs( + Artifact sourceFile, Artifact headersListFile, Map<PathFragment, Artifact> inputArtifactsMap, + ArtifactPathResolver pathResolver) throws ExecException { try { ImmutableList.Builder<Artifact> includeBuilder = ImmutableList.builder(); List<PathFragment> missing = new ArrayList<>(); for (String line : - FileSystemUtils.readLines(headersListFile.getPath(), StandardCharsets.UTF_8)) { + FileSystemUtils.readLines(pathResolver.toPath(headersListFile), StandardCharsets.UTF_8)) { if (line.isEmpty()) { continue; }
diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/HeaderThinningTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/HeaderThinningTest.java index e7bfb84..4063b61 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/objc/HeaderThinningTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/objc/HeaderThinningTest.java
@@ -24,6 +24,7 @@ import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.actions.Artifact.SpecialArtifact; import com.google.devtools.build.lib.actions.Artifact.SpecialArtifactType; +import com.google.devtools.build.lib.actions.ArtifactPathResolver; import com.google.devtools.build.lib.actions.ExecException; import com.google.devtools.build.lib.actions.UserExecException; import com.google.devtools.build.lib.actions.util.ActionsTestUtil; @@ -125,7 +126,8 @@ HeaderThinning.findRequiredHeaderInputs( sourceFile, headersListFile, - createHeaderFilesMap(getPotentialHeaders(expectedHeaders))); + createHeaderFilesMap(getPotentialHeaders(expectedHeaders)), + ArtifactPathResolver.IDENTITY); assertThat(headersFound).containsExactlyElementsIn(expectedHeaders); }