Search in sources :

Example 6 with SpawnAction

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

the class AarImportTest method testClassesJarProvided.

@Test
public void testClassesJarProvided() throws Exception {
    ConfiguredTarget aarImportTarget = getConfiguredTarget("//a:foo");
    Iterable<OutputJar> outputJars = aarImportTarget.getProvider(JavaRuleOutputJarsProvider.class).getOutputJars();
    assertThat(outputJars).hasSize(1);
    Artifact classesJar = outputJars.iterator().next().getClassJar();
    assertThat(classesJar.getFilename()).isEqualTo("classes_and_libs_merged.jar");
    SpawnAction jarMergingAction = ((SpawnAction) getGeneratingAction(classesJar));
    assertThat(jarMergingAction.getArguments()).contains("--dont_change_compression");
}
Also used : SpawnAction(com.google.devtools.build.lib.analysis.actions.SpawnAction) JavaRuleOutputJarsProvider(com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider) OutputJar(com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider.OutputJar) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) FileConfiguredTarget(com.google.devtools.build.lib.analysis.FileConfiguredTarget) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 7 with SpawnAction

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

the class GenRuleConfiguredTargetTest method testJavaMakeVarExpansion.

/** Ensure that Java make variables get expanded under the *host* configuration. */
@Test
public void testJavaMakeVarExpansion() throws Exception {
    String ruleTemplate = "genrule(name = '%s'," + "  srcs = []," + "  cmd = 'echo $(%s) > $@'," + "  outs = ['%s'])";
    scratch.file("foo/BUILD", String.format(ruleTemplate, "java_rule", "JAVA", "java.txt"), String.format(ruleTemplate, "javabase_rule", "JAVABASE", "javabase.txt"));
    Artifact javaOutput = getFileConfiguredTarget("//foo:java.txt").getArtifact();
    Artifact javabaseOutput = getFileConfiguredTarget("//foo:javabase.txt").getArtifact();
    String expectedPattern = "echo %s > %s";
    BuildConfiguration hostConfig = getHostConfiguration();
    String expectedJava = hostConfig.getFragment(Jvm.class).getJavaExecutable().getPathString();
    String expectedJavabase = hostConfig.getFragment(Jvm.class).getJavaHome().getPathString();
    assertCommandEquals(String.format(expectedPattern, expectedJava, javaOutput.getExecPathString()), ((SpawnAction) getGeneratingAction(javaOutput)).getArguments().get(2));
    assertCommandEquals(String.format(expectedPattern, expectedJavabase, javabaseOutput.getExecPathString()), ((SpawnAction) getGeneratingAction(javabaseOutput)).getArguments().get(2));
}
Also used : BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) SpawnAction(com.google.devtools.build.lib.analysis.actions.SpawnAction) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 8 with SpawnAction

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

the class GenRuleConfiguredTargetTest method testActionIsShellCommand.

@Test
public void testActionIsShellCommand() throws Exception {
    scratch.file("genrule1/BUILD", "genrule(name = 'hello_world',", "srcs = ['ignore_me.txt'],", "outs = ['message.txt'],", "cmd  = 'echo \"Hello, world.\" >$(location message.txt)')");
    Artifact messageArtifact = getFileConfiguredTarget("//genrule1:message.txt").getArtifact();
    SpawnAction shellAction = (SpawnAction) getGeneratingAction(messageArtifact);
    Artifact ignoreMeArtifact = getFileConfiguredTarget("//genrule1:ignore_me.txt").getArtifact();
    Artifact genruleSetupArtifact = getFileConfiguredTarget(GENRULE_SETUP).getArtifact();
    assertNotNull(shellAction);
    assertEquals(Sets.newHashSet(ignoreMeArtifact, genruleSetupArtifact), Sets.newHashSet(shellAction.getInputs()));
    assertEquals(Sets.newHashSet(messageArtifact), Sets.newHashSet(shellAction.getOutputs()));
    String expected = "echo \"Hello, world.\" >" + messageArtifact.getExecPathString();
    assertEquals(targetConfig.getShellExecutable().getPathString(), shellAction.getArguments().get(0));
    assertEquals("-c", shellAction.getArguments().get(1));
    assertCommandEquals(expected, shellAction.getArguments().get(2));
}
Also used : SpawnAction(com.google.devtools.build.lib.analysis.actions.SpawnAction) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 9 with SpawnAction

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

the class GenRuleConfiguredTargetTest method testDependentGenrule.

@Test
public void testDependentGenrule() throws Exception {
    scratch.file("genrule1/BUILD", "genrule(name = 'hello_world',", "srcs = ['ignore_me.txt'],", "outs = ['message.txt'],", "cmd  = 'echo \"Hello, world.\" >$(location message.txt)')");
    scratch.file("genrule2/BUILD", "genrule(name = 'goodbye_world',", "srcs = ['goodbye.txt', '//genrule1:hello_world'],", "outs = ['farewell.txt'],", "cmd  = 'echo $(SRCS) >$(location farewell.txt)')");
    getConfiguredTarget("//genrule2:goodbye_world");
    Artifact farewellArtifact = getFileConfiguredTarget("//genrule2:farewell.txt").getArtifact();
    Artifact goodbyeArtifact = getFileConfiguredTarget("//genrule2:goodbye.txt").getArtifact();
    Artifact messageArtifact = getFileConfiguredTarget("//genrule1:message.txt").getArtifact();
    Artifact genruleSetupArtifact = getFileConfiguredTarget(GENRULE_SETUP).getArtifact();
    SpawnAction shellAction = (SpawnAction) getGeneratingAction(farewellArtifact);
    // inputs = { "goodbye.txt", "//genrule1:message.txt" }
    assertEquals(Sets.newHashSet(goodbyeArtifact, messageArtifact, genruleSetupArtifact), Sets.newHashSet(shellAction.getInputs()));
    // outputs = { "farewell.txt" }
    assertEquals(Sets.newHashSet(farewellArtifact), Sets.newHashSet(shellAction.getOutputs()));
    String expected = "echo " + goodbyeArtifact.getExecPathString() + " " + messageArtifact.getExecPathString() + " >" + farewellArtifact.getExecPathString();
    assertCommandEquals(expected, shellAction.getArguments().get(2));
}
Also used : SpawnAction(com.google.devtools.build.lib.analysis.actions.SpawnAction) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 10 with SpawnAction

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

the class AndroidStudioInfoAspectTestBase method verifyPackageManifestSpawnAction.

protected final void verifyPackageManifestSpawnAction(Action genAction) {
    assertEquals(genAction.getMnemonic(), "JavaPackageManifest");
    SpawnAction action = (SpawnAction) genAction;
    assertFalse(action.isShellCommand());
}
Also used : SpawnAction(com.google.devtools.build.lib.analysis.actions.SpawnAction)

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