Skip to content

Commit b13222c

Browse files
move sizer phases in arduino/builder/sizer
1 parent 8f8fe39 commit b13222c

File tree

5 files changed

+38
-39
lines changed

5 files changed

+38
-39
lines changed

arduino/builder/sizer.go

Lines changed: 0 additions & 26 deletions
This file was deleted.

legacy/builder/phases/sizer.go renamed to arduino/builder/sizer/sizer.go

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// Arduino software without disclosing the source code of your own applications.
1414
// To purchase a commercial license, send an email to [email protected].
1515

16-
package phases
16+
package sizer
1717

1818
import (
1919
"encoding/json"
@@ -22,22 +22,46 @@ import (
2222
"regexp"
2323
"strconv"
2424

25-
"github.com/arduino/arduino-cli/arduino/builder"
2625
"github.com/arduino/arduino-cli/arduino/builder/utils"
2726
"github.com/arduino/arduino-cli/i18n"
27+
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2828
"github.com/arduino/go-properties-orderedmap"
2929
"github.com/pkg/errors"
3030
)
3131

3232
var tr = i18n.Tr
3333

34-
func Sizer(
34+
// ExecutableSectionSize represents a section of the executable output file
35+
type ExecutableSectionSize struct {
36+
Name string `json:"name"`
37+
Size int `json:"size"`
38+
MaxSize int `json:"max_size"`
39+
}
40+
41+
// ExecutablesFileSections is an array of ExecutablesFileSection
42+
type ExecutablesFileSections []ExecutableSectionSize
43+
44+
// ToRPCExecutableSectionSizeArray transforms this array into a []*rpc.ExecutableSectionSize
45+
func (s ExecutablesFileSections) ToRPCExecutableSectionSizeArray() []*rpc.ExecutableSectionSize {
46+
res := []*rpc.ExecutableSectionSize{}
47+
for _, section := range s {
48+
res = append(res, &rpc.ExecutableSectionSize{
49+
Name: section.Name,
50+
Size: int64(section.Size),
51+
MaxSize: int64(section.MaxSize),
52+
})
53+
}
54+
return res
55+
}
56+
57+
// Size fixdoc
58+
func Size(
3559
onlyUpdateCompilationDatabase, sketchError, verbose bool,
3660
buildProperties *properties.Map,
3761
stdoutWriter, stderrWriter io.Writer,
3862
printInfoFn, printWarnFn func(msg string),
3963
warningsLevel string,
40-
) (builder.ExecutablesFileSections, error) {
64+
) (ExecutablesFileSections, error) {
4165
if onlyUpdateCompilationDatabase || sketchError {
4266
return nil, nil
4367
}
@@ -53,7 +77,7 @@ func checkSizeAdvanced(buildProperties *properties.Map,
5377
verbose bool,
5478
stdoutWriter, stderrWriter io.Writer,
5579
printInfoFn, printWarnFn func(msg string),
56-
) (builder.ExecutablesFileSections, error) {
80+
) (ExecutablesFileSections, error) {
5781
command, err := utils.PrepareCommandForRecipe(buildProperties, "recipe.advanced_size.pattern", false)
5882
if err != nil {
5983
return nil, errors.New(tr("Error while determining sketch size: %s", err))
@@ -74,7 +98,7 @@ func checkSizeAdvanced(buildProperties *properties.Map,
7498
// likely be printed in red. Errors will stop build/upload.
7599
Severity string `json:"severity"`
76100
// Sections are the sections sizes for machine readable use
77-
Sections []builder.ExecutableSectionSize `json:"sections"`
101+
Sections []ExecutableSectionSize `json:"sections"`
78102
// ErrorMessage is a one line error message like:
79103
// "text section exceeds available space in board"
80104
// it must be set when Severity is "error"
@@ -106,7 +130,7 @@ func checkSize(buildProperties *properties.Map,
106130
stdoutWriter, stderrWriter io.Writer,
107131
printInfoFn, printWarnFn func(msg string),
108132
warningsLevel string,
109-
) (builder.ExecutablesFileSections, error) {
133+
) (ExecutablesFileSections, error) {
110134
properties := buildProperties.Clone()
111135
properties.Set("compiler.warning_flags", properties.Get("compiler.warning_flags."+warningsLevel))
112136

@@ -152,15 +176,15 @@ func checkSize(buildProperties *properties.Map,
152176
}
153177
}
154178

155-
executableSectionsSize := []builder.ExecutableSectionSize{
179+
executableSectionsSize := []ExecutableSectionSize{
156180
{
157181
Name: "text",
158182
Size: textSize,
159183
MaxSize: maxTextSize,
160184
},
161185
}
162186
if maxDataSize > 0 {
163-
executableSectionsSize = append(executableSectionsSize, builder.ExecutableSectionSize{
187+
executableSectionsSize = append(executableSectionsSize, ExecutableSectionSize{
164188
Name: "data",
165189
Size: dataSize,
166190
MaxSize: maxDataSize,

legacy/builder/phases/sizer_test.go renamed to arduino/builder/sizer/sizer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// Arduino software without disclosing the source code of your own applications.
1414
// To purchase a commercial license, send an email to [email protected].
1515

16-
package phases
16+
package sizer
1717

1818
import (
1919
"testing"

legacy/builder/builder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import (
2121

2222
"github.com/arduino/arduino-cli/arduino/builder"
2323
"github.com/arduino/arduino-cli/arduino/builder/preprocessor"
24+
"github.com/arduino/arduino-cli/arduino/builder/sizer"
2425
"github.com/arduino/arduino-cli/arduino/sketch"
2526
"github.com/arduino/arduino-cli/i18n"
26-
"github.com/arduino/arduino-cli/legacy/builder/phases"
2727
"github.com/arduino/arduino-cli/legacy/builder/types"
2828
"github.com/arduino/go-paths-helper"
2929
properties "github.com/arduino/go-properties-orderedmap"
@@ -273,7 +273,7 @@ func (s *Builder) Run(ctx *types.Context) error {
273273
}),
274274

275275
types.BareCommand(func(ctx *types.Context) error {
276-
executableSectionsSize, err := phases.Sizer(
276+
executableSectionsSize, err := sizer.Size(
277277
ctx.OnlyUpdateCompilationDatabase, mainErr != nil, ctx.Verbose,
278278
ctx.BuildProperties,
279279
ctx.Stdout, ctx.Stderr,

legacy/builder/types/context.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/arduino/arduino-cli/arduino/builder/compilation"
2626
"github.com/arduino/arduino-cli/arduino/builder/detector"
2727
"github.com/arduino/arduino-cli/arduino/builder/progress"
28+
"github.com/arduino/arduino-cli/arduino/builder/sizer"
2829
"github.com/arduino/arduino-cli/arduino/cores"
2930
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
3031
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
@@ -88,7 +89,7 @@ type Context struct {
8889
stdLock sync.Mutex
8990

9091
// Sizer results
91-
ExecutableSectionsSize builder.ExecutablesFileSections
92+
ExecutableSectionsSize sizer.ExecutablesFileSections
9293

9394
// Compilation Database to build/update
9495
CompilationDatabase *compilation.Database

0 commit comments

Comments
 (0)