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 turn on automatically while build upon relative path #34043

Closed
JBrVJxsc opened this issue Sep 3, 2019 · 4 comments
Labels
FrozenDueToAge modules WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@JBrVJxsc
Copy link

JBrVJxsc commented Sep 3, 2019

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

$ go version
go version go1.13 darwin/amd64

Does this issue reproduce with the latest release?

Yes.

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/FOOBAR/Library/Caches/go-build"
GOENV="/Users/FOOBAR/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/FOOBAR/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/gs/5npvnn7x1s75tnbcx020t_yr000r7f/T/go-build967562719=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

go mod init // convert the project to the module-based
go build ./src/cli/project/" // from a relative directory. ./src/cli/project isn't in GOPATH (that's why I'm using module).

What did you expect to see?

It should build successfully via module mode.
(If go build directly in the project folder it will detect the go.mod file and use module mode to build successfully)

What did you see instead?

src/cli/project/main.go:4:2: cannot find package "project/cmd" in any of:
/usr/local/go/src/project/cmd (from $GOROOT)
/Users/FOOBAR/go/src/project/cmd (from $GOPATH)

@bcmills bcmills changed the title Module mode doesn't turn on automatically while build upon relative path cmd/go: Module mode doesn't turn on automatically while build upon relative path Sep 4, 2019
@bcmills
Copy link
Contributor

bcmills commented Sep 4, 2019

Please provide concrete steps to reproduce the problem. Specifically, please provide the exact commands run, including any cd commands, and a minimal set of source files.

Note that the go command locates the go.mod file based on its current working directory, not on the directory containing the requested packages — if the go.mod file is in a subdirectory of the current working directory, then the go command will not be able to locate it.

@bcmills bcmills added modules WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Sep 4, 2019
@MHBauer
Copy link

MHBauer commented Sep 25, 2019

Note that the go command locates the go.mod file based on its current working directory, not on the directory containing the requested packages — if the go.mod file is in a subdirectory of the current working directory, then the go command will not be able to locate it.

My understanding reading this is: I must call go build in the directory containing the go.mod file. Is this in the documentation somewhere?

This is surprising to me. Is there a flag to give to go build so it does a cd into the directory before running?

@bcmills
Copy link
Contributor

bcmills commented Sep 27, 2019

I must call go build in the directory containing the go.mod file. Is this in the documentation somewhere?

https://golang.org/cmd/go/#hdr-The_main_module_and_the_build_list

Is there a flag to give to go build so it does a cd into the directory before running?

No. (The argument to go build is, strictly speaking, a package path, not a directory.)

@bcmills bcmills added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Sep 27, 2019
@gopherbot
Copy link
Contributor

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@golang golang locked and limited conversation to collaborators Oct 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge modules WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants