mirror of
https://github.com/golang/go
synced 2024-11-18 14:54:40 -07:00
cmd/go: omit new 'vendor/modules.txt' annotations if the go version is 1.13 or lower
Updates #33848 Change-Id: I887d78179d467030f4177d1834ccefee28a55c8a Reviewed-on: https://go-review.googlesource.com/c/go/+/201257 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
This commit is contained in:
parent
47759fbab7
commit
e7394e178d
@ -19,6 +19,7 @@ import (
|
||||
"cmd/go/internal/imports"
|
||||
"cmd/go/internal/modload"
|
||||
"cmd/go/internal/module"
|
||||
"cmd/go/internal/semver"
|
||||
)
|
||||
|
||||
var cmdVendor = &base.Command{
|
||||
@ -59,10 +60,17 @@ func runVendor(cmd *base.Command, args []string) {
|
||||
modpkgs[m] = append(modpkgs[m], pkg)
|
||||
}
|
||||
|
||||
includeAllReplacements := false
|
||||
isExplicit := map[module.Version]bool{}
|
||||
if gv := modload.ModFile().Go; gv != nil && semver.Compare("v"+gv.Version, "v1.14") >= 0 {
|
||||
// If the Go version is at least 1.14, annotate all explicit 'require' and
|
||||
// 'replace' targets found in the go.mod file so that we can perform a
|
||||
// stronger consistency check when -mod=vendor is set.
|
||||
for _, r := range modload.ModFile().Require {
|
||||
isExplicit[r.Mod] = true
|
||||
}
|
||||
includeAllReplacements = true
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
for _, m := range modload.BuildList()[1:] {
|
||||
@ -89,6 +97,7 @@ func runVendor(cmd *base.Command, args []string) {
|
||||
}
|
||||
}
|
||||
|
||||
if includeAllReplacements {
|
||||
// Record unused and wildcard replacements at the end of the modules.txt file:
|
||||
// without access to the complete build list, the consumer of the vendor
|
||||
// directory can't otherwise determine that those replacements had no effect.
|
||||
@ -105,6 +114,7 @@ func runVendor(cmd *base.Command, args []string) {
|
||||
os.Stderr.WriteString(line)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if buf.Len() == 0 {
|
||||
fmt.Fprintf(os.Stderr, "go: no dependencies to vendor\n")
|
||||
|
17
src/cmd/go/testdata/script/mod_vendor_auto.txt
vendored
17
src/cmd/go/testdata/script/mod_vendor_auto.txt
vendored
@ -6,6 +6,7 @@ env GO111MODULE=on
|
||||
|
||||
cd $WORK/auto
|
||||
cp go.mod go.mod.orig
|
||||
cp $WORK/modules-1.13.txt $WORK/auto/modules.txt
|
||||
|
||||
# An explicit -mod=vendor should force use of the vendor directory.
|
||||
env GOFLAGS=-mod=vendor
|
||||
@ -145,19 +146,23 @@ stderr '^go: inconsistent vendoring in '$WORK/auto':$'
|
||||
stderr '^\texample.com/printversion@v1.0.0: is explicitly required in go.mod, but vendor/modules.txt indicates example.com/printversion@v1.1.0$'
|
||||
stderr '\n\nrun .go mod vendor. to sync, or use -mod=mod or -mod=readonly to ignore the vendor directory$'
|
||||
|
||||
# 'go mod vendor' should write a 1.14 vendor/modules.txt even if
|
||||
# the go version is still 1.13.
|
||||
# If the go version is still 1.13, 'go mod vendor' should write a
|
||||
# matching vendor/modules.txt containing the corrected 1.13 data.
|
||||
go mod vendor
|
||||
cmp $WORK/modules-1.14.txt vendor/modules.txt
|
||||
cmp $WORK/modules-1.13.txt vendor/modules.txt
|
||||
|
||||
go list -mod=vendor -f {{.Dir}} -tags tools all
|
||||
stdout '^'$WORK'[/\\]auto$'
|
||||
stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]printversion$'
|
||||
stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]version$'
|
||||
|
||||
# When the version is upgraded to 1.14, -mod=vendor should kick in
|
||||
# automatically and succeed.
|
||||
# When the version is upgraded to 1.14, 'go mod vendor' should write a
|
||||
# vendor/modules.txt with the updated 1.14 annotations.
|
||||
go mod edit -go=1.14
|
||||
go mod vendor
|
||||
cmp $WORK/modules-1.14.txt vendor/modules.txt
|
||||
|
||||
# Then, -mod=vendor should kick in automatically and succeed.
|
||||
go list -f {{.Dir}} -tags tools all
|
||||
stdout '^'$WORK'[/\\]auto$'
|
||||
stdout '^'$WORK'[/\\]auto[/\\]vendor[/\\]example.com[/\\]printversion$'
|
||||
@ -203,7 +208,7 @@ example.com/printversion
|
||||
example.com/version
|
||||
# example.com/unused => nonexistent.example.com/unused v1.0.0-whatever
|
||||
# example.com/version v1.2.0 => nonexistent.example.com/version v1.2.0
|
||||
-- $WORK/auto/vendor/modules.txt --
|
||||
-- $WORK/modules-1.13.txt --
|
||||
# example.com/printversion v1.0.0
|
||||
example.com/printversion
|
||||
# example.com/version v1.0.0 => ./replacement-version
|
||||
|
Loading…
Reference in New Issue
Block a user