-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
proposal: x/tools/cmd/goimports: support searching for Go packages within a Bazel WORKSPACE #18441
Comments
I'd prefer to wait and figure out what the full story is between $GOPATH, Bazel, and Go 1.9 vendoring work before moving forward with ad hoc changes like this one. I worry that changing goimports would effectively encourage Bazel layout (at least a bit) and fragment the ecosystem in two mutually inoperable halves, killing happy network effects. I'm more interested in figuring out the long-term story instead of the short-term "Proposed implementation" details. |
Thanks, I wasn't aware that we don't want to encourage the Bazel layout. Since you mention that the proposed implementation would be a "shot-term" fix, does this mean that there is some other plan for closing the gap between Golang and Bazel? I wasn't able to find any details so if you could point me to it or share some, that would help. |
There is a plan to figure out the plan, at least. |
/cc @alandonovan, who was looking into Go and Bazel recently. |
Any developments since 1/2017? |
Does this change now with |
Yes. There is currently a change in review that makes goimports work in terms of go/packages go/packages will have a bazel "driver" that knows how to understand the layout by asking bazel itself to tell it about the rules. This is still a work in progress with no solid timeline on when it will be done, but when it is all tools that have been converted to go/packages will start working in bazel workspaces. |
@ianthehat do you have a link to a tracking issue for the go/packages bazel driver so I can follow along? |
This feature request affects the functionality of golang/tools/cmd/goimports.
What version of Go are you using (
go version
)?go version go1.7.3
What operating system and processor architecture are you using (
go env
)?linux/amd64
Background
The feature
Google released Bazel. Bazel's supports for Go is via the Skylark go_rules.
Bazel organizes all source code under a WORKSPACE directory, say /some/path/to/workspace further referred to as the bazel_workspace. The go_rules require the user to set a WORPSKACE-wide variable go_prefix which is the global prefix used to fully qualify all Go import targets. This may be yourcompany further referred to as the bazel_go_prefix.
With this setup a package named foo located in file /some/path/to/workspace/subdir/foo/foo.go should be imported as:
With the above mentioned bazel_go_prefix becomes:
The desired feature is to enable goimports to find packages under a Bazel WORKSPACE and to add correct import paths for these packages.
Proposed implementation
I would add two new flags into the goimports main:
The code in golang/tools/imports/fix.go would be modified as follows:
I have a prototype that I tested this locally. Please let me know if you agree with the proposal above, in which case I will start the code review process.
Alternatively feedback or suggestions are welcome.
The text was updated successfully, but these errors were encountered: