From c3fcd0117784ac05e35120ac0de6c960b400a31e Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Thu, 3 Mar 2022 18:21:37 -0800 Subject: go/build: recognize "unix" build tag The new "unix" build tag matches any Unix or Unix-like system. This is only recognized on go:build lines, not in file names. For #20322 Fixes #51572 Change-Id: I3a991f9e69353b25e259bc6462709cdcd83640fb Reviewed-on: https://go-review.googlesource.com/c/go/+/389934 Trust: Ian Lance Taylor Run-TryBot: Ian Lance Taylor Reviewed-by: Rob Pike TryBot-Result: Gopher Robot --- src/cmd/dist/build.go | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'src/cmd/dist') diff --git a/src/cmd/dist/build.go b/src/cmd/dist/build.go index ba09ce9a7b..4dfaf83ef7 100644 --- a/src/cmd/dist/build.go +++ b/src/cmd/dist/build.go @@ -976,12 +976,41 @@ func packagefile(pkg string) string { return pathf("%s/pkg/%s_%s/%s.a", goroot, goos, goarch, pkg) } +// unixOS is the set of GOOS values matched by the "unix" build tag. +// This is the same list as in go/build/syslist.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, +} + // matchtag reports whether the tag matches this build. func matchtag(tag string) bool { - return tag == "gc" || tag == goos || tag == goarch || tag == "cmd_go_bootstrap" || tag == "go1.1" || - (goos == "android" && tag == "linux") || - (goos == "illumos" && tag == "solaris") || - (goos == "ios" && tag == "darwin") + switch tag { + case "gc", "cmd_go_bootstrap", "go1.1": + return true + case "linux": + return goos == "linux" || goos == "android" + case "solaris": + return goos == "solaris" || goos == "illumos" + case "darwin": + return goos == "darwin" || goos == "ios" + case goos, goarch: + return true + case "unix": + return unixOS[goos] + default: + return false + } } // shouldbuild reports whether we should build this file. -- cgit v1.3