diff --git a/unix/linux/mkall.go b/unix/linux/mkall.go index f1686ac4..4e82c01f 100644 --- a/unix/linux/mkall.go +++ b/unix/linux/mkall.go @@ -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") diff --git a/unix/linux/mksysnum.go b/unix/linux/mksysnum.go index e1ad597d..da9e94f5 100644 --- a/unix/linux/mksysnum.go +++ b/unix/linux/mksysnum.go @@ -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 diff --git a/unix/mkasm_darwin.go b/unix/mkasm_darwin.go index 08c976f2..62b6b8b8 100644 --- a/unix/mkasm_darwin.go +++ b/unix/mkasm_darwin.go @@ -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") diff --git a/unix/mkerrors.sh b/unix/mkerrors.sh index 60ffa48a..87f9d1e3 100755 --- a/unix/mkerrors.sh +++ b/unix/mkerrors.sh @@ -627,6 +627,7 @@ echo '#include ' | $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 diff --git a/unix/mkmerge.go b/unix/mkmerge.go index 054a51d4..9bfd150f 100644 --- a/unix/mkmerge.go +++ b/unix/mkmerge.go @@ -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) diff --git a/unix/mkpost.go b/unix/mkpost.go index edf0f09e..c6b89512 100644 --- a/unix/mkpost.go +++ b/unix/mkpost.go @@ -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)) diff --git a/unix/mksyscall.go b/unix/mksyscall.go index 8dd88ea3..60f55b0b 100644 --- a/unix/mksyscall.go +++ b/unix/mksyscall.go @@ -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 diff --git a/unix/mksyscall_aix_ppc.go b/unix/mksyscall_aix_ppc.go index 4b4c6c40..01431372 100644 --- a/unix/mksyscall_aix_ppc.go +++ b/unix/mksyscall_aix_ppc.go @@ -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 diff --git a/unix/mksyscall_aix_ppc64.go b/unix/mksyscall_aix_ppc64.go index 8ff73179..bfadfd62 100644 --- a/unix/mksyscall_aix_ppc64.go +++ b/unix/mksyscall_aix_ppc64.go @@ -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 diff --git a/unix/mksyscall_solaris.go b/unix/mksyscall_solaris.go index 746dbef6..d5634b1c 100644 --- a/unix/mksyscall_solaris.go +++ b/unix/mksyscall_solaris.go @@ -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 diff --git a/unix/mksysctl_openbsd.go b/unix/mksysctl_openbsd.go index a147c777..3fde87ec 100644 --- a/unix/mksysctl_openbsd.go +++ b/unix/mksysctl_openbsd.go @@ -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 diff --git a/unix/mksysnum.go b/unix/mksysnum.go index 8478df54..812635f1 100644 --- a/unix/mksysnum.go +++ b/unix/mksysnum.go @@ -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