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
+2 -2
View File
@@ -13,12 +13,12 @@ import (
"fmt"
"io"
"path/filepath"
"runtime"
"strings"
"time"
"github.com/gobwas/glob"
"github.com/syncthing/syncthing/lib/build"
"github.com/syncthing/syncthing/lib/fs"
"github.com/syncthing/syncthing/lib/osutil"
"github.com/syncthing/syncthing/lib/sha256"
@@ -35,7 +35,7 @@ const (
var defaultResult Result = resultInclude
func init() {
if runtime.GOOS == "darwin" || runtime.GOOS == "windows" {
if build.IsDarwin || build.IsWindows {
defaultResult |= resultFoldCase
}
}
+6 -7
View File
@@ -12,11 +12,11 @@ import (
"io"
"os"
"path/filepath"
"runtime"
"strings"
"testing"
"time"
"github.com/syncthing/syncthing/lib/build"
"github.com/syncthing/syncthing/lib/fs"
"github.com/syncthing/syncthing/lib/osutil"
)
@@ -210,10 +210,9 @@ func TestCaseSensitivity(t *testing.T) {
match := []string{"test"}
dontMatch := []string{"foo"}
switch runtime.GOOS {
case "darwin", "windows":
if build.IsDarwin || build.IsWindows {
match = append(match, "TEST", "Test", "tESt")
default:
} else {
dontMatch = append(dontMatch, "TEST", "Test", "tESt")
}
@@ -618,7 +617,7 @@ func TestHashOfEmpty(t *testing.T) {
func TestWindowsPatterns(t *testing.T) {
// We should accept patterns as both a/b and a\b and match that against
// both kinds of slash as well.
if runtime.GOOS != "windows" {
if !build.IsWindows {
t.Skip("Windows specific test")
return
}
@@ -643,7 +642,7 @@ func TestWindowsPatterns(t *testing.T) {
func TestAutomaticCaseInsensitivity(t *testing.T) {
// We should do case insensitive matching by default on some platforms.
if runtime.GOOS != "windows" && runtime.GOOS != "darwin" {
if !build.IsWindows && !build.IsDarwin {
t.Skip("Windows/Mac specific test")
return
}
@@ -1205,7 +1204,7 @@ func TestEmptyPatterns(t *testing.T) {
}
func TestWindowsLineEndings(t *testing.T) {
if runtime.GOOS != "windows" {
if !build.IsWindows {
t.Skip("Windows specific")
}