use of com.google.devtools.build.lib.analysis.ConfiguredTarget in project bazel by bazelbuild.
the class CcCommonTest method testIncludeManglingSmoke.
@Test
public void testIncludeManglingSmoke() throws Exception {
scratch.file("third_party/a/BUILD", "licenses(['notice'])", "cc_library(name='a', hdrs=['v1/b/c.h'], strip_include_prefix='v1', include_prefix='lib')");
ConfiguredTarget lib = getConfiguredTarget("//third_party/a");
CppCompilationContext context = lib.getProvider(CppCompilationContext.class);
assertThat(ActionsTestUtil.prettyArtifactNames(context.getDeclaredIncludeSrcs())).containsExactly("third_party/a/_virtual_includes/a/lib/b/c.h");
assertThat(context.getIncludeDirs()).containsExactly(getTargetConfiguration().getBinFragment().getRelative("third_party/a/_virtual_includes/a"));
}
use of com.google.devtools.build.lib.analysis.ConfiguredTarget in project bazel by bazelbuild.
the class CcCommonTest method testExpandLabelInLinkoptsAgainstSrc.
@Test
public void testExpandLabelInLinkoptsAgainstSrc() throws Exception {
scratch.file("coolthing/BUILD", "genrule(name = 'build-that',", " srcs = [ 'foo' ],", " outs = [ 'nicelib.a' ],", " cmd = 'cat $< > $@')");
// In reality the linkopts might contain several externally-provided
// '.a' files with cyclic dependencies amongst them, but in this test
// it suffices to show that one label in linkopts was resolved.
scratch.file("myapp/BUILD", "cc_binary(name = 'myapp',", " srcs = [ '//coolthing:nicelib.a' ],", " linkopts = [ '//coolthing:nicelib.a' ])");
ConfiguredTarget theLib = getConfiguredTarget("//coolthing:build-that");
ConfiguredTarget theApp = getConfiguredTarget("//myapp:myapp");
// make sure we did not print warnings about the linkopt
assertNoEvents();
// make sure the binary is dependent on the static lib
Action linkAction = getGeneratingAction(getOnlyElement(getFilesToBuild(theApp)));
ImmutableList<Artifact> filesToBuild = ImmutableList.copyOf(getFilesToBuild(theLib));
assertTrue(ImmutableSet.copyOf(linkAction.getInputs()).containsAll(filesToBuild));
}
use of com.google.devtools.build.lib.analysis.ConfiguredTarget in project bazel by bazelbuild.
the class CcCommonTest method testEmptyBinary.
@Test
public void testEmptyBinary() throws Exception {
ConfiguredTarget emptybin = getConfiguredTarget("//empty:emptybinary");
assertEquals("emptybinary" + OsUtils.executableExtension(), baseNamesOf(getFilesToBuild(emptybin)));
}
use of com.google.devtools.build.lib.analysis.ConfiguredTarget in project bazel by bazelbuild.
the class CcCommonTest method testArchiveInCcLibrarySrcs.
/**
* Test that we handle ".a" files in cc_library srcs correctly when linking dynamically. In
* particular, if srcs contains only the ".a" file for a library, with no corresponding ".so",
* then we need to link in the ".a" file even when we're linking dynamically. If srcs contains
* both ".a" and ".so" then we should only link in the ".so".
*/
@Test
public void testArchiveInCcLibrarySrcs() throws Exception {
useConfiguration("--cpu=k8");
ConfiguredTarget archiveInSrcsTest = scratchConfiguredTarget("archive_in_srcs", "archive_in_srcs_test", "cc_test(name = 'archive_in_srcs_test',", " srcs = ['archive_in_srcs_test.cc'],", " deps = [':archive_in_srcs_lib'])", "cc_library(name = 'archive_in_srcs_lib',", " srcs = ['libstatic.a', 'libboth.a', 'libboth.so'])");
List<String> artifactNames = baseArtifactNames(getLinkerInputs(archiveInSrcsTest));
assertThat(artifactNames).containsAllOf("libboth.so", "libstatic.a");
assertThat(artifactNames).doesNotContain("libboth.a");
}
use of com.google.devtools.build.lib.analysis.ConfiguredTarget in project bazel by bazelbuild.
the class CcCompileOnlyTest method testCcCompileOnly.
@Test
public void testCcCompileOnly() throws Exception {
useConfiguration("--cpu=k8");
scratch.file("package/BUILD", "cc_binary(name='foo', srcs=['foo.cc', ':bar'], deps = [':foolib'])", "cc_library(name='foolib', srcs=['foolib.cc'])", "genrule(name='bar', outs=['bar.h', 'bar.cc'], cmd='touch $(OUTS)')");
scratch.file("package/foo.cc", "#include <stdio.h>", "int main() {", " printf(\"Hello, world!\\n\");", " return 0;", "}");
scratch.file("package/foolib.cc", "#include <stdio.h>", "int printHeader() {", " printf(\"Hello, library!\\n\");", " return 0;", "}");
ConfiguredTarget target = getConfiguredTarget("//package:foo");
assertNotNull(getArtifactByExecPathSuffix(target, "/foo.pic.o"));
assertNotNull(getArtifactByExecPathSuffix(target, "/bar.pic.o"));
// Check that deps are not built
assertNull(getArtifactByExecPathSuffix(target, "/foolib.pic.o"));
// Check that linking is not executed
assertNull(getArtifactByExecPathSuffix(target, "/foo"));
}
Aggregations