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