From fdd9ec64e87a2972645940c9e2891497bfdbc761 Mon Sep 17 00:00:00 2001 From: Alessio Perugini Date: Tue, 12 Sep 2023 20:12:50 +0200 Subject: [PATCH] remove ExecutableSectionSize from Context --- arduino/builder/builder.go | 8 ++++++++ arduino/builder/sizer.go | 16 ++++++++++++---- commands/compile/compile.go | 2 +- legacy/builder/builder.go | 4 +--- legacy/builder/types/context.go | 3 --- 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/arduino/builder/builder.go b/arduino/builder/builder.go index 931c8b829c9..93c5579b205 100644 --- a/arduino/builder/builder.go +++ b/arduino/builder/builder.go @@ -63,6 +63,9 @@ type Builder struct { // Progress of all various steps Progress *progress.Struct + // Sizer results + executableSectionsSize ExecutablesFileSections + *BuildOptionsManager } @@ -184,3 +187,8 @@ func (b *Builder) GetSketchBuildPath() *paths.Path { func (b *Builder) GetLibrariesBuildPath() *paths.Path { return b.librariesBuildPath } + +// ExecutableSectionsSize fixdoc +func (b *Builder) ExecutableSectionsSize() ExecutablesFileSections { + return b.executableSectionsSize +} diff --git a/arduino/builder/sizer.go b/arduino/builder/sizer.go index 7b984b24f67..7f461f8292e 100644 --- a/arduino/builder/sizer.go +++ b/arduino/builder/sizer.go @@ -51,16 +51,24 @@ func (s ExecutablesFileSections) ToRPCExecutableSectionSizeArray() []*rpc.Execut } // Size fixdoc -func (b *Builder) Size(sketchError bool) (ExecutablesFileSections, error) { +func (b *Builder) Size(sketchError bool) error { if b.onlyUpdateCompilationDatabase || sketchError { - return nil, nil + return nil } + check := b.checkSize if b.buildProperties.ContainsKey("recipe.advanced_size.pattern") { - return b.checkSizeAdvanced() + check = b.checkSizeAdvanced } - return b.checkSize() + result, err := check() + if err != nil { + return err + } + + b.executableSectionsSize = result + + return nil } func (b *Builder) checkSizeAdvanced() (ExecutablesFileSections, error) { diff --git a/commands/compile/compile.go b/commands/compile/compile.go index a599590a6b2..71ff699dcb2 100644 --- a/commands/compile/compile.go +++ b/commands/compile/compile.go @@ -384,7 +384,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream } } - r.ExecutableSectionsSize = builderCtx.ExecutableSectionsSize.ToRPCExecutableSectionSizeArray() + r.ExecutableSectionsSize = sketchBuilder.ExecutableSectionsSize().ToRPCExecutableSectionSizeArray() logrus.Tracef("Compile %s for %s successful", sk.Name, fqbnIn) diff --git a/legacy/builder/builder.go b/legacy/builder/builder.go index 6a5c9a9f3ca..b1c7b29e5fa 100644 --- a/legacy/builder/builder.go +++ b/legacy/builder/builder.go @@ -202,9 +202,7 @@ func (s *Builder) Run(ctx *types.Context) error { }), types.BareCommand(func(ctx *types.Context) error { - executableSectionsSize, err := ctx.Builder.Size(mainErr != nil) - ctx.ExecutableSectionsSize = executableSectionsSize - return err + return ctx.Builder.Size(mainErr != nil) }), } for _, command := range commands { diff --git a/legacy/builder/types/context.go b/legacy/builder/types/context.go index cc8f45c8b33..3e6dd46ba26 100644 --- a/legacy/builder/types/context.go +++ b/legacy/builder/types/context.go @@ -49,9 +49,6 @@ type Context struct { // C++ Parsing LineOffset int - // Sizer results - ExecutableSectionsSize builder.ExecutablesFileSections - // Compilation Database to build/update CompilationDatabase *compilation.Database }