-
Notifications
You must be signed in to change notification settings - Fork 955
compileopts: move {root} replacement to compileopts.Emulator() #2454
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 think I know why CI failed. |
@dgryski please note merge conflict needing resolution, please. |
01e4260
to
b7db2b6
Compare
Fixed. |
var emulator []string | ||
for _, s := range c.Target.Emulator { | ||
emulator = append(emulator, strings.ReplaceAll(s, "{root}", goenv.Get("TINYGOROOT"))) | ||
} |
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 works, but a more efficient version is the following:
var emulator []string | |
for _, s := range c.Target.Emulator { | |
emulator = append(emulator, strings.ReplaceAll(s, "{root}", goenv.Get("TINYGOROOT"))) | |
} | |
emulator = make([]string, len(c.Target.Emulator)) | |
for i, s := range c.Target.Emulator { | |
emulator[i] = strings.ReplaceAll(s, "{root}", goenv.Get("TINYGOROOT")) | |
} |
...probably not worth the effort though. Just an idea. It's even possible the Go compiler recognizes the idiom and optimizes it.
main_test.go
Outdated
// Probably not the best place to handle this | ||
var emulator []string | ||
for _, s := range spec.Emulator { | ||
emulator = append(emulator, strings.ReplaceAll(s, "{root}", goenv.Get("TINYGOROOT"))) | ||
} |
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.
Yeah, that kind of duplication doesn't look good.
What about this?
// Probably not the best place to handle this | |
var emulator []string | |
for _, s := range spec.Emulator { | |
emulator = append(emulator, strings.ReplaceAll(s, "{root}", goenv.Get("TINYGOROOT"))) | |
} | |
config := compileopts.Config{Target: spec} | |
emulator := config.Emulator() |
A bit hacky but it works.
Also, spec.Emulator
is also used below. It probably doesn't matter much though.
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.
Fixed and repushed.
b7db2b6
to
632849f
Compare
@dgryski can you please resolve merge conflicts? Thank you. |
632849f
to
27dbf35
Compare
Rebased. |
Thanks for the improvement @dgryski now merging. |
Follow up for #2387 (comment)