]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fix go list -u -m all with too new retractions dependency
authorSam Thanawalla <samthanawalla@google.com>
Mon, 20 May 2024 20:43:39 +0000 (20:43 +0000)
committerGopher Robot <gobot@golang.org>
Tue, 18 Jun 2024 15:33:06 +0000 (15:33 +0000)
Previously, go would not report retractions of dependencies that have a
newer version of Go. With this change, we will still display retractions despite a version difference when go list -u -m is used.

Fixes: #66403
Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-windows-amd64-longtest
Change-Id: I6406680235e294269836ae4cbe3d5680ca10eea0
Reviewed-on: https://go-review.googlesource.com/c/go/+/588775
Auto-Submit: Sam Thanawalla <samthanawalla@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/cmd/go/internal/modload/modfile.go
src/cmd/go/testdata/mod/example.com_retract_newergoversion_v1.0.0.txt [new file with mode: 0644]
src/cmd/go/testdata/mod/example.com_retract_newergoversion_v1.2.0.txt [new file with mode: 0644]
src/cmd/go/testdata/script/list_retractions_issue66403.txt [new file with mode: 0644]

index 899f1b3d09aca5b51ae082a8e3a453c6421ba07c..1d6b28db19ebd6bbf51524a503e42883388c3e53 100644 (file)
@@ -190,7 +190,7 @@ func CheckRetractions(ctx context.Context, m module.Version) (err error) {
                return err
        }
        summary, err := rawGoModSummary(rm)
-       if err != nil {
+       if err != nil && !errors.Is(err, gover.ErrTooNew) {
                return err
        }
 
@@ -298,7 +298,7 @@ func CheckDeprecation(ctx context.Context, m module.Version) (deprecation string
                return "", err
        }
        summary, err := rawGoModSummary(latest)
-       if err != nil {
+       if err != nil && !errors.Is(err, gover.ErrTooNew) {
                return "", err
        }
        return summary.deprecated, nil
@@ -644,6 +644,8 @@ func goModSummary(m module.Version) (*modFileSummary, error) {
 // its dependencies.
 //
 // rawGoModSummary cannot be used on the main module outside of workspace mode.
+// The modFileSummary can still be used for retractions and deprecations
+// even if a TooNewError is returned.
 func rawGoModSummary(m module.Version) (*modFileSummary, error) {
        if gover.IsToolchain(m.Path) {
                if m.Path == "go" && gover.Compare(m.Version, gover.GoStrictVersion) >= 0 {
@@ -698,12 +700,7 @@ func rawGoModSummary(m module.Version) (*modFileSummary, error) {
                                summary.require = append(summary.require, req.Mod)
                        }
                }
-               if summary.goVersion != "" && gover.Compare(summary.goVersion, gover.GoStrictVersion) >= 0 {
-                       if gover.Compare(summary.goVersion, gover.Local()) > 0 {
-                               return nil, &gover.TooNewError{What: "module " + m.String(), GoVersion: summary.goVersion}
-                       }
-                       summary.require = append(summary.require, module.Version{Path: "go", Version: summary.goVersion})
-               }
+
                if len(f.Retract) > 0 {
                        summary.retract = make([]retraction, 0, len(f.Retract))
                        for _, ret := range f.Retract {
@@ -714,6 +711,16 @@ func rawGoModSummary(m module.Version) (*modFileSummary, error) {
                        }
                }
 
+               // This block must be kept at the end of the function because the summary may
+               // be used for reading retractions or deprecations even if a TooNewError is
+               // returned.
+               if summary.goVersion != "" && gover.Compare(summary.goVersion, gover.GoStrictVersion) >= 0 {
+                       summary.require = append(summary.require, module.Version{Path: "go", Version: summary.goVersion})
+                       if gover.Compare(summary.goVersion, gover.Local()) > 0 {
+                               return summary, &gover.TooNewError{What: "module " + m.String(), GoVersion: summary.goVersion}
+                       }
+               }
+
                return summary, nil
        })
 }
diff --git a/src/cmd/go/testdata/mod/example.com_retract_newergoversion_v1.0.0.txt b/src/cmd/go/testdata/mod/example.com_retract_newergoversion_v1.0.0.txt
new file mode 100644 (file)
index 0000000..21d5352
--- /dev/null
@@ -0,0 +1,10 @@
+-- .mod --
+module example.com/retract/newergoversion
+
+go 1.21
+
+-- .info --
+{"Version":"v1.0.0"}
+
+-- retract.go --
+package newergoversion
\ No newline at end of file
diff --git a/src/cmd/go/testdata/mod/example.com_retract_newergoversion_v1.2.0.txt b/src/cmd/go/testdata/mod/example.com_retract_newergoversion_v1.2.0.txt
new file mode 100644 (file)
index 0000000..7aa28b9
--- /dev/null
@@ -0,0 +1,12 @@
+-- .mod --
+module example.com/retract/newergoversion
+
+go 1.23
+
+retract v1.2.0
+
+-- .info --
+{"Version":"v1.2.0"}
+
+-- retract.go --
+package newergoversion
diff --git a/src/cmd/go/testdata/script/list_retractions_issue66403.txt b/src/cmd/go/testdata/script/list_retractions_issue66403.txt
new file mode 100644 (file)
index 0000000..717d129
--- /dev/null
@@ -0,0 +1,20 @@
+# For issue #66403, go list -u -m all should not fail if a module
+# with retractions has a newer version.
+
+env TESTGO_VERSION=go1.21
+env TESTGO_VERSION_SWITCH=switch
+go list -u -m example.com/retract/newergoversion
+stdout 'example.com/retract/newergoversion v1.0.0'
+! stdout 'v1.2.0'
+
+-- go.mod --
+module example.com/m
+
+go 1.22
+
+require example.com/retract/newergoversion v1.0.0
+
+-- main.go --
+package main
+
+import _ "example.com/retract/newergoversion"
\ No newline at end of file