Search in sources :

Example 6 with ActionExecutionContext

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

the class ParamFileWriteActionTest method testWriteCommandLineWithoutTreeArtifactExpansion.

@Test
public void testWriteCommandLineWithoutTreeArtifactExpansion() throws Exception {
    Action action = createParameterFileWriteAction(ImmutableList.<Artifact>of(), createNormalCommandLine());
    ActionExecutionContext context = actionExecutionContext();
    action.execute(context);
    String content = new String(FileSystemUtils.readContentAsLatin1(outputArtifact.getPath()));
    assertEquals("--flag1\n--flag2\n--flag3\nvalue1\nvalue2", content.trim());
}
Also used : Action(com.google.devtools.build.lib.actions.Action) ActionExecutionContext(com.google.devtools.build.lib.actions.ActionExecutionContext) Test(org.junit.Test)

Example 7 with ActionExecutionContext

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

the class ParamFileWriteActionTest method testWriteCommandLineWithTreeArtifactExpansion.

@Test
public void testWriteCommandLineWithTreeArtifactExpansion() throws Exception {
    Action action = createParameterFileWriteAction(ImmutableList.of(treeArtifact), createTreeArtifactExpansionCommandLine());
    ActionExecutionContext context = actionExecutionContext();
    action.execute(context);
    String content = new String(FileSystemUtils.readContentAsLatin1(outputArtifact.getPath()));
    assertEquals("--flag1\n" + "artifact/myTreeFileArtifact/artifacts/treeFileArtifact1:" + "artifact/myTreeFileArtifact/artifacts/treeFileArtifact2", content.trim());
}
Also used : Action(com.google.devtools.build.lib.actions.Action) ActionExecutionContext(com.google.devtools.build.lib.actions.ActionExecutionContext) Test(org.junit.Test)

Example 8 with ActionExecutionContext

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

the class ParamFileWriteActionTest method actionExecutionContext.

private ActionExecutionContext actionExecutionContext() throws Exception {
    final Iterable<TreeFileArtifact> treeFileArtifacts = ImmutableList.of(createTreeFileArtifact(treeArtifact, "artifacts/treeFileArtifact1"), createTreeFileArtifact(treeArtifact, "artifacts/treeFileArtifact2"));
    ArtifactExpander artifactExpander = new ArtifactExpander() {

        @Override
        public void expand(Artifact artifact, Collection<? super Artifact> output) {
            for (TreeFileArtifact treeFileArtifact : treeFileArtifacts) {
                if (treeFileArtifact.getParent().equals(artifact)) {
                    output.add(treeFileArtifact);
                }
            }
        }
    };
    Executor executor = new TestExecutorBuilder(directories, binTools).build();
    return new ActionExecutionContext(executor, null, null, new FileOutErr(), ImmutableMap.<String, String>of(), artifactExpander);
}
Also used : TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) TestExecutorBuilder(com.google.devtools.build.lib.exec.util.TestExecutorBuilder) ArtifactExpander(com.google.devtools.build.lib.actions.Artifact.ArtifactExpander) Executor(com.google.devtools.build.lib.actions.Executor) FileOutErr(com.google.devtools.build.lib.util.io.FileOutErr) ActionExecutionContext(com.google.devtools.build.lib.actions.ActionExecutionContext) Collection(java.util.Collection) SpecialArtifact(com.google.devtools.build.lib.actions.Artifact.SpecialArtifact) Artifact(com.google.devtools.build.lib.actions.Artifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)

Example 9 with ActionExecutionContext

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

the class PopulateTreeArtifactActionTest method testTreeFileArtifactPathPrefixConflicts.

@Test
public void testTreeFileArtifactPathPrefixConflicts() throws Exception {
    Action action = createPopulateTreeArtifactAction();
    scratch.overwriteFile("archiveManifest.txt", "archive_members/conflict", "archive_members/conflict/1.class");
    ActionExecutionContext executionContext = actionExecutionContext(new ArrayList<Artifact>());
    try {
        action.execute(executionContext);
        fail("Artifact path prefix conflicts, expected exception");
    } catch (ActionExecutionException e) {
    // Expect ActionExecutionException
    }
}
Also used : Action(com.google.devtools.build.lib.actions.Action) ActionExecutionContext(com.google.devtools.build.lib.actions.ActionExecutionContext) ActionExecutionException(com.google.devtools.build.lib.actions.ActionExecutionException) SpecialArtifact(com.google.devtools.build.lib.actions.Artifact.SpecialArtifact) Artifact(com.google.devtools.build.lib.actions.Artifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) Test(org.junit.Test)

Example 10 with ActionExecutionContext

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

the class PopulateTreeArtifactActionTest method testOutputTreeFileArtifactDirsCreated.

@Test
public void testOutputTreeFileArtifactDirsCreated() throws Exception {
    Action action = createPopulateTreeArtifactAction();
    scratch.overwriteFile("archiveManifest.txt", "archive_members/dirA/memberA", "archive_members/dirB/memberB");
    ArrayList<Artifact> treeFileArtifacts = new ArrayList<Artifact>();
    ActionExecutionContext executionContext = actionExecutionContext(treeFileArtifacts);
    action.execute(executionContext);
    // We check whether the parent directory structures of output TreeFileArtifacts exist even
    // though the spawn is not executed (the SpawnActionContext is mocked out).
    assertThat(treeFileArtifacts).hasSize(2);
    for (Artifact treeFileArtifact : treeFileArtifacts) {
        assertThat(treeFileArtifact.getPath().getParentDirectory().exists()).isTrue();
        assertThat(treeFileArtifact.getPath().exists()).isFalse();
    }
}
Also used : Action(com.google.devtools.build.lib.actions.Action) ArrayList(java.util.ArrayList) ActionExecutionContext(com.google.devtools.build.lib.actions.ActionExecutionContext) SpecialArtifact(com.google.devtools.build.lib.actions.Artifact.SpecialArtifact) Artifact(com.google.devtools.build.lib.actions.Artifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) Test(org.junit.Test)

Aggregations

ActionExecutionContext (com.google.devtools.build.lib.actions.ActionExecutionContext)24 Test (org.junit.Test)19 Artifact (com.google.devtools.build.lib.actions.Artifact)17 ActionExecutionException (com.google.devtools.build.lib.actions.ActionExecutionException)13 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)13 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)13 IOException (java.io.IOException)12 BuildFailedException (com.google.devtools.build.lib.actions.BuildFailedException)10 Action (com.google.devtools.build.lib.actions.Action)7 ActionInputHelper.treeFileArtifact (com.google.devtools.build.lib.actions.ActionInputHelper.treeFileArtifact)7 ImmutableList (com.google.common.collect.ImmutableList)4 StoredEventHandler (com.google.devtools.build.lib.events.StoredEventHandler)4 TestExecutorBuilder (com.google.devtools.build.lib.exec.util.TestExecutorBuilder)4 List (java.util.List)4 Executor (com.google.devtools.build.lib.actions.Executor)3 FileOutErr (com.google.devtools.build.lib.util.io.FileOutErr)3 ArrayList (java.util.ArrayList)3 TestAction (com.google.devtools.build.lib.actions.util.TestAction)2 Collection (java.util.Collection)2 Before (org.junit.Before)2