Skip to content

Commit 53ee352

Browse files
committed
goprocess: use debug/buildinfo on Go 1.18 and newer
Use package debug/buildinfo [1] introduced in Go 1.18 [2] when possible. This should avoid previous issues with rsc.io/goversion where Go processes were no longer listed. [1] https://pkg.go.dev/debug/buildinfo [2] https://go.dev/doc/go1.18#debug/buildinfo For #102 For #159 For #160
1 parent 3d102a4 commit 53ee352

File tree

4 files changed

+37
-5
lines changed

4 files changed

+37
-5
lines changed

goprocess/gp.go goprocess/goprocess.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import (
99
"os"
1010
"sync"
1111

12-
goversion "rsc.io/goversion/version"
13-
1412
"github.com/google/gops/internal"
1513
ps "github.com/keybase/go-ps"
1614
)
@@ -119,13 +117,11 @@ func isGo(pr ps.Process) (path, version string, agent, ok bool, err error) {
119117
if err != nil {
120118
return
121119
}
122-
var versionInfo goversion.Version
123-
versionInfo, err = goversion.ReadExe(path)
120+
version, err = goVersion(path)
124121
if err != nil {
125122
return
126123
}
127124
ok = true
128-
version = versionInfo.Release
129125
pidfile, err := internal.PIDFile(pr.Pid())
130126
if err == nil {
131127
_, err := os.Stat(pidfile)

goprocess/goprocess_1.18.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2022 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
//go:build go1.18
6+
// +build go1.18
7+
8+
package goprocess
9+
10+
import "debug/buildinfo"
11+
12+
func goVersion(path string) (string, error) {
13+
info, err := buildinfo.ReadFile(path)
14+
if err != nil {
15+
return "", err
16+
}
17+
return info.GoVersion, nil
18+
}

goprocess/goprocess_lt1.18.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2022 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
//go:build !go1.18
6+
// +build !go1.18
7+
8+
package goprocess
9+
10+
import goversion "rsc.io/goversion/version"
11+
12+
func goVersion(path string) (string, error) {
13+
versionInfo, err := goversion.ReadExe(path)
14+
if err != nil {
15+
return "", err
16+
}
17+
return versionInfo.Release, nil
18+
}
File renamed without changes.

0 commit comments

Comments
 (0)