From dc8f87b7493e173d65d3587389cc41468ba16dc0 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 1 Jun 2021 12:22:12 +0200 Subject: [PATCH] runtime/internal/sys: generate //go:build lines in gengoos.go For #41184 Change-Id: If7a1c3980f47bc28d0a13fe497eaba6178c65c91 Reviewed-on: https://go-review.googlesource.com/c/go/+/323750 Trust: Tobias Klauser Run-TryBot: Tobias Klauser TryBot-Result: Go Bot Reviewed-by: Russ Cox --- src/runtime/internal/sys/gengoos.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/runtime/internal/sys/gengoos.go b/src/runtime/internal/sys/gengoos.go index 51f64a6e5c..ffe962f71d 100644 --- a/src/runtime/internal/sys/gengoos.go +++ b/src/runtime/internal/sys/gengoos.go @@ -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) -- 2.50.0