aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modcmd/vendor.go
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2019-10-15 13:39:13 -0400
committerBryan C. Mills <bcmills@google.com>2019-10-15 18:15:22 +0000
commite7394e178d0ccf2053238b5cb28805f3062907c5 (patch)
tree0fadcd49ba5212786aa6b36664dfae563d8d0a25 /src/cmd/go/internal/modcmd/vendor.go
parent47759fbab76cb4b4de93382158fae5d27924979f (diff)
downloadgo-e7394e178d0ccf2053238b5cb28805f3062907c5.tar.gz
go-e7394e178d0ccf2053238b5cb28805f3062907c5.zip
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>
Diffstat (limited to 'src/cmd/go/internal/modcmd/vendor.go')
-rw-r--r--src/cmd/go/internal/modcmd/vendor.go40
1 files changed, 25 insertions, 15 deletions
diff --git a/src/cmd/go/internal/modcmd/vendor.go b/src/cmd/go/internal/modcmd/vendor.go
index 8509b8b190..bb1cecdbf5 100644
--- a/src/cmd/go/internal/modcmd/vendor.go
+++ b/src/cmd/go/internal/modcmd/vendor.go
@@ -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,9 +60,16 @@ func runVendor(cmd *base.Command, args []string) {
modpkgs[m] = append(modpkgs[m], pkg)
}
+ includeAllReplacements := false
isExplicit := map[module.Version]bool{}
- for _, r := range modload.ModFile().Require {
- isExplicit[r.Mod] = true
+ 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
@@ -89,20 +97,22 @@ func runVendor(cmd *base.Command, args []string) {
}
}
- // 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.
- for _, r := range modload.ModFile().Replace {
- if len(modpkgs[r.Old]) > 0 {
- // We we already recorded this replacement in the entry for the replaced
- // module with the packages it provides.
- continue
- }
+ 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.
+ for _, r := range modload.ModFile().Replace {
+ if len(modpkgs[r.Old]) > 0 {
+ // We we already recorded this replacement in the entry for the replaced
+ // module with the packages it provides.
+ continue
+ }
- line := moduleLine(r.Old, r.New)
- buf.WriteString(line)
- if cfg.BuildV {
- os.Stderr.WriteString(line)
+ line := moduleLine(r.Old, r.New)
+ buf.WriteString(line)
+ if cfg.BuildV {
+ os.Stderr.WriteString(line)
+ }
}
}