Skip to content

Commit

Permalink
Make ArtifactFunctionTest#testMiddlemanArtifact more realistic by mak…
Browse files Browse the repository at this point in the history
…ing the output artifact of a middleman action a middleman artifact.

Step -0.5.

--
PiperOrigin-RevId: 150769517
MOS_MIGRATED_REVID=150769517
  • Loading branch information
janakdr authored and hermione521 committed Mar 22, 2017
1 parent 4b44806 commit a5578af
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -54,7 +55,6 @@
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;
Expand Down Expand Up @@ -165,19 +165,12 @@ public void testMissingMandatoryArtifact() throws Throwable {

@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<ActionAnalysisMetadata> 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");
Expand Down Expand Up @@ -407,6 +400,13 @@ private Artifact createDerivedArtifact(String path) {
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.<Artifact>of(), treeArtifact));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -119,9 +120,12 @@ public void baseSetUp() throws Exception {
}

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 {
Expand Down

0 comments on commit a5578af

Please sign in to comment.