|
18 | 18 | import static com.google.devtools.build.lib.skyframe.BzlLoadValue.keyForBuild;
|
19 | 19 |
|
20 | 20 | import com.google.common.base.Ascii;
|
| 21 | +import com.google.common.base.Preconditions; |
21 | 22 | import com.google.common.collect.ImmutableList;
|
22 | 23 | import com.google.common.collect.ImmutableMap;
|
23 | 24 | import com.google.common.collect.ImmutableSet;
|
|
38 | 39 | import com.google.devtools.build.lib.cmdline.Label;
|
39 | 40 | import com.google.devtools.build.lib.collect.nestedset.Depset;
|
40 | 41 | import com.google.devtools.build.lib.collect.nestedset.Depset.TypeException;
|
| 42 | +import com.google.devtools.build.lib.collect.nestedset.NestedSet; |
41 | 43 | import com.google.devtools.build.lib.packages.Attribute.ComputedDefault;
|
42 | 44 | import com.google.devtools.build.lib.packages.AttributeMap;
|
43 | 45 | import com.google.devtools.build.lib.packages.Info;
|
@@ -709,18 +711,71 @@ public Args getArgs(
|
709 | 711 | @Param(name = "supports_dynamic_linker")
|
710 | 712 | })
|
711 | 713 | public StarlarkList<LibraryInput> convertLibraryToLinkListToLinkerInputList(
|
712 |
| - Depset librariesToLink, |
| 714 | + Depset librariesToLinkDepset, |
713 | 715 | boolean staticMode,
|
714 | 716 | boolean forDynamicLibrary,
|
715 | 717 | boolean supportsDynamicLinker)
|
716 | 718 | throws TypeException {
|
717 |
| - return StarlarkList.copyOf( |
718 |
| - Mutability.IMMUTABLE, |
719 |
| - CcLinkingHelper.convertLibraryToLinkListToLinkerInputList( |
720 |
| - librariesToLink.getSet(LibraryToLink.class), |
721 |
| - staticMode, |
722 |
| - forDynamicLibrary, |
723 |
| - supportsDynamicLinker)); |
| 719 | + // LINT.IfChange |
| 720 | + NestedSet<LibraryToLink> librariesToLink = librariesToLinkDepset.getSet(LibraryToLink.class); |
| 721 | + |
| 722 | + ImmutableList.Builder<LibraryInput> libraryInputsBuilder = ImmutableList.builder(); |
| 723 | + for (LibraryToLink libraryToLink : librariesToLink.toList()) { |
| 724 | + LibraryInput staticLibraryInput = |
| 725 | + libraryToLink.getStaticLibrary() == null ? null : libraryToLink.getStaticLibraryInput(); |
| 726 | + LibraryInput picStaticLibraryInput = |
| 727 | + libraryToLink.getPicStaticLibrary() == null |
| 728 | + ? null |
| 729 | + : libraryToLink.getPicStaticLibraryInput(); |
| 730 | + LibraryInput libraryInputToUse = null; |
| 731 | + if (staticMode) { |
| 732 | + if (forDynamicLibrary) { |
| 733 | + if (picStaticLibraryInput != null) { |
| 734 | + libraryInputToUse = picStaticLibraryInput; |
| 735 | + } else if (staticLibraryInput != null) { |
| 736 | + libraryInputToUse = staticLibraryInput; |
| 737 | + } |
| 738 | + } else { |
| 739 | + if (staticLibraryInput != null) { |
| 740 | + libraryInputToUse = staticLibraryInput; |
| 741 | + } else if (picStaticLibraryInput != null) { |
| 742 | + libraryInputToUse = picStaticLibraryInput; |
| 743 | + } |
| 744 | + } |
| 745 | + if (libraryInputToUse == null) { |
| 746 | + if (libraryToLink.getInterfaceLibrary() != null) { |
| 747 | + libraryInputToUse = libraryToLink.getInterfaceLibraryInput(); |
| 748 | + } else if (libraryToLink.getDynamicLibrary() != null) { |
| 749 | + libraryInputToUse = libraryToLink.getDynamicLibraryInput(); |
| 750 | + } |
| 751 | + } |
| 752 | + } else { |
| 753 | + if (libraryToLink.getInterfaceLibrary() != null) { |
| 754 | + libraryInputToUse = libraryToLink.getInterfaceLibraryInput(); |
| 755 | + } else if (libraryToLink.getDynamicLibrary() != null) { |
| 756 | + libraryInputToUse = libraryToLink.getDynamicLibraryInput(); |
| 757 | + } |
| 758 | + if (libraryInputToUse == null || !supportsDynamicLinker) { |
| 759 | + if (forDynamicLibrary) { |
| 760 | + if (picStaticLibraryInput != null) { |
| 761 | + libraryInputToUse = picStaticLibraryInput; |
| 762 | + } else if (staticLibraryInput != null) { |
| 763 | + libraryInputToUse = staticLibraryInput; |
| 764 | + } |
| 765 | + } else { |
| 766 | + if (staticLibraryInput != null) { |
| 767 | + libraryInputToUse = staticLibraryInput; |
| 768 | + } else if (picStaticLibraryInput != null) { |
| 769 | + libraryInputToUse = picStaticLibraryInput; |
| 770 | + } |
| 771 | + } |
| 772 | + } |
| 773 | + } |
| 774 | + Preconditions.checkNotNull(libraryInputToUse); |
| 775 | + libraryInputsBuilder.add(libraryInputToUse); |
| 776 | + } |
| 777 | + return StarlarkList.copyOf(Mutability.IMMUTABLE, libraryInputsBuilder.build()); |
| 778 | + // LINT.ThenChange(//src/main/starlark/builtins_bzl/common/cc/link/convert_linker_inputs.bzl) |
724 | 779 | }
|
725 | 780 |
|
726 | 781 | @StarlarkMethod(
|
|
0 commit comments