-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
cmd/go: allow cross-module internal imports based on import path prefix #23970
Comments
The problem here is that github.com/gonum/blas imports github.com/gonum/internal/asm/f32, which is outside the blas module. We will need to decide what the rules are for cross-module internal like that. |
The internal packages design document states the rule as:
A compatible rule, thinking just in terms of import paths is:
The example in this issue has github.com/gonum/blas importing github.com/gonum/internal/asm/f32. The path prefix for the internal import is "github.com/gonum". Since github.com/gonum/blas also has that prefix, the import would be allowed. This modified rule would, however, allow a situation that is not allowed by the current implementation (go1.10.1): cross-GOPATH internal imports: Given GOPATH=$HOME/a:$HOME/b and two files: $HOME/a/src/prefix/importer/importer.go:
and $HOME/b/src/prefix/internal/internal.go:
The build fails with:
The modified rule would not disallow this as it only considers the import path and not where the package is on disk. When both files are in the same GOPATH root (e.g., GOPATH=$HOME/combined with files named combined/src/prefix/importer/importer.go and combined/src/prefix/internal/internal.go) the build succeeds. This is the only case I know of where the modified rule differs from the current implementation. The modified rule is, I believe, a valid interpretation of the current rule; thinking of the (de facto) import path hierarchy instead of the disk hierarchy. |
@nathankerr, right, your counter-example is exactly why we can't redefine the general internal import rule as you described. That would allow, for example, every package in the world to import "internal/testenv", which is meant to be internal to the standard library. The use of directory, not import path, was intentional. That said, it does seem like focusing on import path for the narrower case of "one module referring to packages in another module" does make sense, because those could have been in a single GOPATH before anyway. I'll mark this NeedsFix but we need to be careful with the fix not to open things too far. |
@rsc I hadn't considered GOROOT. Good catch. Viewing all modules as being in the same tree (separate from GOROOT) as if they were all in a single GOPATH keeps the original rule intact. |
github.com/cznic/lldb imports github.com/cznic/internal/buffer which seems to be fordbidden, now. |
@tgulacsi Regardless of the solution, if you meanwhile need any of those internal packages made generally importable, please fill an issue at cznic/internal and I will let it happen. The original intent was to let practice show/prove if those API are acceptable/working well. IIRC, they were not changed for a long time, if at all. So I guess it's safe to move them out from 'internal'. |
Thanks, @cznic - my main concern is though I'd happily use vgo as it tries to solve some of my problems, I stumble walls everywhere - github.com/cznic/internal (for github.com/cznic/kv for camlistore.org/pkg/sorted/kvfile), github.com/russross/blackfriday (for I don't know what). I'd file issues to those upstream packages, but I feel vgo is still in its infancy, and don't want to bother those nice guys for such a volatile target. |
@tgulacsi I agree with you: we should be fixing vgo, not forcing other projects to work around its bugs. |
another possible way to look at this: now that we have a that's what the admittedly, this does complexify the logic. |
@sbinet I don't think we have a use-case that requires an explicit list. Let's see how far we get with just the path-based approach for now. |
I think this issue would also have an interesting interaction with the |
Change https://golang.org/cl/125676 mentions this issue: |
So, here's an interesting question: how should Should the effective path for the |
Change https://golang.org/cl/125836 mentions this issue: |
Updates #23970. Change-Id: I2e69ad15b9d1097bfeef9947f03cfa6834a6a049 Reviewed-on: https://go-review.googlesource.com/125676 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
Updates golang#23970. Change-Id: I2e69ad15b9d1097bfeef9947f03cfa6834a6a049 Reviewed-on: https://go-review.googlesource.com/125676 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
Expand mod_internal tests to cover vendoring, replacements, and failure messages. Packages beginning with "golang_org/" resolve to $GOROOT/src/vendor, and should therefore not be visible within module code. Fixes golang#23970. Change-Id: I706e9c4a1d1e025883e84b897972678d0fa3f2bd Reviewed-on: https://go-review.googlesource.com/125836 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
What was the outcome of this problem as hitting similar issues with github.com/mongodb/mongo-go-driver? And lets say trying to use github.com/mongodb/mongo-go-driver/core/connstring. |
|
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (
go env
)?What did you do?
In a new directory with the following files
main.go:
go.mod:
vgo build
fails to build this package.What did you expect to see?
vgo build
should have produced an executable likego build
doesWhat did you see instead?
Additional Comments
The import "github.com/gonum/stat" has moved to "gonum.org/v1/gonum/stat" after which change the example builds as expected.
I'm reporting this because it highlights a difference in how
go
andvgo
handle internal packages, in this case where the internal package is a separate repository.The text was updated successfully, but these errors were encountered: