Search in sources :

Example 76 with Artifact

use of com.google.devtools.build.lib.actions.Artifact in project bazel by bazelbuild.

the class TimestampBuilderTest method testBuildingTransitivePrerequisites.

@Test
public void testBuildingTransitivePrerequisites() throws Exception {
    // hello -> [action1] -> wazuup -> [action2] -> goodbye
    Artifact hello = createSourceArtifact("hello");
    BlazeTestUtils.makeEmptyFile(hello.getPath());
    Artifact wazuup = createDerivedArtifact("wazuup");
    Button button1 = new Button();
    registerAction(new CopyingAction(button1, hello, wazuup));
    Artifact goodbye = createDerivedArtifact("goodbye");
    Button button2 = createActionButton(Sets.newHashSet(wazuup), Sets.newHashSet(goodbye));
    button1.pressed = button2.pressed = false;
    buildArtifacts(cachingBuilder(), wazuup);
    // built wazuup
    assertTrue(button1.pressed);
    // goodbye not built
    assertFalse(button2.pressed);
    button1.pressed = button2.pressed = false;
    buildArtifacts(cachingBuilder(), wazuup);
    // wazuup not rebuilt
    assertFalse(button1.pressed);
    // goodbye not built
    assertFalse(button2.pressed);
    button1.pressed = button2.pressed = false;
    buildArtifacts(cachingBuilder(), goodbye);
    // wazuup not rebuilt
    assertFalse(button1.pressed);
    // built goodbye
    assertTrue(button2.pressed);
    button1.pressed = button2.pressed = false;
    buildArtifacts(cachingBuilder(), goodbye);
    // wazuup not rebuilt
    assertFalse(button1.pressed);
    // goodbye not rebuilt
    assertFalse(button2.pressed);
    hello.getPath().setWritable(true);
    FileSystemUtils.writeContentAsLatin1(hello.getPath(), "new content");
    button1.pressed = button2.pressed = false;
    buildArtifacts(cachingBuilder(), goodbye);
    // hello rebuilt
    assertTrue(button1.pressed);
    // goodbye rebuilt
    assertTrue(button2.pressed);
}
Also used : Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 77 with Artifact

use of com.google.devtools.build.lib.actions.Artifact in project bazel by bazelbuild.

the class TimestampBuilderTest method testModifyingInputCausesActionReexecution.

@Test
public void testModifyingInputCausesActionReexecution() throws Exception {
    // hello -> [action] -> goodbye
    Artifact hello = createSourceArtifact("hello");
    BlazeTestUtils.makeEmptyFile(hello.getPath());
    Artifact goodbye = createDerivedArtifact("goodbye");
    Button button = createActionButton(Sets.newHashSet(hello), Sets.newHashSet(goodbye));
    button.pressed = false;
    buildArtifacts(cachingBuilder(), goodbye);
    // built
    assertTrue(button.pressed);
    button.pressed = false;
    buildArtifacts(cachingBuilder(), goodbye);
    // not rebuilt
    assertFalse(button.pressed);
    hello.getPath().setWritable(true);
    FileSystemUtils.writeContentAsLatin1(hello.getPath(), "new content");
    button.pressed = false;
    buildArtifacts(cachingBuilder(), goodbye);
    // rebuilt
    assertTrue(button.pressed);
    button.pressed = false;
    buildArtifacts(cachingBuilder(), goodbye);
    // not rebuilt
    assertFalse(button.pressed);
}
Also used : Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 78 with Artifact

use of com.google.devtools.build.lib.actions.Artifact in project bazel by bazelbuild.

the class TimestampBuilderTest method testCachingBuilderCachesUntilReset.

@Test
public void testCachingBuilderCachesUntilReset() throws Exception {
    // [action] -> hello
    Artifact hello = createDerivedArtifact("hello");
    Button button = createActionButton(emptySet, Sets.newHashSet(hello));
    button.pressed = false;
    buildArtifacts(cachingBuilder(), hello);
    // built
    assertTrue(button.pressed);
    button.pressed = false;
    buildArtifacts(cachingBuilder(), hello);
    // not rebuilt
    assertFalse(button.pressed);
    inMemoryCache.reset();
    button.pressed = false;
    buildArtifacts(cachingBuilder(), hello);
    // rebuilt
    assertTrue(button.pressed);
}
Also used : Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 79 with Artifact

use of com.google.devtools.build.lib.actions.Artifact in project bazel by bazelbuild.

the class TimestampBuilderTest method testModifyingOutputCausesActionReexecution.

@Test
public void testModifyingOutputCausesActionReexecution() throws Exception {
    // [action] -> hello
    Artifact hello = createDerivedArtifact("hello");
    Button button = createActionButton(emptySet, Sets.newHashSet(hello));
    button.pressed = false;
    buildArtifacts(cachingBuilder(), hello);
    // built
    assertTrue(button.pressed);
    button.pressed = false;
    buildArtifacts(cachingBuilder(), hello);
    // not rebuilt
    assertFalse(button.pressed);
    // Changing the *output* file 'hello' causes 'action' to re-execute, to make things consistent
    // again.
    hello.getPath().setWritable(true);
    FileSystemUtils.writeContentAsLatin1(hello.getPath(), "new content");
    button.pressed = false;
    buildArtifacts(cachingBuilder(), hello);
    // rebuilt
    assertTrue(button.pressed);
    button.pressed = false;
    buildArtifacts(cachingBuilder(), hello);
    // not rebuilt
    assertFalse(button.pressed);
}
Also used : Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 80 with Artifact

use of com.google.devtools.build.lib.actions.Artifact in project bazel by bazelbuild.

the class TimestampBuilderTestCase method createDerivedArtifact.

Artifact createDerivedArtifact(FileSystem fs, String name) {
    Path execRoot = fs.getPath(TestUtils.tmpDir());
    PathFragment execPath = new PathFragment("out").getRelative(name);
    Path path = execRoot.getRelative(execPath);
    return new Artifact(path, Root.asDerivedRoot(execRoot, execRoot.getRelative("out")), execPath, ALL_OWNER);
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) Artifact(com.google.devtools.build.lib.actions.Artifact)

Aggregations

Artifact (com.google.devtools.build.lib.actions.Artifact)659 Test (org.junit.Test)242 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)184 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)83 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)65 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)64 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)51 RuleConfiguredTargetBuilder (com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)50 ImmutableList (com.google.common.collect.ImmutableList)46 Action (com.google.devtools.build.lib.actions.Action)42 IOException (java.io.IOException)42 ArrayList (java.util.ArrayList)40 SpawnAction (com.google.devtools.build.lib.analysis.actions.SpawnAction)38 Path (com.google.devtools.build.lib.vfs.Path)37 HashMap (java.util.HashMap)37 Map (java.util.Map)36 Root (com.google.devtools.build.lib.actions.Root)31 LinkedHashMap (java.util.LinkedHashMap)31 ImmutableMap (com.google.common.collect.ImmutableMap)28 TransitiveInfoCollection (com.google.devtools.build.lib.analysis.TransitiveInfoCollection)28