diff options
23 files changed, 125 insertions, 47 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/actions/ActionExecutionContext.java b/src/main/java/com/google/devtools/build/lib/actions/ActionExecutionContext.java index f356559a86..8a96476d30 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/ActionExecutionContext.java +++ b/src/main/java/com/google/devtools/build/lib/actions/ActionExecutionContext.java @@ -135,6 +135,22 @@ public class ActionExecutionContext implements Closeable { } /** + * Returns the path for an ActionInput. + * + * <p>Notably, in the future, we want any action-scoped artifacts to resolve paths using this + * method instead of {@link Artifact#getPath} because that does not allow filesystem injection. + * + * <p>TODO(shahan): cleanup {@link Action}-scoped references to {@link Artifact.getPath}. + */ + public Path getInputPath(ActionInput input) { + if (input instanceof Artifact) { + // TODO(shahan): replace this with actual logic once we understand what it is. + return ((Artifact) input).getPath(); + } + return executor.getExecRoot().getRelative(input.getExecPath()); + } + + /** * Returns whether failures should have verbose error messages. */ public boolean getVerboseFailures() { diff --git a/src/main/java/com/google/devtools/build/lib/analysis/actions/ExecutableSymlinkAction.java b/src/main/java/com/google/devtools/build/lib/analysis/actions/ExecutableSymlinkAction.java index 1be6ad2ea1..18f79aee64 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/actions/ExecutableSymlinkAction.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/actions/ExecutableSymlinkAction.java @@ -39,7 +39,7 @@ public final class ExecutableSymlinkAction extends SymlinkAction { @Override public ActionResult execute(ActionExecutionContext actionExecutionContext) throws ActionExecutionException { - Path inputPath = getPrimaryInput().getPath(); + Path inputPath = actionExecutionContext.getInputPath(getPrimaryInput()); try { // Validate that input path is a file with the executable bit is set. if (!inputPath.isFile()) { diff --git a/src/main/java/com/google/devtools/build/lib/analysis/actions/LauncherFileWriteAction.java b/src/main/java/com/google/devtools/build/lib/analysis/actions/LauncherFileWriteAction.java index 5ad73764c1..fe880c65fa 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/actions/LauncherFileWriteAction.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/actions/LauncherFileWriteAction.java @@ -75,7 +75,7 @@ public final class LauncherFileWriteAction extends AbstractFileWriteAction { // single-machine execution environment, but problematic with remote execution. Preconditions.checkState(OS.getCurrent() == OS.WINDOWS); return out -> { - InputStream in = this.launcher.getPath().getInputStream(); + InputStream in = ctx.getInputPath(this.launcher).getInputStream(); ByteStreams.copy(in, out); long dataLength = this.launchInfo.write(out); ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES); diff --git a/src/main/java/com/google/devtools/build/lib/analysis/actions/PopulateTreeArtifactAction.java b/src/main/java/com/google/devtools/build/lib/analysis/actions/PopulateTreeArtifactAction.java index 131830a41e..ae6d210ffd 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/actions/PopulateTreeArtifactAction.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/actions/PopulateTreeArtifactAction.java @@ -185,7 +185,7 @@ public final class PopulateTreeArtifactAction extends AbstractAction { try { for (ActionInput fileEntry : spawn.getOutputFiles()) { FileSystemUtils.createDirectoryAndParents( - ((Artifact) fileEntry).getPath().getParentDirectory()); + actionExecutionContext.getInputPath(((Artifact) fileEntry)).getParentDirectory()); } } catch (IOException e) { throw new ActionExecutionException(e, this, false); diff --git a/src/main/java/com/google/devtools/build/lib/analysis/actions/SymlinkAction.java b/src/main/java/com/google/devtools/build/lib/analysis/actions/SymlinkAction.java index 13b7aaaead..ed68eb5f0e 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/actions/SymlinkAction.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/actions/SymlinkAction.java @@ -115,7 +115,7 @@ public class SymlinkAction extends AbstractAction { throws ActionExecutionException { Path srcPath; if (inputPath == null) { - srcPath = getPrimaryInput().getPath(); + srcPath = actionExecutionContext.getInputPath(getPrimaryInput()); } else { srcPath = actionExecutionContext.getExecRoot().getRelative(inputPath); } diff --git a/src/main/java/com/google/devtools/build/lib/analysis/extra/ExtraAction.java b/src/main/java/com/google/devtools/build/lib/analysis/extra/ExtraAction.java index 1b084ba69d..7248874cdd 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/extra/ExtraAction.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/extra/ExtraAction.java @@ -165,7 +165,7 @@ public final class ExtraAction extends SpawnAction { if (createDummyOutput) { for (Artifact output : getOutputs()) { try { - FileSystemUtils.touchFile(output.getPath()); + FileSystemUtils.touchFile(actionExecutionContext.getInputPath(output)); } catch (IOException e) { throw new ActionExecutionException(e.getMessage(), e, this, false); } diff --git a/src/main/java/com/google/devtools/build/lib/bazel/BazelWorkspaceStatusModule.java b/src/main/java/com/google/devtools/build/lib/bazel/BazelWorkspaceStatusModule.java index bf7d4b1d86..40ff96c570 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/BazelWorkspaceStatusModule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/BazelWorkspaceStatusModule.java @@ -220,12 +220,14 @@ public class BazelWorkspaceStatusModule extends BlazeModule { // Only update the stableStatus contents if they are different than what we have on disk. // This is to preserve the old file's mtime so that we do not generate an unnecessary dirty // file on each incremental build. - FileSystemUtils.maybeUpdateContent(stableStatus.getPath(), printStatusMap(stableMap)); + FileSystemUtils.maybeUpdateContent( + actionExecutionContext.getInputPath(stableStatus), printStatusMap(stableMap)); // Contrary to the stableStatus, write the contents of volatileStatus unconditionally // because we know it will be different. This output file is marked as "constant metadata" // so its dirtiness will be ignored anyway. - FileSystemUtils.writeContent(volatileStatus.getPath(), printStatusMap(volatileMap)); + FileSystemUtils.writeContent( + actionExecutionContext.getInputPath(volatileStatus), printStatusMap(volatileMap)); } catch (IOException e) { throw new ActionExecutionException( "Failed to run workspace status command " + options.workspaceStatusCommand, diff --git a/src/main/java/com/google/devtools/build/lib/exec/FileWriteStrategy.java b/src/main/java/com/google/devtools/build/lib/exec/FileWriteStrategy.java index be9841cf0c..d2d8668ede 100644 --- a/src/main/java/com/google/devtools/build/lib/exec/FileWriteStrategy.java +++ b/src/main/java/com/google/devtools/build/lib/exec/FileWriteStrategy.java @@ -51,7 +51,8 @@ public final class FileWriteStrategy implements FileWriteActionContext { AutoProfiler.logged( "running " + action.prettyPrint(), logger, /*minTimeForLoggingInMilliseconds=*/ 100)) { try { - Path outputPath = Iterables.getOnlyElement(action.getOutputs()).getPath(); + Path outputPath = + actionExecutionContext.getInputPath(Iterables.getOnlyElement(action.getOutputs())); try (OutputStream out = new BufferedOutputStream(outputPath.getOutputStream())) { action.newDeterministicWriter(actionExecutionContext).writeOutputFile(out); } diff --git a/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java b/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java index 2dfc22904d..93134e8ef0 100644 --- a/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java +++ b/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java @@ -164,13 +164,18 @@ public class StandaloneTestStrategy extends TestStrategy { } processLastTestAttempt(attempt, dataBuilder, standaloneTestResult.testResultData()); ImmutableList.Builder<Pair<String, Path>> testOutputsBuilder = new ImmutableList.Builder<>(); - if (action.getTestLog().getPath().exists()) { + if (actionExecutionContext.getInputPath(action.getTestLog()).exists()) { testOutputsBuilder.add( - Pair.of(TestFileNameConstants.TEST_LOG, action.getTestLog().getPath())); + Pair.of( + TestFileNameConstants.TEST_LOG, + actionExecutionContext.getInputPath(action.getTestLog()))); } - if (action.getCoverageData() != null && action.getCoverageData().getPath().exists()) { + if (action.getCoverageData() != null + && actionExecutionContext.getInputPath(action.getCoverageData()).exists()) { testOutputsBuilder.add( - Pair.of(TestFileNameConstants.TEST_COVERAGE, action.getCoverageData().getPath())); + Pair.of( + TestFileNameConstants.TEST_COVERAGE, + actionExecutionContext.getInputPath(action.getCoverageData()))); } testOutputsBuilder.addAll(TestResult.testOutputsFromPaths(resolvedPaths)); actionExecutionContext @@ -207,18 +212,21 @@ public class StandaloneTestStrategy extends TestStrategy { // Rename outputs String namePrefix = FileSystemUtils.removeExtension(action.getTestLog().getExecPath().getBaseName()); - Path testRoot = action.getTestLog().getPath().getParentDirectory(); + Path testRoot = actionExecutionContext.getInputPath(action.getTestLog()).getParentDirectory(); Path attemptsDir = testRoot.getChild(namePrefix + "_attempts"); attemptsDir.createDirectory(); String attemptPrefix = "attempt_" + attempt; Path testLog = attemptsDir.getChild(attemptPrefix + ".log"); - if (action.getTestLog().getPath().exists()) { - action.getTestLog().getPath().renameTo(testLog); + if (actionExecutionContext.getInputPath(action.getTestLog()).exists()) { + actionExecutionContext.getInputPath(action.getTestLog()).renameTo(testLog); testOutputsBuilder.add(Pair.of(TestFileNameConstants.TEST_LOG, testLog)); } - if (action.getCoverageData() != null && action.getCoverageData().getPath().exists()) { + if (action.getCoverageData() != null + && actionExecutionContext.getInputPath(action.getCoverageData()).exists()) { testOutputsBuilder.add( - Pair.of(TestFileNameConstants.TEST_COVERAGE, action.getCoverageData().getPath())); + Pair.of( + TestFileNameConstants.TEST_COVERAGE, + actionExecutionContext.getInputPath(action.getCoverageData()))); } // Get the normal test output paths, and then update them to use "attempt_N" names, and @@ -300,8 +308,9 @@ public class StandaloneTestStrategy extends TestStrategy { prepareFileSystem(action, tmpDir, coverageDir, workingDirectory); try (FileOutErr fileOutErr = - new FileOutErr( - action.getTestLog().getPath(), action.resolve(execRoot).getTestStderr())) { + new FileOutErr( + actionExecutionContext.getInputPath(action.getTestLog()), + action.resolve(execRoot).getTestStderr())) { StandaloneTestResult standaloneTestResult = executeTest(action, spawn, actionExecutionContext.withFileOutErr(fileOutErr)); appendStderr(fileOutErr.getOutputPath(), fileOutErr.getErrorPath()); @@ -334,7 +343,7 @@ public class StandaloneTestStrategy extends TestStrategy { TestRunnerAction action, Spawn spawn, ActionExecutionContext actionExecutionContext) throws ExecException, InterruptedException, IOException { Closeable streamed = null; - Path testLogPath = action.getTestLog().getPath(); + Path testLogPath = actionExecutionContext.getInputPath(action.getTestLog()); TestResultData.Builder builder = TestResultData.newBuilder(); long startTime = actionExecutionContext.getClock().currentTimeMillis(); diff --git a/src/main/java/com/google/devtools/build/lib/exec/SymlinkTreeHelper.java b/src/main/java/com/google/devtools/build/lib/exec/SymlinkTreeHelper.java index 143fc971e2..70b0ddd02f 100644 --- a/src/main/java/com/google/devtools/build/lib/exec/SymlinkTreeHelper.java +++ b/src/main/java/com/google/devtools/build/lib/exec/SymlinkTreeHelper.java @@ -113,7 +113,8 @@ public final class SymlinkTreeHelper { Artifact inputManifestArtifact, boolean enableRunfiles) throws ExecException, InterruptedException { - Preconditions.checkState(inputManifestArtifact.getPath().equals(inputManifest)); + Preconditions.checkState( + actionExecutionContext.getInputPath(inputManifestArtifact).equals(inputManifest)); if (enableRunfiles) { return actionExecutionContext .getSpawnActionContext(owner.getMnemonic()) diff --git a/src/main/java/com/google/devtools/build/lib/exec/SymlinkTreeStrategy.java b/src/main/java/com/google/devtools/build/lib/exec/SymlinkTreeStrategy.java index 0bc8e5604a..d672798e2c 100644 --- a/src/main/java/com/google/devtools/build/lib/exec/SymlinkTreeStrategy.java +++ b/src/main/java/com/google/devtools/build/lib/exec/SymlinkTreeStrategy.java @@ -56,16 +56,19 @@ public final class SymlinkTreeStrategy implements SymlinkTreeActionContext { try { if (outputService != null && outputService.canCreateSymlinkTree()) { outputService.createSymlinkTree( - action.getInputManifest().getPath(), - action.getOutputManifest().getPath(), + actionExecutionContext.getInputPath(action.getInputManifest()), + actionExecutionContext.getInputPath(action.getOutputManifest()), action.isFilesetTree(), action.getOutputManifest().getExecPath().getParentDirectory()); return ImmutableList.of(); } else { - SymlinkTreeHelper helper = new SymlinkTreeHelper( - action.getInputManifest().getPath(), - action.getOutputManifest().getPath().getParentDirectory(), - action.isFilesetTree()); + SymlinkTreeHelper helper = + new SymlinkTreeHelper( + actionExecutionContext.getInputPath(action.getInputManifest()), + actionExecutionContext + .getInputPath(action.getOutputManifest()) + .getParentDirectory(), + action.isFilesetTree()); return helper.createSymlinks( action, actionExecutionContext, diff --git a/src/main/java/com/google/devtools/build/lib/exec/TestStrategy.java b/src/main/java/com/google/devtools/build/lib/exec/TestStrategy.java index b5d2350208..3a64bab76a 100644 --- a/src/main/java/com/google/devtools/build/lib/exec/TestStrategy.java +++ b/src/main/java/com/google/devtools/build/lib/exec/TestStrategy.java @@ -387,7 +387,8 @@ public abstract class TestStrategy implements TestActionContext { // an up-to-date check. if (!outputManifest.isSymbolicLink() && Arrays.equals( - outputManifest.getDigest(), execSettings.getInputManifest().getPath().getDigest())) { + outputManifest.getDigest(), + actionExecutionContext.getInputPath(execSettings.getInputManifest()).getDigest())) { return; } } catch (IOException e1) { @@ -402,7 +403,10 @@ public abstract class TestStrategy implements TestActionContext { + execSettings.getExecutable().prettyPrint() + "'.")); - new SymlinkTreeHelper(execSettings.getInputManifest().getPath(), runfilesDir, false) + new SymlinkTreeHelper( + actionExecutionContext.getInputPath(execSettings.getInputManifest()), + runfilesDir, + false) .createSymlinks( testAction, actionExecutionContext, diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CreateIncSymlinkAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CreateIncSymlinkAction.java index bcad6786a7..8e37da5bba 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CreateIncSymlinkAction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CreateIncSymlinkAction.java @@ -68,8 +68,8 @@ public final class CreateIncSymlinkAction extends AbstractAction { throws ActionExecutionException { try { for (Map.Entry<Artifact, Artifact> entry : symlinks.entrySet()) { - Path symlink = entry.getKey().getPath(); - symlink.createSymbolicLink(entry.getValue().getPath()); + Path symlink = actionExecutionContext.getInputPath(entry.getKey()); + symlink.createSymbolicLink(actionExecutionContext.getInputPath(entry.getValue())); } } catch (IOException e) { String message = "IO Error while creating symlink"; diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/FakeCppCompileAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/FakeCppCompileAction.java index 25b22678ea..7906362a3d 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/FakeCppCompileAction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/FakeCppCompileAction.java @@ -237,10 +237,19 @@ public class FakeCppCompileAction extends CppCompileAction { // both. Preconditions.checkState(outputFile.getExecPath().getParentDirectory().equals( getDotdFile().getSafeExecPath().getParentDirectory())); - FileSystemUtils.writeContent(outputFile.getPath(), ISO_8859_1, - outputFile.getPath().getBaseName() + ": " - + "mkdir -p " + outputPrefix + "$(dirname " + outputFile.getExecPath() + ")" - + " && " + argv + "\n"); + FileSystemUtils.writeContent( + actionExecutionContext.getInputPath(outputFile), + ISO_8859_1, + actionExecutionContext.getInputPath(outputFile).getBaseName() + + ": " + + "mkdir -p " + + outputPrefix + + "$(dirname " + + outputFile.getExecPath() + + ")" + + " && " + + argv + + "\n"); } catch (IOException e) { throw new ActionExecutionException("failed to create fake compile command for rule '" + getOwner().getLabel() + ": " + e.getMessage(), this, false); diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/IncludeScanner.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/IncludeScanner.java index 1335470856..782028712a 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/IncludeScanner.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/IncludeScanner.java @@ -158,12 +158,14 @@ public interface IncludeScanner { // the root path for such includes if (included.getRoot().getRoot().isAbsolute()) { if (FileSystemUtils.startsWithAny( - included.getPath().asFragment(), absoluteBuiltInIncludeDirs)) { + actionExecutionContext.getInputPath(included).asFragment(), + absoluteBuiltInIncludeDirs)) { // Skip include files found in absolute include directories. continue; } throw new UserExecException( - "illegal absolute path to include file: " + included.getPath()); + "illegal absolute path to include file: " + + actionExecutionContext.getInputPath(included)); } inputs.add(included); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/LtoBackendAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/LtoBackendAction.java index 2e992fefac..ce171002b6 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/LtoBackendAction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/LtoBackendAction.java @@ -121,12 +121,16 @@ public final class LtoBackendAction extends SpawnAction { // Build set of files this LTO backend artifact will import from. HashSet<PathFragment> importSet = new HashSet<>(); try { - for (String line : FileSystemUtils.iterateLinesAsLatin1(imports.getPath())) { + for (String line : + FileSystemUtils.iterateLinesAsLatin1(actionExecutionContext.getInputPath(imports))) { if (!line.isEmpty()) { PathFragment execPath = PathFragment.create(line); if (execPath.isAbsolute()) { throw new ActionExecutionException( - "Absolute paths not allowed in imports file " + imports.getPath() + ": " + execPath, + "Absolute paths not allowed in imports file " + + actionExecutionContext.getInputPath(imports) + + ": " + + execPath, this, false); } @@ -135,14 +139,20 @@ public final class LtoBackendAction extends SpawnAction { } } catch (IOException e) { throw new ActionExecutionException( - "error iterating imports file " + imports.getPath(), e, this, false); + "error iterating imports file " + actionExecutionContext.getInputPath(imports), + e, + this, + false); } // Convert the import set of paths to the set of bitcode file artifacts. Set<Artifact> bitcodeInputSet = computeBitcodeInputs(importSet); if (bitcodeInputSet.size() != importSet.size()) { throw new ActionExecutionException( - "error computing inputs from imports file " + imports.getPath(), this, false); + "error computing inputs from imports file " + + actionExecutionContext.getInputPath(imports), + this, + false); } updateInputs(createInputs(bitcodeInputSet, getMandatoryInputs())); return bitcodeInputSet; diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/SolibSymlinkAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/SolibSymlinkAction.java index c0c5e3a657..ea9d03758e 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/SolibSymlinkAction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/SolibSymlinkAction.java @@ -62,7 +62,7 @@ public final class SolibSymlinkAction extends AbstractAction { @Override public ActionResult execute(ActionExecutionContext actionExecutionContext) throws ActionExecutionException { - Path mangledPath = symlink.getPath(); + Path mangledPath = actionExecutionContext.getInputPath(symlink); try { mangledPath.createSymbolicLink(target); } catch (IOException e) { diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/WriteBuildInfoHeaderAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/WriteBuildInfoHeaderAction.java index 93e40f95e1..5d977a1dff 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/WriteBuildInfoHeaderAction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/WriteBuildInfoHeaderAction.java @@ -98,7 +98,7 @@ public final class WriteBuildInfoHeaderAction extends AbstractFileWriteAction { final Map<String, String> values = new LinkedHashMap<>(); for (Artifact valueFile : getInputs()) { - values.putAll(WorkspaceStatusAction.parseValues(valueFile.getPath())); + values.putAll(WorkspaceStatusAction.parseValues(ctx.getInputPath(valueFile))); } final boolean redacted = Iterables.isEmpty(getInputs()); diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/WriteBuildInfoPropertiesAction.java b/src/main/java/com/google/devtools/build/lib/rules/java/WriteBuildInfoPropertiesAction.java index a346c26205..26c4cd1b84 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/WriteBuildInfoPropertiesAction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/WriteBuildInfoPropertiesAction.java @@ -152,7 +152,7 @@ public class WriteBuildInfoPropertiesAction extends AbstractFileWriteAction { WorkspaceStatusAction.Context context = ctx.getContext(WorkspaceStatusAction.Context.class); Map<String, String> values = new LinkedHashMap<>(); for (Artifact valueFile : getInputs()) { - values.putAll(WorkspaceStatusAction.parseValues(valueFile.getPath())); + values.putAll(WorkspaceStatusAction.parseValues(ctx.getInputPath(valueFile))); } Map<String, String> keys = new HashMap<>(); diff --git a/src/main/java/com/google/devtools/build/lib/standalone/DummyIncludeScanningContextProvider.java b/src/main/java/com/google/devtools/build/lib/standalone/DummyIncludeScanningContextProvider.java index 33a076a0a6..f42903a5fd 100644 --- a/src/main/java/com/google/devtools/build/lib/standalone/DummyIncludeScanningContextProvider.java +++ b/src/main/java/com/google/devtools/build/lib/standalone/DummyIncludeScanningContextProvider.java @@ -51,7 +51,8 @@ public class DummyIncludeScanningContextProvider extends ActionContextProvider { Artifact primaryOutput, Artifact grepIncludes) throws IOException { - FileSystemUtils.writeContent(primaryOutput.getPath(), new byte[]{}); + FileSystemUtils.writeContent( + actionExecutionContext.getInputPath(primaryOutput), new byte[] {}); } @Override diff --git a/src/main/java/com/google/devtools/build/lib/worker/WorkerTestStrategy.java b/src/main/java/com/google/devtools/build/lib/worker/WorkerTestStrategy.java index 0fb173cf75..2302fc7c1e 100644 --- a/src/main/java/com/google/devtools/build/lib/worker/WorkerTestStrategy.java +++ b/src/main/java/com/google/devtools/build/lib/worker/WorkerTestStrategy.java @@ -124,7 +124,7 @@ public class WorkerTestStrategy extends StandaloneTestStrategy { TestResultData.Builder builder = TestResultData.newBuilder(); - Path testLogPath = action.getTestLog().getPath(); + Path testLogPath = actionExecutionContext.getInputPath(action.getTestLog()); Worker worker = null; WorkerKey key = null; long startTime = actionExecutionContext.getClock().currentTimeMillis(); diff --git a/src/test/java/com/google/devtools/build/lib/exec/StandaloneTestStrategyTest.java b/src/test/java/com/google/devtools/build/lib/exec/StandaloneTestStrategyTest.java index 856f000ccd..57ad24332d 100644 --- a/src/test/java/com/google/devtools/build/lib/exec/StandaloneTestStrategyTest.java +++ b/src/test/java/com/google/devtools/build/lib/exec/StandaloneTestStrategyTest.java @@ -15,6 +15,7 @@ package com.google.devtools.build.lib.exec; import static com.google.common.truth.Truth.assertThat; +import static com.google.devtools.build.lib.testutil.TestConstants.WORKSPACE_NAME; import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.fail; import static org.mockito.Matchers.any; @@ -24,6 +25,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.google.devtools.build.lib.actions.ActionExecutionContext; +import com.google.devtools.build.lib.actions.ActionInput; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.actions.SpawnActionContext; import com.google.devtools.build.lib.actions.SpawnResult; @@ -117,6 +119,7 @@ public final class StandaloneTestStrategyTest extends BuildViewTestCase { when(actionExecutionContext.getClientEnv()).thenReturn(ImmutableMap.of()); when(actionExecutionContext.getEventHandler()).thenReturn(reporter); when(actionExecutionContext.getEventBus()).thenReturn(eventBus); + when(actionExecutionContext.getInputPath(any())).thenAnswer(this::getInputPathMock); SpawnResult expectedSpawnResult = new SpawnResult.Builder() @@ -189,6 +192,8 @@ public final class StandaloneTestStrategyTest extends BuildViewTestCase { when(actionExecutionContext.getClientEnv()).thenReturn(ImmutableMap.of()); when(actionExecutionContext.getEventHandler()).thenReturn(reporter); when(actionExecutionContext.getEventBus()).thenReturn(eventBus); + when(actionExecutionContext.getInputPath(any())).thenAnswer(this::getInputPathMock); + Path outPath = tmpDirRoot.getRelative("test-out.txt"); Path errPath = tmpDirRoot.getRelative("test-err.txt"); FileOutErr outErr = new FileOutErr(outPath, errPath); @@ -272,6 +277,7 @@ public final class StandaloneTestStrategyTest extends BuildViewTestCase { when(actionExecutionContext.getClientEnv()).thenReturn(ImmutableMap.of()); when(actionExecutionContext.getEventHandler()).thenReturn(reporter); when(actionExecutionContext.getEventBus()).thenReturn(eventBus); + when(actionExecutionContext.getInputPath(any())).thenAnswer(this::getInputPathMock); Path outPath = tmpDirRoot.getRelative("test-out.txt"); Path errPath = tmpDirRoot.getRelative("test-err.txt"); FileOutErr outErr = new FileOutErr(outPath, errPath); @@ -307,4 +313,10 @@ public final class StandaloneTestStrategyTest extends BuildViewTestCase { } assertThat(errPath.exists()).isFalse(); } + + private Path getInputPathMock(InvocationOnMock invocation) { + return outputBase + .getRelative("execroot/" + WORKSPACE_NAME) + .getRelative(invocation.getArgumentAt(0, ActionInput.class).getExecPath()); + } } diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CreateIncSymlinkActionTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CreateIncSymlinkActionTest.java index f24f200509..75d05ce460 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CreateIncSymlinkActionTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CreateIncSymlinkActionTest.java @@ -18,9 +18,11 @@ import static com.google.common.truth.Truth.assertThat; import static com.google.devtools.build.lib.actions.util.ActionsTestUtil.NULL_ACTION_OWNER; import com.google.common.collect.ImmutableMap; +import com.google.devtools.build.lib.actions.ActionExecutionContext; import com.google.devtools.build.lib.actions.ActionKeyContext; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.actions.ArtifactRoot; +import com.google.devtools.build.lib.actions.util.DummyExecutor; import com.google.devtools.build.lib.testutil.FoundationTestCase; import com.google.devtools.build.lib.util.Fingerprint; import com.google.devtools.build.lib.vfs.Path; @@ -103,13 +105,19 @@ public class CreateIncSymlinkActionTest extends FoundationTestCase { Artifact b = new Artifact(PathFragment.create("b"), root); CreateIncSymlinkAction action = new CreateIncSymlinkAction(NULL_ACTION_OWNER, ImmutableMap.of(a, b), outputDir); - action.execute(null); + action.execute(makeDummyContext()); symlink.stat(Symlinks.NOFOLLOW); assertThat(symlink.isSymbolicLink()).isTrue(); assertThat(b.getPath().asFragment()).isEqualTo(symlink.readSymbolicLink()); assertThat(rootDirectory.getRelative("a").exists()).isFalse(); } + private ActionExecutionContext makeDummyContext() { + DummyExecutor executor = new DummyExecutor(fileSystem, rootDirectory); + return new ActionExecutionContext( + executor, null, null, null, null, null, ImmutableMap.of(), null); + } + @Test public void testFileRemoved() throws Exception { Path outputDir = rootDirectory.getRelative("out"); |