Skip to content

Commit c788448

Browse files
Simplify IncludesToIncludeFolders
This code was written to handle processing of multiple includes after each other, but it only needs to handle one. This allows simplifying the code a bit. Behaviour should not be changed. Signed-off-by: Matthijs Kooijman <matthijs@stdin.nl>
1 parent 6b29889 commit c788448

File tree

1 file changed

+11
-23
lines changed

1 file changed

+11
-23
lines changed

src/arduino.cc/builder/includes_to_include_folders.go

+11-23
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ type IncludesToIncludeFolders struct{}
4242

4343
func (s *IncludesToIncludeFolders) Run(ctx *types.Context) error {
4444
include := ctx.IncludeJustFound
45-
includes := []string{include}
4645
includeFolders := ctx.IncludeFolders
4746
headerToLibraries := ctx.HeaderToLibraries
4847

@@ -55,43 +54,32 @@ func (s *IncludesToIncludeFolders) Run(ctx *types.Context) error {
5554
return nil;
5655
}
5756

58-
newlyImportedLibraries := resolveLibraries(includes, headerToLibraries, importedLibraries, []*types.Platform{actualPlatform, platform}, libraryResolutionResults)
57+
newlyImportedLibrary := resolveLibrary(include, headerToLibraries, importedLibraries, []*types.Platform{actualPlatform, platform}, libraryResolutionResults)
58+
if newlyImportedLibrary == nil {
59+
return nil;
60+
}
61+
5962
foldersWithSources := ctx.FoldersWithSourceFiles
6063

61-
for _, newlyImportedLibrary := range newlyImportedLibraries {
62-
if !sliceContainsLibrary(importedLibraries, newlyImportedLibrary) {
63-
importedLibraries = append(importedLibraries, newlyImportedLibrary)
64-
sourceFolders := types.LibraryToSourceFolder(newlyImportedLibrary)
65-
for _, sourceFolder := range sourceFolders {
66-
foldersWithSources.Push(sourceFolder)
67-
}
68-
includeFolders = append(includeFolders, newlyImportedLibrary.SrcFolder)
69-
}
64+
importedLibraries = append(importedLibraries, newlyImportedLibrary)
65+
sourceFolders := types.LibraryToSourceFolder(newlyImportedLibrary)
66+
for _, sourceFolder := range sourceFolders {
67+
foldersWithSources.Push(sourceFolder)
7068
}
69+
includeFolders = append(includeFolders, newlyImportedLibrary.SrcFolder)
7170

7271
ctx.ImportedLibraries = importedLibraries
7372
ctx.IncludeFolders = includeFolders
7473

7574
return nil
7675
}
7776

78-
func resolveLibraries(includes []string, headerToLibraries map[string][]*types.Library, importedLibraries []*types.Library, platforms []*types.Platform, libraryResolutionResults map[string]types.LibraryResolutionResult) []*types.Library {
77+
func resolveLibrary(header string, headerToLibraries map[string][]*types.Library, importedLibraries []*types.Library, platforms []*types.Platform, libraryResolutionResults map[string]types.LibraryResolutionResult) *types.Library {
7978
markImportedLibrary := make(map[*types.Library]bool)
8079
for _, library := range importedLibraries {
8180
markImportedLibrary[library] = true
8281
}
83-
var newlyImportedLibraries []*types.Library
84-
for _, header := range includes {
85-
library := resolveLibrary(header, headerToLibraries, markImportedLibrary, platforms, libraryResolutionResults)
86-
if library != nil {
87-
newlyImportedLibraries = append(newlyImportedLibraries, library)
88-
}
89-
}
90-
91-
return newlyImportedLibraries
92-
}
9382

94-
func resolveLibrary(header string, headerToLibraries map[string][]*types.Library, markImportedLibrary map[*types.Library]bool, platforms []*types.Platform, libraryResolutionResults map[string]types.LibraryResolutionResult) *types.Library {
9583
libraries := append([]*types.Library{}, headerToLibraries[header]...)
9684

9785
if libraries == nil || len(libraries) == 0 {

0 commit comments

Comments
 (0)