@Test public void testCppLinkActionExtraActionInfoWithSharedLibraries() throws Exception { ConfiguredTarget hello = getConfiguredTarget("//hello:hello"); Artifact sharedObject = FileType.filter(getFilesToBuild(hello), CppFileTypes.SHARED_LIBRARY).iterator().next(); CppLinkAction action = (CppLinkAction) getGeneratingAction(sharedObject); ExtraActionInfo.Builder builder = action.getExtraActionInfo(); ExtraActionInfo info = builder.build(); assertEquals("CppLink", info.getMnemonic()); CppLinkInfo cppLinkInfo = info.getExtension(CppLinkInfo.cppLinkInfo); assertNotNull(cppLinkInfo); Iterable<String> inputs = Artifact.asExecPaths( LinkerInputs.toLibraryArtifacts(action.getLinkCommandLine().getLinkerInputs())); assertThat(cppLinkInfo.getInputFileList()).containsExactlyElementsIn(inputs); assertEquals(action.getPrimaryOutput().getExecPathString(), cppLinkInfo.getOutputFile()); Artifact interfaceOutput = action.getLinkCommandLine().getInterfaceOutput(); assertEquals(interfaceOutput.getExecPathString(), cppLinkInfo.getInterfaceOutputFile()); assertEquals( action.getLinkCommandLine().getLinkTargetType().name(), cppLinkInfo.getLinkTargetType()); assertEquals( action.getLinkCommandLine().getLinkStaticness().name(), cppLinkInfo.getLinkStaticness()); Iterable<String> linkstamps = Artifact.asExecPaths(action.getLinkCommandLine().getLinkstamps().values()); assertThat(cppLinkInfo.getLinkStampList()).containsExactlyElementsIn(linkstamps); Iterable<String> buildInfoHeaderArtifacts = Artifact.asExecPaths(action.getLinkCommandLine().getBuildInfoHeaderArtifacts()); assertThat(cppLinkInfo.getBuildInfoHeaderArtifactList()) .containsExactlyElementsIn(buildInfoHeaderArtifacts); assertThat(cppLinkInfo.getLinkOptList()) .containsExactlyElementsIn(action.getLinkCommandLine().getLinkopts()); }
@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"); 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"); }