Search in sources :

Example 11 with SpawnAction

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;
}
Also used : Jvm(com.google.devtools.build.lib.rules.java.Jvm) SpawnAction(com.google.devtools.build.lib.analysis.actions.SpawnAction) Builder(com.google.devtools.build.lib.analysis.actions.SpawnAction.Builder) MultimapBuilder(com.google.common.collect.MultimapBuilder) Builder(com.google.devtools.build.lib.analysis.actions.SpawnAction.Builder) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) DeployArchiveBuilder(com.google.devtools.build.lib.rules.java.DeployArchiveBuilder) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 12 with SpawnAction

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));
    }
}
Also used : CustomCommandLine(com.google.devtools.build.lib.analysis.actions.CustomCommandLine) FilesToRunProvider(com.google.devtools.build.lib.analysis.FilesToRunProvider) SpawnAction(com.google.devtools.build.lib.analysis.actions.SpawnAction) PrerequisiteArtifacts(com.google.devtools.build.lib.analysis.PrerequisiteArtifacts) ImmutableList(com.google.common.collect.ImmutableList)

Example 13 with SpawnAction

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));
}
Also used : SpawnAction(com.google.devtools.build.lib.analysis.actions.SpawnAction) FileConfiguredTarget(com.google.devtools.build.lib.analysis.FileConfiguredTarget) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 14 with SpawnAction

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");
}
Also used : SpawnAction(com.google.devtools.build.lib.analysis.actions.SpawnAction) Test(org.junit.Test)

Example 15 with SpawnAction

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));
}
Also used : SpawnAction(com.google.devtools.build.lib.analysis.actions.SpawnAction) FileConfiguredTarget(com.google.devtools.build.lib.analysis.FileConfiguredTarget) Test(org.junit.Test)

Aggregations

SpawnAction (com.google.devtools.build.lib.analysis.actions.SpawnAction)19 Test (org.junit.Test)15 Artifact (com.google.devtools.build.lib.actions.Artifact)9 SkylarkRuleContext (com.google.devtools.build.lib.rules.SkylarkRuleContext)5 FileConfiguredTarget (com.google.devtools.build.lib.analysis.FileConfiguredTarget)4 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)2 RuleConfiguredTargetBuilder (com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder)2 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)2 Jvm (com.google.devtools.build.lib.rules.java.Jvm)2 ImmutableList (com.google.common.collect.ImmutableList)1 MultimapBuilder (com.google.common.collect.MultimapBuilder)1 FilesToRunProvider (com.google.devtools.build.lib.analysis.FilesToRunProvider)1 PrerequisiteArtifacts (com.google.devtools.build.lib.analysis.PrerequisiteArtifacts)1 CustomCommandLine (com.google.devtools.build.lib.analysis.actions.CustomCommandLine)1 Builder (com.google.devtools.build.lib.analysis.actions.SpawnAction.Builder)1 BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)1 DeployArchiveBuilder (com.google.devtools.build.lib.rules.java.DeployArchiveBuilder)1 JavaRuleOutputJarsProvider (com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider)1 OutputJar (com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider.OutputJar)1 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)1