Skip to content

Commit

Permalink
C++: Fix create_library_to_link API method for Windows
Browse files Browse the repository at this point in the history
Fixes #7195

RELNOTES:none
PiperOrigin-RevId: 230523819
  • Loading branch information
oquenchil authored and Copybara-Service committed Jan 23, 2019
1 parent 8c1ff91 commit cae1e81
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 18 deletions.
34 changes: 19 additions & 15 deletions src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -399,22 +399,26 @@ public LibraryToLinkWrapper createLibraryLinkerInput(
/* prefixConsumer= */ true,
/* configuration= */ null);
}

return LibraryToLinkWrapper.builder()
.setLibraryIdentifier(CcLinkingOutputs.libraryIdentifierOf(notNullArtifactForIdentifier))
.setStaticLibrary(staticLibrary)
.setPicStaticLibrary(picStaticLibrary)
.setDynamicLibrary(dynamicLibrary)
.setResolvedSymlinkDynamicLibrary(resolvedSymlinkDynamicLibrary)
.setInterfaceLibrary(interfaceLibrary)
.setResolvedSymlinkInterfaceLibrary(resolvedSymlinkInterfaceLibrary)
.setAlwayslink(alwayslink)
.build();
}
throw new EvalException(
location,
"Must pass parameters: static_library, pic_static_library, dynamic_library, "
+ "interface_library and alwayslink.");
if (staticLibrary == null
&& picStaticLibrary == null
&& dynamicLibrary == null
&& interfaceLibrary == null) {
throw new EvalException(
location,
"Must pass at least one of the following parameters: static_library, pic_static_library, "
+ "dynamic_library and interface_library.");
}
return LibraryToLinkWrapper.builder()
.setLibraryIdentifier(CcLinkingOutputs.libraryIdentifierOf(notNullArtifactForIdentifier))
.setStaticLibrary(staticLibrary)
.setPicStaticLibrary(picStaticLibrary)
.setDynamicLibrary(dynamicLibrary)
.setResolvedSymlinkDynamicLibrary(resolvedSymlinkDynamicLibrary)
.setInterfaceLibrary(interfaceLibrary)
.setResolvedSymlinkInterfaceLibrary(resolvedSymlinkInterfaceLibrary)
.setAlwayslink(alwayslink)
.build();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,22 @@ public void testFlagWhitelist() throws Exception {
+ "will be making breaking changes to this API without prior warning.");
}

@Test
public void testCcLinkingContextOnWindows() throws Exception {
AnalysisMock.get()
.ccSupport()
.setupCrosstool(
mockToolsConfig,
MockCcSupport.COPY_DYNAMIC_LIBRARIES_TO_BINARY_CONFIGURATION,
MockCcSupport.TARGETS_WINDOWS_CONFIGURATION,
"supports_interface_shared_objects: false",
"needsPic: false");
doTestCcLinkingContext(
ImmutableList.of("a.a", "libdep2.a", "b.a", "c.a", "d.a", "libdep1.a"),
ImmutableList.of("a.pic.a", "b.pic.a", "c.pic.a", "e.pic.a"),
ImmutableList.of("a.so", "libdep2.so", "b.so", "e.so", "libdep1.so"));
}

@Test
public void testCcLinkingContext() throws Exception {
AnalysisMock.get()
Expand All @@ -1182,6 +1198,17 @@ public void testCcLinkingContext() throws Exception {
MockCcSupport.PIC_FEATURE,
"supports_interface_shared_objects: false",
"needsPic: true");
doTestCcLinkingContext(
ImmutableList.of("a.a", "b.a", "c.a", "d.a"),
ImmutableList.of("a.pic.a", "libdep2.a", "b.pic.a", "c.pic.a", "e.pic.a", "libdep1.a"),
ImmutableList.of("a.so", "liba_Slibdep2.so", "b.so", "e.so", "liba_Slibdep1.so"));
}

private void doTestCcLinkingContext(
List<String> staticLibraryList,
List<String> picStaticLibraryList,
List<String> dynamicLibraryList)
throws Exception {
useConfiguration();
setUpCcLinkingContextTest();
ConfiguredTarget a = getConfiguredTarget("//a:a");
Expand All @@ -1200,19 +1227,19 @@ public void testCcLinkingContext() throws Exception {
.filter(x -> x.getStaticLibrary() != null)
.map(x -> x.getStaticLibrary().getFilename())
.collect(ImmutableList.toImmutableList()))
.containsExactly("a.a", "b.a", "c.a", "d.a");
.containsExactlyElementsIn(staticLibraryList);
assertThat(
librariesToLink.stream()
.filter(x -> x.getPicStaticLibrary() != null)
.map(x -> x.getPicStaticLibrary().getFilename())
.collect(ImmutableList.toImmutableList()))
.containsExactly("a.pic.a", "libdep2.a", "b.pic.a", "c.pic.a", "e.pic.a", "libdep1.a");
.containsExactlyElementsIn(picStaticLibraryList);
assertThat(
librariesToLink.stream()
.filter(x -> x.getDynamicLibrary() != null)
.map(x -> x.getDynamicLibrary().getFilename())
.collect(ImmutableList.toImmutableList()))
.containsExactly("a.so", "liba_Slibdep2.so", "b.so", "e.so", "liba_Slibdep1.so");
.containsExactlyElementsIn(dynamicLibraryList);
assertThat(
librariesToLink.stream()
.filter(x -> x.getInterfaceLibrary() != null)
Expand Down

0 comments on commit cae1e81

Please sign in to comment.