From f3822368dc42de0a9e48c3373a9b391fa49fb793 Mon Sep 17 00:00:00 2001 From: Connor Hindley Date: Wed, 19 Apr 2023 14:18:29 -0600 Subject: [PATCH 1/2] language/go: Handle `unix` build tag. Fixes #1465 --- language/go/fileinfo.go | 3 +++ rule/platform.go | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/language/go/fileinfo.go b/language/go/fileinfo.go index 990f5070f..cba1b945d 100644 --- a/language/go/fileinfo.go +++ b/language/go/fileinfo.go @@ -525,6 +525,9 @@ func matchesOS(os, value string) bool { if os == value { return true } + if value == "unix" { + return rule.UnixOS[os] + } for _, alias := range rule.OSAliases[os] { if alias == value { return true diff --git a/rule/platform.go b/rule/platform.go index 2d797672d..8ca7ca23b 100644 --- a/rule/platform.go +++ b/rule/platform.go @@ -102,6 +102,23 @@ var OSAliases = map[string][]string{ "ios": {"darwin"}, } +// UnixOS is the set of GOOS values matched by the "unix" build tag. +// This list is from go/src/cmd/dist/build.go. +var UnixOS = map[string]bool{ + "aix": true, + "android": true, + "darwin": true, + "dragonfly": true, + "freebsd": true, + "hurd": true, + "illumos": true, + "ios": true, + "linux": true, + "netbsd": true, + "openbsd": true, + "solaris": true, +} + var ( // KnownOSs is the sorted list of operating systems that Go supports. KnownOSs []string @@ -133,6 +150,8 @@ func init() { KnownOSArchs[p.OS] = append(KnownOSArchs[p.OS], p.Arch) KnownArchOSs[p.Arch] = append(KnownArchOSs[p.Arch], p.OS) } + // unix is a pseudo os + KnownOSSet["unix"] = true KnownOSs = make([]string, 0, len(KnownOSSet)) KnownArchs = make([]string, 0, len(KnownArchSet)) for os := range KnownOSSet { From b7f79b3bc976e866019b3d3fa3ae8a9bfd709257 Mon Sep 17 00:00:00 2001 From: Connor Hindley Date: Wed, 19 Apr 2023 15:02:15 -0600 Subject: [PATCH 2/2] take out unix as a known os --- language/go/fileinfo.go | 3 +-- rule/platform.go | 2 -- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/language/go/fileinfo.go b/language/go/fileinfo.go index cba1b945d..8e6fe266b 100644 --- a/language/go/fileinfo.go +++ b/language/go/fileinfo.go @@ -559,8 +559,7 @@ func checkConstraints(c *config.Config, os, arch, osSuffix, archSuffix string, t if isIgnoredTag(tag) { return true } - - if _, ok := rule.KnownOSSet[tag]; ok { + if _, ok := rule.KnownOSSet[tag]; ok || tag == "unix" { if os == "" { return false } diff --git a/rule/platform.go b/rule/platform.go index 8ca7ca23b..fffac4799 100644 --- a/rule/platform.go +++ b/rule/platform.go @@ -150,8 +150,6 @@ func init() { KnownOSArchs[p.OS] = append(KnownOSArchs[p.OS], p.Arch) KnownArchOSs[p.Arch] = append(KnownArchOSs[p.Arch], p.OS) } - // unix is a pseudo os - KnownOSSet["unix"] = true KnownOSs = make([]string, 0, len(KnownOSSet)) KnownArchs = make([]string, 0, len(KnownArchSet)) for os := range KnownOSSet {