Search in sources :

Example 1 with OutputPathMapper

use of com.google.devtools.build.lib.analysis.actions.SpawnActionTemplate.OutputPathMapper in project bazel by bazelbuild.

the class SpawnActionTemplateTest method testExpandedAction_illegalOutputPath.

@Test
public void testExpandedAction_illegalOutputPath() throws Exception {
    Artifact inputTreeArtifact = createInputTreeArtifact();
    Artifact outputTreeArtifact = createOutputTreeArtifact();
    Iterable<TreeFileArtifact> inputTreeFileArtifacts = createInputTreeFileArtifacts(inputTreeArtifact);
    SpawnActionTemplate.Builder builder = builder(inputTreeArtifact, outputTreeArtifact).setExecutable(new PathFragment("/bin/cp")).setCommandLineTemplate(createSimpleCommandLineTemplate(inputTreeArtifact, outputTreeArtifact));
    OutputPathMapper mapper = new OutputPathMapper() {

        @Override
        public PathFragment parentRelativeOutputPath(TreeFileArtifact inputTreeFileArtifact) {
            return new PathFragment("//absolute/" + inputTreeFileArtifact.getParentRelativePath());
        }
    };
    SpawnActionTemplate actionTemplate = builder.setOutputPathMapper(mapper).build(ActionsTestUtil.NULL_ACTION_OWNER);
    try {
        actionTemplate.generateActionForInputArtifacts(inputTreeFileArtifacts, ArtifactOwner.NULL_OWNER);
        fail("Absolute output paths not allowed, expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    // expected
    }
    mapper = new OutputPathMapper() {

        @Override
        public PathFragment parentRelativeOutputPath(TreeFileArtifact inputTreeFileArtifact) {
            return new PathFragment("../" + inputTreeFileArtifact.getParentRelativePath());
        }
    };
    actionTemplate = builder.setOutputPathMapper(mapper).build(ActionsTestUtil.NULL_ACTION_OWNER);
    try {
        actionTemplate.generateActionForInputArtifacts(inputTreeFileArtifacts, ArtifactOwner.NULL_OWNER);
        fail("Output paths containing '..' not allowed, expected IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    // expected
    }
}
Also used : TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) OutputPathMapper(com.google.devtools.build.lib.analysis.actions.SpawnActionTemplate.OutputPathMapper) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) 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 2 with OutputPathMapper

use of com.google.devtools.build.lib.analysis.actions.SpawnActionTemplate.OutputPathMapper in project bazel by bazelbuild.

the class ActionTemplateExpansionFunctionTest method testThrowsOnArtifactPrefixConflict.

@Test
public void testThrowsOnArtifactPrefixConflict() throws Exception {
    Artifact inputTreeArtifact = createAndPopulateTreeArtifact("inputTreeArtifact", "child0", "child1", "child2");
    Artifact outputTreeArtifact = createTreeArtifact("outputTreeArtifact");
    OutputPathMapper mapper = new OutputPathMapper() {

        private int i = 0;

        @Override
        public PathFragment parentRelativeOutputPath(TreeFileArtifact inputTreeFileArtifact) {
            PathFragment path;
            switch(i) {
                case 0:
                    path = new PathFragment("path_prefix");
                    break;
                case 1:
                    path = new PathFragment("path_prefix/conflict");
                    break;
                default:
                    path = inputTreeFileArtifact.getParentRelativePath();
            }
            ++i;
            return path;
        }
    };
    SpawnActionTemplate spawnActionTemplate = new SpawnActionTemplate.Builder(inputTreeArtifact, outputTreeArtifact).setExecutable(new PathFragment("/bin/cp")).setCommandLineTemplate(CustomCommandLine.builder().build()).setOutputPathMapper(mapper).build(ActionsTestUtil.NULL_ACTION_OWNER);
    try {
        evaluate(spawnActionTemplate);
        fail("Expected ArtifactPrefixConflictException");
    } catch (ArtifactPrefixConflictException e) {
    // Expected ArtifactPrefixConflictException
    }
}
Also used : TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) OutputPathMapper(com.google.devtools.build.lib.analysis.actions.SpawnActionTemplate.OutputPathMapper) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) SpawnActionTemplate(com.google.devtools.build.lib.analysis.actions.SpawnActionTemplate) ArtifactPrefixConflictException(com.google.devtools.build.lib.actions.ArtifactPrefixConflictException) SpecialArtifact(com.google.devtools.build.lib.actions.Artifact.SpecialArtifact) Artifact(com.google.devtools.build.lib.actions.Artifact) OwnedArtifact(com.google.devtools.build.lib.skyframe.ArtifactSkyKey.OwnedArtifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) Test(org.junit.Test)

Example 3 with OutputPathMapper

use of com.google.devtools.build.lib.analysis.actions.SpawnActionTemplate.OutputPathMapper in project bazel by bazelbuild.

the class ActionTemplateExpansionFunctionTest method testThrowsOnActionConflict.

@Test
public void testThrowsOnActionConflict() throws Exception {
    Artifact inputTreeArtifact = createAndPopulateTreeArtifact("inputTreeArtifact", "child0", "child1", "child2");
    Artifact outputTreeArtifact = createTreeArtifact("outputTreeArtifact");
    OutputPathMapper mapper = new OutputPathMapper() {

        @Override
        public PathFragment parentRelativeOutputPath(TreeFileArtifact inputTreeFileArtifact) {
            return new PathFragment("conflict_path");
        }
    };
    SpawnActionTemplate spawnActionTemplate = new SpawnActionTemplate.Builder(inputTreeArtifact, outputTreeArtifact).setExecutable(new PathFragment("/bin/cp")).setCommandLineTemplate(CustomCommandLine.builder().build()).setOutputPathMapper(mapper).build(ActionsTestUtil.NULL_ACTION_OWNER);
    try {
        evaluate(spawnActionTemplate);
        fail("Expected ActionConflictException");
    } catch (ActionConflictException e) {
    // Expected ActionConflictException
    }
}
Also used : TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) ActionConflictException(com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException) OutputPathMapper(com.google.devtools.build.lib.analysis.actions.SpawnActionTemplate.OutputPathMapper) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) SpawnActionTemplate(com.google.devtools.build.lib.analysis.actions.SpawnActionTemplate) SpecialArtifact(com.google.devtools.build.lib.actions.Artifact.SpecialArtifact) Artifact(com.google.devtools.build.lib.actions.Artifact) OwnedArtifact(com.google.devtools.build.lib.skyframe.ArtifactSkyKey.OwnedArtifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) Test(org.junit.Test)

Aggregations

Artifact (com.google.devtools.build.lib.actions.Artifact)3 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)3 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)3 OutputPathMapper (com.google.devtools.build.lib.analysis.actions.SpawnActionTemplate.OutputPathMapper)3 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)3 Test (org.junit.Test)3 SpawnActionTemplate (com.google.devtools.build.lib.analysis.actions.SpawnActionTemplate)2 OwnedArtifact (com.google.devtools.build.lib.skyframe.ArtifactSkyKey.OwnedArtifact)2 ArtifactPrefixConflictException (com.google.devtools.build.lib.actions.ArtifactPrefixConflictException)1 ActionConflictException (com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException)1