]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.21] 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)
committerJoedian Reid <joedian@google.com>
Mon, 24 Jun 2024 16:57:56 +0000 (16:57 +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.

For: #66403
Fixes: #68051
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>
(cherry picked from commit e44fa1c1a9139ad457d8fa84a68afa3f40e7732a)
Reviewed-on: https://go-review.googlesource.com/c/go/+/593375

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 d6c395f1fc52ff4904d384fa4540a19c13770b41..e7ed6fac29419f05aab67287233ff5bb38fd65d6 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
@@ -637,6 +637,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 {
@@ -691,12 +693,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 {
@@ -707,6 +704,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