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>
This commit is contained in:
Tobias Klauser
2021-03-08 11:20:37 +01:00
committed by Tobias Klauser
parent 94ec62e081
commit 68d13333fa
12 changed files with 75 additions and 28 deletions

View File

@@ -598,6 +598,7 @@ func generatePtracePair(arch1, arch2, archName string) error {
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")

View File

@@ -25,8 +25,13 @@ func cmdLine() string {
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 @@ func main() {
}
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

View File

@@ -26,6 +26,7 @@ func writeASMFile(in string, fileName string, buildTags string) {
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")

View File

@@ -627,6 +627,7 @@ echo '#include <signal.h>' | $CC -x c - -E -dM $ccflags |
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

View File

@@ -466,6 +466,7 @@ func merge(mergedFile string, archFiles ...string) error {
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)

View File

@@ -127,7 +127,8 @@ func main() {
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))

View File

@@ -50,8 +50,13 @@ func cmdLine() string {
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 @@ func main() {
}
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

View File

@@ -43,8 +43,13 @@ func cmdLine() string {
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 @@ func main() {
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

View File

@@ -84,8 +84,13 @@ func cmdLine() string {
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 @@ func main() {
// 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 @@ func main() {
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 @@ func main() {
// 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 @@ func main() {
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 @@ import (
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 @@ func syscall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err
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

View File

@@ -44,8 +44,13 @@ func cmdLine() string {
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 @@ func main() {
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

View File

@@ -32,8 +32,13 @@ func cmdLine() string {
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 @@ func main() {
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

View File

@@ -30,8 +30,13 @@ func cmdLine() string {
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 @@ func main() {
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