Search in sources :

Example 91 with ConfiguredTarget

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"));
}
Also used : ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Test(org.junit.Test)

Example 92 with ConfiguredTarget

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));
}
Also used : Action(com.google.devtools.build.lib.actions.Action) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 93 with ConfiguredTarget

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)));
}
Also used : ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Test(org.junit.Test)

Example 94 with ConfiguredTarget

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");
}
Also used : ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Test(org.junit.Test)

Example 95 with ConfiguredTarget

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"));
}
Also used : ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Test(org.junit.Test)

Aggregations

ConfiguredTarget (com.google.devtools.build.lib.analysis.ConfiguredTarget)222 Test (org.junit.Test)178 Artifact (com.google.devtools.build.lib.actions.Artifact)51 FileConfiguredTarget (com.google.devtools.build.lib.analysis.FileConfiguredTarget)41 RuleConfiguredTarget (com.google.devtools.build.lib.analysis.RuleConfiguredTarget)25 Label (com.google.devtools.build.lib.cmdline.Label)17 SkylarkProviders (com.google.devtools.build.lib.analysis.SkylarkProviders)15 BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)13 AnalysisResult (com.google.devtools.build.lib.analysis.BuildView.AnalysisResult)12 Nullable (javax.annotation.Nullable)10 SkylarkClassObject (com.google.devtools.build.lib.packages.SkylarkClassObject)9 Variables (com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables)9 MergedConfiguredTarget (com.google.devtools.build.lib.analysis.MergedConfiguredTarget)7 Map (java.util.Map)7 OutputGroupProvider (com.google.devtools.build.lib.analysis.OutputGroupProvider)6 TestAspects (com.google.devtools.build.lib.analysis.util.TestAspects)6 Attribute (com.google.devtools.build.lib.packages.Attribute)6 RunfilesProvider (com.google.devtools.build.lib.analysis.RunfilesProvider)5 ConfigMatchingProvider (com.google.devtools.build.lib.analysis.config.ConfigMatchingProvider)5 TestFilteringCompleteEvent (com.google.devtools.build.lib.buildtool.buildevent.TestFilteringCompleteEvent)5