Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

goprocess: use debug/buildinfo on Go 1.18 and newer #166

Merged
merged 2 commits into from May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Expand Up @@ -12,8 +12,8 @@ jobs:
test:
strategy:
matrix:
# Minimum supported version (1.12) and the latest few versions
go-version: [1.12, 1.15, 1.16, 1.17]
# Minimum supported version (1.12) and the latest two
go-version: [1.12, 1.17, 1.18]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}

Expand All @@ -27,11 +27,11 @@ jobs:
uses: actions/checkout@v2

- name: Check formatting
if: matrix.go-version == '1.17' && matrix.platform == 'ubuntu-latest'
if: matrix.go-version == '1.18' && matrix.platform == 'ubuntu-latest'
run: diff -u <(echo -n) <(go fmt $(go list ./...))

- name: Check module vendoring
if: matrix.go-version == '1.17' && matrix.platform == 'ubuntu-latest'
if: matrix.go-version == '1.18' && matrix.platform == 'ubuntu-latest'
run: |
go mod tidy
go mod vendor
Expand Down
6 changes: 1 addition & 5 deletions goprocess/gp.go → goprocess/goprocess.go
Expand Up @@ -9,8 +9,6 @@ import (
"os"
"sync"

goversion "rsc.io/goversion/version"

"github.com/google/gops/internal"
ps "github.com/keybase/go-ps"
)
Expand Down Expand Up @@ -119,13 +117,11 @@ func isGo(pr ps.Process) (path, version string, agent, ok bool, err error) {
if err != nil {
return
}
var versionInfo goversion.Version
versionInfo, err = goversion.ReadExe(path)
version, err = goVersion(path)
if err != nil {
return
}
ok = true
version = versionInfo.Release
pidfile, err := internal.PIDFile(pr.Pid())
if err == nil {
_, err := os.Stat(pidfile)
Expand Down
18 changes: 18 additions & 0 deletions goprocess/goprocess_1.18.go
@@ -0,0 +1,18 @@
// Copyright 2022 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.18
// +build go1.18

package goprocess

import "debug/buildinfo"

func goVersion(path string) (string, error) {
info, err := buildinfo.ReadFile(path)
if err != nil {
return "", err
}
return info.GoVersion, nil
}
18 changes: 18 additions & 0 deletions goprocess/goprocess_lt1.18.go
@@ -0,0 +1,18 @@
// Copyright 2022 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.18
// +build !go1.18

package goprocess

import goversion "rsc.io/goversion/version"

func goVersion(path string) (string, error) {
versionInfo, err := goversion.ReadExe(path)
if err != nil {
return "", err
}
return versionInfo.Release, nil
}
File renamed without changes.