Skip to content

Commit cb65c8d

Browse files
author
Bryan C. Mills
committed
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 <[email protected]> Trust: Alex Brainman <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Alex Brainman <[email protected]>
1 parent d5388e2 commit cb65c8d

File tree

5 files changed

+53
-19
lines changed

5 files changed

+53
-19
lines changed

src/internal/syscall/windows/mksyscall.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66

77
package windows
88

9-
//go:generate go run golang.org/x/sys/windows/mkwinsyscall -output zsyscall_windows.go syscall_windows.go security_windows.go psapi_windows.go symlink_windows.go
9+
//go:generate go run ../../../syscall/mksyscall_windows.go -output zsyscall_windows.go syscall_windows.go security_windows.go psapi_windows.go symlink_windows.go

src/internal/syscall/windows/registry/mksyscall.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66

77
package registry
88

9-
//go:generate go run golang.org/x/sys/windows/mkwinsyscall -output zsyscall_windows.go syscall.go
9+
//go:generate go run ../../../../syscall/mksyscall_windows.go -output zsyscall_windows.go syscall.go

src/internal/syscall/windows/zsyscall_windows.go

+13-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/syscall/mksyscall_windows.go

+37-3
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,55 @@
44

55
// +build ignore
66

7+
// mksyscall_windows wraps golang.org/x/sys/windows/mkwinsyscall.
78
package main
89

910
import (
11+
"bytes"
1012
"os"
1113
"os/exec"
1214
"path/filepath"
1315
"runtime"
1416
)
1517

1618
func main() {
17-
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")
18-
args := append([]string{"run", "golang.org/x/sys/windows/mkwinsyscall"}, os.Args[1:]...)
19-
cmd := exec.Command(filepath.Join(runtime.GOROOT(), "bin", "go"), args...)
19+
goTool := filepath.Join(runtime.GOROOT(), "bin", "go")
20+
21+
listCmd := exec.Command(goTool, "list", "-m")
22+
listCmd.Env = append(os.Environ(), "GO111MODULE=on")
23+
24+
var (
25+
cmdEnv []string
26+
modArgs []string
27+
)
28+
if out, err := listCmd.Output(); err == nil && string(bytes.TrimSpace(out)) == "std" {
29+
// Force module mode to use mkwinsyscall at the same version as the x/sys
30+
// module vendored into the standard library.
31+
cmdEnv = append(os.Environ(), "GO111MODULE=on")
32+
33+
// Force -mod=readonly instead of the default -mod=vendor.
34+
//
35+
// mkwinsyscall is not itself vendored into the standard library, and it is
36+
// not feasible to do so at the moment: std-vendored libraries are included
37+
// in the "std" meta-pattern (because in general they *are* linked into
38+
// users binaries separately from the original import paths), and we can't
39+
// allow a binary in the "std" meta-pattern.
40+
modArgs = []string{"-mod=readonly"}
41+
} else {
42+
// Nobody outside the standard library should be using this wrapper: other
43+
// modules can vendor in the mkwinsyscall tool directly (as described in
44+
// https://golang.org/issue/25922), so they don't need this wrapper to
45+
// set module mode and -mod=readonly explicitly.
46+
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")
47+
}
48+
49+
args := append([]string{"run"}, modArgs...)
50+
args = append(args, "golang.org/x/sys/windows/mkwinsyscall")
51+
args = append(args, os.Args[1:]...)
52+
cmd := exec.Command(goTool, args...)
2053
cmd.Stdout = os.Stdout
2154
cmd.Stderr = os.Stderr
55+
cmd.Env = cmdEnv
2256
err := cmd.Run()
2357
if err != nil {
2458
os.Exit(1)

src/syscall/syscall.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
//
2727
package syscall
2828

29-
//go:generate go run golang.org/x/sys/windows/mkwinsyscall -systemdll -output zsyscall_windows.go syscall_windows.go security_windows.go
29+
//go:generate go run ./mksyscall_windows.go -systemdll -output zsyscall_windows.go syscall_windows.go security_windows.go
3030

3131
// StringByteSlice converts a string to a NUL-terminated []byte,
3232
// If s contains a NUL byte this function panics instead of

0 commit comments

Comments
 (0)