diff --git a/arduino/builder/sizer.go b/arduino/builder/sizer.go deleted file mode 100644 index 911f261af67..00000000000 --- a/arduino/builder/sizer.go +++ /dev/null @@ -1,26 +0,0 @@ -package builder - -import rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" - -// ExecutableSectionSize represents a section of the executable output file -type ExecutableSectionSize struct { - Name string `json:"name"` - Size int `json:"size"` - MaxSize int `json:"max_size"` -} - -// ExecutablesFileSections is an array of ExecutablesFileSection -type ExecutablesFileSections []ExecutableSectionSize - -// ToRPCExecutableSectionSizeArray transforms this array into a []*rpc.ExecutableSectionSize -func (s ExecutablesFileSections) ToRPCExecutableSectionSizeArray() []*rpc.ExecutableSectionSize { - res := []*rpc.ExecutableSectionSize{} - for _, section := range s { - res = append(res, &rpc.ExecutableSectionSize{ - Name: section.Name, - Size: int64(section.Size), - MaxSize: int64(section.MaxSize), - }) - } - return res -} diff --git a/legacy/builder/phases/sizer.go b/arduino/builder/sizer/sizer.go similarity index 87% rename from legacy/builder/phases/sizer.go rename to arduino/builder/sizer/sizer.go index bb96a7aaeb2..195ca3c1413 100644 --- a/legacy/builder/phases/sizer.go +++ b/arduino/builder/sizer/sizer.go @@ -13,7 +13,7 @@ // Arduino software without disclosing the source code of your own applications. // To purchase a commercial license, send an email to license@arduino.cc. -package phases +package sizer import ( "encoding/json" @@ -22,22 +22,46 @@ import ( "regexp" "strconv" - "github.com/arduino/arduino-cli/arduino/builder" "github.com/arduino/arduino-cli/arduino/builder/utils" "github.com/arduino/arduino-cli/i18n" + rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" "github.com/arduino/go-properties-orderedmap" "github.com/pkg/errors" ) var tr = i18n.Tr -func Sizer( +// ExecutableSectionSize represents a section of the executable output file +type ExecutableSectionSize struct { + Name string `json:"name"` + Size int `json:"size"` + MaxSize int `json:"max_size"` +} + +// ExecutablesFileSections is an array of ExecutablesFileSection +type ExecutablesFileSections []ExecutableSectionSize + +// ToRPCExecutableSectionSizeArray transforms this array into a []*rpc.ExecutableSectionSize +func (s ExecutablesFileSections) ToRPCExecutableSectionSizeArray() []*rpc.ExecutableSectionSize { + res := []*rpc.ExecutableSectionSize{} + for _, section := range s { + res = append(res, &rpc.ExecutableSectionSize{ + Name: section.Name, + Size: int64(section.Size), + MaxSize: int64(section.MaxSize), + }) + } + return res +} + +// Size fixdoc +func Size( onlyUpdateCompilationDatabase, sketchError, verbose bool, buildProperties *properties.Map, stdoutWriter, stderrWriter io.Writer, printInfoFn, printWarnFn func(msg string), warningsLevel string, -) (builder.ExecutablesFileSections, error) { +) (ExecutablesFileSections, error) { if onlyUpdateCompilationDatabase || sketchError { return nil, nil } @@ -53,7 +77,7 @@ func checkSizeAdvanced(buildProperties *properties.Map, verbose bool, stdoutWriter, stderrWriter io.Writer, printInfoFn, printWarnFn func(msg string), -) (builder.ExecutablesFileSections, error) { +) (ExecutablesFileSections, error) { command, err := utils.PrepareCommandForRecipe(buildProperties, "recipe.advanced_size.pattern", false) if err != nil { return nil, errors.New(tr("Error while determining sketch size: %s", err)) @@ -74,7 +98,7 @@ func checkSizeAdvanced(buildProperties *properties.Map, // likely be printed in red. Errors will stop build/upload. Severity string `json:"severity"` // Sections are the sections sizes for machine readable use - Sections []builder.ExecutableSectionSize `json:"sections"` + Sections []ExecutableSectionSize `json:"sections"` // ErrorMessage is a one line error message like: // "text section exceeds available space in board" // it must be set when Severity is "error" @@ -106,7 +130,7 @@ func checkSize(buildProperties *properties.Map, stdoutWriter, stderrWriter io.Writer, printInfoFn, printWarnFn func(msg string), warningsLevel string, -) (builder.ExecutablesFileSections, error) { +) (ExecutablesFileSections, error) { properties := buildProperties.Clone() properties.Set("compiler.warning_flags", properties.Get("compiler.warning_flags."+warningsLevel)) @@ -152,7 +176,7 @@ func checkSize(buildProperties *properties.Map, } } - executableSectionsSize := []builder.ExecutableSectionSize{ + executableSectionsSize := []ExecutableSectionSize{ { Name: "text", Size: textSize, @@ -160,7 +184,7 @@ func checkSize(buildProperties *properties.Map, }, } if maxDataSize > 0 { - executableSectionsSize = append(executableSectionsSize, builder.ExecutableSectionSize{ + executableSectionsSize = append(executableSectionsSize, ExecutableSectionSize{ Name: "data", Size: dataSize, MaxSize: maxDataSize, diff --git a/legacy/builder/phases/sizer_test.go b/arduino/builder/sizer/sizer_test.go similarity index 99% rename from legacy/builder/phases/sizer_test.go rename to arduino/builder/sizer/sizer_test.go index 42e26fdcfa3..42c3b323d42 100644 --- a/legacy/builder/phases/sizer_test.go +++ b/arduino/builder/sizer/sizer_test.go @@ -13,7 +13,7 @@ // Arduino software without disclosing the source code of your own applications. // To purchase a commercial license, send an email to license@arduino.cc. -package phases +package sizer import ( "testing" diff --git a/legacy/builder/builder.go b/legacy/builder/builder.go index 135644e29bc..a0657046922 100644 --- a/legacy/builder/builder.go +++ b/legacy/builder/builder.go @@ -21,9 +21,9 @@ import ( "github.com/arduino/arduino-cli/arduino/builder" "github.com/arduino/arduino-cli/arduino/builder/preprocessor" + "github.com/arduino/arduino-cli/arduino/builder/sizer" "github.com/arduino/arduino-cli/arduino/sketch" "github.com/arduino/arduino-cli/i18n" - "github.com/arduino/arduino-cli/legacy/builder/phases" "github.com/arduino/arduino-cli/legacy/builder/types" "github.com/arduino/go-paths-helper" properties "github.com/arduino/go-properties-orderedmap" @@ -273,7 +273,7 @@ func (s *Builder) Run(ctx *types.Context) error { }), types.BareCommand(func(ctx *types.Context) error { - executableSectionsSize, err := phases.Sizer( + executableSectionsSize, err := sizer.Size( ctx.OnlyUpdateCompilationDatabase, mainErr != nil, ctx.Verbose, ctx.BuildProperties, ctx.Stdout, ctx.Stderr, diff --git a/legacy/builder/types/context.go b/legacy/builder/types/context.go index 4b6383ad9f8..7c5f394fa24 100644 --- a/legacy/builder/types/context.go +++ b/legacy/builder/types/context.go @@ -25,6 +25,7 @@ import ( "github.com/arduino/arduino-cli/arduino/builder/compilation" "github.com/arduino/arduino-cli/arduino/builder/detector" "github.com/arduino/arduino-cli/arduino/builder/progress" + "github.com/arduino/arduino-cli/arduino/builder/sizer" "github.com/arduino/arduino-cli/arduino/cores" "github.com/arduino/arduino-cli/arduino/cores/packagemanager" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" @@ -88,7 +89,7 @@ type Context struct { stdLock sync.Mutex // Sizer results - ExecutableSectionsSize builder.ExecutablesFileSections + ExecutableSectionsSize sizer.ExecutablesFileSections // Compilation Database to build/update CompilationDatabase *compilation.Database