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: unable to build with v2+ of same module in GOPATH environment #28937

Closed
jadekler opened this issue Nov 24, 2018 · 1 comment

Comments

Projects
None yet
1 participant
@jadekler
Copy link
Contributor

commented Nov 24, 2018

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

$ go version
go version go1.11.2 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
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/deklerk/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/deklerk/workspace/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/tmp/module-testing-2/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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/lk/zs4m7sv12mq2vzk_wfn2tfvm00h16k/T/go-build157331356=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I have a repo https://github.com/jadekler/module-testing-2 with a v1 and a v3. v3 lives in a separate branch.

I place https://github.com/jadekler/module-testing-2 at $GOPATH/src/github.com/jadekler/module-testing-2 and make v1 depend on v3 (see below), run go mod tidy, and go build .

My altered v1 lib.go:

import "github.com/jadekler/module-testing-2/v3"

const LibV1 = "LibV1"
var _ = v3.LibV3

My altered v1 go.mod:

module github.com/jadekler/module-testing-2

require github.com/jadekler/module-testing-2/v3 v3.0.0

What did you expect to see?

  • go mod tidy works, and downloads v3.
  • go build . works.

What did you see instead?

  • go mod tidy works, and downloads v3.
  • go build . gives error:
$ go build .
lib.go:3:8: cannot find package "github.com/jadekler/module-testing-2/v3" in any of:
	/usr/local/go/src/github.com/jadekler/module-testing-2/v3 (from $GOROOT)
	/Users/deklerk/workspace/go/src/github.com/jadekler/module-testing-2/v3 (from $GOPATH)

However, when I place https://github.com/jadekler/module-testing-2 in /tmp and repeat those steps, everything works. This makes me believe it's looking for v3 in my GOPATH (which it will never find, since it's in a branch). I suspect the subdirectory approach of modules does not have this problem.

@jadekler jadekler changed the title cmd/go: unable to build with v2 of same submodule in GOPATH environment cmd/go: unable to build with v2+ of same module in GOPATH environment Nov 24, 2018

@jadekler

This comment has been minimized.

Copy link
Contributor Author

commented Nov 24, 2018

Nevermind, with GO111MODULE=on go build . it works. :)

@jadekler jadekler closed this Nov 24, 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.