mirror of
https://github.com/golang/go
synced 2024-11-19 03:54:42 -07:00
syscall: use go generate to build zsyscall_windows.go
I would like to create new syscalls in src/internal/syscall, and I prefer not to add new shell scripts for that. Replacement for CL 136000043. Change-Id: I840116b5914a2324f516cdb8603c78973d28aeb4 Reviewed-on: https://go-review.googlesource.com/1940 Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
parent
fcfbeb3adf
commit
d00024bd60
@ -244,9 +244,8 @@ solaris_amd64)
|
||||
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
|
||||
;;
|
||||
windows_*)
|
||||
mksyscall=
|
||||
mkerrors=
|
||||
zerrors=
|
||||
echo 'run "go generate syscall_windows.go" instead' 1>&2
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
echo 'unrecognized $GOOS_$GOARCH: ' "$GOOSARCH" 1>&2
|
||||
@ -256,22 +255,13 @@ esac
|
||||
|
||||
(
|
||||
if [ -n "$mkerrors" ]; then echo "$mkerrors |gofmt >$zerrors"; fi
|
||||
case "$GOOS" in
|
||||
windows)
|
||||
echo "GOOS= GOARCH= go build mksyscall_windows.go"
|
||||
echo "./mksyscall_windows syscall_windows.go security_windows.go |gofmt >zsyscall_windows.go"
|
||||
echo "rm -f ./mksyscall_windows"
|
||||
;;
|
||||
*)
|
||||
syscall_goos="syscall_$GOOS.go"
|
||||
case "$GOOS" in
|
||||
darwin | dragonfly | freebsd | netbsd | openbsd)
|
||||
syscall_goos="syscall_bsd.go $syscall_goos"
|
||||
;;
|
||||
esac
|
||||
if [ -n "$mksyscall" ]; then echo "$mksyscall $syscall_goos $GOOSARCH_in |gofmt >zsyscall_$GOOSARCH.go"; fi
|
||||
;;
|
||||
esac
|
||||
if [ -n "$mksyscall" ]; then echo "$mksyscall $syscall_goos syscall_$GOOSARCH.go |gofmt >zsyscall_$GOOSARCH.go"; fi
|
||||
if [ -n "$mksysctl" ]; then echo "$mksysctl |gofmt >$zsysctl"; fi
|
||||
if [ -n "$mksysnum" ]; then echo "$mksysnum |gofmt >zsysnum_$GOOSARCH.go"; fi
|
||||
if [ -n "$mktypes" ]; then echo "$mktypes types_$GOOS.go |gofmt >ztypes_$GOOSARCH.go"; fi
|
||||
|
@ -1,15 +0,0 @@
|
||||
:: Copyright 2013 The Go Authors. All rights reserved.
|
||||
:: Use of this source code is governed by a BSD-style
|
||||
:: license that can be found in the LICENSE file.
|
||||
@echo off
|
||||
|
||||
if exist mkall.sh goto dirok
|
||||
echo mkall_windows.bat must be run from src\syscall directory
|
||||
goto :end
|
||||
:dirok
|
||||
|
||||
go build mksyscall_windows.go
|
||||
.\mksyscall_windows syscall_windows.go security_windows.go |gofmt >zsyscall_windows.go
|
||||
del mksyscall_windows.exe
|
||||
|
||||
:end
|
@ -37,6 +37,8 @@ Usage:
|
||||
mksyscall_windows [flags] [path ...]
|
||||
|
||||
The flags are:
|
||||
-output
|
||||
Specify output file name (outputs to console if blank).
|
||||
-trace
|
||||
Generate print statement after every syscall.
|
||||
*/
|
||||
@ -44,12 +46,15 @@ package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"go/format"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
@ -57,7 +62,10 @@ import (
|
||||
"text/template"
|
||||
)
|
||||
|
||||
var PrintTraceFlag = flag.Bool("trace", false, "generate print statement after every syscall")
|
||||
var (
|
||||
filename = flag.String("output", "", "output file name (standard output if omitted)")
|
||||
printTraceFlag = flag.Bool("trace", false, "generate print statement after every syscall")
|
||||
)
|
||||
|
||||
func trim(s string) string {
|
||||
return strings.Trim(s, " \t")
|
||||
@ -379,7 +387,7 @@ func newFn(s string) (*Fn, error) {
|
||||
f := &Fn{
|
||||
Rets: &Rets{},
|
||||
src: s,
|
||||
PrintTrace: *PrintTraceFlag,
|
||||
PrintTrace: *printTraceFlag,
|
||||
}
|
||||
// function name and args
|
||||
prefix, body, s, found := extractSection(s, '(', ')')
|
||||
@ -669,8 +677,8 @@ func (src *Source) ParseFile(path string) error {
|
||||
// Generate output source file from a source set src.
|
||||
func (src *Source) Generate(w io.Writer) error {
|
||||
funcMap := template.FuncMap{
|
||||
"syscalldot": syscalldot,
|
||||
"packagename": packagename,
|
||||
"syscalldot": syscalldot,
|
||||
}
|
||||
t := template.Must(template.New("main").Funcs(funcMap).Parse(srcTemplate))
|
||||
err := t.Execute(w, src)
|
||||
@ -689,15 +697,31 @@ func usage() {
|
||||
func main() {
|
||||
flag.Usage = usage
|
||||
flag.Parse()
|
||||
if len(os.Args) <= 1 {
|
||||
if len(flag.Args()) <= 0 {
|
||||
fmt.Fprintf(os.Stderr, "no files to parse provided\n")
|
||||
usage()
|
||||
}
|
||||
src, err := ParseFiles(os.Args[1:])
|
||||
|
||||
src, err := ParseFiles(flag.Args())
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if err := src.Generate(os.Stdout); err != nil {
|
||||
|
||||
var buf bytes.Buffer
|
||||
if err := src.Generate(&buf); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
data, err := format.Source(buf.Bytes())
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if *filename == "" {
|
||||
_, err = os.Stdout.Write(data)
|
||||
} else {
|
||||
err = ioutil.WriteFile(*filename, data, 0644)
|
||||
}
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
@ -705,8 +729,7 @@ func main() {
|
||||
// TODO: use println instead to print in the following template
|
||||
const srcTemplate = `
|
||||
|
||||
{{define "main"}}// go build mksyscall_windows.go && ./mksyscall_windows{{range .Files}} {{.}}{{end}}
|
||||
// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
|
||||
{{define "main"}}// MACHINE GENERATED BY 'go generate' COMMAND; DO NOT EDIT
|
||||
|
||||
package {{packagename}}
|
||||
|
||||
|
@ -13,6 +13,8 @@ import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
//go:generate go run mksyscall_windows.go -output zsyscall_windows.go syscall_windows.go security_windows.go
|
||||
|
||||
type Handle uintptr
|
||||
|
||||
const InvalidHandle = ^Handle(0)
|
||||
|
@ -1,5 +1,4 @@
|
||||
// go build mksyscall_windows.go && ./mksyscall_windows syscall_windows.go security_windows.go
|
||||
// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
|
||||
// MACHINE GENERATED BY 'go generate' COMMAND; DO NOT EDIT
|
||||
|
||||
package syscall
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user