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: mod init doesn't handle replacements well #34509

Closed
aaronbee opened this issue Sep 24, 2019 · 2 comments
Closed

cmd/go: mod init doesn't handle replacements well #34509

aaronbee opened this issue Sep 24, 2019 · 2 comments

Comments

@aaronbee
Copy link

@aaronbee aaronbee commented Sep 24, 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?

Same behavior in master.
go version devel +78a3734714 Tue Sep 24 21:33:10 2019 +0000 darwin/amd64

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/aaronb/Library/Caches/go-build"
GOENV="/Users/aaronb/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/aaronb/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.13/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.13/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/aaronb/go/src/arista/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/dh/8tf0gx091zs_02mw_s0c956w0000gp/T/go-build130633312=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Ran go mod init on a repository with a Gopkg.toml/Gopkg.lock generated by dep.
This Gopkg.toml contains an alternative source for an import, which translates to a replace in go.mod.

The intention is that code imports a dependency's original path. The replace is then used to use an alternative repo that contains an additional feature/bug fix that is waiting to merge upstream.

Reproduced here:
https://github.com/aaronbee/replace_repro

What did you expect to see?

After running go mod init, go.mod should be valid:

require upstream_repo v0.0.0

replace upstream_repo => alternate_repo ALT_REVISION

In this case the upstream_path is golang.org/x/tools and alternate_repo is github.com/aaronbee/tools

What did you see instead?

go.mod:

require alternate_repo ALT_REVSION

replace upstream_repo ALT_REVISION => alternate_repo ALT_REVISION

Actual go.mod.

This results in build errors because ALT_REVSION is not present in upstream_repo. It is only valid in alternate_repo.

$ go build
go: finding golang.org/x/tools 5cb9115d21e89da8e75c5b207bfa1c512c315161
go: finding golang.org/x/tools 5cb9115d21e89da8e75c5b207bfa1c512c315161
go: errors parsing go.mod:
/Users/aaronb/go/src/github.com/aaronbee/replace_repro/go.mod:5: replace golang.org/x/tools: version "5cb9115d21e89da8e75c5b207bfa1c512c315161" invalid: unknown revision 5cb9115d21e89da8e75c5b207bfa1c512c315161
@agnivade agnivade changed the title go mod init doesn't handle replacements well cmd/go: mod init doesn't handle replacements well Sep 25, 2019
@hasitpbhatt

This comment has been minimized.

Copy link
Contributor

@hasitpbhatt hasitpbhatt commented Sep 26, 2019

@bcmills I believe replace is written to support mirroring. The code assumes the import paths are ideally mirrors.
e.g. git@test.com:x/y.git and https://test.com/x/y.git as can be observed in https://github.com/golang/go/blob/master/src/cmd/go/internal/modconv/dep.go#L83.

I don't think there's a direct way to find out whether the same hash presents in the source as well as the actual path. In case the paths are mirrors, we may not want to lose the revision info by putting v0.0.0 as the default version.

@bcmills

This comment has been minimized.

Copy link
Member

@bcmills bcmills commented Sep 26, 2019

Duplicate of #33406

@bcmills bcmills marked this as a duplicate of #33406 Sep 26, 2019
@bcmills bcmills closed this Sep 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.