Skip to content

Commit ebbff91

Browse files
committed
[release-branch.go1.21] all: merge master (a7b1793) into release-branch.go1.21
Merge List: + 2023-06-20 a7b1793 cmd/go: do not index std as a module in modcache + 2023-06-20 3d27928 cmd/go: restore go.mod files during toolchain selection + 2023-06-20 3b4b7b8 cmd/distpack: rename go.mod to _go.mod in toolchain modules + 2023-06-20 6459494 cmd/go: disable sumdb less often for toolchain downloads + 2023-06-20 0278981 internal/bisect: add 'q' hash option for quiet hash behavior switching + 2023-06-20 98617fd runtime/trace: add godoc links + 2023-06-19 bc21d6a cmd/go/internal/modfetch: fix retractions slice initial length not zero + 2023-06-17 261e267 os/exec: document a method to check if a process is alive + 2023-06-16 dbf9bf2 cmd/internal/moddeps: allow the "misc" module to be missing from GOROOT + 2023-06-16 0183c1a cmd/compile/internal/syntax: skip GOROOT/misc in TestStdLib if it doesn't exist + 2023-06-16 199fbd4 cmd/internal/testdir: skip Test if GOROOT/test does not exist + 2023-06-16 a48f9c2 go/types: skip tests that require GOROOT/test if it is not present + 2023-06-16 3891ecb go/internal/gcimporter: skip TestImportTypeparamTests if GOROOT/test is missing + 2023-06-16 6087671 cmd/go/internal/test: don't wait for previous test actions when interrupted + 2023-06-16 c1bc446 path/filepath: avoid assuming that GOROOT/test is present + 2023-06-16 9ece9a7 cmd/cgo/internal/testshared: disable gccgo tests on PPC64 + 2023-06-16 23c5e48 cmd/cgo/internal/testshared: strip newline from gccgo -dumpversion + 2023-06-16 cf7ae4f compress/bzip2: fix typo + 2023-06-16 3c8b7a9 net/http: check RemoteAddr isn't nil before dereferencing + 2023-06-16 548790e net/http: close req.Body only when it's non-nil on js + 2023-06-16 6dc2d2a testing/fstest: fix the Glob test when dir entries are out of order + 2023-06-16 2b0ff4b reflect: fix ArenaNew to match documentation + 2023-06-16 4eceefa cmd/distpack: make go_$GOOS_$GOARCH_exec programs executable + 2023-06-16 1a7709d runtime: use 1-byte load for address checking in racecallatomic + 2023-06-15 3e7ec13 cmd/go: fix build config for 'go list -cover' + 2023-06-15 30b17f4 net/http: only disable Fetch API in tests + 2023-06-15 65db95d math: document that Min/Max differ from min/max + 2023-06-15 60e6afb cmd/compile: do not report division by error during typecheck + 2023-06-15 f6e0dcc slices: add sort benchmark for sorted strings Change-Id: If342a000b719335fbbb421f027a8b253b07c1cab
2 parents 1c1c824 + a7b1793 commit ebbff91

File tree

41 files changed

+685
-81
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+685
-81
lines changed

src/cmd/cgo/internal/testshared/shared_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,10 @@ func TestThreeGopathShlibs(t *testing.T) {
731731
func requireGccgo(t *testing.T) {
732732
t.Helper()
733733

734+
if runtime.GOARCH == "ppc64" || runtime.GOARCH == "ppc64le" {
735+
t.Skip("gccgo test skipped on PPC64 until issue #60798 is resolved")
736+
}
737+
734738
gccgoName := os.Getenv("GCCGO")
735739
if gccgoName == "" {
736740
gccgoName = "gccgo"
@@ -748,7 +752,7 @@ func requireGccgo(t *testing.T) {
748752
if dot > 0 {
749753
output = output[:dot]
750754
}
751-
major, err := strconv.Atoi(string(output))
755+
major, err := strconv.Atoi(strings.TrimSpace(string(output)))
752756
if err != nil {
753757
t.Skipf("can't parse gccgo version number %s", output)
754758
}

src/cmd/compile/internal/syntax/parser_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ func TestStdLib(t *testing.T) {
7070
filepath.Join(goroot, "src"),
7171
filepath.Join(goroot, "misc"),
7272
} {
73+
if filepath.Base(dir) == "misc" {
74+
// cmd/distpack deletes GOROOT/misc, so skip that directory if it isn't present.
75+
// cmd/distpack also requires GOROOT/VERSION to exist, so use that to
76+
// suppress false-positive skips.
77+
if _, err := os.Stat(dir); os.IsNotExist(err) {
78+
if _, err := os.Stat(filepath.Join(testenv.GOROOT(t), "VERSION")); err == nil {
79+
fmt.Printf("%s not present; skipping\n", dir)
80+
continue
81+
}
82+
}
83+
}
84+
7385
walkDirs(t, dir, func(filename string) {
7486
if skipRx != nil && skipRx.MatchString(filename) {
7587
// Always report skipped files since regexp

src/cmd/compile/internal/typecheck/expr.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,6 @@ func tcArith(n ir.Node, op ir.Op, l, r ir.Node) (ir.Node, ir.Node, *types.Type)
184184
}
185185
}
186186

187-
if (op == ir.ODIV || op == ir.OMOD) && ir.IsConst(r, constant.Int) {
188-
if constant.Sign(r.Val()) == 0 {
189-
base.Errorf("division by zero")
190-
return l, r, nil
191-
}
192-
}
193-
194187
return l, r, t
195188
}
196189

src/cmd/compile/internal/types2/stdlib_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ func firstComment(filename string) (first string) {
206206
func testTestDir(t *testing.T, path string, ignore ...string) {
207207
files, err := os.ReadDir(path)
208208
if err != nil {
209+
// cmd/distpack deletes GOROOT/test, so skip the test if it isn't present.
210+
// cmd/distpack also requires GOROOT/VERSION to exist, so use that to
211+
// suppress false-positive skips.
212+
if _, err := os.Stat(filepath.Join(testenv.GOROOT(t), "test")); os.IsNotExist(err) {
213+
if _, err := os.Stat(filepath.Join(testenv.GOROOT(t), "VERSION")); err == nil {
214+
t.Skipf("skipping: GOROOT/test not present")
215+
}
216+
}
209217
t.Fatal(err)
210218
}
211219

src/cmd/distpack/archive.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (a *Archive) Add(name, src string, info fs.FileInfo) {
9292
}
9393

9494
// Sort sorts the files in the archive.
95-
// It is only necessary to call Sort after calling Add.
95+
// It is only necessary to call Sort after calling Add or RenameGoMod.
9696
// ArchiveDir returns a sorted archive, and the other methods
9797
// preserve the sorting of the archive.
9898
func (a *Archive) Sort() {
@@ -164,6 +164,16 @@ func (a *Archive) SetTime(t time.Time) {
164164
}
165165
}
166166

167+
// RenameGoMod renames the go.mod files in the archive to _go.mod,
168+
// for use with the module form, which cannot contain other go.mod files.
169+
func (a *Archive) RenameGoMod() {
170+
for i, f := range a.Files {
171+
if strings.HasSuffix(f.Name, "/go.mod") {
172+
a.Files[i].Name = strings.TrimSuffix(f.Name, "go.mod") + "_go.mod"
173+
}
174+
}
175+
}
176+
167177
func amatch(pattern, name string) (bool, error) {
168178
// firstN returns the prefix of name corresponding to the first n path elements.
169179
// If n <= 0, firstN returns the entire name.

src/cmd/distpack/pack.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@
1414
// A cross-compiled distribution for goos/goarch can be built using:
1515
//
1616
// GOOS=goos GOARCH=goarch ./make.bash -distpack
17+
//
18+
// To test that the module downloads are usable with the go command:
19+
//
20+
// ./make.bash -distpack
21+
// mkdir -p /tmp/goproxy/golang.org/toolchain/
22+
// ln -sf $(pwd)/../pkg/distpack /tmp/goproxy/golang.org/toolchain/@v
23+
// GOPROXY=file:///tmp/goproxy GOTOOLCHAIN=$(sed 1q ../VERSION) gotip version
24+
//
25+
// gotip can be replaced with an older released Go version once there is one.
26+
// It just can't be the one make.bash built, because it knows it is already that
27+
// version and will skip the download.
1728
package main
1829

1930
import (
@@ -199,6 +210,8 @@ func main() {
199210
)
200211
modVers := modVersionPrefix + "-" + version + "." + goosDashGoarch
201212
modArch.AddPrefix(modPath + "@" + modVers)
213+
modArch.RenameGoMod()
214+
modArch.Sort()
202215
testMod(modArch)
203216

204217
// distpack returns the full path to name in the distpack directory.
@@ -235,6 +248,8 @@ func mode(name string, _ fs.FileMode) fs.FileMode {
235248
strings.HasSuffix(name, ".pl") ||
236249
strings.HasSuffix(name, ".rc") {
237250
return 0o755
251+
} else if ok, _ := amatch("**/go_?*_?*_exec", name); ok {
252+
return 0o755
238253
}
239254
return 0o644
240255
}

src/cmd/distpack/test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ var modRules = []testRule{
9595
{name: "golang.org/toolchain@*/pkg/tool/*/compile", goos: "darwin"},
9696
{name: "golang.org/toolchain@*/pkg/tool/*/compile", goos: "windows", exclude: true},
9797
{name: "golang.org/toolchain@*/pkg/tool/*/compile.exe", goos: "windows"},
98+
99+
// go.mod are renamed to _go.mod.
100+
{name: "**/go.mod", exclude: true},
101+
{name: "**/_go.mod"},
98102
}
99103

100104
func testSrc(a *Archive) {

src/cmd/go/go_unix_test.go

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
5+
//go:build unix
66

77
package main_test
88

99
import (
10+
"bufio"
11+
"context"
12+
"internal/testenv"
13+
"io"
1014
"os"
15+
"os/exec"
16+
"slices"
17+
"strings"
1118
"syscall"
1219
"testing"
1320
)
@@ -33,3 +40,80 @@ func TestGoBuildUmask(t *testing.T) {
3340
t.Fatalf("wrote x with mode=%v, wanted no 0077 bits", mode)
3441
}
3542
}
43+
44+
// TestTestInterrupt verifies the fix for issue #60203.
45+
//
46+
// If the whole process group for a 'go test' invocation receives
47+
// SIGINT (as would be sent by pressing ^C on a console),
48+
// it should return quickly, not deadlock.
49+
func TestTestInterrupt(t *testing.T) {
50+
if testing.Short() {
51+
t.Skipf("skipping in short mode: test executes many subprocesses")
52+
}
53+
// Don't run this test in parallel, for the same reason.
54+
55+
tg := testgo(t)
56+
defer tg.cleanup()
57+
tg.setenv("GOROOT", testGOROOT)
58+
59+
ctx, cancel := context.WithCancel(context.Background())
60+
cmd := testenv.CommandContext(t, ctx, tg.goTool(), "test", "std", "-short", "-count=1")
61+
cmd.Dir = tg.execDir
62+
63+
// Override $TMPDIR when running the tests: since we're terminating the tests
64+
// with a signal they might fail to clean up some temp files, and we don't
65+
// want that to cause an "unexpected files" failure at the end of the run.
66+
cmd.Env = append(slices.Clip(tg.env), tempEnvName()+"="+t.TempDir())
67+
68+
cmd.SysProcAttr = &syscall.SysProcAttr{
69+
Setpgid: true,
70+
}
71+
cmd.Cancel = func() error {
72+
pgid := cmd.Process.Pid
73+
return syscall.Kill(-pgid, syscall.SIGINT)
74+
}
75+
76+
pipe, err := cmd.StdoutPipe()
77+
if err != nil {
78+
t.Fatal(err)
79+
}
80+
81+
t.Logf("running %v", cmd)
82+
if err := cmd.Start(); err != nil {
83+
t.Fatal(err)
84+
}
85+
86+
stdout := new(strings.Builder)
87+
r := bufio.NewReader(pipe)
88+
line, err := r.ReadString('\n')
89+
if err != nil {
90+
t.Fatal(err)
91+
}
92+
stdout.WriteString(line)
93+
94+
// The output line for some test was written, so we know things are in progress.
95+
//
96+
// Cancel the rest of the run by sending SIGINT to the process group:
97+
// it should finish up and exit with a nonzero status,
98+
// not have to be killed with SIGKILL.
99+
cancel()
100+
101+
io.Copy(stdout, r)
102+
if stdout.Len() > 0 {
103+
t.Logf("stdout:\n%s", stdout)
104+
}
105+
err = cmd.Wait()
106+
107+
ee, _ := err.(*exec.ExitError)
108+
if ee == nil {
109+
t.Fatalf("unexpectedly finished with nonzero status")
110+
}
111+
if len(ee.Stderr) > 0 {
112+
t.Logf("stderr:\n%s", ee.Stderr)
113+
}
114+
if !ee.Exited() {
115+
t.Fatalf("'go test' did not exit after interrupt: %v", err)
116+
}
117+
118+
t.Logf("interrupted tests without deadlocking")
119+
}

src/cmd/go/internal/list/list.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,9 @@ func runList(ctx context.Context, cmd *base.Command, args []string) {
730730
a.Deps = append(a.Deps, b.AutoAction(work.ModeInstall, work.ModeInstall, p))
731731
}
732732
}
733+
if cfg.Experiment.CoverageRedesign && cfg.BuildCover {
734+
load.PrepareForCoverageBuild(pkgs)
735+
}
733736
b.Do(ctx, a)
734737
}
735738

src/cmd/go/internal/modfetch/coderepo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ func (r *codeRepo) retractedVersions(ctx context.Context) (func(string) bool, er
10131013
if err != nil {
10141014
return nil, err
10151015
}
1016-
retractions := make([]modfile.VersionInterval, len(f.Retract))
1016+
retractions := make([]modfile.VersionInterval, 0, len(f.Retract))
10171017
for _, r := range f.Retract {
10181018
retractions = append(retractions, r.VersionInterval)
10191019
}

src/cmd/go/internal/modfetch/sumdb.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,34 @@ import (
3434
// useSumDB reports whether to use the Go checksum database for the given module.
3535
func useSumDB(mod module.Version) bool {
3636
if mod.Path == "golang.org/toolchain" {
37+
must := true
3738
// Downloaded toolchains cannot be listed in go.sum,
3839
// so we require checksum database lookups even if
3940
// GOSUMDB=off or GONOSUMDB matches the pattern.
4041
// If GOSUMDB=off, then the eventual lookup will fail
4142
// with a good error message.
42-
return true
43+
44+
// Exception #1: using GOPROXY=file:// to test a distpack.
45+
if strings.HasPrefix(cfg.GOPROXY, "file://") && !strings.ContainsAny(cfg.GOPROXY, ",|") {
46+
must = false
47+
}
48+
// Exception #2: the Go proxy+checksum database cannot check itself
49+
// while doing the initial download.
50+
if strings.Contains(os.Getenv("GIT_HTTP_USER_AGENT"), "proxy.golang.org") {
51+
must = false
52+
}
53+
54+
// Another potential exception would be GOPROXY=direct,
55+
// but that would make toolchain downloads only as secure
56+
// as HTTPS, and in particular they'd be susceptible to MITM
57+
// attacks on systems with less-than-trustworthy root certificates.
58+
// The checksum database provides a stronger guarantee,
59+
// so we don't make that exception.
60+
61+
// Otherwise, require the checksum database.
62+
if must {
63+
return true
64+
}
4365
}
4466
return cfg.GOSUMDB != "off" && !module.MatchPrefixPatterns(cfg.GONOSUMDB, mod.Path)
4567
}

src/cmd/go/internal/modindex/read.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func GetModule(modroot string) (*Module, error) {
160160
return nil, errNotFromModuleCache
161161
}
162162
modroot = filepath.Clean(modroot)
163-
if !str.HasFilePathPrefix(modroot, cfg.GOMODCACHE) {
163+
if str.HasFilePathPrefix(modroot, cfg.GOROOTsrc) || !str.HasFilePathPrefix(modroot, cfg.GOMODCACHE) {
164164
return nil, errNotFromModuleCache
165165
}
166166
return openIndexModule(modroot, true)

src/cmd/go/internal/test/test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,15 @@ func (lockedStdout) Write(b []byte) (int, error) {
12171217

12181218
func (r *runTestActor) Act(b *work.Builder, ctx context.Context, a *work.Action) error {
12191219
// Wait for previous test to get started and print its first json line.
1220-
<-r.prev
1220+
select {
1221+
case <-r.prev:
1222+
case <-base.Interrupted:
1223+
// We can't wait for the previous test action to complete: we don't start
1224+
// new actions after an interrupt, so if that action wasn't already running
1225+
// it might never happen. Instead, just don't log anything for this action.
1226+
base.SetExitStatus(1)
1227+
return nil
1228+
}
12211229

12221230
if a.Failed {
12231231
// We were unable to build the binary.

0 commit comments

Comments
 (0)