@@ -129,10 +129,13 @@ func resolveLibrary(header string, headerToLibraries map[string][]*types.Library
129
129
return
130
130
}
131
131
132
- library := findLibraryOutsideAnyPlatform (header , libraries , platforms )
132
+ librariesInPlatforms := librariesInSomePlatform (libraries , platforms )
133
+ librariesOutsidePlatforms := filterOutLibrariesFrom (libraries , librariesInPlatforms )
134
+
135
+ library := findBestLibraryOutsideAnyPlatform (header , librariesOutsidePlatforms , platforms )
133
136
134
137
if library == nil {
135
- library = findLibraryInPlatforms (header , libraries , platforms )
138
+ library = findBestLibraryInPlatforms (header , librariesInPlatforms , platforms )
136
139
}
137
140
138
141
if library == nil {
@@ -146,10 +149,10 @@ func resolveLibrary(header string, headerToLibraries map[string][]*types.Library
146
149
markImportedLibrary [library ] = true
147
150
}
148
151
149
- func findLibraryInPlatforms (header string , libraries []* types.Library , platforms []* types.Platform ) * types.Library {
152
+ func findBestLibraryInPlatforms (header string , librariesInPlatforms []* types.Library , platforms []* types.Platform ) * types.Library {
150
153
for _ , platform := range platforms {
151
154
if platform != nil {
152
- librariesWithinSpecifiedPlatform := librariesWithinPlatform (libraries , platform )
155
+ librariesWithinSpecifiedPlatform := librariesWithinPlatform (librariesInPlatforms , platform )
153
156
library := findBestLibraryWithHeader (header , librariesWithinSpecifiedPlatform )
154
157
if library != nil {
155
158
return library
@@ -160,9 +163,7 @@ func findLibraryInPlatforms(header string, libraries []*types.Library, platforms
160
163
return nil
161
164
}
162
165
163
- func findLibraryOutsideAnyPlatform (header string , libraries []* types.Library , platforms []* types.Platform ) * types.Library {
164
- librariesOutsidePlatforms := librariesOutsideAnyPlatform (libraries , platforms )
165
-
166
+ func findBestLibraryOutsideAnyPlatform (header string , librariesOutsidePlatforms []* types.Library , platforms []* types.Platform ) * types.Library {
166
167
for _ , platform := range platforms {
167
168
if platform != nil {
168
169
library := findBestLibraryWithHeader (header , librariesCompatibleWithPlatform (librariesOutsidePlatforms , platform ))
@@ -175,25 +176,15 @@ func findLibraryOutsideAnyPlatform(header string, libraries []*types.Library, pl
175
176
return findBestLibraryWithHeader (header , librariesOutsidePlatforms )
176
177
}
177
178
178
- func librariesOutsideAnyPlatform (libraries []* types.Library , platforms []* types.Platform ) []* types.Library {
179
- allLibsAsMap := make (map [* types.Library ]bool )
180
- for _ , lib := range libraries {
181
- allLibsAsMap [lib ] = true
182
- }
179
+ func librariesInSomePlatform (libraries []* types.Library , platforms []* types.Platform ) []* types.Library {
180
+ librariesInPlatforms := []* types.Library {}
183
181
for _ , platform := range platforms {
184
182
if platform != nil {
185
183
librariesWithinSpecifiedPlatform := librariesWithinPlatform (libraries , platform )
186
- for _ , libraryWithinPlatform := range librariesWithinSpecifiedPlatform {
187
- delete (allLibsAsMap , libraryWithinPlatform )
188
- }
184
+ librariesInPlatforms = append (librariesInPlatforms , librariesWithinSpecifiedPlatform ... )
189
185
}
190
186
}
191
-
192
- librariesOutsidePlatforms := []* types.Library {}
193
- for lib , _ := range allLibsAsMap {
194
- librariesOutsidePlatforms = append (librariesOutsidePlatforms , lib )
195
- }
196
- return librariesOutsidePlatforms
187
+ return librariesInPlatforms
197
188
}
198
189
199
190
func markImportedLibraryContainsOneOfCandidates (markImportedLibrary map [* types.Library ]bool , libraries []* types.Library ) bool {
@@ -216,16 +207,35 @@ func useAlreadyImportedLibraryWithSameNameIfExists(library *types.Library, markI
216
207
return library
217
208
}
218
209
219
- func filterOutLibraryFrom (libraries []* types.Library , library * types.Library ) []* types.Library {
210
+ func filterOutLibraryFrom (libraries []* types.Library , libraryToRemove * types.Library ) []* types.Library {
220
211
filteredOutLibraries := []* types.Library {}
221
212
for _ , lib := range libraries {
222
- if lib != library {
213
+ if lib != libraryToRemove {
223
214
filteredOutLibraries = append (filteredOutLibraries , lib )
224
215
}
225
216
}
226
217
return filteredOutLibraries
227
218
}
228
219
220
+ func filterOutLibrariesFrom (libraries []* types.Library , librariesToRemove []* types.Library ) []* types.Library {
221
+ filteredOutLibraries := []* types.Library {}
222
+ for _ , lib := range libraries {
223
+ if findLibraryIn (librariesToRemove , lib ) == nil {
224
+ filteredOutLibraries = append (filteredOutLibraries , lib )
225
+ }
226
+ }
227
+ return filteredOutLibraries
228
+ }
229
+
230
+ func findLibraryIn (libraries []* types.Library , library * types.Library ) * types.Library {
231
+ for _ , lib := range libraries {
232
+ if lib == library {
233
+ return lib
234
+ }
235
+ }
236
+ return nil
237
+ }
238
+
229
239
func libraryCompatibleWithPlatform (library * types.Library , platform * types.Platform ) bool {
230
240
if len (library .Archs ) == 0 {
231
241
return true
0 commit comments