-
Notifications
You must be signed in to change notification settings - Fork 17.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/go/internal: factor out modload.QueryPackage and use in in modget
modload.Import contains a loop that looks for the module containing a package. Because we overload Import to locate both packages and modules, that loop contains a bunch of special-cases for modules with empty roots. In this change, we factor out the loop into a new function (QueryPackage) and use that directly in modget.getQuery. That restores the invariant that the paths passed to modload.Import must be importable packages, and fixes 'go get' lookups for packages that have moved between a module and submodules with the same path prefix. Updates #26602. Change-Id: I8bc8340c17f2df062d03ce720f4dc18b2ba406b2 Reviewed-on: https://go-review.googlesource.com/128136 Reviewed-by: Russ Cox <rsc@golang.org>
- Loading branch information
Bryan C. Mills
committed
Aug 9, 2018
1 parent
a1cbbe0
commit 261609f
Showing
14 changed files
with
172 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Written by hand. | ||
Test case for package moved into a parent module. | ||
|
||
-- .mod -- | ||
module example.com/join/subpkg | ||
-- .info -- | ||
{"Version": "v1.0.0"} | ||
-- x.go -- | ||
package subpkg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Written by hand. | ||
Test case for package moved into a parent module. | ||
|
||
-- .mod -- | ||
module example.com/join/subpkg | ||
|
||
require example.com/join v1.1.0 | ||
-- .info -- | ||
{"Version": "v1.1.0"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Written by hand. | ||
Test case for package moved into a parent module. | ||
|
||
-- .mod -- | ||
module example.com/join | ||
-- .info -- | ||
{"Version": "v1.0.0"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Written by hand. | ||
Test case for package moved into a parent module. | ||
|
||
-- .mod -- | ||
module example.com/join | ||
-- .info -- | ||
{"Version": "v1.1.0"} | ||
-- subpkg/x.go -- | ||
package subpkg |
11 changes: 11 additions & 0 deletions
11
src/cmd/go/testdata/mod/example.com_split_subpkg_v1.1.0.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Written by hand. | ||
Test case for getting a package that has been moved to a different module. | ||
|
||
-- .mod -- | ||
module example.com/split/subpkg | ||
|
||
require example.com/split v1.1.0 | ||
-- .info -- | ||
{"Version": "v1.1.0"} | ||
-- x.go -- | ||
package subpkg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Written by hand. | ||
Test case for getting a package that has been moved to a different module. | ||
|
||
-- .mod -- | ||
module example.com/split | ||
-- .info -- | ||
{"Version": "v1.0.0"} | ||
-- subpkg/x.go -- | ||
package subpkg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Written by hand. | ||
Test case for getting a package that has been moved to a different module. | ||
|
||
-- .mod -- | ||
module example.com/split | ||
|
||
require example.com/split/subpkg v1.1.0 | ||
-- .info -- | ||
{"Version": "v1.1.0"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
env GO111MODULE=on | ||
|
||
# A 'go get' that worked at a previous version should continue to work at that version, | ||
# even if the package was subsequently moved into a submodule. | ||
go mod init example.com/foo | ||
go get -d example.com/split/subpkg@v1.0.0 | ||
go list -m all | ||
stdout 'example.com/split v1.0.0' | ||
|
||
# A 'go get' that simultaneously upgrades away conflicting package defitions is not ambiguous. | ||
go get example.com/split/subpkg@v1.1.0 | ||
|
||
# A 'go get' without an upgrade should find the package. | ||
rm go.mod | ||
go mod init example.com/foo | ||
go get -d example.com/split/subpkg | ||
go list -m all | ||
stdout 'example.com/split/subpkg v1.1.0' | ||
|
||
|
||
# A 'go get' that worked at a previous version should continue to work at that version, | ||
# even if the package was subsequently moved into a parent module. | ||
rm go.mod | ||
go mod init example.com/foo | ||
go get -d example.com/join/subpkg@v1.0.0 | ||
go list -m all | ||
stdout 'example.com/join/subpkg v1.0.0' | ||
|
||
# A 'go get' that simultaneously upgrades away conflicting package definitions is not ambiguous. | ||
go get example.com/join/subpkg@v1.1.0 | ||
|
||
# A 'go get' without an upgrade should find the package. | ||
rm go.mod | ||
go mod init example.com/foo | ||
go get -d example.com/join/subpkg@v1.1.0 | ||
go list -m all | ||
stdout 'example.com/join v1.1.0' |