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 GenRuleConfiguredTargetTest method testOutputDirExpansion.
/** Ensure that variable $(@D) gets expanded correctly in the genrule cmd. */
@Test
public void testOutputDirExpansion() throws Exception {
scratch.file("foo/BUILD", "genrule(name = 'bar',", " srcs = ['bar_in.txt'],", " cmd = 'touch $(@D)',", " outs = ['bar/bar_out.txt'])", "genrule(name = 'baz',", " srcs = ['bar/bar_out.txt'],", " cmd = 'touch $(@D)',", " outs = ['logs/baz_out.txt', 'logs/baz.log'])");
getConfiguredTarget("//foo:bar");
FileConfiguredTarget bazOutTarget = getFileConfiguredTarget("//foo:logs/baz_out.txt");
SpawnAction bazAction = (SpawnAction) getGeneratingAction(bazOutTarget.getArtifact());
// Make sure the expansion for $(@D) results in the
// directory of the BUILD file ("foo"), not the common parent
// directory of the output files ("logs")
String bazExpected = "touch " + bazOutTarget.getArtifact().getExecPath().getParentDirectory().getParentDirectory().getPathString();
assertCommandEquals(bazExpected, bazAction.getArguments().get(2));
assertThat(bazAction.getArguments().get(2)).endsWith("/foo");
getConfiguredTarget("//foo:bar");
Artifact barOut = bazAction.getInputs().iterator().next();
assertTrue(barOut.getExecPath().endsWith(new PathFragment("foo/bar/bar_out.txt")));
SpawnAction barAction = (SpawnAction) getGeneratingAction(barOut);
String barExpected = "touch " + barOut.getExecPath().getParentDirectory().getPathString();
assertCommandEquals(barExpected, barAction.getArguments().get(2));
assertFalse(bazExpected.equals(barExpected));
}
use of com.google.devtools.build.lib.analysis.actions.SpawnAction in project bazel by bazelbuild.
the class GenRuleConfiguredTargetTest method testRequiresDarwin.
@Test
public void testRequiresDarwin() throws Exception {
scratch.file("foo/BUILD", "genrule(name='darwin', srcs=[], outs=['macout'], cmd='', tags=['requires-darwin'])");
SpawnAction action = getSpawnAction("//foo:darwin");
assertThat(action.getExecutionInfo().keySet()).contains("requires-darwin");
// requires-darwin causes /bin/bash to be hard-coded, see CommandHelper.shellPath().
assertThat(action.getCommandFilename()).isEqualTo("/bin/bash");
}
use of com.google.devtools.build.lib.analysis.actions.SpawnAction in project bazel by bazelbuild.
the class GenRuleConfiguredTargetTest method testMakeVarExpansion.
/** Ensure that variable $(CC) gets expanded correctly in the genrule cmd. */
@Test
public void testMakeVarExpansion() throws Exception {
scratch.file("foo/BUILD", "genrule(name = 'bar',", " srcs = ['bar.cc'],", " cmd = '$(CC) -o $(OUTS) $(SRCS) $$shellvar',", " outs = ['bar.o'])");
FileConfiguredTarget barOutTarget = getFileConfiguredTarget("//foo:bar.o");
FileConfiguredTarget barInTarget = getFileConfiguredTarget("//foo:bar.cc");
SpawnAction barAction = (SpawnAction) getGeneratingAction(barOutTarget.getArtifact());
String cc = "" + targetConfig.getFragment(CppConfiguration.class).getCppExecutable();
String expected = cc + " -o " + barOutTarget.getArtifact().getExecPathString() + " " + barInTarget.getArtifact().getRootRelativePath().getPathString() + " $shellvar";
assertCommandEquals(expected, barAction.getArguments().get(2));
}
Aggregations