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:
@@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user