Search in sources :

Example 71 with Artifact

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

the class TimestampBuilderTest method testUnneededInputs.

@Test
public void testUnneededInputs() throws Exception {
    Artifact hello = createSourceArtifact("hello");
    BlazeTestUtils.makeEmptyFile(hello.getPath());
    Artifact optional = createSourceArtifact("hello.optional");
    Artifact goodbye = createDerivedArtifact("goodbye");
    Button button = createActionButton(Sets.newHashSet(hello, optional), Sets.newHashSet(goodbye));
    button.pressed = false;
    buildArtifacts(cachingBuilder(), goodbye);
    // built
    assertTrue(button.pressed);
    button.pressed = false;
    buildArtifacts(cachingBuilder(), goodbye);
    // not rebuilt
    assertFalse(button.pressed);
    BlazeTestUtils.makeEmptyFile(optional.getPath());
    button.pressed = false;
    buildArtifacts(cachingBuilder(), goodbye);
    // built
    assertTrue(button.pressed);
    button.pressed = false;
    buildArtifacts(cachingBuilder(), goodbye);
    // not rebuilt
    assertFalse(button.pressed);
    optional.getPath().delete();
    button.pressed = false;
    buildArtifacts(cachingBuilder(), goodbye);
    // built
    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 72 with Artifact

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

the class TimestampBuilderTest method testOnlyModifyingInputContentCausesReexecution.

@Test
public void testOnlyModifyingInputContentCausesReexecution() throws Exception {
    // hello -> [action] -> goodbye
    Artifact hello = createSourceArtifact("hello");
    // touch file to create the directory structure
    BlazeTestUtils.makeEmptyFile(hello.getPath());
    FileSystemUtils.writeContentAsLatin1(hello.getPath(), "content1");
    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);
    FileSystemUtils.touchFile(hello.getPath());
    button.pressed = false;
    buildArtifacts(cachingBuilder(), goodbye);
    // still not rebuilt
    assertFalse(button.pressed);
    FileSystemUtils.writeContentAsLatin1(hello.getPath(), "content2");
    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 73 with Artifact

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

the class TimestampBuilderTest method testBuildingNonexistentSourcefileFails.

@Test
public void testBuildingNonexistentSourcefileFails() throws Exception {
    reporter.removeHandler(failFastHandler);
    Artifact hello = createSourceArtifact("hello");
    try {
        buildArtifacts(cachingBuilder(), hello);
        fail("Expected input file to be missing");
    } catch (BuildFailedException e) {
        assertThat(e).hasMessage("missing input file '" + hello.getPath() + "'");
    }
}
Also used : BuildFailedException(com.google.devtools.build.lib.actions.BuildFailedException) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 74 with Artifact

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

the class TimestampBuilderTest method testWillNotRebuildActionsWithEmptyListOfInputsSpuriously.

@Test
public void testWillNotRebuildActionsWithEmptyListOfInputsSpuriously() throws Exception {
    Artifact anOutputFile = createDerivedArtifact("anOutputFile");
    Artifact anotherOutputFile = createDerivedArtifact("anotherOutputFile");
    Collection<Artifact> noInputs = Collections.emptySet();
    Button aButton = createActionButton(noInputs, Sets.newHashSet(anOutputFile));
    Button anotherButton = createActionButton(noInputs, Sets.newHashSet(anotherOutputFile));
    buildArtifacts(cachingBuilder(), anOutputFile, anotherOutputFile);
    assertTrue(aButton.pressed);
    assertTrue(anotherButton.pressed);
    aButton.pressed = anotherButton.pressed = false;
    buildArtifacts(cachingBuilder(), anOutputFile, anotherOutputFile);
    assertFalse(aButton.pressed);
    assertFalse(anotherButton.pressed);
}
Also used : Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 75 with Artifact

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

the class TimestampBuilderTest method testAmnesiacBuilderAlwaysRebuilds.

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

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