unix: add //go:build lines when generating files

The //+go:build lines were added by running Go 1.17 gofmt in CL 294490.
Make sure to retain them when re-generating files in this package.

For golang/go#41184.

Change-Id: Ia418b8c0eb4291a0db3f4bb97685bde78d0ff016
Reviewed-on: https://go-review.googlesource.com/c/sys/+/296889
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
diff --git a/unix/linux/mkall.go b/unix/linux/mkall.go
index f1686ac..4e82c01 100644
--- a/unix/linux/mkall.go
+++ b/unix/linux/mkall.go
@@ -598,6 +598,7 @@
 	buf := bufio.NewWriter(f)
 	fmt.Fprintf(buf, "// Code generated by linux/mkall.go generatePtracePair(%q, %q). DO NOT EDIT.\n", arch1, arch2)
 	fmt.Fprintf(buf, "\n")
+	fmt.Fprintf(buf, "//go:build linux && (%s || %s)\n", arch1, arch2)
 	fmt.Fprintf(buf, "// +build linux\n")
 	fmt.Fprintf(buf, "// +build %s %s\n", arch1, arch2)
 	fmt.Fprintf(buf, "\n")
diff --git a/unix/linux/mksysnum.go b/unix/linux/mksysnum.go
index e1ad597..da9e94f 100644
--- a/unix/linux/mksysnum.go
+++ b/unix/linux/mksysnum.go
@@ -25,8 +25,13 @@
 	return "go run linux/mksysnum.go " + strings.Join(os.Args[1:], " ")
 }
 
-// buildTags returns build tags
-func buildTags() string {
+// goBuildTags returns build tags in the go:build format.
+func goBuildTags() string {
+	return fmt.Sprintf("%s && %s", goarch, goos)
+}
+
+// plusBuildTags returns build tags in the +build format.
+func plusBuildTags() string {
 	return fmt.Sprintf("%s,%s", goarch, goos)
 }
 
@@ -129,12 +134,13 @@
 	}
 	err = s.Err()
 	checkErr(err)
-	fmt.Printf(template, cmdLine(), buildTags(), text)
+	fmt.Printf(template, cmdLine(), goBuildTags(), plusBuildTags(), text)
 }
 
 const template = `// %s
 // Code generated by the command above; see README.md. DO NOT EDIT.
 
+//go:build %s
 // +build %s
 
 package unix
diff --git a/unix/mkasm_darwin.go b/unix/mkasm_darwin.go
index 08c976f..62b6b8b 100644
--- a/unix/mkasm_darwin.go
+++ b/unix/mkasm_darwin.go
@@ -26,6 +26,7 @@
 	fmt.Fprintf(&out, "// go run mkasm_darwin.go %s\n", strings.Join(os.Args[1:], " "))
 	fmt.Fprintf(&out, "// Code generated by the command above; DO NOT EDIT.\n")
 	fmt.Fprintf(&out, "\n")
+	fmt.Fprintf(&out, "//go:build %s\n", buildTags)
 	fmt.Fprintf(&out, "// +build %s\n", buildTags)
 	fmt.Fprintf(&out, "\n")
 	fmt.Fprintf(&out, "#include \"textflag.h\"\n")
diff --git a/unix/mkerrors.sh b/unix/mkerrors.sh
index 60ffa48..87f9d1e 100755
--- a/unix/mkerrors.sh
+++ b/unix/mkerrors.sh
@@ -627,6 +627,7 @@
 echo '// mkerrors.sh' "$@"
 echo '// Code generated by the command above; see README.md. DO NOT EDIT.'
 echo
+echo "//go:build ${GOARCH} && ${GOOS}"
 echo "// +build ${GOARCH},${GOOS}"
 echo
 go tool cgo -godefs -- "$@" _const.go >_error.out
diff --git a/unix/mkmerge.go b/unix/mkmerge.go
index 054a51d..9bfd150 100644
--- a/unix/mkmerge.go
+++ b/unix/mkmerge.go
@@ -466,6 +466,7 @@
 	buf := bufio.NewWriter(f)
 	fmt.Fprintln(buf, "// Code generated by mkmerge.go; DO NOT EDIT.")
 	fmt.Fprintln(buf)
+	fmt.Fprintf(buf, "//go:build %s\n", goos)
 	fmt.Fprintf(buf, "// +build %s\n", goos)
 	fmt.Fprintln(buf)
 	buf.Write(mergedSrc)
diff --git a/unix/mkpost.go b/unix/mkpost.go
index edf0f09..c6b8951 100644
--- a/unix/mkpost.go
+++ b/unix/mkpost.go
@@ -127,7 +127,8 @@
 	replacement := fmt.Sprintf(`$1 | go run mkpost.go
 // Code generated by the command above; see README.md. DO NOT EDIT.
 
-// +build %s,%s`, goarch, goos)
+//go:build %s && %s
+// +build %s,%s`, goarch, goos, goarch, goos)
 	cgoCommandRegex := regexp.MustCompile(`(cgo -godefs .*)`)
 	b = cgoCommandRegex.ReplaceAll(b, []byte(replacement))
 
diff --git a/unix/mksyscall.go b/unix/mksyscall.go
index 8dd88ea..60f55b0 100644
--- a/unix/mksyscall.go
+++ b/unix/mksyscall.go
@@ -50,8 +50,13 @@
 	return "go run mksyscall.go " + strings.Join(os.Args[1:], " ")
 }
 
-// buildTags returns build tags
-func buildTags() string {
+// goBuildTags returns build tags in the go:build format.
+func goBuildTags() string {
+	return strings.ReplaceAll(*tags, ",", " && ")
+}
+
+// plusBuildTags returns build tags in the +build format.
+func plusBuildTags() string {
 	return *tags
 }
 
@@ -372,12 +377,13 @@
 		}
 		file.Close()
 	}
-	fmt.Printf(srcTemplate, cmdLine(), buildTags(), text)
+	fmt.Printf(srcTemplate, cmdLine(), goBuildTags(), plusBuildTags(), text)
 }
 
 const srcTemplate = `// %s
 // Code generated by the command above; see README.md. DO NOT EDIT.
 
+//go:build %s
 // +build %s
 
 package unix
diff --git a/unix/mksyscall_aix_ppc.go b/unix/mksyscall_aix_ppc.go
index 4b4c6c4..0143137 100644
--- a/unix/mksyscall_aix_ppc.go
+++ b/unix/mksyscall_aix_ppc.go
@@ -43,8 +43,13 @@
 	return "go run mksyscall_aix_ppc.go " + strings.Join(os.Args[1:], " ")
 }
 
-// buildTags returns build tags
-func buildTags() string {
+// goBuildTags returns build tags in the go:build format.
+func goBuildTags() string {
+	return strings.ReplaceAll(*tags, ",", " && ")
+}
+
+// plusBuildTags returns build tags in the +build format.
+func plusBuildTags() string {
 	return *tags
 }
 
@@ -389,12 +394,13 @@
 		imp = "import \"golang.org/x/sys/unix\"\n"
 
 	}
-	fmt.Printf(srcTemplate, cmdLine(), buildTags(), pack, cExtern, imp, text)
+	fmt.Printf(srcTemplate, cmdLine(), goBuildTags(), plusBuildTags(), pack, cExtern, imp, text)
 }
 
 const srcTemplate = `// %s
 // Code generated by the command above; see README.md. DO NOT EDIT.
 
+//go:build %s
 // +build %s
 
 package %s
diff --git a/unix/mksyscall_aix_ppc64.go b/unix/mksyscall_aix_ppc64.go
index 8ff7317..bfadfd6 100644
--- a/unix/mksyscall_aix_ppc64.go
+++ b/unix/mksyscall_aix_ppc64.go
@@ -84,8 +84,13 @@
 	return "go run mksyscall_aix_ppc64.go " + strings.Join(os.Args[1:], " ")
 }
 
-// buildTags returns build tags
-func buildTags() string {
+// goBuildTags returns build tags in the go:build format.
+func goBuildTags() string {
+	return strings.ReplaceAll(*tags, ",", " && ")
+}
+
+// plusBuildTags returns build tags in the +build format.
+func plusBuildTags() string {
 	return *tags
 }
 
@@ -521,7 +526,7 @@
 
 	// Print zsyscall_aix_ppc64.go
 	err := ioutil.WriteFile("zsyscall_aix_ppc64.go",
-		[]byte(fmt.Sprintf(srcTemplate1, cmdLine(), buildTags(), pack, imp, textcommon)),
+		[]byte(fmt.Sprintf(srcTemplate1, cmdLine(), goBuildTags(), plusBuildTags(), pack, imp, textcommon)),
 		0644)
 	if err != nil {
 		fmt.Fprintf(os.Stderr, err.Error())
@@ -532,7 +537,7 @@
 	vardecls := "\t" + strings.Join(vars, ",\n\t")
 	vardecls += " syscallFunc"
 	err = ioutil.WriteFile("zsyscall_aix_ppc64_gc.go",
-		[]byte(fmt.Sprintf(srcTemplate2, cmdLine(), buildTags(), pack, imp, dynimports, linknames, vardecls, textgc)),
+		[]byte(fmt.Sprintf(srcTemplate2, cmdLine(), goBuildTags(), plusBuildTags(), pack, imp, dynimports, linknames, vardecls, textgc)),
 		0644)
 	if err != nil {
 		fmt.Fprintf(os.Stderr, err.Error())
@@ -541,7 +546,7 @@
 
 	// Print zsyscall_aix_ppc64_gccgo.go
 	err = ioutil.WriteFile("zsyscall_aix_ppc64_gccgo.go",
-		[]byte(fmt.Sprintf(srcTemplate3, cmdLine(), buildTags(), pack, cExtern, imp, textgccgo)),
+		[]byte(fmt.Sprintf(srcTemplate3, cmdLine(), goBuildTags(), plusBuildTags(), pack, cExtern, imp, textgccgo)),
 		0644)
 	if err != nil {
 		fmt.Fprintf(os.Stderr, err.Error())
@@ -552,6 +557,7 @@
 const srcTemplate1 = `// %s
 // Code generated by the command above; see README.md. DO NOT EDIT.
 
+//go:build %s
 // +build %s
 
 package %s
@@ -568,8 +574,8 @@
 const srcTemplate2 = `// %s
 // Code generated by the command above; see README.md. DO NOT EDIT.
 
-// +build %s
-// +build gc
+//go:build %s && gc
+// +build %s,gc
 
 package %s
 
@@ -594,8 +600,8 @@
 const srcTemplate3 = `// %s
 // Code generated by the command above; see README.md. DO NOT EDIT.
 
-// +build %s
-// +build gccgo
+//go:build %s && gccgo
+// +build %s,gccgo
 
 package %s
 
diff --git a/unix/mksyscall_solaris.go b/unix/mksyscall_solaris.go
index 746dbef..d5634b1 100644
--- a/unix/mksyscall_solaris.go
+++ b/unix/mksyscall_solaris.go
@@ -44,8 +44,13 @@
 	return "go run mksyscall_solaris.go " + strings.Join(os.Args[1:], " ")
 }
 
-// buildTags returns build tags
-func buildTags() string {
+// goBuildTags returns build tags in the go:build format.
+func goBuildTags() string {
+	return strings.ReplaceAll(*tags, ",", " && ")
+}
+
+// plusBuildTags returns build tags in the +build format.
+func plusBuildTags() string {
 	return *tags
 }
 
@@ -315,12 +320,13 @@
 
 	vardecls := "\t" + strings.Join(vars, ",\n\t")
 	vardecls += " syscallFunc"
-	fmt.Printf(srcTemplate, cmdLine(), buildTags(), pack, syscallimp, imp, dynimports, linknames, vardecls, text)
+	fmt.Printf(srcTemplate, cmdLine(), goBuildTags(), plusBuildTags(), pack, syscallimp, imp, dynimports, linknames, vardecls, text)
 }
 
 const srcTemplate = `// %s
 // Code generated by the command above; see README.md. DO NOT EDIT.
 
+//go:build %s
 // +build %s
 
 package %s
diff --git a/unix/mksysctl_openbsd.go b/unix/mksysctl_openbsd.go
index a147c77..3fde87e 100644
--- a/unix/mksysctl_openbsd.go
+++ b/unix/mksysctl_openbsd.go
@@ -32,8 +32,13 @@
 	return "go run mksysctl_openbsd.go " + strings.Join(os.Args[1:], " ")
 }
 
-// buildTags returns build tags.
-func buildTags() string {
+// goBuildTags returns build tags in the go:build format.
+func goBuildTags() string {
+	return fmt.Sprintf("%s && %s", goarch, goos)
+}
+
+// plusBuildTags returns build tags in the +build format.
+func plusBuildTags() string {
 	return fmt.Sprintf("%s,%s", goarch, goos)
 }
 
@@ -331,12 +336,13 @@
 	sort.Strings(sysCtl)
 	text := strings.Join(sysCtl, "")
 
-	fmt.Printf(srcTemplate, cmdLine(), buildTags(), text)
+	fmt.Printf(srcTemplate, cmdLine(), goBuildTags(), plusBuildTags(), text)
 }
 
 const srcTemplate = `// %s
 // Code generated by the command above; DO NOT EDIT.
 
+//go:build %s
 // +build %s
 
 package unix
diff --git a/unix/mksysnum.go b/unix/mksysnum.go
index 8478df5..812635f 100644
--- a/unix/mksysnum.go
+++ b/unix/mksysnum.go
@@ -30,8 +30,13 @@
 	return "go run mksysnum.go " + strings.Join(os.Args[1:], " ")
 }
 
-// buildTags returns build tags
-func buildTags() string {
+// goBuildTags returns build tags in the go:build format.
+func goBuildTags() string {
+	return fmt.Sprintf("%s && %s", goarch, goos)
+}
+
+// plusBuildTags returns build tags in the +build format.
+func plusBuildTags() string {
 	return fmt.Sprintf("%s,%s", goarch, goos)
 }
 
@@ -170,12 +175,13 @@
 	err := s.Err()
 	checkErr(err)
 
-	fmt.Printf(template, cmdLine(), buildTags(), text)
+	fmt.Printf(template, cmdLine(), goBuildTags(), plusBuildTags(), text)
 }
 
 const template = `// %s
 // Code generated by the command above; see README.md. DO NOT EDIT.
 
+//go:build %s
 // +build %s
 
 package unix