Skip to content

Commit de46825

Browse files
Remove IncludesToIncludeFolders.Run
In previous commits, this method has been signficantly simplified, reducing it to little more than a wrapper around the resolveLibrary helper function. This commit renames resolveLibrary to ResolveLibrary to make it public and lets findIncludesUntilDone call it directly (instead of going through IncludesToIncludeFolders). findIncludesUntilDone now also takes care of processing the ResolveLibrary result, which was previously done by IncludesToIncludeFolders. The signature of ResolveLibrary is also changed to accept a Context, so it can now extract the needed variables itself, instead of needing IncludesToIncludeFolders to extract them. Note that the filename that contains ResolveLibrary is no longer entirely accurate, but this will be fixed in a later commit (to simplify review of this commit). Signed-off-by: Matthijs Kooijman <matthijs@stdin.nl>
1 parent adc8cf9 commit de46825

File tree

2 files changed

+15
-35
lines changed

2 files changed

+15
-35
lines changed

src/arduino.cc/builder/container_find_includes.go

+13-4
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,10 @@ func runCommand(ctx *types.Context, command types.Command) error {
8484

8585
func findIncludesUntilDone(ctx *types.Context, sourceFilePath string) error {
8686
targetFilePath := utils.NULLFile()
87-
importedLibraries := ctx.ImportedLibraries
8887
for {
8988
commands := []types.Command{
9089
&GCCPreprocRunnerForDiscoveringIncludes{SourceFilePath: sourceFilePath, TargetFilePath: targetFilePath},
9190
&IncludesFinderWithRegExp{Source: &ctx.SourceGccMinusE},
92-
&IncludesToIncludeFolders{},
9391
}
9492
for _, command := range commands {
9593
err := runCommand(ctx, command)
@@ -102,10 +100,21 @@ func findIncludesUntilDone(ctx *types.Context, sourceFilePath string) error {
102100
return nil
103101
}
104102

105-
if len(ctx.ImportedLibraries) == len(importedLibraries) {
103+
library := ResolveLibrary(ctx, ctx.IncludeJustFound)
104+
if library == nil {
105+
// Library could not be resolved, show error
106106
err := runCommand(ctx, &GCCPreprocRunner{TargetFileName: constants.FILE_CTAGS_TARGET_FOR_GCC_MINUS_E})
107107
return i18n.WrapError(err)
108108
}
109-
importedLibraries = ctx.ImportedLibraries
109+
110+
// Add this library to the list of libraries, the
111+
// include path and queue its source files for further
112+
// include scanning
113+
ctx.ImportedLibraries = append(ctx.ImportedLibraries, library)
114+
ctx.IncludeFolders = append(ctx.IncludeFolders, library.SrcFolder)
115+
sourceFolders := types.LibraryToSourceFolder(library)
116+
for _, sourceFolder := range sourceFolders {
117+
QueueSourceFilesFromFolder(ctx.CollectedSourceFiles, sourceFolder.Folder, sourceFolder.Recurse)
118+
}
110119
}
111120
}

src/arduino.cc/builder/includes_to_include_folders.go

+2-31
Original file line numberDiff line numberDiff line change
@@ -38,41 +38,12 @@ import (
3838
"arduino.cc/builder/utils"
3939
)
4040

41-
type IncludesToIncludeFolders struct{}
42-
43-
func (s *IncludesToIncludeFolders) Run(ctx *types.Context) error {
44-
include := ctx.IncludeJustFound
45-
includeFolders := ctx.IncludeFolders
41+
func ResolveLibrary(ctx *types.Context, header string) *types.Library {
4642
headerToLibraries := ctx.HeaderToLibraries
47-
48-
platform := ctx.TargetPlatform
49-
actualPlatform := ctx.ActualPlatform
43+
platforms := []*types.Platform{ctx.ActualPlatform, ctx.TargetPlatform}
5044
libraryResolutionResults := ctx.LibrariesResolutionResults
5145
importedLibraries := ctx.ImportedLibraries
5246

53-
if include == "" {
54-
return nil;
55-
}
56-
57-
newlyImportedLibrary := resolveLibrary(include, headerToLibraries, importedLibraries, []*types.Platform{actualPlatform, platform}, libraryResolutionResults)
58-
if newlyImportedLibrary == nil {
59-
return nil;
60-
}
61-
62-
importedLibraries = append(importedLibraries, newlyImportedLibrary)
63-
sourceFolders := types.LibraryToSourceFolder(newlyImportedLibrary)
64-
for _, sourceFolder := range sourceFolders {
65-
QueueSourceFilesFromFolder(ctx.CollectedSourceFiles, sourceFolder.Folder, sourceFolder.Recurse)
66-
}
67-
includeFolders = append(includeFolders, newlyImportedLibrary.SrcFolder)
68-
69-
ctx.ImportedLibraries = importedLibraries
70-
ctx.IncludeFolders = includeFolders
71-
72-
return nil
73-
}
74-
75-
func resolveLibrary(header string, headerToLibraries map[string][]*types.Library, importedLibraries []*types.Library, platforms []*types.Platform, libraryResolutionResults map[string]types.LibraryResolutionResult) *types.Library {
7647
markImportedLibrary := make(map[*types.Library]bool)
7748
for _, library := range importedLibraries {
7849
markImportedLibrary[library] = true

0 commit comments

Comments
 (0)