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

modules: replace directive with moved dependency not working consistently #39081

Closed
dominicbarnes opened this issue May 14, 2020 · 3 comments
Closed

Comments

@dominicbarnes
Copy link

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

$ go version
go version go1.14.2 linux/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="/home/dominic/.cache/go-build"
GOENV="/home/dominic/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY="github.com/segment*"
GONOSUMDB="github.com/segment*"
GOOS="linux"
GOPATH="/home/dominic/dev"
GOPRIVATE="github.com/segment*"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go-1.14"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.14/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/dominic/Desktop/go-modules-bug/go.mod"
CGO_CFLAGS="-I/home/dominic/src/db2/clidriver/include"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-L/home/dominic/src/db2/clidriver/lib"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build523802799=/tmp/go-build -gno-record-gcc-switches"

What did you do?

My project is using a dependency (bitbucket.org/phiggins/db2cli) that has a test package with another dependency ("odbc") which has recently moved from Google Code to Github.

main.go

package main

import _ "bitbucket.org/phiggins/db2cli"

func main() {}

go.mod

module bug-report

go 1.14

Since this dependency isn't a direct one, I'm still able to run many commands (eg: go mod vendor, go test) without any trouble. However, upon trying to run go mod tidy, I get the following error:

go: finding module for package code.google.com/p/odbc
bug-report imports
	bitbucket.org/phiggins/db2cli tested by
	bitbucket.org/phiggins/db2cli.test imports
	code.google.com/p/odbc: cannot find module providing package code.google.com/p/odbc: unrecognized import path "code.google.com/p/odbc": parse https://code.google.com/p/odbc?go-get=1: no go-import meta tags ()

Once I realized this was a moved dependency, I addressed this with the following replace directive in my go.mod:

replace code.google.com/p/odbc => github.com/alexbrainman/odbc latest

Unfortunately, go mod tidy still does not work fully, though as far as I understand the replace directive is what should be used to resolve such an issue.

What did you expect to see?

I would expect the replace directive to allow go mod tidy to continue working, notably to prune unused dependencies.

What did you see instead?

Running go mod tidy prints this error just before exiting with error code 1:

go: github.com/alexbrainman/odbc@v0.0.0-20200426075526-f0492dfa1575 used for two different module paths (code.google.com/p/odbc and github.com/alexbrainman/odbc)

Consequently, go mod tidy no longer prunes unused dependencies. On a related note, the command go mod why prints this same error and also fails to work as designed.

@seankhliao
Copy link
Member

an unfortunate consequence of the way modules work

the odbc package declares it's module name as github.com/alexbrainman/odbc here but was required as code.google.com/p/odbc in your dependency and in your replace

I believe the only correct fix is to update the dependency to use the new path (or since it appears inactive, fork the repo and fix it yourself)

@bcmills
Copy link
Contributor

bcmills commented May 18, 2020

See also #26904.

@cagedmantis
Copy link
Contributor

@dominicbarnes I'm going to mark this as a duplicate issue and close it since there is already an existing issue #26904. Please feel free to follow up if you feel this issue was closed in error.

@golang golang locked and limited conversation to collaborators May 19, 2021
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

5 participants