Search in sources :

Example 1 with FileConfiguredTarget

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

the class SkylarkIntegrationTest method testActions.

@Test
public void testActions() throws Exception {
    scratch.file("test/skylark/extension.bzl", "def custom_rule_impl(ctx):", "  attr1 = ctx.files.attr1", "  output = ctx.outputs.o", "  ctx.action(", "    inputs = attr1,", "    outputs = [output],", "    command = 'echo')", "", "custom_rule = rule(implementation = custom_rule_impl,", "  attrs = {'attr1': attr.label_list(mandatory=True, allow_files=True)},", "  outputs = {'o': 'o.txt'})");
    scratch.file("test/skylark/BUILD", "load('/test/skylark/extension', 'custom_rule')", "", "custom_rule(name = 'cr', attr1 = [':a.txt'])");
    getConfiguredTarget("//test/skylark:cr");
    FileConfiguredTarget target = getFileConfiguredTarget("//test/skylark:o.txt");
    assertThat(ActionsTestUtil.baseArtifactNames(getGeneratingAction(target.getArtifact()).getInputs())).containsExactly("a.txt");
}
Also used : FileConfiguredTarget(com.google.devtools.build.lib.analysis.FileConfiguredTarget) Test(org.junit.Test)

Example 2 with FileConfiguredTarget

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

the class AarImportTest method testExportsPropagatesResources.

@Test
public void testExportsPropagatesResources() throws Exception {
    FileConfiguredTarget appTarget = getFileConfiguredTarget("//java:app.apk");
    Set<Artifact> artifacts = actionsTestUtil().artifactClosureOf(appTarget.getArtifact());
    ConfiguredTarget bar = getConfiguredTarget("//a:bar");
    Artifact barResources = ActionsTestUtil.getFirstArtifactEndingWith(artifacts, "_aar/unzipped/resources/bar");
    assertThat(barResources).isNotNull();
    assertThat(barResources.getArtifactOwner().getLabel()).isEqualTo(bar.getLabel());
    ConfiguredTarget foo = getConfiguredTarget("//a:foo");
    Artifact fooResources = ActionsTestUtil.getFirstArtifactEndingWith(artifacts, "_aar/unzipped/resources/foo");
    assertThat(fooResources).isNotNull();
    assertThat(fooResources.getArtifactOwner().getLabel()).isEqualTo(foo.getLabel());
}
Also used : FileConfiguredTarget(com.google.devtools.build.lib.analysis.FileConfiguredTarget) 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 3 with FileConfiguredTarget

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

the class GenRuleConfiguredTargetTest method testDependenciesViaFiles.

/**
   * Ensure that the actions / artifacts created by genrule dependencies allow us to follow the
   * chain of generated files backward.
   */
@Test
public void testDependenciesViaFiles() throws Exception {
    scratch.file("foo/BUILD", "genrule(name = 'bar',", "        srcs = ['bar_in.txt'],", "        cmd = 'touch $(OUTS)',", "        outs = ['bar_out.txt'])", "genrule(name = 'baz',", "        srcs = ['bar_out.txt'],", "        cmd = 'touch $(OUTS)',", "        outs = ['baz_out.txt'])");
    FileConfiguredTarget bazOutTarget = getFileConfiguredTarget("//foo:baz_out.txt");
    Action bazAction = getGeneratingAction(bazOutTarget.getArtifact());
    Artifact barOut = bazAction.getInputs().iterator().next();
    assertTrue(barOut.getExecPath().endsWith(new PathFragment("foo/bar_out.txt")));
    Action barAction = getGeneratingAction(barOut);
    Artifact barIn = barAction.getInputs().iterator().next();
    assertTrue(barIn.getExecPath().endsWith(new PathFragment("foo/bar_in.txt")));
}
Also used : SpawnAction(com.google.devtools.build.lib.analysis.actions.SpawnAction) Action(com.google.devtools.build.lib.actions.Action) 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 4 with FileConfiguredTarget

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

the class FilegroupConfiguredTargetTest method testDependencyGraph.

@Test
public void testDependencyGraph() throws Exception {
    scratch.file("java/com/google/test/BUILD", "java_binary(name  = 'test_app',", "    resources = [':data'],", "    create_executable = 0,", "    srcs  = ['InputFile.java', 'InputFile2.java'])", "filegroup(name  = 'data',", "          srcs = ['b.txt', 'a.txt'])");
    FileConfiguredTarget appOutput = getFileConfiguredTarget("//java/com/google/test:test_app.jar");
    assertEquals("b.txt a.txt", actionsTestUtil().predecessorClosureOf(appOutput.getArtifact(), FileType.of(".txt")));
}
Also used : FileConfiguredTarget(com.google.devtools.build.lib.analysis.FileConfiguredTarget) Test(org.junit.Test)

Example 5 with FileConfiguredTarget

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

the class AarImportTest method testExportsPropagatesMergedAarJars.

@Test
public void testExportsPropagatesMergedAarJars() throws Exception {
    FileConfiguredTarget appTarget = getFileConfiguredTarget("//java:app.apk");
    Set<Artifact> artifacts = actionsTestUtil().artifactClosureOf(appTarget.getArtifact());
    ConfiguredTarget bar = getConfiguredTarget("//a:bar");
    Artifact barClassesJar = ActionsTestUtil.getFirstArtifactEndingWith(artifacts, "bar/classes_and_libs_merged.jar");
    // Verify that bar/classes_and_libs_merged.jar was in the artifact closure.
    assertThat(barClassesJar).isNotNull();
    assertThat(barClassesJar.getArtifactOwner().getLabel()).isEqualTo(bar.getLabel());
    ConfiguredTarget foo = getConfiguredTarget("//a:foo");
    Artifact fooClassesJar = ActionsTestUtil.getFirstArtifactEndingWith(artifacts, "foo/classes_and_libs_merged.jar");
    // Verify that foo/classes_and_libs_merged.jar was in the artifact closure.
    assertThat(fooClassesJar).isNotNull();
    assertThat(fooClassesJar.getArtifactOwner().getLabel()).isEqualTo(foo.getLabel());
    ConfiguredTarget baz = getConfiguredTarget("//java:baz.jar");
    Artifact bazJar = ActionsTestUtil.getFirstArtifactEndingWith(artifacts, "baz.jar");
    // Verify that baz.jar was in the artifact closure
    assertThat(bazJar).isNotNull();
    assertThat(bazJar.getArtifactOwner().getLabel()).isEqualTo(baz.getLabel());
}
Also used : FileConfiguredTarget(com.google.devtools.build.lib.analysis.FileConfiguredTarget) 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)

Aggregations

FileConfiguredTarget (com.google.devtools.build.lib.analysis.FileConfiguredTarget)7 Test (org.junit.Test)7 Artifact (com.google.devtools.build.lib.actions.Artifact)4 SpawnAction (com.google.devtools.build.lib.analysis.actions.SpawnAction)3 ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)2 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)2 Action (com.google.devtools.build.lib.actions.Action)1