1
0
mirror of https://github.com/golang/go synced 2024-11-22 04:14:42 -07:00

cmd/cgo: use slices.Index

Now that Go 1.22.6 is the minimum bootstrap toolchain (cf. CL 606156),
the slices package (introduced in Go 1.21) can be used in packages built
using the bootstrap toolchain.

For #64751

Change-Id: Ife0daa37c0982d9ec1afab07b9d40a1dfee9b7d4
Reviewed-on: https://go-review.googlesource.com/c/go/+/610575
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
Tobias Klauser 2024-09-04 13:31:19 +02:00 committed by Gopher Robot
parent c3f16307b3
commit 634363e3ca

View File

@ -10,13 +10,14 @@ import (
"go/token"
"os"
"os/exec"
"slices"
)
// run runs the command argv, feeding in stdin on standard input.
// It returns the output to standard output and standard error.
// ok indicates whether the command exited successfully.
func run(stdin []byte, argv []string) (stdout, stderr []byte, ok bool) {
if i := find(argv, "-xc"); i >= 0 && argv[len(argv)-1] == "-" {
if i := slices.Index(argv, "-xc"); i >= 0 && argv[len(argv)-1] == "-" {
// Some compilers have trouble with standard input.
// Others have trouble with -xc.
// Avoid both problems by writing a file with a .c extension.
@ -69,15 +70,6 @@ func run(stdin []byte, argv []string) (stdout, stderr []byte, ok bool) {
return
}
func find(argv []string, target string) int {
for i, arg := range argv {
if arg == target {
return i
}
}
return -1
}
func lineno(pos token.Pos) string {
return fset.Position(pos).String()
}