]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/go: fix incorrect determination of import path is DirImportPath
authorMichael Matloob <matloob@golang.org>
Thu, 6 Oct 2022 17:41:02 +0000 (13:41 -0400)
committerMichael Matloob <matloob@golang.org>
Thu, 6 Oct 2022 18:18:22 +0000 (18:18 +0000)
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>
src/cmd/go/internal/modload/load.go
src/cmd/go/testdata/script/vendor_internal.txt [new file with mode: 0644]

index e74780a7b288e00749e833b8de71132790fcdc2f..afd6c80370c745cded597e9b09af5024dcc35274 100644 (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
                        }
diff --git a/src/cmd/go/testdata/script/vendor_internal.txt b/src/cmd/go/testdata/script/vendor_internal.txt
new file mode 100644 (file)
index 0000000..4c0f1fa
--- /dev/null
@@ -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
\ No newline at end of file