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: Go modules reads go.mod file from parent directory #33300

Closed
0x7CA opened this issue Jul 26, 2019 · 2 comments
Closed

cmd/go: Go modules reads go.mod file from parent directory #33300

0x7CA opened this issue Jul 26, 2019 · 2 comments

Comments

@0x7CA
Copy link

0x7CA commented Jul 26, 2019

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

$ go version 1.12.4

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
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/CC/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/CC/go/"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/CC/go/src/project/go.mod"
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-build911813928=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Given the following situation:

project
├── lib1
│   └── lib1.go
├── app1
│   └── main.go
└── go.mod

  • project is in the gopath under /home/CC/go/src/project/
  • app1 imports lib1 with "project/lib1"
  • Only the project root has a go.mod file, which contains 3rd party imports

When go build is executed in app1, lib1 is fetched locally, while 3rd party imports such as "github.com/BurntSushi/toml" are fetched remotely with the latest revision. If a "github.com/BurntSushi/toml" version is specified in the go.mod file in the project root, go build in app1 will fetch that specific version.

What did you expect to see?

go build in app1 builds without go modules, or always fetches latest revision of all dependencies. I expected the go.mod file in the project root to be ignored.

Is it intended that go module works if there is only a go mod file in the parent project directory?

@AlexRouSg
Copy link
Contributor

Is it intended that go module works if there is only a go mod file in the parent project directory?

Yes.

A module is defined by a tree of Go source files with a go.mod file in the tree's root directory.

https://tip.golang.org/cmd/go/#hdr-Defining_a_module

@ALTree
Copy link
Member

ALTree commented Jul 26, 2019

What @AlexRouSg said. Closing here.

@ALTree ALTree closed this as completed Jul 26, 2019
@golang golang locked and limited conversation to collaborators Jul 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants