Skip to content

Commit 3442bd6

Browse files
committed
Added support for advanced-sizers
1 parent a6b718f commit 3442bd6

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

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

+47-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package phases
1717

1818
import (
19+
"encoding/json"
1920
"fmt"
2021
"regexp"
2122
"strconv"
@@ -41,11 +42,56 @@ func (s *Sizer) Run(ctx *types.Context) error {
4142

4243
buildProperties := ctx.BuildProperties
4344

45+
if buildProperties.ContainsKey("recipe.advanced_size.pattern") {
46+
err := checkSizeAdvanced(ctx, buildProperties)
47+
return errors.WithStack(err)
48+
}
49+
4450
err := checkSize(ctx, buildProperties)
51+
return errors.WithStack(err)
52+
}
53+
54+
func checkSizeAdvanced(ctx *types.Context, properties *properties.Map) error {
55+
command, err := builder_utils.PrepareCommandForRecipe(properties, "recipe.advanced_size.pattern", false)
4556
if err != nil {
46-
return errors.WithStack(err)
57+
return errors.New("Error while determining sketch size: " + err.Error())
58+
}
59+
60+
out, _, err := utils.ExecCommand(ctx, command, utils.Capture /* stdout */, utils.Show /* stderr */)
61+
if err != nil {
62+
return errors.New("Error while determining sketch size: " + err.Error())
63+
}
64+
65+
type AdvancedSizerResponse struct {
66+
// Output are the messages displayed in console to the user
67+
Output string `json:"output"`
68+
// Severity may be one of "info", "warning" or "error". Warnings and errors will
69+
// likely be printed in red. Errors will stop build/upload.
70+
Severity string `json:"severity"`
71+
// Sections are the sections sizes for machine readable use
72+
Sections []types.ExecutableSectionSize `json:"sections"`
73+
// ErrorMessage is a one line error message like:
74+
// "text section exceeds available space in board"
75+
// it must be set when Severity is "error"
76+
ErrorMessage string `json:"error"`
4777
}
4878

79+
var resp AdvancedSizerResponse
80+
if err := json.Unmarshal(out, &resp); err != nil {
81+
return errors.New("Error while determining sketch size: " + err.Error())
82+
}
83+
84+
ctx.ExecutableSectionsSize = resp.Sections
85+
logger := ctx.GetLogger()
86+
switch resp.Severity {
87+
case "error":
88+
logger.Println("error", "{0}", resp.Output)
89+
return errors.New(resp.ErrorMessage)
90+
case "warning":
91+
logger.Println("warn", "{0}", resp.Output)
92+
default: // "info"
93+
logger.Println("info", "{0}", resp.Output)
94+
}
4995
return nil
5096
}
5197

0 commit comments

Comments
 (0)