Skip to content

Commit 593f083

Browse files
matloobromaindoumenc
authored andcommitted
cmd/go: set dependency go versions for go install --mod=readonly mod@vers
When running go install --mod=readonly module@version. modfetch.GoSumFile was not set, so the checksumOk check that's done when checking whether we need to set the GoVersion from the go mod file was failing. Bypass the checksumOk check when there's no GoSumFile. For golang#54908 Change-Id: I56cf9d36a505b1223e6bf82a7d455746e2f09849 Reviewed-on: https://go-review.googlesource.com/c/go/+/439855 Reviewed-by: Bryan Mills <[email protected]> Run-TryBot: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Michael Matloob <[email protected]>
1 parent a890328 commit 593f083

File tree

5 files changed

+58
-2
lines changed

5 files changed

+58
-2
lines changed

Diff for: src/cmd/go/internal/modload/build.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ func moduleInfo(ctx context.Context, rs *Requirements, m module.Version, mode Li
319319
}
320320

321321
checksumOk := func(suffix string) bool {
322-
return rs == nil || m.Version == "" || cfg.BuildMod == "mod" ||
322+
return rs == nil || m.Version == "" || !mustHaveSums() ||
323323
modfetch.HaveSum(module.Version{Path: m.Path, Version: m.Version + suffix})
324324
}
325325

Diff for: src/cmd/go/internal/modload/import.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -714,14 +714,20 @@ func fetch(ctx context.Context, mod module.Version) (dir string, isLocal bool, e
714714
mod = r
715715
}
716716

717-
if HasModRoot() && cfg.BuildMod == "readonly" && !inWorkspaceMode() && !modfetch.HaveSum(mod) {
717+
if mustHaveSums() && !modfetch.HaveSum(mod) {
718718
return "", false, module.VersionError(mod, &sumMissingError{})
719719
}
720720

721721
dir, err = modfetch.Download(ctx, mod)
722722
return dir, false, err
723723
}
724724

725+
// mustHaveSums reports whether we require that all checksums
726+
// needed to load or build packages are already present in the go.sum file.
727+
func mustHaveSums() bool {
728+
return HasModRoot() && cfg.BuildMod == "readonly" && !inWorkspaceMode()
729+
}
730+
725731
type sumMissingError struct {
726732
suggestion string
727733
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
example.com/depends/on/generics v1.0.0
2+
written by hand
3+
4+
-- .mod --
5+
module example.com/depends/on/generics
6+
7+
go 1.18
8+
9+
require example.com/generics v1.0.0
10+
-- .info --
11+
{"Version":"v1.0.0"}
12+
-- go.mod --
13+
module example.com/depends/on/generics
14+
15+
go 1.18
16+
17+
require example.com/generics v1.0.0
18+
-- main.go --
19+
package main
20+
21+
import "example.com/generics"
22+
23+
func main() {generics.Bar()}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
example.com/generics v1.0.0
2+
written by hand
3+
4+
-- .mod --
5+
module example.com/generics
6+
7+
go 1.18
8+
-- .info --
9+
{"Version":"v1.0.0"}
10+
-- go.mod --
11+
module example.com/generics
12+
13+
go 1.18
14+
-- generics.go --
15+
package generics
16+
17+
type Int interface {
18+
~int
19+
}
20+
21+
func Bar() {}

Diff for: src/cmd/go/testdata/script/install_dep_version.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Regression test for Issue #54908. When running a go install module@version
2+
# with --mod=readonly moduleInfo was not setting the GoVersion for the module
3+
# because the checksumOk function was failing because modfetch.GoSumFile
4+
# was not set when running outside of a module.
5+
6+
go install --mod=readonly example.com/depends/on/[email protected]

0 commit comments

Comments
 (0)