Search in sources :

Example 1 with SpawnAction

use of com.google.devtools.build.lib.analysis.actions.SpawnAction in project bazel by bazelbuild.

the class SkylarkRuleImplementationFunctionsTest method testCreateSpawnActionShellCommandList.

@Test
public void testCreateSpawnActionShellCommandList() throws Exception {
    SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
    evalRuleContextCode(ruleContext, "ruleContext.action(", "  inputs = ruleContext.files.srcs,", "  outputs = ruleContext.files.srcs,", "  mnemonic = 'DummyMnemonic',", "  command = ['dummy_command', '--arg1', '--arg2'],", "  progress_message = 'dummy_message')");
    SpawnAction action = (SpawnAction) Iterables.getOnlyElement(ruleContext.getRuleContext().getAnalysisEnvironment().getRegisteredActions());
    assertThat(action.getArguments()).containsExactly("dummy_command", "--arg1", "--arg2").inOrder();
}
Also used : SpawnAction(com.google.devtools.build.lib.analysis.actions.SpawnAction) SkylarkRuleContext(com.google.devtools.build.lib.rules.SkylarkRuleContext) Test(org.junit.Test)

Example 2 with SpawnAction

use of com.google.devtools.build.lib.analysis.actions.SpawnAction in project bazel by bazelbuild.

the class SkylarkRuleImplementationFunctionsTest method testCreateSpawnActionEnvAndExecInfo.

@Test
public void testCreateSpawnActionEnvAndExecInfo() throws Exception {
    SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
    evalRuleContextCode(ruleContext, "env = {'a' : 'b'}", "ruleContext.action(", "  inputs = ruleContext.files.srcs,", "  outputs = ruleContext.files.srcs,", "  env = env,", "  execution_requirements = env,", "  mnemonic = 'DummyMnemonic',", "  command = 'dummy_command',", "  progress_message = 'dummy_message')");
    SpawnAction action = (SpawnAction) Iterables.getOnlyElement(ruleContext.getRuleContext().getAnalysisEnvironment().getRegisteredActions());
    assertEquals(ImmutableMap.of("a", "b"), action.getEnvironment());
    assertEquals(ImmutableMap.of("a", "b"), action.getExecutionInfo());
}
Also used : SpawnAction(com.google.devtools.build.lib.analysis.actions.SpawnAction) SkylarkRuleContext(com.google.devtools.build.lib.rules.SkylarkRuleContext) Test(org.junit.Test)

Example 3 with SpawnAction

use of com.google.devtools.build.lib.analysis.actions.SpawnAction in project bazel by bazelbuild.

the class SkylarkRuleImplementationFunctionsTest method testCreateSpawnActionArgumentsWithCommand.

@Test
public void testCreateSpawnActionArgumentsWithCommand() throws Exception {
    SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
    createTestSpawnAction(ruleContext);
    SpawnAction action = (SpawnAction) Iterables.getOnlyElement(ruleContext.getRuleContext().getAnalysisEnvironment().getRegisteredActions());
    assertArtifactFilenames(action.getInputs(), "a.txt", "b.img");
    assertArtifactFilenames(action.getOutputs(), "a.txt", "b.img");
    MoreAsserts.assertContainsSublist(action.getArguments(), "-c", "dummy_command", "", "--a", "--b");
    assertEquals("DummyMnemonic", action.getMnemonic());
    assertEquals("dummy_message", action.getProgressMessage());
    assertEquals(targetConfig.getLocalShellEnvironment(), action.getEnvironment());
}
Also used : SpawnAction(com.google.devtools.build.lib.analysis.actions.SpawnAction) SkylarkRuleContext(com.google.devtools.build.lib.rules.SkylarkRuleContext) Test(org.junit.Test)

Example 4 with SpawnAction

use of com.google.devtools.build.lib.analysis.actions.SpawnAction in project bazel by bazelbuild.

the class AarImport method singleJarSpawnActionBuilder.

// Adds the appropriate SpawnAction options depending on if SingleJar is a jar or not.
private static SpawnAction.Builder singleJarSpawnActionBuilder(RuleContext ruleContext) {
    SpawnAction.Builder builder = new SpawnAction.Builder();
    Artifact singleJar = JavaToolchainProvider.fromRuleContext(ruleContext).getSingleJar();
    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) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) RuleConfiguredTargetBuilder(com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 5 with SpawnAction

use of com.google.devtools.build.lib.analysis.actions.SpawnAction in project bazel by bazelbuild.

the class AarImportTest method testNativeLibsZipMakesItIntoApk.

@Test
public void testNativeLibsZipMakesItIntoApk() throws Exception {
    scratch.file("java/com/google/android/hello/BUILD", "aar_import(", "    name = 'my_aar',", "    aar = 'my_aar.aar',", ")", "android_binary(", "    name = 'my_app',", "    srcs = ['HelloApp.java'],", "    deps = [':my_aar'],", "    manifest = 'AndroidManifest.xml',", ")");
    ConfiguredTarget binary = getConfiguredTarget("//java/com/google/android/hello:my_app");
    SpawnAction apkBuilderAction = (SpawnAction) actionsTestUtil().getActionForArtifactEndingWith(getFilesToBuild(binary), "my_app_unsigned.apk");
    assertThat(Iterables.find(apkBuilderAction.getArguments(), Predicates.containsPattern("_aar/my_aar/native_libs.zip$"))).isNotEmpty();
}
Also used : SpawnAction(com.google.devtools.build.lib.analysis.actions.SpawnAction) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) 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