-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: cmd/go: module semantics in $GOPATH/src #26377
Comments
@bcmills do you mean Because Instead I think with My unease with the proposal above is the complexity in terms of implementation and understanding, the latter of which is probably most "critical". |
Yes, thanks! (Edited to fix.) |
That's true, but it breaks the previous invariants of working in For example, users might expect that they can use modules-in- I suppose we could build a standalone tool that does that, and |
But if this is a documented behaviour, is breaking this invariant so bad? Because using |
And given we're moving away from |
Just spotted @bcmills, but think the issue title needs updating too?! 😄 |
I, for one, am fairly likely to set It's good to document potentially-confusing behavior, but better still to make the behavior less confusing. I hope this proposal would do the latter, although it's possible that implicitly changing
I think you underestimate my ability to forget about configuration options I've applied. 🙂 |
I'm still not 100% convinced that getting rid of
That's possible with the current Or, perhaps you instead use So instead of getting rid of For example, if I add a local |
For Go 1.11, GO111MODULE=auto really needs to have no effect on commands people run in GOPATH. Otherwise we break people who have not opted in to modules. Also GO111MODULE is meant only as a transition mechanism and will go away like GO15VENDOREXPERIMENT did: we can't add anything to it that we're not comfortable throwing away in Go 1.13. The plan described here is aiming at trying to provide a file system checkout of dependencies that can be edited to affect the operation of the original. That's an important workflow to enable but overloading GOPATH is probably the wrong approach: really any such tree of files should be scoped to working on one specific module instead of the more diffuse "this is the whole world" of GOPATH. There was an interesting discussion on golang-dev this morning, and I'm sure we'll learn more about what we need along those lines as we use modules more. Closing this issue, though. |
(Caveat: I'm not sure whether this is actually a good idea, and I'm really not sure whether it's feasible in time for the 1.11 experiment.)
In this golang-dev message, @rsc explains why
GO111MODULE=auto
doesn't work inside$GOPATH/src
:I think there is a way to make modules work within
$GOPATH/src
without changing the existing meaning of$GOPATH/src
.When
GO111MODULE=on
orGO111MODULE=auto
,When the user runs
go get mod/pkg@version
within$GOPATH/src
, update the contents of$GOPATH/src
to match the versions implied by that dependency.$GOPATH/src
) any modules needed to satisfy the (transitive) imports ofmod/pkg
, just like the oldgo get
but taking versions into account.go get
should fail (the same as it does today if you rungo get -u pkg
with modified dependencies).$GOPATH/src
, update their contents too — even if they are not needed to satisfy imports.$GOPATH/src
contents unchanged for any module that was removed from the build list entirely.If a build within a module in
$GOPATH/src
imports a package from a module that is not present in$GOPATH/src
, copy that module into$GOPATH/src
(asgo get
would do).Whenever any package within any module in
$GOPATH/src
is built, update itsgo.mod
file to reflect the actual contents of$GOPATH/src
. That way, any futurego
commands within that module will produce the same contents as the current build.⚠ This is the difficult part of this proposal!
go.mod
file with the contents of its (transitive) dependencies in$GOPATH/src
, ignoring any modules that are not present (e.g., because they were not needed to satisfy transitive imports).require
directives from that module'sgo.mod
file. Addreplace
directives for any (transitive) dependencies that do not match the versions implied by that module'sgo.mod
. If the source code stored in$GOPATH
still matches a committed (and non-excluded) version, use that version as the replacement; otherwise, use the local filesystem path.replace
directives do not affect other modules, ignore changes to them when comparing the contents of dependencies, including viago.sum
checksums.If a build within a module in
$GOPATH/src
imports a package that is present in$GOPATH/src
but does not have an associated module, addrequire
andreplace
directives (pointing into$GOPATH
) to thego.mod
files for all affected modules, as if there were a top-levelgo.mod
for$GOPATH/src
itself.I believe that those steps maintain the essential properties of both
$GOPATH
and modules. Namely:$GOPATH/src
are exactly the files used for builds within$GOPATH/src
.$GOPATH/src
are present in$GOPATH/src
.go.mod
files within$GOPATH/src
accurately describe the sources used for builds.go.mod
files within$GOPATH/src
include requirements for all packages imported during builds.(CC @FiloSottile @myitcv @natefinch)
The text was updated successfully, but these errors were encountered: