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: module mode doesn't work without go.mod #26994

Closed
computermouth opened this issue Aug 15, 2018 · 4 comments
Closed

cmd/go: module mode doesn't work without go.mod #26994

computermouth opened this issue Aug 15, 2018 · 4 comments
Labels
FrozenDueToAge modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@computermouth
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.10.3 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

Debian Stretch

$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/${USER}/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/${USER}/go"
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build573429602=/tmp/go-build -gno-record-gcc-switches"

What did you expect to see, what did you see instead?

$ go build -o bin/thing cmd/hello-world/main.go 
$ vgo build -o bin/thing cmd/hello-world/main.go 
go: cannot determine module path for source directory /home/${USER}/work/tools (outside GOPATH, no import comments)

Maybe I'm wrong here, and I've just missed some bit of documentation. But I was originally expecting the following to work:

$ vgo build cmd/hello-world/

Is there currently no implementation to specify a directory beyond the cwd? As shown above, even the behavior of the old go build path/to/main.go no longer works with vgo. Is there a plan for the top level directory or specifying go.mods to build from an outside directory?

@andybons andybons added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. modules labels Aug 15, 2018
@andybons andybons added this to the Unplanned milestone Aug 15, 2018
@andybons
Copy link
Member

@rsc @bcmills @ianlancetaylor

@rsc
Copy link
Contributor

rsc commented Aug 18, 2018

We haven't worked out the story for what to do when no go.mod can be found. There will probably need to be a mop-up go.mod somewhere like GOPATH/src/go.mod.

@rsc rsc changed the title cmd/go: vgo build can't build from a specified directory cmd/go: module mode doesn't work without go.mod Aug 18, 2018
@myitcv
Copy link
Member

myitcv commented Nov 14, 2018

Related to #24250 in that go get and go run working outside of a module are being defined in that issue.

@bcmills
Copy link
Contributor

bcmills commented Nov 14, 2018

go build some/directory/ can't work without a module definition: the package path is observable at run-time (e.g. using the reflect package), and the package path depends on the module path.

go build some/file.go can and probably will, since that already synthesizes a fake package (and hence doesn't care about paths). (See the current draft behavior in CL 148517.)

Closing as a duplicate of #24250: it's not precisely the same issue, but shares the same fix.

@bcmills bcmills closed this as completed Nov 14, 2018
@golang golang locked and limited conversation to collaborators Nov 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

6 participants