From a5578af6fdddd643f3be4d1de14d026c73b4f3e2 Mon Sep 17 00:00:00 2001 From: Janak Ramakrishnan Date: Tue, 21 Mar 2017 17:28:39 +0000 Subject: Make ArtifactFunctionTest#testMiddlemanArtifact more realistic by making the output artifact of a middleman action a middleman artifact. Step -0.5. -- PiperOrigin-RevId: 150769517 MOS_MIGRATED_REVID=150769517 --- .../build/lib/skyframe/ArtifactFunctionTest.java | 18 +++++++++--------- .../build/lib/skyframe/ArtifactFunctionTestCase.java | 6 +++++- 2 files changed, 14 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTest.java index 7ceec1b936..71bb32abbc 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTest.java @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. package com.google.devtools.build.lib.skyframe; + import static com.google.common.truth.Truth.assertThat; import static com.google.devtools.build.lib.skyframe.FileArtifactValue.create; import static org.junit.Assert.assertArrayEquals; @@ -54,7 +55,6 @@ import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.util.Arrays; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; import org.junit.Before; import org.junit.Test; @@ -165,19 +165,12 @@ public class ArtifactFunctionTest extends ArtifactFunctionTestCase { @Test public void testMiddlemanArtifact() throws Throwable { - Artifact output = createDerivedArtifact("output"); + Artifact output = createMiddlemanArtifact("output"); Artifact input1 = createSourceArtifact("input1"); Artifact input2 = createDerivedArtifact("input2"); Action action = new DummyAction( ImmutableList.of(input1, input2), output, MiddlemanType.AGGREGATING_MIDDLEMAN); - // Overwrite default generating action with this one. - for (Iterator it = actions.iterator(); it.hasNext(); ) { - if (it.next().getOutputs().contains(output)) { - it.remove(); - break; - } - } actions.add(action); file(input2.getPath(), "contents"); file(input1.getPath(), "source contents"); @@ -407,6 +400,13 @@ public class ArtifactFunctionTest extends ArtifactFunctionTestCase { return output; } + private Artifact createMiddlemanArtifact(String path) { + Root middlemanRoot = Root.middlemanRoot(middlemanPath, middlemanPath.getRelative("out")); + Path fullPath = middlemanRoot.getPath().getRelative(path); + return new Artifact( + fullPath, middlemanRoot, fullPath.relativeTo(middlemanRoot.getExecRoot()), ALL_OWNER); + } + private Artifact createDerivedTreeArtifactWithAction(String path) { Artifact treeArtifact = createDerivedTreeArtifactOnly(path); actions.add(new DummyAction(ImmutableList.of(), treeArtifact)); diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTestCase.java b/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTestCase.java index bea29c1d9f..a5989761a8 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTestCase.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTestCase.java @@ -60,6 +60,7 @@ abstract class ArtifactFunctionTestCase { protected SequentialBuildDriver driver; protected MemoizingEvaluator evaluator; protected Path root; + protected Path middlemanPath; /** * The test action execution function. The Skyframe evaluator's action execution function @@ -119,9 +120,12 @@ abstract class ArtifactFunctionTestCase { } protected void setupRoot(CustomInMemoryFs fs) throws IOException { - root = fs.getPath(TestUtils.tmpDir()); + Path tmpDir = fs.getPath(TestUtils.tmpDir()); + root = tmpDir.getChild("root"); FileSystemUtils.createDirectoryAndParents(root); FileSystemUtils.createEmptyFile(root.getRelative("WORKSPACE")); + middlemanPath = tmpDir.getChild("middlemanRoot"); + FileSystemUtils.createDirectoryAndParents(middlemanPath); } protected static void writeFile(Path path, String contents) throws IOException { -- cgit v1.2.3