Search in sources :

Example 81 with ConfiguredTarget

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

the class CcLibraryConfiguredTargetTest method getCppModuleMapAction.

private CppModuleMapAction getCppModuleMapAction(String label) throws Exception {
    ConfiguredTarget target = getConfiguredTarget(label);
    CppModuleMap cppModuleMap = target.getProvider(CppCompilationContext.class).getCppModuleMap();
    return (CppModuleMapAction) getGeneratingAction(cppModuleMap.getArtifact());
}
Also used : ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget)

Example 82 with ConfiguredTarget

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

the class CcLibraryConfiguredTargetTest method testLinkActionCanConsumeArtifactExtensions.

@Test
public void testLinkActionCanConsumeArtifactExtensions() throws Exception {
    AnalysisMock.get().ccSupport().setupCrosstool(mockToolsConfig, MockCcSupport.STATIC_LINK_TWEAKED_CONFIGURATION);
    useConfiguration("--features=" + Link.LinkTargetType.STATIC_LIBRARY.getActionName());
    ConfiguredTarget hello = getConfiguredTarget("//hello:hello");
    Artifact archive = FileType.filter(getFilesToBuild(hello), FileType.of(".tweaked.a")).iterator().next();
    CppLinkAction action = (CppLinkAction) getGeneratingAction(archive);
    assertThat(action.getArgv()).contains(archive.getExecPathString());
}
Also used : ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Example 83 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 84 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 85 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)

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