summaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modinfo
diff options
context:
space:
mode:
authorJay Conrod <jayconrod@google.com>2020-04-15 13:56:09 -0400
committerJay Conrod <jayconrod@google.com>2020-08-26 21:12:37 +0000
commitc769f034d796769ad10fc03fe6866b36039d1a09 (patch)
tree282c9cdb6aac0f7fd13bfc937df66d248a6f9a04 /src/cmd/go/internal/modinfo
parentdb821b54d1a8dffa85a9a3cf599f83a19184f020 (diff)
downloadgo-git-c769f034d796769ad10fc03fe6866b36039d1a09.tar.gz
cmd/go/internal/modload: support go.mod retract directive
The go command now recognizes 'retract' directives in go.mod. A retract directive may be used by a module author to indicate a version should not be used. The go command will not automatically upgrade to a retracted version. Retracted versions will not be considered when resolving version queries like "latest" that don't refer to a specific version. Internally, when the go command resolves a version query, it will find the highest release version (or pre-release if no release is available), then it will load retractions from the go.mod file for that version. Comments on retractions are treated as a rationale and may appear in error messages. Retractions are only loaded when a query is resolved, so this should have no impact on performance for most builds, except when go.mod is incomplete. For #24031 Change-Id: I17d643b9e03a3445676dbf1a5a351090c6ff6914 Reviewed-on: https://go-review.googlesource.com/c/go/+/228380 Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd/go/internal/modinfo')
-rw-r--r--src/cmd/go/internal/modinfo/info.go17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/cmd/go/internal/modinfo/info.go b/src/cmd/go/internal/modinfo/info.go
index 07248d1a61..897be56397 100644
--- a/src/cmd/go/internal/modinfo/info.go
+++ b/src/cmd/go/internal/modinfo/info.go
@@ -21,6 +21,7 @@ type ModulePublic struct {
Dir string `json:",omitempty"` // directory holding local copy of files, if any
GoMod string `json:",omitempty"` // path to go.mod file describing module, if any
GoVersion string `json:",omitempty"` // go version used in module
+ Retracted []string `json:",omitempty"` // retraction information, if any (with -retracted or -u)
Error *ModuleError `json:",omitempty"` // error loading module
}
@@ -30,18 +31,26 @@ type ModuleError struct {
func (m *ModulePublic) String() string {
s := m.Path
+ versionString := func(mm *ModulePublic) string {
+ v := mm.Version
+ if len(mm.Retracted) == 0 {
+ return v
+ }
+ return v + " (retracted)"
+ }
+
if m.Version != "" {
- s += " " + m.Version
+ s += " " + versionString(m)
if m.Update != nil {
- s += " [" + m.Update.Version + "]"
+ s += " [" + versionString(m.Update) + "]"
}
}
if m.Replace != nil {
s += " => " + m.Replace.Path
if m.Replace.Version != "" {
- s += " " + m.Replace.Version
+ s += " " + versionString(m.Replace)
if m.Replace.Update != nil {
- s += " [" + m.Replace.Update.Version + "]"
+ s += " [" + versionString(m.Replace.Update) + "]"
}
}
}