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: error out in 'go mod tidy' if the result uses a module for multiple paths #34650

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

Comments

@budougumi0617
Copy link

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=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/budougumi0617/Library/Caches/go-build"
GOENV="/Users/budougumi0617/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/budougumi0617/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/opt/go/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/budougumi0617/go/src/github.com/budougumi0617/til/go/tui/promptui/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/sy/ls4cfp216x774g54brzl67yw0000gn/T/go-build596997761=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

https://play.golang.org/p/LTTwK6ldWiB

I put below files in current directory.

main.go

package main

import (
        "fmt"

        "github.com/manifoldco/promptui"
)

func main() {
        fmt.Println(promptui.FGRed)
}

go.mod

module github.com/budougumi0617/til/go/tui/promptui

go 1.13

require (
        github.com/BurntSushi/toml v0.3.1 // indirect
        github.com/alecthomas/units v0.0.0-20190910110746-680d30ca3117 // indirect
        github.com/manifoldco/promptui v0.3.2
        github.com/nicksnyder/go-i18n v1.10.1 // indirect
        gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20180810215634-df19058c872c // indirect
)

replace github.com/nicksnyder/go-i18n v1.10.1 => github.com/nicksnyder/go-i18n/v2 v2.0.2

go build command is success.

$ go clean --modcache
$ rm go.sum
$ go build . // build ok

And, I did go mod tidy command for format go.mod. As a result, go mod tidy changed go.modfile.

$ cp go.mod go.mod.before // keep original go.mod file
$ go mod tidy
$ diff go.mod.before go.mod
--- go.mod.before       2019-10-01 16:25:03.000000000 +0900
+++ go.mod      2019-10-01 16:25:11.000000000 +0900
@@ -7,6 +7,7 @@
        github.com/alecthomas/units v0.0.0-20190910110746-680d30ca3117 // indirect
        github.com/manifoldco/promptui v0.3.2
        github.com/nicksnyder/go-i18n v1.10.1 // indirect
+       github.com/nicksnyder/go-i18n/v2 v2.0.2 // indirect
        gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20180810215634-df19058c872c // indirect
 )

But, go build now failed.

$ go build .
go: github.com/nicksnyder/go-i18n/v2@v2.0.2 used for two different module paths (github.com/nicksnyder/go-i18n and github.com/nicksnyder/go-i18n/v2)

What did you expect to see?

I expect the result of go mod tidy is able to buld, or go mod tidy failed if go.mod file is invalid.

What did you see instead?

I tried same procedures, on docker. Unfortunately, I get same result.

$ docker container run -it --name my_golang -v $(pwd):/go/src/ golang:latest
go env Output ( on container)
$ root@734e4aabfb61:/go/src# go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/go/src/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-build324591870=/tmp/go-build -gno-record-gcc-switches"
@andybons
Copy link
Member

andybons commented Oct 2, 2019

@bcmills @jayconrod

@andybons andybons added modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Oct 2, 2019
@andybons andybons added this to the Unplanned milestone Oct 2, 2019
@bcmills bcmills changed the title cmd/go: Fail "go build" command after "go mod tidy" cmd/go: error out in 'go mod tidy' if the result uses a module for multiple paths Oct 2, 2019
@bcmills bcmills added help wanted NeedsFix The path to resolution is known, but the work has not been done. labels Oct 2, 2019
@gopherbot gopherbot removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 2, 2019
@bcmills
Copy link
Contributor

bcmills commented Oct 2, 2019

replace directives replace source code, not import paths, so attempting to use a replace directive in this way would break internal import statements within the module in question and is therefore not supported.

(Redirecting imports paths is #26904, which I am still hoping to address for 1.14.)

However, I agree that go mod tidy should have reported this error instead of deferring it until go build.

@gopherbot
Copy link

Change https://golang.org/cl/199598 mentions this issue: cmd/go/internal/modcmd: error out if one module with two different paths

@golang golang locked and limited conversation to collaborators Oct 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted modules NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants