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: go list -json -m does not provide Replace.Path relative to current directory when using workspaces #54263

Open
mlaventure opened this issue Aug 4, 2022 · 1 comment
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@mlaventure
Copy link

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

$ go version
go version go1.18.5 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/mlaventure/.cache/go-build"
GOENV="/home/mlaventure/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/mlaventure/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/mlaventure/go"
GOPRIVATE=""
GOPROXY="direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18.5"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/mlaventure/tmp/go/workspace/fubar/go.mod"
GOWORK="/home/mlaventure/tmp/go/workspace/go.work"
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-build500860194=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Given a monorepo setup as follow:

~/tmp/go $ tree
.
├── foo
│   ├── foo.go
│   └── go.mod
└── workspace
    ├── fubar
    │   ├── go.mod
    │   └── main.go
    └── go.work

3 directories, 5 files

With the following go.work:

go 1.18

use ./fubar

replace github.com/foo/foo => ../foo

When getting the list of replaced modules, the .Replace.Path entry is given relative to the go.work file instead of relative to the current folder the command was invoked from. The command ran was the following:

~/tmp/go/workspace/fubar$ go list -json -m all

What did you expect to see?

Path being appropriately set to reflect the current directory

{
        "Path": "github.com/foo/foo",
        "Version": "v0.0.0-00010101000000-000000000000",
        "Replace": {
                "Path": "../../foo",
                "Dir": "/home/mlaventure/tmp/go/foo",
                "GoMod": "/home/mlaventure/tmp/go/foo/go.mod",
                "GoVersion": "1.18"
        },
        "Indirect": true,
        "Dir": "/home/mlaventure/tmp/go/foo",
        "GoMod": "/home/mlaventure/tmp/go/foo/go.mod",
        "GoVersion": "1.18"
}

What did you see instead?

{                                                 
        "Path": "github.com/foo/foo",                                                                                                                                                                                                                                                                                                                      
        "Version": "v0.0.0-00010101000000-000000000000",
        "Replace": {
                "Path": "../foo",
                "Dir": "/home/mlaventure/tmp/go/foo",
                "GoMod": "/home/mlaventure/tmp/go/foo/go.mod",
                "GoVersion": "1.18"
        },
        "Indirect": true,
        "Dir": "/home/mlaventure/tmp/go/foo",
        "GoMod": "/home/mlaventure/tmp/go/foo/go.mod",
        "GoVersion": "1.18"
}
@dmitshur dmitshur added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. GoCommand cmd/go labels Aug 4, 2022
@dmitshur dmitshur added this to the Backlog milestone Aug 4, 2022
@dmitshur
Copy link
Contributor

dmitshur commented Aug 4, 2022

CC @bcmills, @matloob.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

2 participants