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

Comments

Projects
None yet
5 participants
@computermouth
Copy link

commented Aug 15, 2018

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

This comment has been minimized.

Copy link
Member

commented Aug 15, 2018

@rsc

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Member

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 Nov 14, 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.