]> Cypherpunks repositories - gostls13.git/commitdiff
go/build: recognize "unix" build tag
authorIan Lance Taylor <iant@golang.org>
Fri, 4 Mar 2022 02:21:37 +0000 (18:21 -0800)
committerIan Lance Taylor <iant@golang.org>
Mon, 28 Mar 2022 22:28:20 +0000 (22:28 +0000)
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 <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/dist/build.go
src/cmd/go/alldocs.go
src/cmd/go/internal/help/helpdoc.go
src/go/build/build.go
src/go/build/syslist.go

index ba09ce9a7b8d721df51ced2e929477fa84d327c0..4dfaf83ef7f99bd6c9bf18cb43c3aa642c7e4e06 100644 (file)
@@ -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.
index 8410731a28ae2827578925c05e4adf8ce9dda60b..f9d78b59e32f54267c912f13abd2ab675ce6d503 100644 (file)
 //       GOOS environment variable.
 //     - the target architecture, as spelled by runtime.GOARCH, set with the
 //       GOARCH environment variable.
+//     - "unix", if GOOS is a Unix or Unix-like system.
 //     - the compiler being used, either "gc" or "gccgo"
 //     - "cgo", if the cgo command is supported (see CGO_ENABLED in
 //       'go help environment').
index 28ddaac8f172f62a4fe8368524c57c4946bb1d7b..36bc4f28b7ce1c413f3231c21f48398e21985d15 100644 (file)
@@ -843,6 +843,7 @@ During a particular build, the following words are satisfied:
          GOOS environment variable.
        - the target architecture, as spelled by runtime.GOARCH, set with the
          GOARCH environment variable.
+       - "unix", if GOOS is a Unix or Unix-like system.
        - the compiler being used, either "gc" or "gccgo"
        - "cgo", if the cgo command is supported (see CGO_ENABLED in
          'go help environment').
index cacdbef4eee2557ed4f0ad63a7e08c2fe1130a78..df505312ce32a66f353977858eb93e096f0709e4 100644 (file)
@@ -1913,6 +1913,9 @@ func (ctxt *Context) matchTag(name string, allTags map[string]bool) bool {
        if ctxt.GOOS == "ios" && name == "darwin" {
                return true
        }
+       if name == "unix" && unixOS[ctxt.GOOS] {
+               return true
+       }
 
        // other tags
        for _, tag := range ctxt.BuildTags {
index 6b62b63042bb0bdcae68b73b74a23da7b14d8c13..ea67662c3e2c97dc172408049a49c6466c75e60c 100644 (file)
@@ -4,9 +4,9 @@
 
 package build
 
-// Past, present, and future known GOOS and GOARCH values.
-// Do not remove from this list, as these are used for go/build filename matching.
-
+// knownOS is the list of past, present, and future known GOOS values.
+// Do not remove from this list, as it is used for filename matching.
+// If you add an entry to this list, look at unixOS, below.
 var knownOS = map[string]bool{
        "aix":       true,
        "android":   true,
@@ -26,6 +26,27 @@ var knownOS = map[string]bool{
        "windows":   true,
        "zos":       true,
 }
+
+// unixOS is the set of GOOS values matched by the "unix" build tag.
+// This is not used for filename matching.
+// This list also appears in 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,
+}
+
+// knownArch is the list of past, present, and future known GOARCH values.
+// Do not remove from this list, as it is used for filename matching.
 var knownArch = map[string]bool{
        "386":         true,
        "amd64":       true,