Skip to content

Commit

Permalink
[release-branch.go1.21] all: merge master (a7b1793) into release-bran…
Browse files Browse the repository at this point in the history
…ch.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
  • Loading branch information
dmitshur committed Jun 20, 2023
2 parents 1c1c824 + a7b1793 commit ebbff91
Show file tree
Hide file tree
Showing 41 changed files with 685 additions and 81 deletions.
6 changes: 5 additions & 1 deletion src/cmd/cgo/internal/testshared/shared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,10 @@ func TestThreeGopathShlibs(t *testing.T) {
func requireGccgo(t *testing.T) {
t.Helper()

if runtime.GOARCH == "ppc64" || runtime.GOARCH == "ppc64le" {
t.Skip("gccgo test skipped on PPC64 until issue #60798 is resolved")
}

gccgoName := os.Getenv("GCCGO")
if gccgoName == "" {
gccgoName = "gccgo"
Expand All @@ -748,7 +752,7 @@ func requireGccgo(t *testing.T) {
if dot > 0 {
output = output[:dot]
}
major, err := strconv.Atoi(string(output))
major, err := strconv.Atoi(strings.TrimSpace(string(output)))
if err != nil {
t.Skipf("can't parse gccgo version number %s", output)
}
Expand Down
12 changes: 12 additions & 0 deletions src/cmd/compile/internal/syntax/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ func TestStdLib(t *testing.T) {
filepath.Join(goroot, "src"),
filepath.Join(goroot, "misc"),
} {
if filepath.Base(dir) == "misc" {
// cmd/distpack deletes GOROOT/misc, so skip that directory if it isn't present.
// cmd/distpack also requires GOROOT/VERSION to exist, so use that to
// suppress false-positive skips.
if _, err := os.Stat(dir); os.IsNotExist(err) {
if _, err := os.Stat(filepath.Join(testenv.GOROOT(t), "VERSION")); err == nil {
fmt.Printf("%s not present; skipping\n", dir)
continue
}
}
}

walkDirs(t, dir, func(filename string) {
if skipRx != nil && skipRx.MatchString(filename) {
// Always report skipped files since regexp
Expand Down
7 changes: 0 additions & 7 deletions src/cmd/compile/internal/typecheck/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,6 @@ func tcArith(n ir.Node, op ir.Op, l, r ir.Node) (ir.Node, ir.Node, *types.Type)
}
}

if (op == ir.ODIV || op == ir.OMOD) && ir.IsConst(r, constant.Int) {
if constant.Sign(r.Val()) == 0 {
base.Errorf("division by zero")
return l, r, nil
}
}

return l, r, t
}

Expand Down
8 changes: 8 additions & 0 deletions src/cmd/compile/internal/types2/stdlib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ func firstComment(filename string) (first string) {
func testTestDir(t *testing.T, path string, ignore ...string) {
files, err := os.ReadDir(path)
if err != nil {
// cmd/distpack deletes GOROOT/test, so skip the test if it isn't present.
// cmd/distpack also requires GOROOT/VERSION to exist, so use that to
// suppress false-positive skips.
if _, err := os.Stat(filepath.Join(testenv.GOROOT(t), "test")); os.IsNotExist(err) {
if _, err := os.Stat(filepath.Join(testenv.GOROOT(t), "VERSION")); err == nil {
t.Skipf("skipping: GOROOT/test not present")
}
}
t.Fatal(err)
}

Expand Down
12 changes: 11 additions & 1 deletion src/cmd/distpack/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (a *Archive) Add(name, src string, info fs.FileInfo) {
}

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

// RenameGoMod renames the go.mod files in the archive to _go.mod,
// for use with the module form, which cannot contain other go.mod files.
func (a *Archive) RenameGoMod() {
for i, f := range a.Files {
if strings.HasSuffix(f.Name, "/go.mod") {
a.Files[i].Name = strings.TrimSuffix(f.Name, "go.mod") + "_go.mod"
}
}
}

func amatch(pattern, name string) (bool, error) {
// firstN returns the prefix of name corresponding to the first n path elements.
// If n <= 0, firstN returns the entire name.
Expand Down
15 changes: 15 additions & 0 deletions src/cmd/distpack/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@
// A cross-compiled distribution for goos/goarch can be built using:
//
// GOOS=goos GOARCH=goarch ./make.bash -distpack
//
// To test that the module downloads are usable with the go command:
//
// ./make.bash -distpack
// mkdir -p /tmp/goproxy/golang.org/toolchain/
// ln -sf $(pwd)/../pkg/distpack /tmp/goproxy/golang.org/toolchain/@v
// GOPROXY=file:///tmp/goproxy GOTOOLCHAIN=$(sed 1q ../VERSION) gotip version
//
// gotip can be replaced with an older released Go version once there is one.
// It just can't be the one make.bash built, because it knows it is already that
// version and will skip the download.
package main

import (
Expand Down Expand Up @@ -199,6 +210,8 @@ func main() {
)
modVers := modVersionPrefix + "-" + version + "." + goosDashGoarch
modArch.AddPrefix(modPath + "@" + modVers)
modArch.RenameGoMod()
modArch.Sort()
testMod(modArch)

// distpack returns the full path to name in the distpack directory.
Expand Down Expand Up @@ -235,6 +248,8 @@ func mode(name string, _ fs.FileMode) fs.FileMode {
strings.HasSuffix(name, ".pl") ||
strings.HasSuffix(name, ".rc") {
return 0o755
} else if ok, _ := amatch("**/go_?*_?*_exec", name); ok {
return 0o755
}
return 0o644
}
Expand Down
4 changes: 4 additions & 0 deletions src/cmd/distpack/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ var modRules = []testRule{
{name: "golang.org/toolchain@*/pkg/tool/*/compile", goos: "darwin"},
{name: "golang.org/toolchain@*/pkg/tool/*/compile", goos: "windows", exclude: true},
{name: "golang.org/toolchain@*/pkg/tool/*/compile.exe", goos: "windows"},

// go.mod are renamed to _go.mod.
{name: "**/go.mod", exclude: true},
{name: "**/_go.mod"},
}

func testSrc(a *Archive) {
Expand Down
86 changes: 85 additions & 1 deletion src/cmd/go/go_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
//go:build unix

package main_test

import (
"bufio"
"context"
"internal/testenv"
"io"
"os"
"os/exec"
"slices"
"strings"
"syscall"
"testing"
)
Expand All @@ -33,3 +40,80 @@ func TestGoBuildUmask(t *testing.T) {
t.Fatalf("wrote x with mode=%v, wanted no 0077 bits", mode)
}
}

// TestTestInterrupt verifies the fix for issue #60203.
//
// If the whole process group for a 'go test' invocation receives
// SIGINT (as would be sent by pressing ^C on a console),
// it should return quickly, not deadlock.
func TestTestInterrupt(t *testing.T) {
if testing.Short() {
t.Skipf("skipping in short mode: test executes many subprocesses")
}
// Don't run this test in parallel, for the same reason.

tg := testgo(t)
defer tg.cleanup()
tg.setenv("GOROOT", testGOROOT)

ctx, cancel := context.WithCancel(context.Background())
cmd := testenv.CommandContext(t, ctx, tg.goTool(), "test", "std", "-short", "-count=1")
cmd.Dir = tg.execDir

// Override $TMPDIR when running the tests: since we're terminating the tests
// with a signal they might fail to clean up some temp files, and we don't
// want that to cause an "unexpected files" failure at the end of the run.
cmd.Env = append(slices.Clip(tg.env), tempEnvName()+"="+t.TempDir())

cmd.SysProcAttr = &syscall.SysProcAttr{
Setpgid: true,
}
cmd.Cancel = func() error {
pgid := cmd.Process.Pid
return syscall.Kill(-pgid, syscall.SIGINT)
}

pipe, err := cmd.StdoutPipe()
if err != nil {
t.Fatal(err)
}

t.Logf("running %v", cmd)
if err := cmd.Start(); err != nil {
t.Fatal(err)
}

stdout := new(strings.Builder)
r := bufio.NewReader(pipe)
line, err := r.ReadString('\n')
if err != nil {
t.Fatal(err)
}
stdout.WriteString(line)

// The output line for some test was written, so we know things are in progress.
//
// Cancel the rest of the run by sending SIGINT to the process group:
// it should finish up and exit with a nonzero status,
// not have to be killed with SIGKILL.
cancel()

io.Copy(stdout, r)
if stdout.Len() > 0 {
t.Logf("stdout:\n%s", stdout)
}
err = cmd.Wait()

ee, _ := err.(*exec.ExitError)
if ee == nil {
t.Fatalf("unexpectedly finished with nonzero status")
}
if len(ee.Stderr) > 0 {
t.Logf("stderr:\n%s", ee.Stderr)
}
if !ee.Exited() {
t.Fatalf("'go test' did not exit after interrupt: %v", err)
}

t.Logf("interrupted tests without deadlocking")
}
3 changes: 3 additions & 0 deletions src/cmd/go/internal/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,9 @@ func runList(ctx context.Context, cmd *base.Command, args []string) {
a.Deps = append(a.Deps, b.AutoAction(work.ModeInstall, work.ModeInstall, p))
}
}
if cfg.Experiment.CoverageRedesign && cfg.BuildCover {
load.PrepareForCoverageBuild(pkgs)
}
b.Do(ctx, a)
}

Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/internal/modfetch/coderepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ func (r *codeRepo) retractedVersions(ctx context.Context) (func(string) bool, er
if err != nil {
return nil, err
}
retractions := make([]modfile.VersionInterval, len(f.Retract))
retractions := make([]modfile.VersionInterval, 0, len(f.Retract))
for _, r := range f.Retract {
retractions = append(retractions, r.VersionInterval)
}
Expand Down
24 changes: 23 additions & 1 deletion src/cmd/go/internal/modfetch/sumdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,34 @@ import (
// useSumDB reports whether to use the Go checksum database for the given module.
func useSumDB(mod module.Version) bool {
if mod.Path == "golang.org/toolchain" {
must := true
// Downloaded toolchains cannot be listed in go.sum,
// so we require checksum database lookups even if
// GOSUMDB=off or GONOSUMDB matches the pattern.
// If GOSUMDB=off, then the eventual lookup will fail
// with a good error message.
return true

// Exception #1: using GOPROXY=file:// to test a distpack.
if strings.HasPrefix(cfg.GOPROXY, "file://") && !strings.ContainsAny(cfg.GOPROXY, ",|") {
must = false
}
// Exception #2: the Go proxy+checksum database cannot check itself
// while doing the initial download.
if strings.Contains(os.Getenv("GIT_HTTP_USER_AGENT"), "proxy.golang.org") {
must = false
}

// Another potential exception would be GOPROXY=direct,
// but that would make toolchain downloads only as secure
// as HTTPS, and in particular they'd be susceptible to MITM
// attacks on systems with less-than-trustworthy root certificates.
// The checksum database provides a stronger guarantee,
// so we don't make that exception.

// Otherwise, require the checksum database.
if must {
return true
}
}
return cfg.GOSUMDB != "off" && !module.MatchPrefixPatterns(cfg.GONOSUMDB, mod.Path)
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/internal/modindex/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func GetModule(modroot string) (*Module, error) {
return nil, errNotFromModuleCache
}
modroot = filepath.Clean(modroot)
if !str.HasFilePathPrefix(modroot, cfg.GOMODCACHE) {
if str.HasFilePathPrefix(modroot, cfg.GOROOTsrc) || !str.HasFilePathPrefix(modroot, cfg.GOMODCACHE) {
return nil, errNotFromModuleCache
}
return openIndexModule(modroot, true)
Expand Down
10 changes: 9 additions & 1 deletion src/cmd/go/internal/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,15 @@ func (lockedStdout) Write(b []byte) (int, error) {

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

if a.Failed {
// We were unable to build the binary.
Expand Down

0 comments on commit ebbff91

Please sign in to comment.