@@ -24,6 +24,7 @@ import (
24
24
"github.com/arduino/arduino-cli/arduino/builder/logger"
25
25
"github.com/arduino/arduino-cli/arduino/builder/progress"
26
26
"github.com/arduino/arduino-cli/arduino/cores"
27
+ "github.com/arduino/arduino-cli/arduino/libraries/librariesmanager"
27
28
"github.com/arduino/arduino-cli/arduino/sketch"
28
29
"github.com/arduino/go-paths-helper"
29
30
"github.com/arduino/go-properties-orderedmap"
@@ -78,6 +79,7 @@ type Builder struct {
78
79
79
80
buildArtifacts * BuildArtifacts
80
81
82
+ * detector.SketchLibrariesDetector
81
83
* BuildOptionsManager
82
84
}
83
85
@@ -110,6 +112,9 @@ func NewBuilder(
110
112
sourceOverrides map [string ]string ,
111
113
onlyUpdateCompilationDatabase bool ,
112
114
targetPlatform , actualPlatform * cores.PlatformRelease ,
115
+ useCachedLibrariesResolution bool ,
116
+ librariesManager * librariesmanager.LibrariesManager ,
117
+ libraryDirs paths.PathList ,
113
118
logger * logger.BuilderLogger ,
114
119
progressStats * progress.Struct ,
115
120
) (* Builder , error ) {
@@ -164,6 +169,18 @@ func NewBuilder(
164
169
progressStats = progress .New (nil )
165
170
}
166
171
172
+ libsManager , libsResolver , verboseOut , err := detector .LibrariesLoader (
173
+ useCachedLibrariesResolution , librariesManager ,
174
+ builtInLibrariesDirs , libraryDirs , otherLibrariesDirs ,
175
+ actualPlatform , targetPlatform ,
176
+ )
177
+ if err != nil {
178
+ return nil , err
179
+ }
180
+ if logger .Verbose () {
181
+ logger .Warn (string (verboseOut ))
182
+ }
183
+
167
184
return & Builder {
168
185
sketch : sk ,
169
186
buildProperties : buildProperties ,
@@ -184,6 +201,12 @@ func NewBuilder(
184
201
buildArtifacts : & BuildArtifacts {},
185
202
targetPlatform : targetPlatform ,
186
203
actualPlatform : actualPlatform ,
204
+ SketchLibrariesDetector : detector .NewSketchLibrariesDetector (
205
+ libsManager , libsResolver ,
206
+ useCachedLibrariesResolution ,
207
+ onlyUpdateCompilationDatabase ,
208
+ logger ,
209
+ ),
187
210
BuildOptionsManager : NewBuildOptionsManager (
188
211
hardwareDirs , builtInToolsDirs , otherLibrariesDirs ,
189
212
builtInLibrariesDirs , buildPath ,
@@ -230,13 +253,13 @@ func (b *Builder) TargetPlatform() *cores.PlatformRelease {
230
253
}
231
254
232
255
// Preprocess fixdoc
233
- func (b * Builder ) Preprocess (detector * detector. SketchLibrariesDetector ) error {
256
+ func (b * Builder ) Preprocess () error {
234
257
b .Progress .AddSubSteps (6 )
235
258
defer b .Progress .RemoveSubSteps ()
236
- return b .preprocess (detector )
259
+ return b .preprocess ()
237
260
}
238
261
239
- func (b * Builder ) preprocess (detector * detector. SketchLibrariesDetector ) error {
262
+ func (b * Builder ) preprocess () error {
240
263
if err := b .buildPath .MkdirAll (); err != nil {
241
264
return err
242
265
}
@@ -260,7 +283,7 @@ func (b *Builder) preprocess(detector *detector.SketchLibrariesDetector) error {
260
283
b .Progress .PushProgress ()
261
284
262
285
b .logIfVerbose (false , tr ("Detecting libraries used..." ))
263
- err := detector .FindIncludes (
286
+ err := b . SketchLibrariesDetector .FindIncludes (
264
287
b .GetBuildPath (),
265
288
b .GetBuildProperties ().GetPath ("build.core.path" ),
266
289
b .GetBuildProperties ().GetPath ("build.variant.path" ),
@@ -276,12 +299,12 @@ func (b *Builder) preprocess(detector *detector.SketchLibrariesDetector) error {
276
299
b .Progress .CompleteStep ()
277
300
b .Progress .PushProgress ()
278
301
279
- b .WarnAboutArchIncompatibleLibraries (detector .ImportedLibraries ())
302
+ b .WarnAboutArchIncompatibleLibraries (b . SketchLibrariesDetector .ImportedLibraries ())
280
303
b .Progress .CompleteStep ()
281
304
b .Progress .PushProgress ()
282
305
283
306
b .logIfVerbose (false , tr ("Generating function prototypes..." ))
284
- if err := b .PreprocessSketch (detector .IncludeFolders ()); err != nil {
307
+ if err := b .PreprocessSketch (b . SketchLibrariesDetector .IncludeFolders ()); err != nil {
285
308
return err
286
309
}
287
310
b .Progress .CompleteStep ()
@@ -309,28 +332,28 @@ func (b *Builder) logIfVerbose(warn bool, msg string) {
309
332
}
310
333
311
334
// Build fixdoc
312
- func (b * Builder ) Build (detector * detector. SketchLibrariesDetector ) error {
335
+ func (b * Builder ) Build () error {
313
336
b .Progress .AddSubSteps (6 /** preprocess **/ + 21 /** build **/ )
314
337
defer b .Progress .RemoveSubSteps ()
315
338
316
- if err := b .preprocess (detector ); err != nil {
339
+ if err := b .preprocess (); err != nil {
317
340
return err
318
341
}
319
342
320
- buildErr := b .build (detector )
343
+ buildErr := b .build ()
321
344
322
- detector .PrintUsedAndNotUsedLibraries (buildErr != nil )
345
+ b . SketchLibrariesDetector .PrintUsedAndNotUsedLibraries (buildErr != nil )
323
346
b .Progress .CompleteStep ()
324
347
b .Progress .PushProgress ()
325
348
326
- b .PrintUsedLibraries (detector .ImportedLibraries ())
349
+ b .PrintUsedLibraries (b . SketchLibrariesDetector .ImportedLibraries ())
327
350
b .Progress .CompleteStep ()
328
351
b .Progress .PushProgress ()
329
352
330
353
if buildErr != nil {
331
354
return buildErr
332
355
}
333
- if err := b .ExportProjectCMake (detector . ImportedLibraries (), detector .IncludeFolders ()); err != nil {
356
+ if err := b .ExportProjectCMake (b . SketchLibrariesDetector . ImportedLibraries (), b . SketchLibrariesDetector .IncludeFolders ()); err != nil {
334
357
return err
335
358
}
336
359
b .Progress .CompleteStep ()
@@ -346,15 +369,15 @@ func (b *Builder) Build(detector *detector.SketchLibrariesDetector) error {
346
369
}
347
370
348
371
// Build fixdoc
349
- func (b * Builder ) build (detector * detector. SketchLibrariesDetector ) error {
372
+ func (b * Builder ) build () error {
350
373
b .logIfVerbose (false , tr ("Compiling sketch..." ))
351
374
if err := b .RunRecipe ("recipe.hooks.sketch.prebuild" , ".pattern" , false ); err != nil {
352
375
return err
353
376
}
354
377
b .Progress .CompleteStep ()
355
378
b .Progress .PushProgress ()
356
379
357
- if err := b .BuildSketch (detector .IncludeFolders ()); err != nil {
380
+ if err := b .BuildSketch (b . SketchLibrariesDetector .IncludeFolders ()); err != nil {
358
381
return err
359
382
}
360
383
b .Progress .CompleteStep ()
@@ -373,13 +396,13 @@ func (b *Builder) build(detector *detector.SketchLibrariesDetector) error {
373
396
b .Progress .CompleteStep ()
374
397
b .Progress .PushProgress ()
375
398
376
- if err := b .RemoveUnusedCompiledLibraries (detector .ImportedLibraries ()); err != nil {
399
+ if err := b .RemoveUnusedCompiledLibraries (b . SketchLibrariesDetector .ImportedLibraries ()); err != nil {
377
400
return err
378
401
}
379
402
b .Progress .CompleteStep ()
380
403
b .Progress .PushProgress ()
381
404
382
- if err := b .BuildLibraries (detector . IncludeFolders (), detector .ImportedLibraries ()); err != nil {
405
+ if err := b .BuildLibraries (b . SketchLibrariesDetector . IncludeFolders (), b . SketchLibrariesDetector .ImportedLibraries ()); err != nil {
383
406
return err
384
407
}
385
408
b .Progress .CompleteStep ()
0 commit comments