]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/internal/sys: generate //go:build lines in gengoos.go
authorTobias Klauser <tklauser@distanz.ch>
Tue, 1 Jun 2021 10:22:12 +0000 (12:22 +0200)
committerTobias Klauser <tobias.klauser@gmail.com>
Wed, 2 Jun 2021 08:17:59 +0000 (08:17 +0000)
For #41184

Change-Id: If7a1c3980f47bc28d0a13fe497eaba6178c65c91
Reviewed-on: https://go-review.googlesource.com/c/go/+/323750
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
src/runtime/internal/sys/gengoos.go

index 51f64a6e5c667976b9c6f81a757d0e8218980687..ffe962f71df61c89cba3261d7e017c5de4e432b2 100644 (file)
@@ -48,18 +48,21 @@ func main() {
                if target == "nacl" {
                        continue
                }
-               var buf bytes.Buffer
-               fmt.Fprintf(&buf, "// Code generated by gengoos.go using 'go generate'. DO NOT EDIT.\n\n")
+               var tags []string
                if target == "linux" {
-                       fmt.Fprintf(&buf, "// +build !android\n") // must explicitly exclude android for linux
+                       tags = append(tags, "!android") // must explicitly exclude android for linux
                }
                if target == "solaris" {
-                       fmt.Fprintf(&buf, "// +build !illumos\n") // must explicitly exclude illumos for solaris
+                       tags = append(tags, "!illumos") // must explicitly exclude illumos for solaris
                }
                if target == "darwin" {
-                       fmt.Fprintf(&buf, "// +build !ios\n") // must explicitly exclude ios for darwin
+                       tags = append(tags, "!ios") // must explicitly exclude ios for darwin
                }
-               fmt.Fprintf(&buf, "// +build %s\n\n", target) // must explicitly include target for bootstrapping purposes
+               tags = append(tags, target) // must explicitly include target for bootstrapping purposes
+               var buf bytes.Buffer
+               fmt.Fprintf(&buf, "// Code generated by gengoos.go using 'go generate'. DO NOT EDIT.\n\n")
+               fmt.Fprintf(&buf, "//go:build %s\n", strings.Join(tags, " && "))
+               fmt.Fprintf(&buf, "// +build %s\n\n", strings.Join(tags, ","))
                fmt.Fprintf(&buf, "package sys\n\n")
                fmt.Fprintf(&buf, "const GOOS = `%s`\n\n", target)
                for _, goos := range gooses {
@@ -81,6 +84,7 @@ func main() {
                }
                var buf bytes.Buffer
                fmt.Fprintf(&buf, "// Code generated by gengoos.go using 'go generate'. DO NOT EDIT.\n\n")
+               fmt.Fprintf(&buf, "//go:build %s\n", target)
                fmt.Fprintf(&buf, "// +build %s\n\n", target) // must explicitly include target for bootstrapping purposes
                fmt.Fprintf(&buf, "package sys\n\n")
                fmt.Fprintf(&buf, "const GOARCH = `%s`\n\n", target)