@@ -98,7 +98,6 @@ import (
98
98
"os/exec"
99
99
"time"
100
100
101
- "github.com/arduino/arduino-cli/arduino/sketch"
102
101
"github.com/arduino/arduino-cli/legacy/builder/builder_utils"
103
102
"github.com/arduino/arduino-cli/legacy/builder/types"
104
103
"github.com/arduino/arduino-cli/legacy/builder/utils"
@@ -127,9 +126,16 @@ func (s *ContainerFindIncludes) findIncludes(ctx *types.Context) error {
127
126
if variantPath := ctx .BuildProperties .GetPath ("build.variant.path" ); variantPath != nil {
128
127
finder .UseIncludeDir (variantPath )
129
128
}
129
+ finder .AddSourceFile (ctx .SketchBuildPath , ctx .SketchBuildPath , paths .New (ctx .Sketch .MainFile .Base ()+ ".cpp" ))
130
+ finder .AddSourceDir (ctx .SketchBuildPath , ctx .SketchBuildPath , false /* recurse */ )
131
+ if srcSubfolderPath := ctx .SketchBuildPath .Join ("src" ); srcSubfolderPath .IsDir () {
132
+ finder .AddSourceDir (srcSubfolderPath , ctx .SketchBuildPath , true /* recurse */ )
133
+ }
134
+
130
135
if err := finder .DetectLibraries (); err != nil {
131
136
return err
132
137
}
138
+
133
139
ctx .IncludeFolders .AddAllMissing (finder .IncludeDirsFound )
134
140
if err := runCommand (ctx , & FailIfImportedLibraryIsWrong {}); err != nil {
135
141
return errors .WithStack (err )
@@ -145,19 +151,17 @@ type CppIncludesFinder struct {
145
151
IncludeDirsFound paths.PathList
146
152
ctx * types.Context
147
153
cache * includeCache
148
- sketch * sketch.Sketch
149
154
queue * UniqueSourceFileQueue
150
155
log * logrus.Entry
151
156
}
152
157
153
158
// NewCppIncludesFinder create a new include
154
159
func NewCppIncludesFinder (ctx * types.Context ) * CppIncludesFinder {
155
160
return & CppIncludesFinder {
156
- ctx : ctx ,
157
- cache : loadCacheFrom (ctx .BuildPath .Join ("includes.cache" )),
158
- sketch : ctx .Sketch ,
159
- queue : & UniqueSourceFileQueue {},
160
- log : logrus .WithField ("task" , "DetectingLibraries" ),
161
+ ctx : ctx ,
162
+ cache : loadCacheFrom (ctx .BuildPath .Join ("includes.cache" )),
163
+ queue : & UniqueSourceFileQueue {},
164
+ log : logrus .WithField ("task" , "DetectingLibraries" ),
161
165
}
162
166
}
163
167
@@ -168,19 +172,6 @@ func (f *CppIncludesFinder) DetectLibraries() error {
168
172
f .cache .AddAndCheckEntry (nil , "" , includeDir )
169
173
}
170
174
171
- mergedfile , err := MakeSourceFile (f .ctx .SketchBuildPath , f .ctx .SketchBuildPath , paths .New (f .sketch .MainFile .Base ()+ ".cpp" ))
172
- if err != nil {
173
- return errors .WithStack (err )
174
- }
175
- f .log .Debugf ("Queueing merged sketch: %s" , mergedfile )
176
- f .queue .Push (mergedfile )
177
-
178
- f .queueSourceFilesFromFolder (f .ctx .SketchBuildPath , f .ctx .SketchBuildPath , false /* recurse */ )
179
- srcSubfolderPath := f .ctx .SketchBuildPath .Join ("src" )
180
- if srcSubfolderPath .IsDir () {
181
- f .queueSourceFilesFromFolder (srcSubfolderPath , f .ctx .SketchBuildPath , true /* recurse */ )
182
- }
183
-
184
175
for ! f .queue .Empty () {
185
176
if err := f .findIncludesUntilDone (f .queue .Pop ()); err != nil {
186
177
f .cache .Remove ()
@@ -201,6 +192,38 @@ func (f *CppIncludesFinder) UseIncludeDir(includeDir *paths.Path) {
201
192
f .IncludeDirsFound .Add (includeDir )
202
193
}
203
194
195
+ // AddSourceFile adds a source file to be examined to look for library imports
196
+ func (f * CppIncludesFinder ) AddSourceFile (sourceRoot , buildRoot , srcPath * paths.Path ) error {
197
+ if file , err := MakeSourceFile (sourceRoot , buildRoot , srcPath ); err == nil {
198
+ f .log .Debugf ("Queueing source file: %s" , file )
199
+ f .queue .Push (file )
200
+ } else {
201
+ return errors .WithStack (err )
202
+ }
203
+ return nil
204
+ }
205
+
206
+ // AddSourceDir adds a directory of source file to be examined to look for library imports
207
+ func (f * CppIncludesFinder ) AddSourceDir (srcDir , buildDir * paths.Path , recurse bool ) error {
208
+ extensions := func (ext string ) bool { return ADDITIONAL_FILE_VALID_EXTENSIONS_NO_HEADERS [ext ] }
209
+ f .log .Debugf (" Queueing source files from %s (recurse %v)" , srcDir , recurse )
210
+ filePaths , err := utils .FindFilesInFolder (srcDir .String (), extensions , recurse )
211
+ if err != nil {
212
+ return errors .WithStack (err )
213
+ }
214
+
215
+ for _ , filePath := range filePaths {
216
+ sourceFile , err := MakeSourceFile (srcDir , buildDir , paths .New (filePath ))
217
+ if err != nil {
218
+ return errors .WithStack (err )
219
+ }
220
+ f .log .Debugf (" Queuing %s" , sourceFile )
221
+ f .queue .Push (sourceFile )
222
+ }
223
+
224
+ return nil
225
+ }
226
+
204
227
func runCommand (ctx * types.Context , command types.Command ) error {
205
228
PrintRingNameIfDebug (ctx , command )
206
229
err := command .Run (ctx )
@@ -444,33 +467,13 @@ func (f *CppIncludesFinder) findIncludesUntilDone(sourceFile *SourceFile) error
444
467
f .ctx .Info (tr ("Skipping dependencies detection for precompiled library %[1]s" , library .Name ))
445
468
}
446
469
} else {
447
- f .queueSourceFilesFromFolder (buildDir , sourceDir .Dir , sourceDir .Recurse )
470
+ f .AddSourceDir (buildDir , sourceDir .Dir , sourceDir .Recurse )
448
471
}
449
472
}
450
473
first = false
451
474
}
452
475
}
453
476
454
- func (f * CppIncludesFinder ) queueSourceFilesFromFolder (srcDir , buildDir * paths.Path , recurse bool ) error {
455
- extensions := func (ext string ) bool { return ADDITIONAL_FILE_VALID_EXTENSIONS_NO_HEADERS [ext ] }
456
- f .log .Debugf (" Queueing source files from %s (recurse %v)" , srcDir , recurse )
457
- filePaths , err := utils .FindFilesInFolder (srcDir .String (), extensions , recurse )
458
- if err != nil {
459
- return errors .WithStack (err )
460
- }
461
-
462
- for _ , filePath := range filePaths {
463
- sourceFile , err := MakeSourceFile (srcDir , buildDir , paths .New (filePath ))
464
- if err != nil {
465
- return errors .WithStack (err )
466
- }
467
- f .log .Debugf (" Queuing %s" , sourceFile )
468
- f .queue .Push (sourceFile )
469
- }
470
-
471
- return nil
472
- }
473
-
474
477
// SourceFile represent a source file, it keeps a reference to the root source
475
478
// directory and the corresponding build root directory.
476
479
type SourceFile struct {
0 commit comments