Skip to content

Commit b6530f6

Browse files
committed
Added support for advanced-sizers
1 parent e39c110 commit b6530f6

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
"regexp"
2021
"strconv"
2122

@@ -40,11 +41,56 @@ func (s *Sizer) Run(ctx *types.Context) error {
4041

4142
buildProperties := ctx.BuildProperties
4243

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

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

0 commit comments

Comments
 (0)