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");
}
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));
}
};
}
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);
}
Aggregations