summaryrefslogtreecommitdiffstats
path: root/vendor/golang.org/x/sys/unix/mkpost.go
diff options
context:
space:
mode:
authorAntonio Huete Jimenez <tuxillo@quantumachine.net>2018-10-27 01:18:40 +0200
committertechknowlogick <hello@techknowlogick.com>2018-10-26 19:18:40 -0400
commit99c09dfbfa818c753459e90db5ff12a323d2936f (patch)
tree207f9b07137f2c01a9b7ebf53cc63da89731f518 /vendor/golang.org/x/sys/unix/mkpost.go
parent2af57c78206272c771e0798db953b9dea42e2fbe (diff)
downloadgitea-99c09dfbfa818c753459e90db5ff12a323d2936f.tar.gz
gitea-99c09dfbfa818c753459e90db5ff12a323d2936f.zip
Update vendor/golang.org/x/sys (#5059)
Diffstat (limited to 'vendor/golang.org/x/sys/unix/mkpost.go')
-rw-r--r--vendor/golang.org/x/sys/unix/mkpost.go92
1 files changed, 64 insertions, 28 deletions
diff --git a/vendor/golang.org/x/sys/unix/mkpost.go b/vendor/golang.org/x/sys/unix/mkpost.go
index ed50d902af..7e5c22c473 100644
--- a/vendor/golang.org/x/sys/unix/mkpost.go
+++ b/vendor/golang.org/x/sys/unix/mkpost.go
@@ -8,10 +8,11 @@
// modify the generated types. It is used to clean up
// the sys API in an architecture specific manner.
//
-// mkpost is run after cgo -godefs by mkall.sh.
+// mkpost is run after cgo -godefs; see README.md.
package main
import (
+ "bytes"
"fmt"
"go/format"
"io/ioutil"
@@ -21,42 +22,77 @@ import (
)
func main() {
+ // Get the OS and architecture (using GOARCH_TARGET if it exists)
+ goos := os.Getenv("GOOS")
+ goarch := os.Getenv("GOARCH_TARGET")
+ if goarch == "" {
+ goarch = os.Getenv("GOARCH")
+ }
+ // Check that we are using the new build system if we should be.
+ if goos == "linux" && goarch != "sparc64" {
+ if os.Getenv("GOLANG_SYS_BUILD") != "docker" {
+ os.Stderr.WriteString("In the new build system, mkpost should not be called directly.\n")
+ os.Stderr.WriteString("See README.md\n")
+ os.Exit(1)
+ }
+ }
+
b, err := ioutil.ReadAll(os.Stdin)
if err != nil {
log.Fatal(err)
}
- s := string(b)
- goarch := os.Getenv("GOARCH")
- goos := os.Getenv("GOOS")
- if goarch == "s390x" && goos == "linux" {
- // Export the types of PtraceRegs fields.
- re := regexp.MustCompile("ptrace(Psw|Fpregs|Per)")
- s = re.ReplaceAllString(s, "Ptrace$1")
-
- // Replace padding fields inserted by cgo with blank identifiers.
- re = regexp.MustCompile("Pad_cgo[A-Za-z0-9_]*")
- s = re.ReplaceAllString(s, "_")
-
- // Replace other unwanted fields with blank identifiers.
- re = regexp.MustCompile("X_[A-Za-z0-9_]*")
- s = re.ReplaceAllString(s, "_")
-
- // Replace the control_regs union with a blank identifier for now.
- re = regexp.MustCompile("(Control_regs)\\s+\\[0\\]uint64")
- s = re.ReplaceAllString(s, "_ [0]uint64")
- }
+ // Intentionally export __val fields in Fsid and Sigset_t
+ valRegex := regexp.MustCompile(`type (Fsid|Sigset_t) struct {(\s+)X__val(\s+\S+\s+)}`)
+ b = valRegex.ReplaceAll(b, []byte("type $1 struct {${2}Val$3}"))
+
+ // If we have empty Ptrace structs, we should delete them. Only s390x emits
+ // nonempty Ptrace structs.
+ ptraceRexexp := regexp.MustCompile(`type Ptrace((Psw|Fpregs|Per) struct {\s*})`)
+ b = ptraceRexexp.ReplaceAll(b, nil)
+
+ // Replace the control_regs union with a blank identifier for now.
+ controlRegsRegex := regexp.MustCompile(`(Control_regs)\s+\[0\]uint64`)
+ b = controlRegsRegex.ReplaceAll(b, []byte("_ [0]uint64"))
+
+ // Remove fields that are added by glibc
+ // Note that this is unstable as the identifers are private.
+ removeFieldsRegex := regexp.MustCompile(`X__glibc\S*`)
+ b = removeFieldsRegex.ReplaceAll(b, []byte("_"))
+
+ // Convert [65]int8 to [65]byte in Utsname members to simplify
+ // conversion to string; see golang.org/issue/20753
+ convertUtsnameRegex := regexp.MustCompile(`((Sys|Node|Domain)name|Release|Version|Machine)(\s+)\[(\d+)\]u?int8`)
+ b = convertUtsnameRegex.ReplaceAll(b, []byte("$1$3[$4]byte"))
+
+ // Remove spare fields (e.g. in Statx_t)
+ spareFieldsRegex := regexp.MustCompile(`X__spare\S*`)
+ b = spareFieldsRegex.ReplaceAll(b, []byte("_"))
+
+ // Remove cgo padding fields
+ removePaddingFieldsRegex := regexp.MustCompile(`Pad_cgo_\d+`)
+ b = removePaddingFieldsRegex.ReplaceAll(b, []byte("_"))
+
+ // Remove padding, hidden, or unused fields
+ removeFieldsRegex = regexp.MustCompile(`\b(X_\S+|Padding)`)
+ b = removeFieldsRegex.ReplaceAll(b, []byte("_"))
+
+ // Remove the first line of warning from cgo
+ b = b[bytes.IndexByte(b, '\n')+1:]
+ // Modify the command in the header to include:
+ // mkpost, our own warning, and a build tag.
+ 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)
+ cgoCommandRegex := regexp.MustCompile(`(cgo -godefs .*)`)
+ b = cgoCommandRegex.ReplaceAll(b, []byte(replacement))
// gofmt
- b, err = format.Source([]byte(s))
+ b, err = format.Source(b)
if err != nil {
log.Fatal(err)
}
- // Append this command to the header to show where the new file
- // came from.
- re := regexp.MustCompile("(cgo -godefs [a-zA-Z0-9_]+\\.go.*)")
- b = re.ReplaceAll(b, []byte("$1 | go run mkpost.go"))
-
- fmt.Printf("%s", b)
+ os.Stdout.Write(b)
}