Search in sources :

Example 1 with ActionExecutionContext

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

the class TreeArtifactBuildTest method testInputTreeArtifactPerActionFileCache.

@Test
public void testInputTreeArtifactPerActionFileCache() throws Exception {
    TouchingTestAction actionOne = new TouchingTestAction(outOneFileOne, outOneFileTwo);
    registerAction(actionOne);
    final Artifact normalOutput = createDerivedArtifact("normal/out");
    Action testAction = new TestAction(TestAction.NO_EFFECT, ImmutableList.of(outOne), ImmutableList.of(normalOutput)) {

        @Override
        public void execute(ActionExecutionContext actionExecutionContext) {
            try {
                // Check the file cache for input TreeFileArtifacts.
                ActionInputFileCache fileCache = actionExecutionContext.getActionInputFileCache();
                assertThat(fileCache.getDigest(outOneFileOne)).isNotNull();
                assertThat(fileCache.getDigest(outOneFileTwo)).isNotNull();
                // Touch the action output.
                touchFile(normalOutput);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
    registerAction(testAction);
    buildArtifact(normalOutput);
}
Also used : ActionInputFileCache(com.google.devtools.build.lib.actions.ActionInputFileCache) Action(com.google.devtools.build.lib.actions.Action) TestAction(com.google.devtools.build.lib.actions.util.TestAction) DummyAction(com.google.devtools.build.lib.actions.util.TestAction.DummyAction) 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) ActionInputHelper.treeFileArtifact(com.google.devtools.build.lib.actions.ActionInputHelper.treeFileArtifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) ActionExecutionException(com.google.devtools.build.lib.actions.ActionExecutionException) BuildFailedException(com.google.devtools.build.lib.actions.BuildFailedException) IOException(java.io.IOException) TestAction(com.google.devtools.build.lib.actions.util.TestAction) Test(org.junit.Test)

Example 2 with ActionExecutionContext

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

the class TreeArtifactBuildTest method testDigestInjection.

// This is more a smoke test than anything, because it turns out that:
// 1) there is no easy way to turn fast digests on/off for these test cases, and
// 2) injectDigest() doesn't really complain if you inject bad digests or digests
// for nonexistent files. Instead some weird error shows up down the line.
// In fact, there are no tests for injectDigest anywhere in the codebase.
// So all we're really testing here is that injectDigest() doesn't throw a weird exception.
// TODO(bazel-team): write real tests for injectDigest, here and elsewhere.
@Test
public void testDigestInjection() throws Exception {
    TreeArtifactTestAction action = new TreeArtifactTestAction(outOne) {

        @Override
        public void execute(ActionExecutionContext actionExecutionContext) throws ActionExecutionException {
            try {
                writeFile(outOneFileOne, "one");
                writeFile(outOneFileTwo, "two");
                MetadataHandler md = actionExecutionContext.getMetadataHandler();
                FileStatus stat = outOneFileOne.getPath().stat(Symlinks.NOFOLLOW);
                md.injectDigest(outOneFileOne, new InjectedStat(stat.getLastModifiedTime(), stat.getSize(), stat.getNodeId()), Hashing.md5().hashString("one", Charset.forName("UTF-8")).asBytes());
                stat = outOneFileTwo.getPath().stat(Symlinks.NOFOLLOW);
                md.injectDigest(outOneFileTwo, new InjectedStat(stat.getLastModifiedTime(), stat.getSize(), stat.getNodeId()), Hashing.md5().hashString("two", Charset.forName("UTF-8")).asBytes());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
    registerAction(action);
    buildArtifact(action.getSoleOutput());
}
Also used : FileStatus(com.google.devtools.build.lib.vfs.FileStatus) ActionExecutionContext(com.google.devtools.build.lib.actions.ActionExecutionContext) InjectedStat(com.google.devtools.build.lib.actions.cache.InjectedStat) MetadataHandler(com.google.devtools.build.lib.actions.cache.MetadataHandler) ActionExecutionException(com.google.devtools.build.lib.actions.ActionExecutionException) BuildFailedException(com.google.devtools.build.lib.actions.BuildFailedException) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with ActionExecutionContext

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

the class TreeArtifactBuildTest method testOutputsAreReadOnlyAndExecutable.

@Test
public void testOutputsAreReadOnlyAndExecutable() throws Exception {
    final Artifact out = createTreeArtifact("output");
    TreeArtifactTestAction action = new TreeArtifactTestAction(out) {

        @Override
        public void execute(ActionExecutionContext actionExecutionContext) {
            try {
                writeFile(out.getPath().getChild("one"), "one");
                writeFile(out.getPath().getChild("two"), "two");
                writeFile(out.getPath().getChild("three").getChild("four"), "three/four");
                registerOutput(actionExecutionContext, "one");
                registerOutput(actionExecutionContext, "two");
                registerOutput(actionExecutionContext, "three/four");
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
    registerAction(action);
    buildArtifact(action.getSoleOutput());
    checkDirectoryPermissions(out.getPath());
    checkFilePermissions(out.getPath().getChild("one"));
    checkFilePermissions(out.getPath().getChild("two"));
    checkDirectoryPermissions(out.getPath().getChild("three"));
    checkFilePermissions(out.getPath().getChild("three").getChild("four"));
}
Also used : 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) ActionInputHelper.treeFileArtifact(com.google.devtools.build.lib.actions.ActionInputHelper.treeFileArtifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) ActionExecutionException(com.google.devtools.build.lib.actions.ActionExecutionException) BuildFailedException(com.google.devtools.build.lib.actions.BuildFailedException) IOException(java.io.IOException) Test(org.junit.Test)

Example 4 with ActionExecutionContext

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

the class TreeArtifactBuildTest method testRelativeSymlinkTraversingOutsideOfTreeArtifactRejected.

@Test
public void testRelativeSymlinkTraversingOutsideOfTreeArtifactRejected() throws Exception {
    // Failure expected
    StoredEventHandler storingEventHandler = new StoredEventHandler();
    reporter.removeHandler(failFastHandler);
    reporter.addHandler(storingEventHandler);
    final Artifact out = createTreeArtifact("output");
    TreeArtifactTestAction action = new TreeArtifactTestAction(out) {

        @Override
        public void execute(ActionExecutionContext actionExecutionContext) {
            try {
                writeFile(out.getPath().getChild("one"), "one");
                writeFile(out.getPath().getChild("two"), "two");
                FileSystemUtils.ensureSymbolicLink(out.getPath().getChild("links").getChild("link"), "../../output/random/pointer");
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
    registerAction(action);
    try {
        buildArtifact(action.getSoleOutput());
        // Should have thrown
        fail();
    } catch (BuildFailedException e) {
        List<Event> errors = ImmutableList.copyOf(Iterables.filter(storingEventHandler.getEvents(), IS_ERROR_EVENT));
        assertThat(errors).hasSize(2);
        assertThat(errors.get(0).getMessage()).contains("A TreeArtifact may not contain relative symlinks whose target paths traverse " + "outside of the TreeArtifact");
        assertThat(errors.get(1).getMessage()).contains("not all outputs were created or valid");
    }
}
Also used : StoredEventHandler(com.google.devtools.build.lib.events.StoredEventHandler) BuildFailedException(com.google.devtools.build.lib.actions.BuildFailedException) ActionExecutionContext(com.google.devtools.build.lib.actions.ActionExecutionContext) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) SpecialArtifact(com.google.devtools.build.lib.actions.Artifact.SpecialArtifact) Artifact(com.google.devtools.build.lib.actions.Artifact) ActionInputHelper.treeFileArtifact(com.google.devtools.build.lib.actions.ActionInputHelper.treeFileArtifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) ActionExecutionException(com.google.devtools.build.lib.actions.ActionExecutionException) BuildFailedException(com.google.devtools.build.lib.actions.BuildFailedException) IOException(java.io.IOException) Test(org.junit.Test)

Example 5 with ActionExecutionContext

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

the class SymlinkActionTest method testSymlink.

@Test
public void testSymlink() throws Exception {
    Executor executor = new TestExecutorBuilder(directories, null).build();
    action.execute(new ActionExecutionContext(executor, null, null, null, ImmutableMap.<String, String>of(), null));
    assertTrue(output.isSymbolicLink());
    assertEquals(input, output.resolveSymbolicLinks());
    assertEquals(inputArtifact, action.getPrimaryInput());
    assertEquals(outputArtifact, action.getPrimaryOutput());
}
Also used : TestExecutorBuilder(com.google.devtools.build.lib.exec.util.TestExecutorBuilder) Executor(com.google.devtools.build.lib.actions.Executor) ActionExecutionContext(com.google.devtools.build.lib.actions.ActionExecutionContext) 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