Skip to content

Commit dbbe4cc

Browse files
committed
cmd/dist: log OS version when testing
As a follow-up to https://golang.org/cl/371474, add the OS version to the metadata printed for each test. This is a redo of CL 371475. This version updates go.mod and conforms to the changes made in the parent commit. Fixes #50146. Change-Id: Iba5541cc8dd2c85c1fa3a215e30c8c3f9b6aaaab Reviewed-on: https://go-review.googlesource.com/c/go/+/378590 Reviewed-by: Austin Clements <[email protected]> Trust: Michael Pratt <[email protected]> Run-TryBot: Michael Pratt <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 67f1a43 commit dbbe4cc

File tree

7 files changed

+112
-1
lines changed

7 files changed

+112
-1
lines changed

src/cmd/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ require (
77
golang.org/x/arch v0.0.0-20210923205945-b76863e36670
88
golang.org/x/mod v0.6.0-dev.0.20211102181907-3a5865c02020
99
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
10+
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d
1011
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
1112
golang.org/x/tools v0.1.9-0.20220124164225-97de9ec46646
1213
)
1314

1415
require (
1516
github.com/ianlancetaylor/demangle v0.0.0-20210905161508-09a460cdf81d // indirect
1617
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 // indirect
17-
golang.org/x/sys v0.0.0-20211205182925-97ca703d548d // indirect
1818
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
1919
)

src/cmd/internal/metadata/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package main
99

1010
import (
11+
"cmd/internal/osinfo"
1112
"fmt"
1213
"internal/sysinfo"
1314
"runtime"
@@ -16,4 +17,11 @@ import (
1617
func main() {
1718
fmt.Printf("# GOARCH: %s\n", runtime.GOARCH)
1819
fmt.Printf("# CPU: %s\n", sysinfo.CPU.Name())
20+
21+
fmt.Printf("# GOOS: %s\n", runtime.GOOS)
22+
ver, err := osinfo.Version()
23+
if err != nil {
24+
ver = fmt.Sprintf("UNKNOWN: error determining OS version: %v", err)
25+
}
26+
fmt.Printf("# OS Version: %s\n", ver)
1927
}

src/cmd/internal/osinfo/doc.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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+
// Package osinfo provides OS metadata.
6+
package osinfo

src/cmd/internal/osinfo/os_js.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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 js
6+
7+
package osinfo
8+
9+
import (
10+
"fmt"
11+
)
12+
13+
// Version returns the OS version name/number.
14+
func Version() (string, error) {
15+
// Version detection on wasm varies depending on the underlying runtime
16+
// (browser, node, etc), nor is there a standard via something like
17+
// WASI (see https://go.dev/issue/31105). We could attempt multiple
18+
// combinations, but for now we leave this unimplemented for
19+
// simplicity.
20+
return "", fmt.Errorf("unimplemented")
21+
}

src/cmd/internal/osinfo/os_plan9.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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 plan9
6+
7+
package osinfo
8+
9+
import (
10+
"os"
11+
)
12+
13+
// Version returns the OS version name/number.
14+
func Version() (string, error) {
15+
b, err := os.ReadFile("/dev/osversion")
16+
if err != nil {
17+
return "", err
18+
}
19+
20+
return string(b), nil
21+
}

src/cmd/internal/osinfo/os_unix.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
6+
7+
package osinfo
8+
9+
import (
10+
"bytes"
11+
12+
"golang.org/x/sys/unix"
13+
)
14+
15+
func utsString(b []byte) string {
16+
i := bytes.IndexByte(b, 0)
17+
if i == -1 {
18+
return string(b)
19+
}
20+
return string(b[:i])
21+
}
22+
23+
// Version returns the OS version name/number.
24+
func Version() (string, error) {
25+
var uts unix.Utsname
26+
if err := unix.Uname(&uts); err != nil {
27+
return "", err
28+
}
29+
30+
sysname := utsString(uts.Sysname[:])
31+
release := utsString(uts.Release[:])
32+
version := utsString(uts.Version[:])
33+
machine := utsString(uts.Machine[:])
34+
35+
return sysname + " " + release + " " + version + " " + machine, nil
36+
}

src/cmd/internal/osinfo/os_windows.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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 windows
6+
7+
package osinfo
8+
9+
import (
10+
"fmt"
11+
12+
"golang.org/x/sys/windows"
13+
)
14+
15+
// Version returns the OS version name/number.
16+
func Version() (string, error) {
17+
major, minor, patch := windows.RtlGetNtVersionNumbers()
18+
return fmt.Sprintf("%d.%d.%d", major, minor, patch), nil
19+
}

0 commit comments

Comments
 (0)