Search in sources :

Example 6 with FileConfiguredTarget

use of com.google.devtools.build.lib.analysis.FileConfiguredTarget 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 7 with FileConfiguredTarget

use of com.google.devtools.build.lib.analysis.FileConfiguredTarget 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

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