Search in sources :

Example 1 with ActionInputFileCache

use of com.google.devtools.build.lib.actions.ActionInputFileCache 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 ActionInputFileCache

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

the class SpawnInputExpanderTest method testRunfilesSymlink.

@Test
public void testRunfilesSymlink() throws Exception {
    Artifact artifact = new Artifact(fs.getPath("/root/dir/file"), Root.asSourceRoot(fs.getPath("/root")));
    Runfiles runfiles = new Runfiles.Builder("workspace").addSymlink(new PathFragment("symlink"), artifact).build();
    RunfilesSupplier supplier = new RunfilesSupplierImpl(new PathFragment("runfiles"), runfiles);
    ActionInputFileCache mockCache = Mockito.mock(ActionInputFileCache.class);
    Mockito.when(mockCache.isFile(artifact)).thenReturn(true);
    expander.addRunfilesToInputs(inputMappings, supplier, mockCache);
    assertThat(inputMappings).hasSize(1);
    assertThat(inputMappings).containsEntry(new PathFragment("runfiles/workspace/symlink"), artifact);
}
Also used : Runfiles(com.google.devtools.build.lib.analysis.Runfiles) ActionInputFileCache(com.google.devtools.build.lib.actions.ActionInputFileCache) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) RunfilesSupplierImpl(com.google.devtools.build.lib.analysis.RunfilesSupplierImpl) Artifact(com.google.devtools.build.lib.actions.Artifact) EmptyRunfilesSupplier(com.google.devtools.build.lib.actions.EmptyRunfilesSupplier) RunfilesSupplier(com.google.devtools.build.lib.actions.RunfilesSupplier) Test(org.junit.Test)

Example 3 with ActionInputFileCache

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

the class SpawnInputExpanderTest method testRunfilesRootSymlink.

@Test
public void testRunfilesRootSymlink() throws Exception {
    Artifact artifact = new Artifact(fs.getPath("/root/dir/file"), Root.asSourceRoot(fs.getPath("/root")));
    Runfiles runfiles = new Runfiles.Builder("workspace").addRootSymlink(new PathFragment("symlink"), artifact).build();
    RunfilesSupplier supplier = new RunfilesSupplierImpl(new PathFragment("runfiles"), runfiles);
    ActionInputFileCache mockCache = Mockito.mock(ActionInputFileCache.class);
    Mockito.when(mockCache.isFile(artifact)).thenReturn(true);
    expander.addRunfilesToInputs(inputMappings, supplier, mockCache);
    assertThat(inputMappings).hasSize(2);
    assertThat(inputMappings).containsEntry(new PathFragment("runfiles/symlink"), artifact);
    // If there's no other entry, Runfiles adds an empty file in the workspace to make sure the
    // directory gets created.
    assertThat(inputMappings).containsEntry(new PathFragment("runfiles/workspace/.runfile"), SpawnInputExpander.EMPTY_FILE);
}
Also used : Runfiles(com.google.devtools.build.lib.analysis.Runfiles) ActionInputFileCache(com.google.devtools.build.lib.actions.ActionInputFileCache) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) RunfilesSupplierImpl(com.google.devtools.build.lib.analysis.RunfilesSupplierImpl) Artifact(com.google.devtools.build.lib.actions.Artifact) EmptyRunfilesSupplier(com.google.devtools.build.lib.actions.EmptyRunfilesSupplier) RunfilesSupplier(com.google.devtools.build.lib.actions.RunfilesSupplier) Test(org.junit.Test)

Example 4 with ActionInputFileCache

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

the class SpawnInputExpanderTest method testRunfilesDirectoryNonStrict.

@Test
public void testRunfilesDirectoryNonStrict() throws Exception {
    Artifact artifact = new Artifact(fs.getPath("/root/dir/file"), Root.asSourceRoot(fs.getPath("/root")));
    Runfiles runfiles = new Runfiles.Builder("workspace").addArtifact(artifact).build();
    RunfilesSupplier supplier = new RunfilesSupplierImpl(new PathFragment("runfiles"), runfiles);
    ActionInputFileCache mockCache = Mockito.mock(ActionInputFileCache.class);
    Mockito.when(mockCache.isFile(artifact)).thenReturn(false);
    expander = new SpawnInputExpander(/*strict=*/
    false);
    expander.addRunfilesToInputs(inputMappings, supplier, mockCache);
    assertThat(inputMappings).hasSize(1);
    assertThat(inputMappings).containsEntry(new PathFragment("runfiles/workspace/dir/file"), artifact);
}
Also used : Runfiles(com.google.devtools.build.lib.analysis.Runfiles) ActionInputFileCache(com.google.devtools.build.lib.actions.ActionInputFileCache) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) RunfilesSupplierImpl(com.google.devtools.build.lib.analysis.RunfilesSupplierImpl) Artifact(com.google.devtools.build.lib.actions.Artifact) EmptyRunfilesSupplier(com.google.devtools.build.lib.actions.EmptyRunfilesSupplier) RunfilesSupplier(com.google.devtools.build.lib.actions.RunfilesSupplier) Test(org.junit.Test)

Example 5 with ActionInputFileCache

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

the class SpawnInputExpanderTest method testRunfilesDirectoryStrict.

@Test
public void testRunfilesDirectoryStrict() throws Exception {
    Artifact artifact = new Artifact(fs.getPath("/root/dir/file"), Root.asSourceRoot(fs.getPath("/root")));
    Runfiles runfiles = new Runfiles.Builder("workspace").addArtifact(artifact).build();
    RunfilesSupplier supplier = new RunfilesSupplierImpl(new PathFragment("runfiles"), runfiles);
    ActionInputFileCache mockCache = Mockito.mock(ActionInputFileCache.class);
    Mockito.when(mockCache.isFile(artifact)).thenReturn(false);
    try {
        expander.addRunfilesToInputs(inputMappings, supplier, mockCache);
        fail();
    } catch (IOException expected) {
        assertThat(expected.getMessage().contains("Not a file: /root/dir/file")).isTrue();
    }
}
Also used : Runfiles(com.google.devtools.build.lib.analysis.Runfiles) ActionInputFileCache(com.google.devtools.build.lib.actions.ActionInputFileCache) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) IOException(java.io.IOException) RunfilesSupplierImpl(com.google.devtools.build.lib.analysis.RunfilesSupplierImpl) Artifact(com.google.devtools.build.lib.actions.Artifact) EmptyRunfilesSupplier(com.google.devtools.build.lib.actions.EmptyRunfilesSupplier) RunfilesSupplier(com.google.devtools.build.lib.actions.RunfilesSupplier) Test(org.junit.Test)

Aggregations

ActionInputFileCache (com.google.devtools.build.lib.actions.ActionInputFileCache)9 Artifact (com.google.devtools.build.lib.actions.Artifact)8 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)7 Test (org.junit.Test)7 EmptyRunfilesSupplier (com.google.devtools.build.lib.actions.EmptyRunfilesSupplier)6 RunfilesSupplier (com.google.devtools.build.lib.actions.RunfilesSupplier)6 Runfiles (com.google.devtools.build.lib.analysis.Runfiles)6 RunfilesSupplierImpl (com.google.devtools.build.lib.analysis.RunfilesSupplierImpl)6 BuildFailedException (com.google.devtools.build.lib.actions.BuildFailedException)2 Executor (com.google.devtools.build.lib.actions.Executor)2 Path (com.google.devtools.build.lib.vfs.Path)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Range (com.google.common.collect.Range)1 HashCode (com.google.common.hash.HashCode)1 Action (com.google.devtools.build.lib.actions.Action)1 ActionCacheChecker (com.google.devtools.build.lib.actions.ActionCacheChecker)1 ActionExecutionContext (com.google.devtools.build.lib.actions.ActionExecutionContext)1