all: Add build constants for runtime.GOOS comparisons (#8442)

all: Add package runtimeos for runtime.GOOS comparisons

I grew tired of hand written string comparisons. This adds generated
constants for the GOOS values, and predefined Is$OS constants that can
be iffed on. In a couple of places I rewrote trivial switch:es to if:s,
and added Illumos where we checked for Solaris (because they are
effectively the same, and if we're going to target one of them that
would be Illumos...).
This commit is contained in:
Jakob Borg
2022-07-28 19:36:39 +02:00
committed by GitHub
parent f13d65262a
commit a3c724f2c3
51 changed files with 282 additions and 192 deletions

View File

@@ -12,9 +12,10 @@ package integration
import (
"log"
"os"
"runtime"
"syscall"
"time"
"github.com/syncthing/syncthing/lib/build"
)
func printUsage(name string, proc *os.ProcessState, total int64) {
@@ -22,7 +23,7 @@ func printUsage(name string, proc *os.ProcessState, total int64) {
mib := total / 1024 / 1024
log.Printf("%s: Utime: %s / MiB", name, time.Duration(rusage.Utime.Nano()/mib))
log.Printf("%s: Stime: %s / MiB", name, time.Duration(rusage.Stime.Nano()/mib))
if runtime.GOOS == "darwin" {
if build.IsDarwin {
// Darwin reports in bytes, Linux seems to report in KiB even
// though the manpage says otherwise.
rusage.Maxrss /= 1024

View File

@@ -25,6 +25,7 @@ import (
"time"
"unicode"
"github.com/syncthing/syncthing/lib/build"
"github.com/syncthing/syncthing/lib/rc"
"github.com/syncthing/syncthing/lib/sha256"
)
@@ -174,7 +175,7 @@ func alterFiles(dir string) error {
// Change capitalization
case r == 2 && comps > 3 && rand.Float64() < 0.2:
if runtime.GOOS == "darwin" || runtime.GOOS == "windows" {
if build.IsDarwin || build.IsWindows {
// Syncthing is currently broken for case-only renames on case-
// insensitive platforms.
// https://github.com/syncthing/syncthing/issues/1787