Search in sources :

Example 86 with ConfiguredTarget

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

the class CcLibraryConfiguredTargetTest method testUsesCrosstoolIfLinkActionDefined.

/**
   * Tests that if a given crosstool defines action configs for all link actions, that the link
   * action will be configured from the crosstool instead of from hard-coded action_configs in
   * {@code CppLinkActionConfigs}.
   */
@Test
public void testUsesCrosstoolIfLinkActionDefined() throws Exception {
    String completeBrokenActionConfigs = Joiner.on("\n").join(MockCcSupport.INCOMPLETE_EXECUTABLE_ACTION_CONFIG, MockCcSupport.INCOMPLETE_DYNAMIC_LIBRARY_ACTION_CONFIG, MockCcSupport.INCOMPLETE_STATIC_LIBRARY_ACTION_CONFIG, MockCcSupport.INCOMPLETE_PIC_STATIC_LIBRARY_ACTION_CONFIG, MockCcSupport.INCOMPLETE_ALWAYS_LINK_STATIC_LIBRARY_ACTION_CONFIG, MockCcSupport.INCOMPLETE_ALWAYS_LINK_PIC_STATIC_LIBRARY_EXECUTABLE_ACTION_CONFIG, MockCcSupport.INCOMPLETE_INTERFACE_DYNAMIC_LIBRARY_ACTION_CONFIG);
    AnalysisMock.get().ccSupport().setupCrosstool(mockToolsConfig, completeBrokenActionConfigs);
    useConfiguration("--features=" + Link.LinkTargetType.EXECUTABLE.getActionName(), "--features=" + Link.LinkTargetType.DYNAMIC_LIBRARY.getActionName(), "--features=" + Link.LinkTargetType.STATIC_LIBRARY.getActionName(), "--features=" + Link.LinkTargetType.PIC_STATIC_LIBRARY.getActionName(), "--features=" + Link.LinkTargetType.ALWAYS_LINK_STATIC_LIBRARY.getActionName(), "--features=" + Link.LinkTargetType.ALWAYS_LINK_PIC_STATIC_LIBRARY.getActionName(), "--features=" + Link.LinkTargetType.INTERFACE_DYNAMIC_LIBRARY.getActionName());
    ConfiguredTarget hello = getConfiguredTarget("//hello:hello_static");
    Artifact archive = FileType.filter(getFilesToBuild(hello), CppFileTypes.ARCHIVE).iterator().next();
    CppLinkAction action = (CppLinkAction) getGeneratingAction(archive);
    assertThat(Joiner.on(" ").join(action.getArgv())).doesNotContain("hello.pic.o");
}
Also used : ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 87 with ConfiguredTarget

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

the class CcLibraryConfiguredTargetTest method testSoName.

@Test
public void testSoName() throws Exception {
    // Without interface shared libraries.
    useConfiguration("--nointerface_shared_objects");
    ConfiguredTarget hello = getConfiguredTarget("//hello:hello");
    Artifact sharedObject = getOnlyElement(FileType.filter(getFilesToBuild(hello), CppFileTypes.SHARED_LIBRARY));
    CppLinkAction action = (CppLinkAction) getGeneratingAction(sharedObject);
    for (String option : action.getLinkCommandLine().getLinkopts()) {
        assertThat(option).doesNotContain("-Wl,-soname");
    }
    // With interface shared libraries.
    useConfiguration("--interface_shared_objects");
    useConfiguration("--cpu=k8");
    hello = getConfiguredTarget("//hello:hello");
    sharedObject = FileType.filter(getFilesToBuild(hello), CppFileTypes.SHARED_LIBRARY).iterator().next();
    action = (CppLinkAction) getGeneratingAction(sharedObject);
    assertThat(action.getLinkCommandLine().getLinkopts()).contains("-Wl,-soname=libhello_Slibhello.so");
}
Also used : ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 88 with ConfiguredTarget

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

the class CcCommonTest method testUseIsystemForIncludes.

@Test
public void testUseIsystemForIncludes() throws Exception {
    // Tests the effect of --use_isystem_for_includes.
    scratch.file("no_includes/BUILD", "cc_library(name = 'no_includes',", "           srcs = ['no_includes.cc'])");
    ConfiguredTarget noIncludes = getConfiguredTarget("//no_includes:no_includes");
    scratch.file("bang/BUILD", "cc_library(name = 'bang',", "           srcs = ['bang.cc'],", "           includes = ['bang_includes'])");
    ConfiguredTarget foo = getConfiguredTarget("//bang:bang");
    String includesRoot = "bang/bang_includes";
    List<PathFragment> expected = new ImmutableList.Builder<PathFragment>().addAll(noIncludes.getProvider(CppCompilationContext.class).getSystemIncludeDirs()).add(new PathFragment(includesRoot)).add(targetConfig.getGenfilesFragment().getRelative(includesRoot)).build();
    assertThat(foo.getProvider(CppCompilationContext.class).getSystemIncludeDirs()).containsExactlyElementsIn(expected);
}
Also used : PathFragment(com.google.devtools.build.lib.vfs.PathFragment) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Test(org.junit.Test)

Example 89 with ConfiguredTarget

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

the class CcCommonTest method testVersionedSharedLibrarySupport.

/** Tests that shared libraries of the form "libfoo.so.1.2" are permitted within "srcs". */
@Test
public void testVersionedSharedLibrarySupport() throws Exception {
    ConfiguredTarget target = scratchConfiguredTarget("mypackage", "mybinary", "cc_binary(name = 'mybinary',", "           srcs = ['mybinary.cc'],", "           deps = [':mylib'])", "cc_library(name = 'mylib',", "           srcs = ['libshared.so', 'libshared.so.1.1', 'foo.cc'])");
    List<String> artifactNames = baseArtifactNames(getLinkerInputs(target));
    assertThat(artifactNames).containsAllOf("libshared.so", "libshared.so.1.1");
}
Also used : ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Test(org.junit.Test)

Example 90 with ConfiguredTarget

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

the class CcCommonTest method getCopts.

private List<String> getCopts(String target) throws Exception {
    ConfiguredTarget cLib = getConfiguredTarget(target);
    Artifact object = getOnlyElement(getOutputGroup(cLib, OutputGroupProvider.FILES_TO_COMPILE));
    CppCompileAction compileAction = (CppCompileAction) getGeneratingAction(object);
    return compileAction.getCompilerOptions();
}
Also used : ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Artifact(com.google.devtools.build.lib.actions.Artifact)

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