1
0
mirror of https://github.com/golang/go synced 2024-11-17 07:45:09 -07:00

cmd/go: fix incorrect determination of import path is DirImportPath

In practice this only shows up when a vendored package, imported on the
command line, imports an internal package.

Change-Id: I34c161d1f1ef15a87c58a422f17d11f77fbac53f
Reviewed-on: https://go-review.googlesource.com/c/go/+/439735
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
This commit is contained in:
Michael Matloob 2022-10-06 13:41:02 -04:00
parent 9dfadf911d
commit fda5dcd9bb
2 changed files with 17 additions and 0 deletions

View File

@ -753,6 +753,7 @@ func (mms *MainModuleSet) DirImportPath(ctx context.Context, dir string) (path s
suffix := filepath.ToSlash(dir[len(modRoot):])
if strings.HasPrefix(suffix, "/vendor/") {
longestPrefixPath = strings.TrimPrefix(suffix, "/vendor/")
continue
}
longestPrefixPath = mms.PathPrefix(v) + suffix
}

View File

@ -0,0 +1,16 @@
go build ./vendor/foo.com/internal/bar/a
-- go.mod --
module example.com/x
go 1.19
require "foo.com/internal/bar" v1.0.0
-- vendor/modules.txt --
# foo.com/internal/bar v1.0.0
## explicit
foo.com/internal/bar/a
-- vendor/foo.com/internal/bar/a/a.go --
package a
import _ "foo.com/internal/bar/b"
-- vendor/foo.com/internal/bar/b/b.go --
package b