13
13
// Arduino software without disclosing the source code of your own applications.
14
14
// To purchase a commercial license, send an email to [email protected] .
15
15
16
- package phases
16
+ package sizer
17
17
18
18
import (
19
19
"encoding/json"
@@ -22,22 +22,46 @@ import (
22
22
"regexp"
23
23
"strconv"
24
24
25
- "github.com/arduino/arduino-cli/arduino/builder"
26
25
"github.com/arduino/arduino-cli/arduino/builder/utils"
27
26
"github.com/arduino/arduino-cli/i18n"
27
+ rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
28
28
"github.com/arduino/go-properties-orderedmap"
29
29
"github.com/pkg/errors"
30
30
)
31
31
32
32
var tr = i18n .Tr
33
33
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 (
35
59
onlyUpdateCompilationDatabase , sketchError , verbose bool ,
36
60
buildProperties * properties.Map ,
37
61
stdoutWriter , stderrWriter io.Writer ,
38
62
printInfoFn , printWarnFn func (msg string ),
39
63
warningsLevel string ,
40
- ) (builder. ExecutablesFileSections , error ) {
64
+ ) (ExecutablesFileSections , error ) {
41
65
if onlyUpdateCompilationDatabase || sketchError {
42
66
return nil , nil
43
67
}
@@ -53,7 +77,7 @@ func checkSizeAdvanced(buildProperties *properties.Map,
53
77
verbose bool ,
54
78
stdoutWriter , stderrWriter io.Writer ,
55
79
printInfoFn , printWarnFn func (msg string ),
56
- ) (builder. ExecutablesFileSections , error ) {
80
+ ) (ExecutablesFileSections , error ) {
57
81
command , err := utils .PrepareCommandForRecipe (buildProperties , "recipe.advanced_size.pattern" , false )
58
82
if err != nil {
59
83
return nil , errors .New (tr ("Error while determining sketch size: %s" , err ))
@@ -74,7 +98,7 @@ func checkSizeAdvanced(buildProperties *properties.Map,
74
98
// likely be printed in red. Errors will stop build/upload.
75
99
Severity string `json:"severity"`
76
100
// Sections are the sections sizes for machine readable use
77
- Sections []builder. ExecutableSectionSize `json:"sections"`
101
+ Sections []ExecutableSectionSize `json:"sections"`
78
102
// ErrorMessage is a one line error message like:
79
103
// "text section exceeds available space in board"
80
104
// it must be set when Severity is "error"
@@ -106,7 +130,7 @@ func checkSize(buildProperties *properties.Map,
106
130
stdoutWriter , stderrWriter io.Writer ,
107
131
printInfoFn , printWarnFn func (msg string ),
108
132
warningsLevel string ,
109
- ) (builder. ExecutablesFileSections , error ) {
133
+ ) (ExecutablesFileSections , error ) {
110
134
properties := buildProperties .Clone ()
111
135
properties .Set ("compiler.warning_flags" , properties .Get ("compiler.warning_flags." + warningsLevel ))
112
136
@@ -152,15 +176,15 @@ func checkSize(buildProperties *properties.Map,
152
176
}
153
177
}
154
178
155
- executableSectionsSize := []builder. ExecutableSectionSize {
179
+ executableSectionsSize := []ExecutableSectionSize {
156
180
{
157
181
Name : "text" ,
158
182
Size : textSize ,
159
183
MaxSize : maxTextSize ,
160
184
},
161
185
}
162
186
if maxDataSize > 0 {
163
- executableSectionsSize = append (executableSectionsSize , builder. ExecutableSectionSize {
187
+ executableSectionsSize = append (executableSectionsSize , ExecutableSectionSize {
164
188
Name : "data" ,
165
189
Size : dataSize ,
166
190
MaxSize : maxDataSize ,
0 commit comments