@@ -53,7 +53,7 @@ func (s *IncludesToIncludeFolders) Run(context map[string]interface{}) error {
53
53
if utils .MapHas (context , constants .CTX_IMPORTED_LIBRARIES ) {
54
54
importedLibraries = context [constants .CTX_IMPORTED_LIBRARIES ].([]* types.Library )
55
55
}
56
- newlyImportedLibraries , err := resolveLibraries (includes , headerToLibraries , []* types.Platform {platform , actualPlatform }, libraryResolutionResults )
56
+ newlyImportedLibraries , err := resolveLibraries (includes , headerToLibraries , importedLibraries , []* types.Platform {platform , actualPlatform }, libraryResolutionResults )
57
57
if err != nil {
58
58
return utils .WrapError (err )
59
59
}
@@ -92,24 +92,27 @@ func resolveIncludeFolders(importedLibraries []*types.Library, buildProperties m
92
92
}
93
93
94
94
//FIXME it's also resolving previously resolved libraries
95
- func resolveLibraries (includes []string , headerToLibraries map [string ][]* types.Library , platforms []* types.Platform , libraryResolutionResults map [string ]types.LibraryResolutionResult ) ([]* types.Library , error ) {
95
+ func resolveLibraries (includes []string , headerToLibraries map [string ][]* types.Library , importedLibraries [] * types. Library , platforms []* types.Platform , libraryResolutionResults map [string ]types.LibraryResolutionResult ) ([]* types.Library , error ) {
96
96
markImportedLibrary := make (map [* types.Library ]bool )
97
+ for _ , library := range importedLibraries {
98
+ markImportedLibrary [library ] = true
99
+ }
97
100
for _ , header := range includes {
98
101
resolveLibrary (header , headerToLibraries , markImportedLibrary , platforms , libraryResolutionResults )
99
102
}
100
103
101
- var importedLibraries []* types.Library
104
+ var newlyImportedLibraries []* types.Library
102
105
for library , _ := range markImportedLibrary {
103
- importedLibraries = append (importedLibraries , library )
106
+ newlyImportedLibraries = append (newlyImportedLibraries , library )
104
107
}
105
108
106
- return importedLibraries , nil
109
+ return newlyImportedLibraries , nil
107
110
}
108
111
109
112
func resolveLibrary (header string , headerToLibraries map [string ][]* types.Library , markImportedLibrary map [* types.Library ]bool , platforms []* types.Platform , libraryResolutionResults map [string ]types.LibraryResolutionResult ) {
110
113
libraries := headerToLibraries [header ]
111
114
112
- if libraries == nil {
115
+ if libraries == nil || len ( libraries ) == 0 {
113
116
return
114
117
}
115
118
@@ -118,6 +121,10 @@ func resolveLibrary(header string, headerToLibraries map[string][]*types.Library
118
121
return
119
122
}
120
123
124
+ if markedLibrariesContainOneOfCandidate (markImportedLibrary , libraries ) {
125
+ return
126
+ }
127
+
121
128
var library * types.Library
122
129
123
130
for _ , platform := range platforms {
@@ -138,14 +145,36 @@ func resolveLibrary(header string, headerToLibraries map[string][]*types.Library
138
145
}
139
146
140
147
if library == nil {
141
- library = libraries [0 ]
148
+ library = libraries [len ( libraries ) - 1 ]
142
149
}
143
150
151
+ library = useAlreadyImportedLibraryWithSameNameIfExists (library , markImportedLibrary )
152
+
144
153
libraryResolutionResults [header ] = types.LibraryResolutionResult {Library : library , NotUsedLibraries : filterOutLibraryFrom (libraries , library )}
145
154
146
155
markImportedLibrary [library ] = true
147
156
}
148
157
158
+ func markedLibrariesContainOneOfCandidate (markImportedLibrary map [* types.Library ]bool , libraries []* types.Library ) bool {
159
+ for markedLibrary , _ := range markImportedLibrary {
160
+ for _ , library := range libraries {
161
+ if markedLibrary == library {
162
+ return true
163
+ }
164
+ }
165
+ }
166
+ return false
167
+ }
168
+
169
+ func useAlreadyImportedLibraryWithSameNameIfExists (library * types.Library , markImportedLibrary map [* types.Library ]bool ) * types.Library {
170
+ for lib , _ := range markImportedLibrary {
171
+ if lib .Name == library .Name {
172
+ return lib
173
+ }
174
+ }
175
+ return library
176
+ }
177
+
149
178
func filterOutLibraryFrom (libraries []* types.Library , library * types.Library ) []* types.Library {
150
179
filteredOutLibraries := []* types.Library {}
151
180
for _ , lib := range libraries {
0 commit comments