aboutsummaryrefslogtreecommitdiff
path: root/src/syscall
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2020-10-12 10:51:34 -0400
committerBryan C. Mills <bcmills@google.com>2020-11-02 15:31:49 +0000
commitcb65c8d58ac76abdaa6d14cc0742ca23d00ff524 (patch)
tree34665266a574582fb125d6875f22baa2f886d1a5 /src/syscall
parentd5388e23b5c75bf8189b173051d24a0176a5a303 (diff)
downloadgo-cb65c8d58ac76abdaa6d14cc0742ca23d00ff524.tar.gz
go-cb65c8d58ac76abdaa6d14cc0742ca23d00ff524.zip
syscall: switch go:generate directives back to mksyscall_windows.go
Adjust mksyscall_windows.go to activate module mode and set -mod=readonly, and to suppress its own deprecation warning when run from within GOROOT/src. We can't vendor the mkwinsyscall tool in to the std module directly, because std-vendored dependencies (unlike the dependencies of all other modules) turn into actual, distinct packages in 'std' when viewed from outside the 'std' module. We don't want to introduce a binary in the 'std' meta-pattern, but we also don't particularly want to add more special-cases to the 'go' command right now when we have an existing wrapper program that can do the job. I also regenerated the affected packages to ensure that they are consistent with the current version of mksyscall, which produced some declaration-order changes in internal/syscall/windows/zsyscall_windows.go. Fixes #41916 Updates #25922 Change-Id: If6e6f8ba3dd372a7ecd6820ee6c0ca38d55f0f35 Reviewed-on: https://go-review.googlesource.com/c/go/+/261499 Trust: Bryan C. Mills <bcmills@google.com> Trust: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Diffstat (limited to 'src/syscall')
-rw-r--r--src/syscall/mksyscall_windows.go40
-rw-r--r--src/syscall/syscall.go2
2 files changed, 38 insertions, 4 deletions
diff --git a/src/syscall/mksyscall_windows.go b/src/syscall/mksyscall_windows.go
index d66bf7865f..240254b2c7 100644
--- a/src/syscall/mksyscall_windows.go
+++ b/src/syscall/mksyscall_windows.go
@@ -4,9 +4,11 @@
// +build ignore
+// mksyscall_windows wraps golang.org/x/sys/windows/mkwinsyscall.
package main
import (
+ "bytes"
"os"
"os/exec"
"path/filepath"
@@ -14,11 +16,43 @@ import (
)
func main() {
- os.Stderr.WriteString("WARNING: Please switch from using:\n go run $GOROOT/src/syscall/mksyscall_windows.go\nto using:\n go run golang.org/x/sys/windows/mkwinsyscall\n")
- args := append([]string{"run", "golang.org/x/sys/windows/mkwinsyscall"}, os.Args[1:]...)
- cmd := exec.Command(filepath.Join(runtime.GOROOT(), "bin", "go"), args...)
+ goTool := filepath.Join(runtime.GOROOT(), "bin", "go")
+
+ listCmd := exec.Command(goTool, "list", "-m")
+ listCmd.Env = append(os.Environ(), "GO111MODULE=on")
+
+ var (
+ cmdEnv []string
+ modArgs []string
+ )
+ if out, err := listCmd.Output(); err == nil && string(bytes.TrimSpace(out)) == "std" {
+ // Force module mode to use mkwinsyscall at the same version as the x/sys
+ // module vendored into the standard library.
+ cmdEnv = append(os.Environ(), "GO111MODULE=on")
+
+ // Force -mod=readonly instead of the default -mod=vendor.
+ //
+ // mkwinsyscall is not itself vendored into the standard library, and it is
+ // not feasible to do so at the moment: std-vendored libraries are included
+ // in the "std" meta-pattern (because in general they *are* linked into
+ // users binaries separately from the original import paths), and we can't
+ // allow a binary in the "std" meta-pattern.
+ modArgs = []string{"-mod=readonly"}
+ } else {
+ // Nobody outside the standard library should be using this wrapper: other
+ // modules can vendor in the mkwinsyscall tool directly (as described in
+ // https://golang.org/issue/25922), so they don't need this wrapper to
+ // set module mode and -mod=readonly explicitly.
+ os.Stderr.WriteString("WARNING: Please switch from using:\n go run $GOROOT/src/syscall/mksyscall_windows.go\nto using:\n go run golang.org/x/sys/windows/mkwinsyscall\n")
+ }
+
+ args := append([]string{"run"}, modArgs...)
+ args = append(args, "golang.org/x/sys/windows/mkwinsyscall")
+ args = append(args, os.Args[1:]...)
+ cmd := exec.Command(goTool, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
+ cmd.Env = cmdEnv
err := cmd.Run()
if err != nil {
os.Exit(1)
diff --git a/src/syscall/syscall.go b/src/syscall/syscall.go
index 980ef9d27f..2e7a3ae5f2 100644
--- a/src/syscall/syscall.go
+++ b/src/syscall/syscall.go
@@ -26,7 +26,7 @@
//
package syscall
-//go:generate go run golang.org/x/sys/windows/mkwinsyscall -systemdll -output zsyscall_windows.go syscall_windows.go security_windows.go
+//go:generate go run ./mksyscall_windows.go -systemdll -output zsyscall_windows.go syscall_windows.go security_windows.go
// StringByteSlice converts a string to a NUL-terminated []byte,
// If s contains a NUL byte this function panics instead of