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

go/build: resolve package in GOPATH when GO111MODULE=on outside module #34669

Closed
jayconrod opened this issue Oct 2, 2019 · 3 comments
Closed
Labels
FrozenDueToAge modules NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@jayconrod
Copy link
Contributor

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

$ go version
go version go1.13.1 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="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/jayconrod/Library/Caches/go-build"
GOENV="/Users/jayconrod/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/jayconrod/Code/test2"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/go/installed"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/go/installed/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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/rq/x0692kqj6ml8cvrhcqh5bswc008xj1/T/go-build420384392=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

cd $(mktemp -d)
mkdir -p src/example.com/p
echo 'package p' >src/example.com/p/p.go
export GO111MODULE=on
export GOPATH=$(pwd)

go doc example.com/p

What did you expect to see?

go doc example.com/p should fail. Module mode is turned on explicitly with GO111MODULE=on, and that package only exists in this fake GOPATH.

What did you see instead?

go doc example.com/p succeeds with the output below:

warning: pattern "all" matched no module dependencies


Analysis

go doc executes cmd/doc, which loads a package with go/build.Import. There is a heuristic which guesses whether module mode is enabled by looking for a go.mod file. If one is found, it loads the package by executing go list.

The heuristic should assume modules are enabled when GO111MODULE is explicitly on.

@jayconrod jayconrod added NeedsFix The path to resolution is known, but the work has not been done. modules labels Oct 2, 2019
@jayconrod jayconrod added this to the Go1.14 milestone Oct 2, 2019
@jayconrod jayconrod self-assigned this Oct 2, 2019
@gopherbot
Copy link

Change https://golang.org/cl/198778 mentions this issue: cmd/go: forbid resolving import to modules when outside of a module

@jayconrod jayconrod changed the title go/build: resolved package in GOPATH when GO111MODULE=on outside module go/build: resolve package in GOPATH when GO111MODULE=on outside module Oct 8, 2019
@gopherbot
Copy link

Change https://golang.org/cl/199818 mentions this issue: go/build: import packages in module mode when GO111MODULE is "on"

@gopherbot
Copy link

Change https://golang.org/cl/199819 mentions this issue: cmd/doc: show original import error when package cannot be found

@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
gopherbot pushed a commit that referenced this issue Oct 9, 2019
Updates #34669

Change-Id: I8d0ee68885e804e131f42a512080486f9b25e9dd
Reviewed-on: https://go-review.googlesource.com/c/go/+/199819
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
@golang golang locked and limited conversation to collaborators Oct 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge modules NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

3 participants