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));
}
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));
}
Aggregations