diff --git a/internal/platform/platform.go b/internal/platform/platform.go index 39d6fe2..964e122 100644 --- a/internal/platform/platform.go +++ b/internal/platform/platform.go @@ -24,28 +24,20 @@ import "runtime" // has been disabled. In such case, the code will return "ios" when // using arm{,64} and "macos" when using x86{,_64}. func Name() string { - if name := cgoname(); name != "unknown" { - return name - } - return puregoname(runtime.GOOS, runtime.GOARCH) + return name(runtime.GOOS) } -func puregoname(goos, goarch string) string { +// name is a utility function for implementing Name. +func name(goos string) string { + // Note: since go1.16 we have the ios port, so the ambiguity + // between ios and darwin is now gone. + // + // See https://golang.org/doc/go1.16#darwin switch goos { - case "android", "linux", "windows": + case "android", "linux", "windows", "ios": return goos case "darwin": - return detectDarwin(goarch) - } - return "unknown" -} - -func detectDarwin(goarch string) string { - switch goarch { - case "386", "amd64": return "macos" - case "arm", "arm64": - return "ios" } return "unknown" } diff --git a/internal/platform/platform_cgo.go b/internal/platform/platform_cgo.go deleted file mode 100644 index 192293a..0000000 --- a/internal/platform/platform_cgo.go +++ /dev/null @@ -1,31 +0,0 @@ -// +build cgo - -package platform - -// -// /* Guess the platform in which we are. -// -// See: -// */ -// -//#if defined __ANDROID__ -//# define OONI_PLATFORM "android" -//#elif defined __linux__ -//# define OONI_PLATFORM "linux" -//#elif defined _WIN32 -//# define OONI_PLATFORM "windows" -//#elif defined __APPLE__ -//# include -//# if TARGET_OS_IPHONE -//# define OONI_PLATFORM "ios" -//# else -//# define OONI_PLATFORM "macos" -//# endif -//#else -//# define OONI_PLATFORM "unknown" -//#endif -import "C" - -func cgoname() string { - return C.OONI_PLATFORM -} diff --git a/internal/platform/platform_otherwise.go b/internal/platform/platform_otherwise.go deleted file mode 100644 index b7a7b25..0000000 --- a/internal/platform/platform_otherwise.go +++ /dev/null @@ -1,7 +0,0 @@ -// +build !cgo - -package platform - -func cgoname() string { - return "unknown" -} diff --git a/internal/platform/platform_test.go b/internal/platform/platform_test.go index e759070..674849d 100644 --- a/internal/platform/platform_test.go +++ b/internal/platform/platform_test.go @@ -16,51 +16,32 @@ func TestGood(t *testing.T) { } } -func TestPuregoname(t *testing.T) { +func TestName(t *testing.T) { var runtimevariables = []struct { expected string - goarch string goos string }{{ expected: "android", - goarch: "*", goos: "android", }, { expected: "ios", - goarch: "arm64", - goos: "darwin", - }, { - expected: "ios", - goarch: "arm", - goos: "darwin", + goos: "ios", }, { expected: "linux", - goarch: "*", goos: "linux", }, { expected: "macos", - goarch: "amd64", - goos: "darwin", - }, { - expected: "macos", - goarch: "386", goos: "darwin", }, { expected: "unknown", - goarch: "*", goos: "solaris", - }, { - expected: "unknown", - goarch: "mips", - goos: "darwin", }, { expected: "windows", - goarch: "*", goos: "windows", }} for _, v := range runtimevariables { - t.Run(fmt.Sprintf("with %s/%s", v.goos, v.goarch), func(t *testing.T) { - if puregoname(v.goos, v.goarch) != v.expected { + t.Run(fmt.Sprintf("with %s", v.goos), func(t *testing.T) { + if name(v.goos) != v.expected { t.Fatal("unexpected results") } })