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

cmd/go: unexpected behavior of 'go build all' outside of GOPATH #27053

Closed
hyangah opened this issue Aug 17, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@hyangah
Copy link
Contributor

commented Aug 17, 2018

Using go version devel +751ea9369a Fri Aug 17 14:56:26 2018 +0000 linux/amd64

Running the go build all command outside my GOPATH before creating the go.mod file caused the build to walk up and down the directory tree, discover sources under my usual GOPATH ($HOME/go), and attempt to build all the packages there (and fail). The error message is confusing, and if GOPATH contains a lot of packages, it will take a long time till error messages are emitted and the command fails.

GOPATH=$HOME/go
PWD=$HOME/scratch/testmod

GO111MODULE=auto (the default)

If explicitly set GO111MODULE=on and run go build all, it automatically creates the new go.mod file as expected.

@hyangah hyangah changed the title cmd/build: unexpected behavior of 'go build all' outside of GOPATH cmd/go: unexpected behavior of 'go build all' outside of GOPATH Aug 17, 2018

@rsc

This comment has been minimized.

Copy link
Contributor

commented Aug 18, 2018

Note that this is the same behavior you'd get inside GOPATH.
Yes, it's not terribly useful (unless you keep your GOPATH tidy).
That's why I felt it was OK to redefine what 'all' means in module mode. :-)
As far as this being the old GOPATH-based behavior, it's not going to change now:
we'll just kill it with the rest of GOPATH instead.

It sounds like maybe you think the module mode should have kicked in,
but there is no go.mod. Module mode only kicks in when you are
outside GOPATH and inside a directory tree with a go.mod.
It's not just "outside GOPATH": people run go commands outside GOPATH
all the time referring to things inside GOPATH, that's always worked,
and it can't flip into module mode unexpectedly.

So both halves of this are unfortunate but working as intended:
(1) the old all really means "all", as terrible as that is, and
(2) not having a go.mod really means to use GOPATH,
because not using GOPATH would break lots of existing uses.

@rsc rsc closed this Aug 18, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.