@@ -125,27 +125,14 @@ func resolveLibrary(header string, headerToLibraries map[string][]*types.Library
125
125
return
126
126
}
127
127
128
- if markedLibrariesContainOneOfCandidate (markImportedLibrary , libraries ) {
128
+ if markImportedLibraryContainsOneOfCandidates (markImportedLibrary , libraries ) {
129
129
return
130
130
}
131
131
132
- var library * types.Library
133
-
134
- for _ , platform := range platforms {
135
- if platform != nil && library == nil {
136
- librariesWithinSpecifiedPlatform := librariesWithinPlatform (libraries , platform )
137
- library = findBestLibraryWithHeader (header , librariesWithinSpecifiedPlatform )
138
- }
139
- }
140
-
141
- for _ , platform := range platforms {
142
- if platform != nil && library == nil {
143
- library = findBestLibraryWithHeader (header , librariesCompatibleWithPlatform (libraries , platform ))
144
- }
145
- }
132
+ library := findLibraryOutsideAnyPlatform (header , libraries , platforms )
146
133
147
134
if library == nil {
148
- library = findBestLibraryWithHeader (header , libraries )
135
+ library = findLibraryInPlatforms (header , libraries , platforms )
149
136
}
150
137
151
138
if library == nil {
@@ -159,7 +146,57 @@ func resolveLibrary(header string, headerToLibraries map[string][]*types.Library
159
146
markImportedLibrary [library ] = true
160
147
}
161
148
162
- func markedLibrariesContainOneOfCandidate (markImportedLibrary map [* types.Library ]bool , libraries []* types.Library ) bool {
149
+ func findLibraryInPlatforms (header string , libraries []* types.Library , platforms []* types.Platform ) * types.Library {
150
+ for _ , platform := range platforms {
151
+ if platform != nil {
152
+ librariesWithinSpecifiedPlatform := librariesWithinPlatform (libraries , platform )
153
+ library := findBestLibraryWithHeader (header , librariesWithinSpecifiedPlatform )
154
+ if library != nil {
155
+ return library
156
+ }
157
+ }
158
+ }
159
+
160
+ return nil
161
+ }
162
+
163
+ func findLibraryOutsideAnyPlatform (header string , libraries []* types.Library , platforms []* types.Platform ) * types.Library {
164
+ librariesOutsidePlatforms := librariesOutsideAnyPlatform (libraries , platforms )
165
+
166
+ for _ , platform := range platforms {
167
+ if platform != nil {
168
+ library := findBestLibraryWithHeader (header , librariesCompatibleWithPlatform (librariesOutsidePlatforms , platform ))
169
+ if library != nil {
170
+ return library
171
+ }
172
+ }
173
+ }
174
+
175
+ return findBestLibraryWithHeader (header , librariesOutsidePlatforms )
176
+ }
177
+
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
+ }
183
+ for _ , platform := range platforms {
184
+ if platform != nil {
185
+ librariesWithinSpecifiedPlatform := librariesWithinPlatform (libraries , platform )
186
+ for _ , libraryWithinPlatform := range librariesWithinSpecifiedPlatform {
187
+ delete (allLibsAsMap , libraryWithinPlatform )
188
+ }
189
+ }
190
+ }
191
+
192
+ librariesOutsidePlatforms := []* types.Library {}
193
+ for lib , _ := range allLibsAsMap {
194
+ librariesOutsidePlatforms = append (librariesOutsidePlatforms , lib )
195
+ }
196
+ return librariesOutsidePlatforms
197
+ }
198
+
199
+ func markImportedLibraryContainsOneOfCandidates (markImportedLibrary map [* types.Library ]bool , libraries []* types.Library ) bool {
163
200
for markedLibrary , _ := range markImportedLibrary {
164
201
for _ , library := range libraries {
165
202
if markedLibrary == library {
@@ -211,7 +248,7 @@ func librariesCompatibleWithPlatform(libraries []*types.Library, platform *types
211
248
}
212
249
213
250
func librariesWithinPlatform (libraries []* types.Library , platform * types.Platform ) []* types.Library {
214
- var librariesWithinSpecifiedPlatform []* types.Library
251
+ librariesWithinSpecifiedPlatform := []* types.Library {}
215
252
for _ , library := range libraries {
216
253
cleanPlatformFolder := filepath .Clean (platform .Folder )
217
254
cleanLibraryFolder := filepath .Clean (library .SrcFolder )
0 commit comments