Skip to content

Commit 409a133

Browse files
committed
Added binary size to compile json output
1 parent 9679267 commit 409a133

File tree

5 files changed

+170
-23
lines changed

5 files changed

+170
-23
lines changed

Diff for: commands/compile/compile.go

+1
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.W
200200

201201
r.BuildPath = builderCtx.BuildPath.String()
202202
r.UsedLibraries = importedLibs
203+
r.ExecutableSectionsSize = builderCtx.ExecutableSectionsSize.ToRPCExecutableSectionSizeArray()
203204
}
204205
}()
205206

Diff for: legacy/builder/phases/sizer.go

+15
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,21 @@ func checkSize(ctx *types.Context, buildProperties *properties.Map) error {
8888
}
8989
}
9090

91+
ctx.ExecutableSectionsSize = []types.ExecutableSectionSize{
92+
{
93+
Name: "text",
94+
Size: textSize,
95+
MaxSize: maxTextSize,
96+
},
97+
}
98+
if maxDataSize > 0 {
99+
ctx.ExecutableSectionsSize = append(ctx.ExecutableSectionsSize, types.ExecutableSectionSize{
100+
Name: "data",
101+
Size: dataSize,
102+
MaxSize: maxDataSize,
103+
})
104+
}
105+
91106
if textSize > maxTextSize {
92107
logger.Println(constants.LOG_LEVEL_ERROR, constants.MSG_SIZER_TEXT_TOO_BIG)
93108
return errors.New("text section exceeds available space in board")

Diff for: legacy/builder/types/context.go

+27
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/arduino/arduino-cli/arduino/libraries/librariesmanager"
2626
"github.com/arduino/arduino-cli/arduino/libraries/librariesresolver"
2727
"github.com/arduino/arduino-cli/legacy/builder/i18n"
28+
rpc "github.com/arduino/arduino-cli/rpc/commands"
2829
paths "github.com/arduino/go-paths-helper"
2930
properties "github.com/arduino/go-properties-orderedmap"
3031
)
@@ -159,6 +160,32 @@ type Context struct {
159160
// Out and Err stream to redirect all Exec commands
160161
ExecStdout io.Writer
161162
ExecStderr io.Writer
163+
164+
// Sizer results
165+
ExecutableSectionsSize ExecutablesFileSections
166+
}
167+
168+
// ExecutableSectionSize represents a section of the executable output file
169+
type ExecutableSectionSize struct {
170+
Name string
171+
Size int
172+
MaxSize int
173+
}
174+
175+
// ExecutablesFileSections is an array of ExecutablesFileSection
176+
type ExecutablesFileSections []ExecutableSectionSize
177+
178+
// ToRPCExecutableSectionSizeArray transforms this array into a []*rpc.ExecutableSectionSize
179+
func (s ExecutablesFileSections) ToRPCExecutableSectionSizeArray() []*rpc.ExecutableSectionSize {
180+
res := []*rpc.ExecutableSectionSize{}
181+
for _, section := range s {
182+
res = append(res, &rpc.ExecutableSectionSize{
183+
Name: section.Name,
184+
Size: int64(section.Size),
185+
MaxSize: int64(section.MaxSize),
186+
})
187+
}
188+
return res
162189
}
163190

164191
func (ctx *Context) ExtractBuildOptions() *properties.Map {

Diff for: rpc/commands/compile.pb.go

+120-23
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: rpc/commands/compile.proto

+7
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,11 @@ message CompileResp {
4848
bytes err_stream = 2; // The error output of the compilation process.
4949
string build_path = 3; // The compiler build path
5050
repeated Library used_libraries = 4; // The libraries used in the build
51+
repeated ExecutableSectionSize executable_sections_size = 5; // The size of the executable split by sections
5152
}
53+
54+
message ExecutableSectionSize {
55+
string name = 1;
56+
int64 size = 2;
57+
int64 maxSize = 3;
58+
}

0 commit comments

Comments
 (0)