From e87f416f0b10c5548721e6cdae2132b88e262c5a Mon Sep 17 00:00:00 2001 From: qiulaidongfeng <2645477756@qq.com> Date: Sun, 5 Nov 2023 12:59:48 +0800 Subject: [PATCH] cmd/bisect: inline cmdInterrupt --- cmd/bisect/go119.go | 13 ------------- cmd/bisect/go120.go | 26 -------------------------- cmd/bisect/main.go | 13 ++++++++++--- 3 files changed, 10 insertions(+), 42 deletions(-) delete mode 100644 cmd/bisect/go119.go delete mode 100644 cmd/bisect/go120.go diff --git a/cmd/bisect/go119.go b/cmd/bisect/go119.go deleted file mode 100644 index debe4e0c253..00000000000 --- a/cmd/bisect/go119.go +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2023 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -//go:build !go1.20 - -package main - -import "os/exec" - -func cmdInterrupt(cmd *exec.Cmd) { - // cmd.Cancel and cmd.WaitDelay not available before Go 1.20. -} diff --git a/cmd/bisect/go120.go b/cmd/bisect/go120.go deleted file mode 100644 index c85edf7b575..00000000000 --- a/cmd/bisect/go120.go +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2023 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -//go:build go1.20 - -package main - -import ( - "os" - "os/exec" - "time" -) - -func cmdInterrupt(cmd *exec.Cmd) { - cmd.Cancel = func() error { - // On timeout, send interrupt, - // in hopes of shutting down process tree. - // Ignore errors sending signal; it's all best effort - // and not even implemented on Windows. - // TODO(rsc): Maybe use a new process group and kill the whole group? - cmd.Process.Signal(os.Interrupt) - return nil - } - cmd.WaitDelay = 2 * time.Second -} diff --git a/cmd/bisect/main.go b/cmd/bisect/main.go index 6a3745c0582..28892628079 100644 --- a/cmd/bisect/main.go +++ b/cmd/bisect/main.go @@ -640,9 +640,16 @@ func (b *Bisect) run(suffix string) *Result { } cmd := exec.CommandContext(ctx, b.Cmd, args...) cmd.Env = append(os.Environ(), env...) - // Set up cmd.Cancel, cmd.WaitDelay on Go 1.20 and later - // TODO(rsc): Inline go120.go's cmdInterrupt once we stop supporting Go 1.19. - cmdInterrupt(cmd) + cmd.Cancel = func() error { + // On timeout, send interrupt, + // in hopes of shutting down process tree. + // Ignore errors sending signal; it's all best effort + // and not even implemented on Windows. + // TODO(rsc): Maybe use a new process group and kill the whole group? + cmd.Process.Signal(os.Interrupt) + return nil + } + cmd.WaitDelay = 2 * time.Second out, err = cmd.CombinedOutput() }