Search in sources :

Example 1 with ArtifactExpander

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

the class CustomCommandLineTest method testJoinExpandedTreeArtifactExecPath.

@Test
public void testJoinExpandedTreeArtifactExecPath() {
    Artifact treeArtifact = createTreeArtifact("myTreeArtifact");
    CommandLine commandLine = CustomCommandLine.builder().add("hello").addJoinExpandedTreeArtifactExecPath(":", treeArtifact).build();
    assertThat(commandLine.arguments()).containsExactly("hello", "JoinExpandedTreeArtifactExecPathsArg{ delimiter: :, treeArtifact: myTreeArtifact}");
    final Iterable<TreeFileArtifact> treeFileArtifacts = ImmutableList.of(createTreeFileArtifact(treeArtifact, "children/child1"), createTreeFileArtifact(treeArtifact, "children/child2"));
    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);
                }
            }
        }
    };
    assertThat(commandLine.arguments(artifactExpander)).containsExactly("hello", "myTreeArtifact/children/child1:myTreeArtifact/children/child2");
}
Also used : TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) CommandLine(com.google.devtools.build.lib.analysis.actions.CommandLine) CustomCommandLine(com.google.devtools.build.lib.analysis.actions.CustomCommandLine) ArtifactExpander(com.google.devtools.build.lib.actions.Artifact.ArtifactExpander) Collection(java.util.Collection) SpecialArtifact(com.google.devtools.build.lib.actions.Artifact.SpecialArtifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) Test(org.junit.Test)

Example 2 with ArtifactExpander

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

the class CppModuleMapAction method newDeterministicWriter.

@Override
public DeterministicWriter newDeterministicWriter(ActionExecutionContext ctx) {
    final ArtifactExpander artifactExpander = ctx.getArtifactExpander();
    return new DeterministicWriter() {

        @Override
        public void writeOutputFile(OutputStream out) throws IOException {
            StringBuilder content = new StringBuilder();
            PathFragment fragment = cppModuleMap.getArtifact().getExecPath();
            int segmentsToExecPath = fragment.segmentCount() - 1;
            // For details about the different header types, see:
            // http://clang.llvm.org/docs/Modules.html#header-declaration
            String leadingPeriods = moduleMapHomeIsCwd ? "" : Strings.repeat("../", segmentsToExecPath);
            content.append("module \"").append(cppModuleMap.getName()).append("\" {\n");
            content.append("  export *\n");
            HashSet<PathFragment> deduper = new HashSet<>();
            for (Artifact artifact : expandedHeaders(artifactExpander, publicHeaders)) {
                appendHeader(content, "", artifact.getExecPath(), leadingPeriods, /*canCompile=*/
                true, deduper);
            }
            for (Artifact artifact : expandedHeaders(artifactExpander, privateHeaders)) {
                appendHeader(content, "private", artifact.getExecPath(), leadingPeriods, /*canCompile=*/
                true, deduper);
            }
            for (PathFragment additionalExportedHeader : additionalExportedHeaders) {
                appendHeader(content, "", additionalExportedHeader, leadingPeriods, /*canCompile*/
                false, deduper);
            }
            for (CppModuleMap dep : dependencies) {
                content.append("  use \"").append(dep.getName()).append("\"\n");
            }
            content.append("}");
            if (externDependencies) {
                for (CppModuleMap dep : dependencies) {
                    content.append("\nextern module \"").append(dep.getName()).append("\" \"").append(leadingPeriods).append(dep.getArtifact().getExecPath()).append("\"");
                }
            }
            out.write(content.toString().getBytes(StandardCharsets.ISO_8859_1));
        }
    };
}
Also used : ArtifactExpander(com.google.devtools.build.lib.actions.Artifact.ArtifactExpander) OutputStream(java.io.OutputStream) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) Fingerprint(com.google.devtools.build.lib.util.Fingerprint) Artifact(com.google.devtools.build.lib.actions.Artifact) HashSet(java.util.HashSet)

Example 3 with ArtifactExpander

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

Aggregations

ArtifactExpander (com.google.devtools.build.lib.actions.Artifact.ArtifactExpander)3 Artifact (com.google.devtools.build.lib.actions.Artifact)2 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)2 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)2 Collection (java.util.Collection)2 ActionExecutionContext (com.google.devtools.build.lib.actions.ActionExecutionContext)1 Executor (com.google.devtools.build.lib.actions.Executor)1 CommandLine (com.google.devtools.build.lib.analysis.actions.CommandLine)1 CustomCommandLine (com.google.devtools.build.lib.analysis.actions.CustomCommandLine)1 TestExecutorBuilder (com.google.devtools.build.lib.exec.util.TestExecutorBuilder)1 Fingerprint (com.google.devtools.build.lib.util.Fingerprint)1 FileOutErr (com.google.devtools.build.lib.util.io.FileOutErr)1 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)1 OutputStream (java.io.OutputStream)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1