Skip to content

Commit c3fcd01

Browse files
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 <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> Reviewed-by: Rob Pike <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 32fdad1 commit c3fcd01

File tree

5 files changed

+62
-7
lines changed

5 files changed

+62
-7
lines changed

src/cmd/dist/build.go

+33-4
Original file line numberDiff line numberDiff line change
@@ -976,12 +976,41 @@ func packagefile(pkg string) string {
976976
return pathf("%s/pkg/%s_%s/%s.a", goroot, goos, goarch, pkg)
977977
}
978978

979+
// unixOS is the set of GOOS values matched by the "unix" build tag.
980+
// This is the same list as in go/build/syslist.go.
981+
var unixOS = map[string]bool{
982+
"aix": true,
983+
"android": true,
984+
"darwin": true,
985+
"dragonfly": true,
986+
"freebsd": true,
987+
"hurd": true,
988+
"illumos": true,
989+
"ios": true,
990+
"linux": true,
991+
"netbsd": true,
992+
"openbsd": true,
993+
"solaris": true,
994+
}
995+
979996
// matchtag reports whether the tag matches this build.
980997
func matchtag(tag string) bool {
981-
return tag == "gc" || tag == goos || tag == goarch || tag == "cmd_go_bootstrap" || tag == "go1.1" ||
982-
(goos == "android" && tag == "linux") ||
983-
(goos == "illumos" && tag == "solaris") ||
984-
(goos == "ios" && tag == "darwin")
998+
switch tag {
999+
case "gc", "cmd_go_bootstrap", "go1.1":
1000+
return true
1001+
case "linux":
1002+
return goos == "linux" || goos == "android"
1003+
case "solaris":
1004+
return goos == "solaris" || goos == "illumos"
1005+
case "darwin":
1006+
return goos == "darwin" || goos == "ios"
1007+
case goos, goarch:
1008+
return true
1009+
case "unix":
1010+
return unixOS[goos]
1011+
default:
1012+
return false
1013+
}
9851014
}
9861015

9871016
// shouldbuild reports whether we should build this file.

src/cmd/go/alldocs.go

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/go/internal/help/helpdoc.go

+1
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,7 @@ During a particular build, the following words are satisfied:
843843
GOOS environment variable.
844844
- the target architecture, as spelled by runtime.GOARCH, set with the
845845
GOARCH environment variable.
846+
- "unix", if GOOS is a Unix or Unix-like system.
846847
- the compiler being used, either "gc" or "gccgo"
847848
- "cgo", if the cgo command is supported (see CGO_ENABLED in
848849
'go help environment').

src/go/build/build.go

+3
Original file line numberDiff line numberDiff line change
@@ -1913,6 +1913,9 @@ func (ctxt *Context) matchTag(name string, allTags map[string]bool) bool {
19131913
if ctxt.GOOS == "ios" && name == "darwin" {
19141914
return true
19151915
}
1916+
if name == "unix" && unixOS[ctxt.GOOS] {
1917+
return true
1918+
}
19161919

19171920
// other tags
19181921
for _, tag := range ctxt.BuildTags {

src/go/build/syslist.go

+24-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
package build
66

7-
// Past, present, and future known GOOS and GOARCH values.
8-
// Do not remove from this list, as these are used for go/build filename matching.
9-
7+
// knownOS is the list of past, present, and future known GOOS values.
8+
// Do not remove from this list, as it is used for filename matching.
9+
// If you add an entry to this list, look at unixOS, below.
1010
var knownOS = map[string]bool{
1111
"aix": true,
1212
"android": true,
@@ -26,6 +26,27 @@ var knownOS = map[string]bool{
2626
"windows": true,
2727
"zos": true,
2828
}
29+
30+
// unixOS is the set of GOOS values matched by the "unix" build tag.
31+
// This is not used for filename matching.
32+
// This list also appears in cmd/dist/build.go.
33+
var unixOS = map[string]bool{
34+
"aix": true,
35+
"android": true,
36+
"darwin": true,
37+
"dragonfly": true,
38+
"freebsd": true,
39+
"hurd": true,
40+
"illumos": true,
41+
"ios": true,
42+
"linux": true,
43+
"netbsd": true,
44+
"openbsd": true,
45+
"solaris": true,
46+
}
47+
48+
// knownArch is the list of past, present, and future known GOARCH values.
49+
// Do not remove from this list, as it is used for filename matching.
2950
var knownArch = map[string]bool{
3051
"386": true,
3152
"amd64": true,

0 commit comments

Comments
 (0)