use of com.google.devtools.build.lib.analysis.actions.SpawnAction in project bazel by bazelbuild.
the class AndroidBinary method singleJarSpawnActionBuilder.
// Adds the appropriate SpawnAction options depending on if SingleJar is a jar or not.
private static SpawnAction.Builder singleJarSpawnActionBuilder(RuleContext ruleContext) {
Artifact singleJar = JavaToolchainProvider.fromRuleContext(ruleContext).getSingleJar();
SpawnAction.Builder builder = new SpawnAction.Builder();
if (singleJar.getFilename().endsWith(".jar")) {
builder.setJarExecutable(ruleContext.getHostConfiguration().getFragment(Jvm.class).getJavaExecutable(), singleJar, JavaToolchainProvider.fromRuleContext(ruleContext).getJvmOptions()).addTransitiveInputs(JavaHelper.getHostJavabaseInputs(ruleContext));
} else {
builder.setExecutable(singleJar);
}
return builder;
}
use of com.google.devtools.build.lib.analysis.actions.SpawnAction in project bazel by bazelbuild.
the class CompilationSupport method registerHeaderScanningActions.
/**
* Creates and registers ObjcHeaderScanning {@link SpawnAction}. Groups all the actions by their
* compilation command line arguments and creates a ObjcHeaderScanning action for each unique one.
*/
protected void registerHeaderScanningActions(ImmutableList<ObjcHeaderThinningInfo> headerThinningInfo, ObjcProvider objcProvider, CompilationArtifacts compilationArtifacts) {
if (headerThinningInfo.isEmpty()) {
return;
}
FilesToRunProvider headerScannerTool = getHeaderThinningToolExecutable();
PrerequisiteArtifacts appleSdks = ruleContext.getPrerequisiteArtifacts(ObjcRuleClasses.APPLE_SDK_ATTRIBUTE, Mode.TARGET);
ListMultimap<ImmutableList<String>, ObjcHeaderThinningInfo> objcHeaderThinningInfoByCommandLine = groupActionsByCommandLine(headerThinningInfo);
// Register a header scanning spawn action for each unique set of command line arguments
for (ImmutableList<String> args : objcHeaderThinningInfoByCommandLine.keySet()) {
SpawnAction.Builder builder = new SpawnAction.Builder().setMnemonic("ObjcHeaderScanning").setExecutable(headerScannerTool).addInputs(appleSdks.list());
CustomCommandLine.Builder cmdLine = CustomCommandLine.builder().add("--arch").add(appleConfiguration.getSingleArchitecture().toLowerCase()).add("--platform").add(appleConfiguration.getSingleArchPlatform().getLowerCaseNameInPlist()).add("--sdk_version").add(appleConfiguration.getSdkVersionForPlatform(appleConfiguration.getSingleArchPlatform()).toStringWithMinimumComponents(2)).add("--xcode_version").add(appleConfiguration.getXcodeVersion().toStringWithMinimumComponents(2)).add("--");
for (ObjcHeaderThinningInfo info : objcHeaderThinningInfoByCommandLine.get(args)) {
cmdLine.addJoinPaths(":", Lists.newArrayList(info.sourceFile.getExecPath(), info.headersListFile.getExecPath()));
builder.addInput(info.sourceFile).addOutput(info.headersListFile);
}
ruleContext.registerAction(builder.setCommandLine(cmdLine.add("--").add(args).build()).addInputs(compilationArtifacts.getPrivateHdrs()).addTransitiveInputs(attributes.hdrs()).addTransitiveInputs(objcProvider.get(ObjcProvider.HEADER)).addInputs(compilationArtifacts.getPchFile().asSet()).addTransitiveInputs(objcProvider.get(ObjcProvider.STATIC_FRAMEWORK_FILE)).addTransitiveInputs(objcProvider.get(ObjcProvider.DYNAMIC_FRAMEWORK_FILE)).build(ruleContext));
}
}
use of com.google.devtools.build.lib.analysis.actions.SpawnAction in project bazel by bazelbuild.
the class SkylarkRuleContextTest method testCreateSpawnActionArgumentsWithExecutableFilesToRunProvider.
@Test
public void testCreateSpawnActionArgumentsWithExecutableFilesToRunProvider() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:androidlib");
evalRuleContextCode(ruleContext, "ruleContext.action(\n" + " inputs = ruleContext.files.srcs,\n" + " outputs = ruleContext.files.srcs,\n" + " arguments = ['--a','--b'],\n" + " executable = ruleContext.executable._jarjar_bin)\n");
SpawnAction action = (SpawnAction) Iterables.getOnlyElement(ruleContext.getRuleContext().getAnalysisEnvironment().getRegisteredActions());
assertThat(action.getCommandFilename()).matches("^.*/jarjar_bin(\\.cmd){0,1}$");
}
use of com.google.devtools.build.lib.analysis.actions.SpawnAction in project bazel by bazelbuild.
the class SkylarkRuleImplementationFunctionsTest method testCreateSpawnActionArgumentsWithExecutable.
@Test
public void testCreateSpawnActionArgumentsWithExecutable() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
evalRuleContextCode(ruleContext, "ruleContext.action(", " inputs = ruleContext.files.srcs,", " outputs = ruleContext.files.srcs,", " arguments = ['--a','--b'],", " executable = ruleContext.files.tools[0])");
SpawnAction action = (SpawnAction) Iterables.getOnlyElement(ruleContext.getRuleContext().getAnalysisEnvironment().getRegisteredActions());
assertArtifactFilenames(action.getInputs(), "a.txt", "b.img", "t.exe");
assertArtifactFilenames(action.getOutputs(), "a.txt", "b.img");
MoreAsserts.assertContainsSublist(action.getArguments(), "foo/t.exe", "--a", "--b");
}
Aggregations