@@ -18,14 +18,17 @@ package builder
1818import (
1919 "errors"
2020 "fmt"
21+ "io"
2122
22- "github.com/arduino/arduino-cli/arduino/builder/compilation"
23- "github.com/arduino/arduino-cli/arduino/builder/detector"
24- "github.com/arduino/arduino-cli/arduino/builder/logger"
25- "github.com/arduino/arduino-cli/arduino/builder/progress"
23+ "github.com/arduino/arduino-cli/arduino/builder/internal/ compilation"
24+ "github.com/arduino/arduino-cli/arduino/builder/internal/ detector"
25+ "github.com/arduino/arduino-cli/arduino/builder/internal/ logger"
26+ "github.com/arduino/arduino-cli/arduino/builder/internal/ progress"
2627 "github.com/arduino/arduino-cli/arduino/cores"
28+ "github.com/arduino/arduino-cli/arduino/libraries"
2729 "github.com/arduino/arduino-cli/arduino/libraries/librariesmanager"
2830 "github.com/arduino/arduino-cli/arduino/sketch"
31+ rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2932 "github.com/arduino/go-paths-helper"
3033 "github.com/arduino/go-properties-orderedmap"
3134)
@@ -77,14 +80,15 @@ type Builder struct {
7780 targetPlatform * cores.PlatformRelease
7881 actualPlatform * cores.PlatformRelease
7982
80- buildArtifacts * BuildArtifacts
83+ buildArtifacts * buildArtifacts
8184
82- * detector.SketchLibrariesDetector
83- * BuildOptionsManager
85+ buildOptions * buildOptions
86+
87+ libsDetector * detector.SketchLibrariesDetector
8488}
8589
86- // BuildArtifacts contains the result of various build
87- type BuildArtifacts struct {
90+ // buildArtifacts contains the result of various build
91+ type buildArtifacts struct {
8892 // populated by BuildCore
8993 coreArchiveFilePath * paths.Path
9094 coreObjectsFiles paths.PathList
@@ -115,8 +119,8 @@ func NewBuilder(
115119 useCachedLibrariesResolution bool ,
116120 librariesManager * librariesmanager.LibrariesManager ,
117121 libraryDirs paths.PathList ,
118- logger * logger. BuilderLogger ,
119- progressStats * progress. Struct ,
122+ stdout , stderr io. Writer , verbose bool , warningsLevel string ,
123+ progresCB rpc. TaskProgressCB ,
120124) (* Builder , error ) {
121125 buildProperties := properties .NewMap ()
122126 if boardBuildProperties != nil {
@@ -165,10 +169,7 @@ func NewBuilder(
165169 return nil , ErrSketchCannotBeLocatedInBuildPath
166170 }
167171
168- if progressStats == nil {
169- progressStats = progress .New (nil )
170- }
171-
172+ logger := logger .New (stdout , stderr , verbose , warningsLevel )
172173 libsManager , libsResolver , verboseOut , err := detector .LibrariesLoader (
173174 useCachedLibrariesResolution , librariesManager ,
174175 builtInLibrariesDirs , libraryDirs , otherLibrariesDirs ,
@@ -196,18 +197,18 @@ func NewBuilder(
196197 sourceOverrides : sourceOverrides ,
197198 onlyUpdateCompilationDatabase : onlyUpdateCompilationDatabase ,
198199 compilationDatabase : compilation .NewDatabase (buildPath .Join ("compile_commands.json" )),
199- Progress : progressStats ,
200+ Progress : progress . New ( progresCB ) ,
200201 executableSectionsSize : []ExecutableSectionSize {},
201- buildArtifacts : & BuildArtifacts {},
202+ buildArtifacts : & buildArtifacts {},
202203 targetPlatform : targetPlatform ,
203204 actualPlatform : actualPlatform ,
204- SketchLibrariesDetector : detector .NewSketchLibrariesDetector (
205+ libsDetector : detector .NewSketchLibrariesDetector (
205206 libsManager , libsResolver ,
206207 useCachedLibrariesResolution ,
207208 onlyUpdateCompilationDatabase ,
208209 logger ,
209210 ),
210- BuildOptionsManager : NewBuildOptionsManager (
211+ buildOptions : newBuildOptions (
211212 hardwareDirs , builtInToolsDirs , otherLibrariesDirs ,
212213 builtInLibrariesDirs , buildPath ,
213214 sk ,
@@ -217,7 +218,6 @@ func NewBuilder(
217218 buildProperties .Get ("compiler.optimization_flags" ),
218219 buildProperties .GetPath ("runtime.platform.path" ),
219220 buildProperties .GetPath ("build.core.path" ), // TODO can we buildCorePath ?
220- logger ,
221221 ),
222222 }, nil
223223}
@@ -237,6 +237,11 @@ func (b *Builder) ExecutableSectionsSize() ExecutablesFileSections {
237237 return b .executableSectionsSize
238238}
239239
240+ // ImportedLibraries fixdoc
241+ func (b * Builder ) ImportedLibraries () libraries.List {
242+ return b .libsDetector .ImportedLibraries ()
243+ }
244+
240245// Preprocess fixdoc
241246func (b * Builder ) Preprocess () error {
242247 b .Progress .AddSubSteps (6 )
@@ -249,7 +254,10 @@ func (b *Builder) preprocess() error {
249254 return err
250255 }
251256
252- if err := b .BuildOptionsManager .WipeBuildPath (); err != nil {
257+ if err := b .wipeBuildPathIfBuildOptionsChanged (); err != nil {
258+ return err
259+ }
260+ if err := b .createBuildOptionsJSON (); err != nil {
253261 return err
254262 }
255263 b .Progress .CompleteStep ()
@@ -268,7 +276,7 @@ func (b *Builder) preprocess() error {
268276 b .Progress .PushProgress ()
269277
270278 b .logIfVerbose (false , tr ("Detecting libraries used..." ))
271- err := b .SketchLibrariesDetector .FindIncludes (
279+ err := b .libsDetector .FindIncludes (
272280 b .buildPath ,
273281 b .buildProperties .GetPath ("build.core.path" ),
274282 b .buildProperties .GetPath ("build.variant.path" ),
@@ -284,12 +292,12 @@ func (b *Builder) preprocess() error {
284292 b .Progress .CompleteStep ()
285293 b .Progress .PushProgress ()
286294
287- b .warnAboutArchIncompatibleLibraries (b .SketchLibrariesDetector .ImportedLibraries ())
295+ b .warnAboutArchIncompatibleLibraries (b .libsDetector .ImportedLibraries ())
288296 b .Progress .CompleteStep ()
289297 b .Progress .PushProgress ()
290298
291299 b .logIfVerbose (false , tr ("Generating function prototypes..." ))
292- if err := b .preprocessSketch (b .SketchLibrariesDetector .IncludeFolders ()); err != nil {
300+ if err := b .preprocessSketch (b .libsDetector .IncludeFolders ()); err != nil {
293301 return err
294302 }
295303 b .Progress .CompleteStep ()
@@ -327,18 +335,18 @@ func (b *Builder) Build() error {
327335
328336 buildErr := b .build ()
329337
330- b .SketchLibrariesDetector .PrintUsedAndNotUsedLibraries (buildErr != nil )
338+ b .libsDetector .PrintUsedAndNotUsedLibraries (buildErr != nil )
331339 b .Progress .CompleteStep ()
332340 b .Progress .PushProgress ()
333341
334- b .printUsedLibraries (b .SketchLibrariesDetector .ImportedLibraries ())
342+ b .printUsedLibraries (b .libsDetector .ImportedLibraries ())
335343 b .Progress .CompleteStep ()
336344 b .Progress .PushProgress ()
337345
338346 if buildErr != nil {
339347 return buildErr
340348 }
341- if err := b .exportProjectCMake (b .SketchLibrariesDetector .ImportedLibraries (), b .SketchLibrariesDetector .IncludeFolders ()); err != nil {
349+ if err := b .exportProjectCMake (b .libsDetector .ImportedLibraries (), b .libsDetector .IncludeFolders ()); err != nil {
342350 return err
343351 }
344352 b .Progress .CompleteStep ()
@@ -362,7 +370,7 @@ func (b *Builder) build() error {
362370 b .Progress .CompleteStep ()
363371 b .Progress .PushProgress ()
364372
365- if err := b .BuildSketch (b .SketchLibrariesDetector .IncludeFolders ()); err != nil {
373+ if err := b .BuildSketch (b .libsDetector .IncludeFolders ()); err != nil {
366374 return err
367375 }
368376 b .Progress .CompleteStep ()
@@ -381,13 +389,13 @@ func (b *Builder) build() error {
381389 b .Progress .CompleteStep ()
382390 b .Progress .PushProgress ()
383391
384- if err := b .removeUnusedCompiledLibraries (b .SketchLibrariesDetector .ImportedLibraries ()); err != nil {
392+ if err := b .removeUnusedCompiledLibraries (b .libsDetector .ImportedLibraries ()); err != nil {
385393 return err
386394 }
387395 b .Progress .CompleteStep ()
388396 b .Progress .PushProgress ()
389397
390- if err := b .buildLibraries (b .SketchLibrariesDetector .IncludeFolders (), b .SketchLibrariesDetector .ImportedLibraries ()); err != nil {
398+ if err := b .buildLibraries (b .libsDetector .IncludeFolders (), b .libsDetector .ImportedLibraries ()); err != nil {
391399 return err
392400 }
393401 b .Progress .CompleteStep ()
0 commit comments