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