-
-
Notifications
You must be signed in to change notification settings - Fork 114
Move sketch size calculation to Golang #189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I'm getting
Is it a locale issue? |
@matteosuppo Could be... Which locale are you using? Mine is |
|
a3e2f29
to
1b08e44
Compare
✅ Build completed. ⬇️ Build URL: ℹ️ To test this build:
|
Works for me |
// force multiline match prepending "(?m)" to the actual regexp | ||
|
||
if len(properties["recipe.size.regex"]) > 0 { | ||
textRegexp := regexp.MustCompile("(?m)" + properties["recipe.size.regex"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
regexp.Compile
should be used instead of regexp.MustCompile
because is not said that recipe.size.regex
contains a valid regular expression. In case of error we should print a warning and ignore the regexp as it was missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also means the printing code above should be changed to not print sketch size when the regex is missing.
|
||
if maxTextSizeString == "" { | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this limitation? Even for boards without a max size, showing the current size is useful (and the IDE does it currently).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, but the original code returns if no max size is specified https://github.com/arduino/Arduino/blob/21ff728c59c1a2fb138348f4e1f6cb4999ff27f5/arduino-core/src/cc/arduino/Compiler.java#L303 .
In fact, max sketch size is compulsory right now 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, missed that part. I probably remembered the data max size being optional, no the text size. Still, it might be nice to make the max text size optional now, while we're here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has been compulsory from the beginning (from IDE 1.0 era), making it optional now will not provide any benefit IMHO.
maxDataSize := -1 | ||
|
||
if maxDataSizeString != "" { | ||
maxDataSize, _ = strconv.Atoi(maxDataSizeString) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does Atoi return on an error? Is the first return value even defined in that case? Or should the err value (that is now ignored) be checked instead? This also applies to some other Atoi calls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Failing Atoi
should, in fact, report an error. These are problems normally encountered by core devs, so a stacktrace could be better than an error message... Anyway, actual java code doesn't perform any check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by "report an error"? Panic?
Given that Atoi returns (int, err), I would expect it will return a non-nil error value, but I'm wondering what the returned int value is in that case.
// force multiline match prepending "(?m)" to the actual regexp | ||
|
||
if len(properties["recipe.size.regex"]) > 0 { | ||
textRegexp := regexp.MustCompile("(?m)" + properties["recipe.size.regex"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also means the printing code above should be changed to not print sketch size when the regex is missing.
} | ||
|
||
logger.Fprintln(os.Stdout, logLevel, "Sketch uses {0} bytes ({2}%%) of program storage space. Maximum is {1} bytes.", strconv.Itoa(textSize), strconv.Itoa(maxTextSize), strconv.Itoa(textSize*100/maxTextSize)) | ||
if dataSize > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This hides the message when dataSize is 0, though that can still be a valid size. Perhaps the "error" value should be < 0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dataSize
should be initialized as -1
, as in the Java code, fixing it! Thanks for spotting 😉
✅ Build completed. ⬇️ Build URL: ℹ️ To test this build:
|
Looks good. As for "to be squashed" commits, do you know about |
Sure, I only wanted to keep track of the changes to avoid overwriting your comments 😄 |
My suggestion would be to use |
I've added some more errors check and a test. |
Signed-off-by: Martino Facchin <[email protected]>
This helps creating the test on the next commit. Signed-off-by: Cristian Maglie <[email protected]>
Signed-off-by: Cristian Maglie <[email protected]>
Signed-off-by: Martino Facchin <[email protected]>
0444a12
to
3a4c024
Compare
✅ Build completed. ⬇️ Build URL: ℹ️ To test this build:
|
ATM Java IDE takes care of calculating the size of a sketch (https://github.com/arduino/Arduino/blob/ec2e9a642a085b32701cf81297ee7c1570177195/arduino-core/src/processing/app/debug/Sizer.java)
This function can be safely moved to the builder BUT there are a couple of gotchas:
- The error path is "concurrent" (Java side) with the stdout path, so the output is perfect when run in go but becomes confused when displayed through "MessageSiphon". The 200ms delay before returning an error solves this (in a very ugly way)The commits should be squashed and the constants moved to constants.go
@cmaglie @matteosuppo @00alis @mastrolinux