From: Jay Conrod Date: Wed, 22 Jan 2020 23:46:11 +0000 (-0800) Subject: cmd/go: unify trimpath logic for -mod=vendor, -mod=mod X-Git-Tag: go1.14rc1~79 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=64378c233b69ca577a23a85285aa9adf3849d7f5;p=gostls13.git cmd/go: unify trimpath logic for -mod=vendor, -mod=mod If a package has a module with a version, the package's directory is replaced with the module path and version, followed by the package's path within the module. This is a follow up to CL 214945. We no longer check whether the module has a directory (with -mod=vendor, it does not). Updates #36566 Change-Id: I5bc952b13bc7b4659f58ee555bd6c6a087eb7792 Reviewed-on: https://go-review.googlesource.com/c/go/+/215940 Run-TryBot: Jay Conrod Reviewed-by: Bryan C. Mills --- diff --git a/src/cmd/go/internal/work/gc.go b/src/cmd/go/internal/work/gc.go index daa88d3114..7d17c0c01e 100644 --- a/src/cmd/go/internal/work/gc.go +++ b/src/cmd/go/internal/work/gc.go @@ -227,8 +227,8 @@ func (a *Action) trimpath() string { // For "go build -trimpath", rewrite package source directory // to a file system-independent path (just the import path). if cfg.BuildTrimpath { - if m := a.Package.Module; m != nil && m.Dir != "" && m.Version != "" { - rewrite += ";" + m.Dir + "=>" + m.Path + "@" + m.Version + if m := a.Package.Module; m != nil && m.Version != "" { + rewrite += ";" + a.Package.Dir + "=>" + m.Path + "@" + m.Version + strings.TrimPrefix(a.Package.ImportPath, m.Path) } else { rewrite += ";" + a.Package.Dir + "=>" + a.Package.ImportPath } diff --git a/src/cmd/go/testdata/script/mod_vendor_trimpath.txt b/src/cmd/go/testdata/script/mod_vendor_trimpath.txt index 241a303675..c419fc9793 100644 --- a/src/cmd/go/testdata/script/mod_vendor_trimpath.txt +++ b/src/cmd/go/testdata/script/mod_vendor_trimpath.txt @@ -17,9 +17,9 @@ go run main.go stdout vendor # With -trimpath, everything before the package path should be trimmed. -# Unlike with -mod=mod, we don't include versions as part of the module name. +# As with -mod=mod, the version should appear as part of the module path. go run -trimpath main.go -stdout example.com/stack/stack.go +stdout example.com/stack@v1.0.0/stack.go -- go.mod -- module example.com/main