diff --git a/src/test/java/com/google/devtools/build/lib/sandbox/SandboxHelpersTest.java b/src/test/java/com/google/devtools/build/lib/sandbox/SandboxHelpersTest.java index 58f66a3ed46c00..7528de5a88a195 100644 --- a/src/test/java/com/google/devtools/build/lib/sandbox/SandboxHelpersTest.java +++ b/src/test/java/com/google/devtools/build/lib/sandbox/SandboxHelpersTest.java @@ -70,12 +70,14 @@ public class SandboxHelpersTest { private final Scratch scratch = new Scratch(); - private Path execRoot; + private Path execRootPath; + private Root execRoot; @Nullable private ExecutorService executorToCleanup; @Before public void createExecRoot() throws IOException { - execRoot = scratch.dir("/execRoot"); + execRootPath = scratch.dir("/execRoot"); + execRoot = Root.fromPath(execRootPath); } @After @@ -88,6 +90,10 @@ public void shutdownExecutor() throws InterruptedException { executorToCleanup.awaitTermination(TestUtils.WAIT_TIMEOUT_SECONDS, SECONDS); } + private RootedPath execRootedPath(String execPath) { + return RootedPath.toRootedPath(execRoot, PathFragment.create(execPath)); + } + @Test public void processInputFiles_materializesParamFile() throws Exception { SandboxHelpers sandboxHelpers = new SandboxHelpers(); @@ -98,15 +104,15 @@ public void processInputFiles_materializesParamFile() throws Exception { ParameterFileType.UNQUOTED, UTF_8); - SandboxInputs inputs = sandboxHelpers.processInputFiles(inputMap(paramFile), execRoot); + SandboxInputs inputs = sandboxHelpers.processInputFiles(inputMap(paramFile), execRootPath); assertThat(inputs.getFiles()) - .containsExactly(PathFragment.create("paramFile"), execRoot.getChild("paramFile")); + .containsExactly(PathFragment.create("paramFile"), execRootedPath("paramFile")); assertThat(inputs.getSymlinks()).isEmpty(); - assertThat(FileSystemUtils.readLines(execRoot.getChild("paramFile"), UTF_8)) + assertThat(FileSystemUtils.readLines(execRootPath.getChild("paramFile"), UTF_8)) .containsExactly("-a", "-b") .inOrder(); - assertThat(execRoot.getChild("paramFile").isExecutable()).isTrue(); + assertThat(execRootPath.getChild("paramFile").isExecutable()).isTrue(); } @Test @@ -117,16 +123,15 @@ public void processInputFiles_materializesBinToolsFile() throws Exception { scratch.file("tool", "#!/bin/bash", "echo hello"), PathFragment.create("_bin/say_hello")); - SandboxInputs inputs = sandboxHelpers.processInputFiles(inputMap(tool), execRoot); + SandboxInputs inputs = sandboxHelpers.processInputFiles(inputMap(tool), execRootPath); assertThat(inputs.getFiles()) - .containsExactly( - PathFragment.create("_bin/say_hello"), execRoot.getRelative("_bin/say_hello")); + .containsExactly(PathFragment.create("_bin/say_hello"), execRootedPath("_bin/say_hello")); assertThat(inputs.getSymlinks()).isEmpty(); - assertThat(FileSystemUtils.readLines(execRoot.getRelative("_bin/say_hello"), UTF_8)) + assertThat(FileSystemUtils.readLines(execRootPath.getRelative("_bin/say_hello"), UTF_8)) .containsExactly("#!/bin/bash", "echo hello") .inOrder(); - assertThat(execRoot.getRelative("_bin/say_hello").isExecutable()).isTrue(); + assertThat(execRootPath.getRelative("_bin/say_hello").isExecutable()).isTrue(); } /** @@ -235,7 +240,7 @@ public void cleanExisting_updatesDirs() throws IOException, InterruptedException RootedPath inputTxt = RootedPath.toRootedPath( Root.fromPath(scratch.getFileSystem().getPath("/")), PathFragment.create("hello.txt")); - Path rootDir = execRoot.getParentDirectory(); + Path rootDir = execRootPath.getParentDirectory(); PathFragment input1 = PathFragment.create("existing/directory/with/input1.txt"); PathFragment input2 = PathFragment.create("partial/directory/input2.txt"); PathFragment input3 = PathFragment.create("new/directory/input3.txt"); @@ -263,17 +268,17 @@ public void cleanExisting_updatesDirs() throws IOException, InterruptedException assertThat(inputsToCreate).containsExactly(input1, input2, input3); // inputdir1 exists fully - execRoot.getRelative(inputDir1).createDirectoryAndParents(); + execRootPath.getRelative(inputDir1).createDirectoryAndParents(); // inputdir2 exists partially, should be kept nonetheless. - execRoot + execRootPath .getRelative(inputDir2) .getParentDirectory() .getRelative("doomedSubdir") .createDirectoryAndParents(); // inputDir3 just doesn't exist // outputDir only exists partially - execRoot.getRelative(outputDir).getParentDirectory().createDirectoryAndParents(); - execRoot.getRelative("justSomeDir/thatIsDoomed").createDirectoryAndParents(); + execRootPath.getRelative(outputDir).getParentDirectory().createDirectoryAndParents(); + execRootPath.getRelative("justSomeDir/thatIsDoomed").createDirectoryAndParents(); // `thiswillbeafile/output` simulates a directory that was in the stashed dir but whose same // path is used later for a regular file. scratch.dir("/execRoot/thiswillbeafile/output"); @@ -285,21 +290,21 @@ public void cleanExisting_updatesDirs() throws IOException, InterruptedException ImmutableMap.of(input1, inputTxt, input2, inputTxt, input3, inputTxt, input4, inputTxt), ImmutableMap.of(), ImmutableMap.of(), ImmutableSet.of()); - SandboxHelpers.cleanExisting(rootDir, inputs2, inputsToCreate, dirsToCreate, execRoot); + SandboxHelpers.cleanExisting(rootDir, inputs2, inputsToCreate, dirsToCreate, execRootPath); assertThat(dirsToCreate).containsExactly(inputDir2, inputDir3, outputDir); - assertThat(execRoot.getRelative("existing/directory/with").exists()).isTrue(); - assertThat(execRoot.getRelative("partial").exists()).isTrue(); - assertThat(execRoot.getRelative("partial/doomedSubdir").exists()).isFalse(); - assertThat(execRoot.getRelative("partial/directory").exists()).isFalse(); - assertThat(execRoot.getRelative("justSomeDir/thatIsDoomed").exists()).isFalse(); - assertThat(execRoot.getRelative("out").exists()).isTrue(); - assertThat(execRoot.getRelative("out/dir").exists()).isFalse(); + assertThat(execRootPath.getRelative("existing/directory/with").exists()).isTrue(); + assertThat(execRootPath.getRelative("partial").exists()).isTrue(); + assertThat(execRootPath.getRelative("partial/doomedSubdir").exists()).isFalse(); + assertThat(execRootPath.getRelative("partial/directory").exists()).isFalse(); + assertThat(execRootPath.getRelative("justSomeDir/thatIsDoomed").exists()).isFalse(); + assertThat(execRootPath.getRelative("out").exists()).isTrue(); + assertThat(execRootPath.getRelative("out/dir").exists()).isFalse(); } @Test public void populateInputsAndDirsToCreate_createsMappedDirectories() { ArtifactRoot outputRoot = - ArtifactRoot.asDerivedRoot(execRoot, ArtifactRoot.RootType.Output, "outputs"); + ArtifactRoot.asDerivedRoot(execRootPath, ArtifactRoot.RootType.Output, "outputs"); ActionInput outputFile = ActionsTestUtil.createArtifact(outputRoot, "bin/config/dir/file"); ActionInput outputDir = ActionsTestUtil.createTreeArtifactWithGeneratingAction( @@ -339,13 +344,13 @@ public void moveOutputs_mappedPathMovedToUnmappedPath() throws Exception { .setPathMapper(pathMapper) .build(); var sandboxHelpers = new SandboxHelpers(); - Path sandboxBase = execRoot.getRelative("sandbox"); + Path sandboxBase = execRootPath.getRelative("sandbox"); PathFragment mappedOutputPath = PathFragment.create("bin/output"); sandboxBase.getRelative(mappedOutputPath).getParentDirectory().createDirectoryAndParents(); FileSystemUtils.writeLinesAs( sandboxBase.getRelative(mappedOutputPath), UTF_8, "hello", "pathmapper"); - Path realBase = execRoot.getRelative("real"); + Path realBase = execRootPath.getRelative("real"); SandboxHelpers.moveOutputs(sandboxHelpers.getOutputs(spawn), sandboxBase, realBase); assertThat(