use of com.google.devtools.build.lib.analysis.actions.CustomCommandLine in project bazel by bazelbuild.
the class DexArchiveAspect method createDesugarAction.
private static Artifact createDesugarAction(RuleContext ruleContext, String desugarPrereqName, Artifact jar, ImmutableList<Artifact> bootclasspath, NestedSet<Artifact> classpath, Artifact result) {
CustomCommandLine args = new CustomCommandLine.Builder().addExecPath("--input", jar).addExecPath("--output", result).addBeforeEachExecPath("--classpath_entry", classpath).addBeforeEachExecPath("--bootclasspath_entry", bootclasspath).build();
// Just use params file, since classpaths can get long
Artifact paramFile = ruleContext.getDerivedArtifact(ParameterFile.derivePath(result.getRootRelativePath()), result.getRoot());
ruleContext.registerAction(new ParameterFileWriteAction(ruleContext.getActionOwner(), paramFile, args, ParameterFile.ParameterFileType.UNQUOTED, ISO_8859_1));
ruleContext.registerAction(new SpawnAction.Builder().setExecutable(ruleContext.getExecutablePrerequisite(desugarPrereqName, Mode.HOST)).addArgument("@" + paramFile.getExecPathString()).addInput(jar).addInput(paramFile).addInputs(bootclasspath).addTransitiveInputs(classpath).addOutput(result).setMnemonic("Desugar").setProgressMessage("Desugaring " + jar.prettyPrint() + " for Android").build(ruleContext));
return result;
}
use of com.google.devtools.build.lib.analysis.actions.CustomCommandLine in project bazel by bazelbuild.
the class LegacyCompilationSupport method registerCompileActionTemplate.
/**
* Registers a SpawnActionTemplate to compile the source file tree artifact, {@code sourceFiles},
* which can contain multiple concrete source files unknown at analysis time. At execution time,
* the SpawnActionTemplate will register one ObjcCompile action for each individual source file
* under {@code sourceFiles}.
*
* <p>Note that this method currently does not support code coverage and sources other than ObjC
* sources.
*
* @param sourceFiles tree artifact containing source files to compile
* @param objFiles tree artifact containing object files compiled from {@code sourceFiles}
* @param objcProvider ObjcProvider instance for this invocation
* @param priorityHeaders priority headers to be included before the dependency headers
* @param moduleMap the module map generated from the associated headers
* @param compilationArtifacts the CompilationArtifacts instance for this invocation
* @param otherFlags extra compilation flags to add to the compile action command line
*/
private void registerCompileActionTemplate(Artifact sourceFiles, Artifact objFiles, ObjcProvider objcProvider, Iterable<PathFragment> priorityHeaders, Optional<CppModuleMap> moduleMap, CompilationArtifacts compilationArtifacts, Iterable<String> otherFlags) {
CustomCommandLine commandLine = compileActionCommandLine(sourceFiles, objFiles, objcProvider, priorityHeaders, moduleMap, compilationArtifacts.getPchFile(), Optional.<Artifact>absent(), otherFlags, /* runCodeCoverage=*/
false, /* isCPlusPlusSource=*/
false);
AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);
Platform platform = appleConfiguration.getSingleArchPlatform();
NestedSet<Artifact> moduleMapInputs = NestedSetBuilder.emptySet(Order.STABLE_ORDER);
if (objcConfiguration.moduleMapsEnabled()) {
moduleMapInputs = objcProvider.get(MODULE_MAP);
}
ruleContext.registerAction(new SpawnActionTemplate.Builder(sourceFiles, objFiles).setMnemonics("ObjcCompileActionTemplate", "ObjcCompile").setExecutable(xcrunwrapper(ruleContext)).setCommandLineTemplate(commandLine).setEnvironment(ObjcRuleClasses.appleToolchainEnvironment(appleConfiguration, platform)).setExecutionInfo(ObjcRuleClasses.darwinActionExecutionRequirement()).setOutputPathMapper(COMPILE_ACTION_TEMPLATE_OUTPUT_PATH_MAPPER).addCommonTransitiveInputs(objcProvider.get(HEADER)).addCommonTransitiveInputs(moduleMapInputs).addCommonInputs(compilationArtifacts.getPrivateHdrs()).addCommonTransitiveInputs(objcProvider.get(STATIC_FRAMEWORK_FILE)).addCommonTransitiveInputs(objcProvider.get(DYNAMIC_FRAMEWORK_FILE)).addCommonInputs(compilationArtifacts.getPchFile().asSet()).build(ruleContext.getActionOwner()));
}
use of com.google.devtools.build.lib.analysis.actions.CustomCommandLine in project bazel by bazelbuild.
the class CompilationSupport method registerJ2ObjcDeadCodeRemovalActions.
/**
* Registers actions to perform J2Objc dead code removal.
*/
protected void registerJ2ObjcDeadCodeRemovalActions(ObjcProvider objcProvider, J2ObjcMappingFileProvider j2ObjcMappingFileProvider, J2ObjcEntryClassProvider j2ObjcEntryClassProvider) {
NestedSet<String> entryClasses = j2ObjcEntryClassProvider.getEntryClasses();
Artifact pruner = ruleContext.getPrerequisiteArtifact("$j2objc_dead_code_pruner", Mode.HOST);
NestedSet<Artifact> j2ObjcDependencyMappingFiles = j2ObjcMappingFileProvider.getDependencyMappingFiles();
NestedSet<Artifact> j2ObjcHeaderMappingFiles = j2ObjcMappingFileProvider.getHeaderMappingFiles();
NestedSet<Artifact> j2ObjcArchiveSourceMappingFiles = j2ObjcMappingFileProvider.getArchiveSourceMappingFiles();
for (Artifact j2objcArchive : objcProvider.get(ObjcProvider.J2OBJC_LIBRARY)) {
PathFragment paramFilePath = FileSystemUtils.replaceExtension(j2objcArchive.getOwner().toPathFragment(), ".param.j2objc");
Artifact paramFile = ruleContext.getUniqueDirectoryArtifact("_j2objc_pruned", paramFilePath, buildConfiguration.getBinDirectory(ruleContext.getRule().getRepository()));
Artifact prunedJ2ObjcArchive = intermediateArtifacts.j2objcPrunedArchive(j2objcArchive);
Artifact dummyArchive = Iterables.getOnlyElement(ruleContext.getPrerequisite("$dummy_lib", Mode.TARGET, ObjcProvider.class).get(LIBRARY));
CustomCommandLine commandLine = CustomCommandLine.builder().addExecPath("--input_archive", j2objcArchive).addExecPath("--output_archive", prunedJ2ObjcArchive).addExecPath("--dummy_archive", dummyArchive).addExecPath("--xcrunwrapper", xcrunwrapper(ruleContext).getExecutable()).addJoinExecPaths("--dependency_mapping_files", ",", j2ObjcDependencyMappingFiles).addJoinExecPaths("--header_mapping_files", ",", j2ObjcHeaderMappingFiles).addJoinExecPaths("--archive_source_mapping_files", ",", j2ObjcArchiveSourceMappingFiles).add("--entry_classes").add(Joiner.on(",").join(entryClasses)).build();
ruleContext.registerAction(new ParameterFileWriteAction(ruleContext.getActionOwner(), paramFile, commandLine, ParameterFile.ParameterFileType.UNQUOTED, ISO_8859_1));
ruleContext.registerAction(ObjcRuleClasses.spawnAppleEnvActionBuilder(appleConfiguration, appleConfiguration.getSingleArchPlatform()).setMnemonic("DummyPruner").setExecutable(pruner).addInput(dummyArchive).addInput(pruner).addInput(paramFile).addInput(j2objcArchive).addInput(xcrunwrapper(ruleContext).getExecutable()).addTransitiveInputs(j2ObjcDependencyMappingFiles).addTransitiveInputs(j2ObjcHeaderMappingFiles).addTransitiveInputs(j2ObjcArchiveSourceMappingFiles).setCommandLine(CustomCommandLine.builder().addPaths("@%s", paramFile.getExecPath()).build()).addOutput(prunedJ2ObjcArchive).build(ruleContext));
}
}
use of com.google.devtools.build.lib.analysis.actions.CustomCommandLine in project bazel by bazelbuild.
the class CustomCommandLineTest method testArtifactExecPathArgs.
@Test
public void testArtifactExecPathArgs() {
CustomCommandLine cl = CustomCommandLine.builder().addExecPath("--path", artifact1).build();
assertEquals(ImmutableList.of("--path", "dir/file1.txt"), cl.arguments());
}
use of com.google.devtools.build.lib.analysis.actions.CustomCommandLine in project bazel by bazelbuild.
the class CustomCommandLineTest method testTreeFileArtifactArgThrowWithoutSubstitution.
@Test
public void testTreeFileArtifactArgThrowWithoutSubstitution() {
Artifact treeArtifactOne = createTreeArtifact("myArtifact/treeArtifact1");
Artifact treeArtifactTwo = createTreeArtifact("myArtifact/treeArtifact2");
CustomCommandLine commandLineTemplate = CustomCommandLine.builder().addPlaceholderTreeArtifactExecPath("--argOne", treeArtifactOne).addPlaceholderTreeArtifactExecPath("--argTwo", treeArtifactTwo).build();
try {
commandLineTemplate.arguments();
fail("No substitution map provided, expected NullPointerException");
} catch (NullPointerException e) {
// expected
}
}
Aggregations