Skip to content

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

Merged
merged 2 commits into from
Jan 17, 2022

Conversation

dgryski
Copy link
Member

@dgryski dgryski commented Dec 31, 2021

Follow up for #2387 (comment)

@dgryski
Copy link
Member Author

dgryski commented Dec 31, 2021

I think I know why CI failed.

@deadprogram deadprogram requested a review from aykevl January 4, 2022 08:24
@deadprogram
Copy link
Member

@dgryski please note merge conflict needing resolution, please.

@dgryski dgryski force-pushed the dgryski/root-compileopts branch from 01e4260 to b7db2b6 Compare January 4, 2022 21:56
@dgryski
Copy link
Member Author

dgryski commented Jan 4, 2022

Fixed.

Comment on lines +467 to +471
var emulator []string
for _, s := range c.Target.Emulator {
emulator = append(emulator, strings.ReplaceAll(s, "{root}", goenv.Get("TINYGOROOT")))
}
Copy link
Member

@aykevl aykevl Jan 14, 2022

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:

Suggested change
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
Comment on lines 373 to 377
// 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")))
}
Copy link
Member

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?

Suggested change
// 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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed and repushed.

@dgryski dgryski force-pushed the dgryski/root-compileopts branch from b7db2b6 to 632849f Compare January 14, 2022 17:09
@deadprogram
Copy link
Member

@dgryski can you please resolve merge conflicts? Thank you.

@dgryski dgryski force-pushed the dgryski/root-compileopts branch from 632849f to 27dbf35 Compare January 16, 2022 22:20
@dgryski
Copy link
Member Author

dgryski commented Jan 16, 2022

Rebased.

@deadprogram
Copy link
Member

Thanks for the improvement @dgryski now merging.

@deadprogram deadprogram merged commit 233f5c6 into tinygo-org:dev Jan 17, 2022
@dgryski dgryski deleted the dgryski/root-compileopts branch January 21, 2022 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants