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
+6 -6
View File
@@ -15,6 +15,8 @@ import (
"runtime"
"strconv"
"strings"
"github.com/syncthing/syncthing/lib/build"
)
type Release struct {
@@ -236,15 +238,13 @@ func releaseNames(tag string) []string {
// standard, containing both the architecture/OS and the tag name we
// expect. This protects against malformed release data potentially
// tricking us into doing a downgrade.
switch runtime.GOOS {
case "darwin":
if build.IsDarwin {
return []string{
fmt.Sprintf("syncthing-macos-%s-%s.", runtime.GOARCH, tag),
fmt.Sprintf("syncthing-macosx-%s-%s.", runtime.GOARCH, tag),
}
default:
return []string{
fmt.Sprintf("syncthing-%s-%s-%s.", runtime.GOOS, runtime.GOARCH, tag),
}
}
return []string{
fmt.Sprintf("syncthing-%s-%s-%s.", runtime.GOOS, runtime.GOARCH, tag),
}
}
+3 -1
View File
@@ -14,6 +14,8 @@ import (
"runtime"
"strings"
"testing"
"github.com/syncthing/syncthing/lib/build"
)
var versions = []struct {
@@ -120,7 +122,7 @@ func TestSelectedRelease(t *testing.T) {
}
func TestSelectedReleaseMacOS(t *testing.T) {
if runtime.GOOS != "darwin" {
if !build.IsDarwin {
t.Skip("macOS only")
}