Skip to content

Commit cf97b26

Browse files
author
Federico Fissore
committedOct 1, 2015
Extract function, for sake of readability
Signed-off-by: Federico Fissore <f.fissore@arduino.cc>
1 parent 9c76224 commit cf97b26

File tree

1 file changed

+49
-36
lines changed

1 file changed

+49
-36
lines changed
 

‎src/arduino.cc/builder/includes_to_include_folders.go

+49-36
Original file line numberDiff line numberDiff line change
@@ -88,41 +88,7 @@ func resolveIncludeFolders(importedLibraries []*types.Library, buildProperties m
8888
func resolveLibraries(includes []string, headerToLibraries map[string][]*types.Library, previousImportedLibraries []*types.Library, platforms []*types.Platform, debugLevel int, logger i18n.Logger) ([]*types.Library, error) {
8989
markImportedLibrary := make(map[*types.Library]bool)
9090
for _, header := range includes {
91-
libraries := headerToLibraries[header]
92-
if libraries != nil {
93-
if len(libraries) == 1 {
94-
markImportedLibrary[libraries[0]] = true
95-
} else {
96-
var library *types.Library
97-
for _, platform := range platforms {
98-
if platform != nil && library == nil {
99-
librariesWithinSpecifiedPlatform := librariesWithinPlatform(libraries, platform)
100-
library = findBestLibraryWithHeader(header, librariesWithinSpecifiedPlatform)
101-
}
102-
}
103-
for _, platform := range platforms {
104-
if platform != nil && library == nil {
105-
library = findBestLibraryWithHeader(header, librariesCompatibleWithPlatform(libraries, platform))
106-
}
107-
}
108-
if library == nil {
109-
library = findBestLibraryWithHeader(header, libraries)
110-
}
111-
if library == nil {
112-
library = libraries[0]
113-
}
114-
if debugLevel > 0 && !sliceContainsLibrary(previousImportedLibraries, library) {
115-
logger.Fprintln(os.Stderr, constants.MSG_LIBRARIES_MULTIPLE_LIBS_FOUND_FOR, header)
116-
logger.Fprintln(os.Stderr, constants.MSG_LIBRARIES_USED, library.Folder)
117-
for _, notUsedLibrary := range libraries {
118-
if library != notUsedLibrary {
119-
logger.Fprintln(os.Stderr, constants.MSG_LIBRARIES_NOT_USED, notUsedLibrary.Folder)
120-
}
121-
}
122-
}
123-
markImportedLibrary[library] = true
124-
}
125-
}
91+
resolveLibrary(header, headerToLibraries, markImportedLibrary, previousImportedLibraries, platforms, debugLevel, logger)
12692
}
12793

12894
var importedLibraries []*types.Library
@@ -133,6 +99,53 @@ func resolveLibraries(includes []string, headerToLibraries map[string][]*types.L
13399
return importedLibraries, nil
134100
}
135101

102+
func resolveLibrary(header string, headerToLibraries map[string][]*types.Library, markImportedLibrary map[*types.Library]bool, previousImportedLibraries []*types.Library, platforms []*types.Platform, debugLevel int, logger i18n.Logger) {
103+
libraries := headerToLibraries[header]
104+
105+
if libraries == nil {
106+
return
107+
}
108+
109+
if len(libraries) == 1 {
110+
markImportedLibrary[libraries[0]] = true
111+
return
112+
}
113+
114+
var library *types.Library
115+
116+
for _, platform := range platforms {
117+
if platform != nil && library == nil {
118+
librariesWithinSpecifiedPlatform := librariesWithinPlatform(libraries, platform)
119+
library = findBestLibraryWithHeader(header, librariesWithinSpecifiedPlatform)
120+
}
121+
}
122+
123+
for _, platform := range platforms {
124+
if platform != nil && library == nil {
125+
library = findBestLibraryWithHeader(header, librariesCompatibleWithPlatform(libraries, platform))
126+
}
127+
}
128+
129+
if library == nil {
130+
library = findBestLibraryWithHeader(header, libraries)
131+
}
132+
133+
if library == nil {
134+
library = libraries[0]
135+
}
136+
137+
if debugLevel > 0 && !sliceContainsLibrary(previousImportedLibraries, library) {
138+
logger.Fprintln(os.Stderr, constants.MSG_LIBRARIES_MULTIPLE_LIBS_FOUND_FOR, header)
139+
logger.Fprintln(os.Stderr, constants.MSG_LIBRARIES_USED, library.Folder)
140+
for _, notUsedLibrary := range libraries {
141+
if library != notUsedLibrary {
142+
logger.Fprintln(os.Stderr, constants.MSG_LIBRARIES_NOT_USED, notUsedLibrary.Folder)
143+
}
144+
}
145+
}
146+
markImportedLibrary[library] = true
147+
}
148+
136149
func libraryCompatibleWithPlatform(library *types.Library, platform *types.Platform) bool {
137150
if len(library.Archs) == 0 {
138151
return true
@@ -234,7 +247,7 @@ func findLibWithNameContaining(name string, libraries []*types.Library) *types.L
234247
return nil
235248
}
236249

237-
// thank you golang for s***ing: I can't use/recycle/adapt utils.SliceContains
250+
// thank you golang: I can not use/recycle/adapt utils.SliceContains
238251
func sliceContainsLibrary(slice []*types.Library, target *types.Library) bool {
239252
for _, value := range slice {
240253
if value == target {

0 commit comments

Comments
 (0)