Skip to content

Commit

Permalink
move sizer phases in arduino/builder/sizer
Browse files Browse the repository at this point in the history
  • Loading branch information
alessio-perugini committed Sep 11, 2023
1 parent 8f8fe39 commit b13222c
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 39 deletions.
26 changes: 0 additions & 26 deletions arduino/builder/sizer.go

This file was deleted.

42 changes: 33 additions & 9 deletions legacy/builder/phases/sizer.go → arduino/builder/sizer/sizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to [email protected].

package phases
package sizer

import (
"encoding/json"
Expand All @@ -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
}
Expand All @@ -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))
Expand All @@ -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"
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -152,15 +176,15 @@ func checkSize(buildProperties *properties.Map,
}
}

executableSectionsSize := []builder.ExecutableSectionSize{
executableSectionsSize := []ExecutableSectionSize{
{
Name: "text",
Size: textSize,
MaxSize: maxTextSize,
},
}
if maxDataSize > 0 {
executableSectionsSize = append(executableSectionsSize, builder.ExecutableSectionSize{
executableSectionsSize = append(executableSectionsSize, ExecutableSectionSize{
Name: "data",
Size: dataSize,
MaxSize: maxDataSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to [email protected].

package phases
package sizer

import (
"testing"
Expand Down
4 changes: 2 additions & 2 deletions legacy/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion legacy/builder/types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b13222c

Please sign in to comment.