Skip to content
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

Append path into trimpath if option already exists #2994

Merged
merged 2 commits into from
Nov 30, 2021

Conversation

Reflejo
Copy link
Contributor

@Reflejo Reflejo commented Oct 31, 2021

What type of PR is this?

Bug fix

What does this PR do? Why is it needed?

Appends paths to trimpath as opposed to override potential used-defined flags.

Which issues(s) does this PR fix?

User defined trimpath through gc_goopts are being overriden since a second -trimpath is being set. This change appends the path using : which has been supported by go for a while (see https://go-review.googlesource.com/c/go/+/173344/)

@google-cla google-cla bot added the cla: yes label Oct 31, 2021
@achew22
Copy link
Member

achew22 commented Oct 31, 2021

As a rule of thumb, changes to the rules_go compiler infra that aren't accompanied by a regression test are rarely merged. Changes like this are difficult to understand without the context provided by understanding what the current behavior is and what the authors proposed new behavior is. Would you be willing to put a test together to go with this change so we can better understand the problem and, as an added bonus, prevent regressions in the future?

@Reflejo
Copy link
Contributor Author

Reflejo commented Oct 31, 2021

I don't mind writing the tests provided that the maintainers are onboard with the change. That was my plan; the template mentions to submit the PR to discuss test strategies, so that's what I did

@Reflejo
Copy link
Contributor Author

Reflejo commented Oct 31, 2021

Ok I added a test case that shows the issue. The test will fail with all_test.go:22: plugin.Open("plugin"): plugin was built with a different version of package go_plugin_with_proto_library/validate without this change.

This is because the plugin and the host are creating the pb.go file on different build folders which then is included into their binaries. This doesn't work because go plugins are very finicky about dependencies matching exactly and the filepath difference will break it, hence why trimpath is needed.

@Reflejo
Copy link
Contributor Author

Reflejo commented Nov 4, 2021

@achew22 thoughts?

@robfig
Copy link
Contributor

robfig commented Nov 30, 2021

This change looks good to me, and the multi-element trimpath commit was included in Go 1.13 which is old enough that we don't need to worry. Merging, thank you!

@robfig robfig merged commit c59f544 into bazel-contrib:master Nov 30, 2021
@RaduBerinde
Copy link

RaduBerinde commented Jan 14, 2022

The separator in the go code is a semicolon (;), not a colon (:)..

https://github.com/golang/go/blob/e550c3054586a224d949cc8fa030bac0887bee51/src/cmd/internal/objabi/line.go

@RaduBerinde
Copy link

Also note that later on, we call absArgs with -trimpath which assumes the argument is a single path. It will not work correctly with the more complex syntax.

https://github.com/bazelbuild/rules_go/blob/ba7bdfd6b5118d135ae3f7984c94103510bf4167/go/tools/builders/compilepkg.go#L476

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants