gl: use go generate to generate gldebug.go by invoking gendebug.go
Change-Id: I7d682d153da5b200f9dd5cea8d09d76935daa18c Reviewed-on: https://go-review.googlesource.com/1225 Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
parent
81f7d26930
commit
daf6d8060b
@ -33,3 +33,5 @@ The gldebug tracing has very high overhead, so make sure to remove
|
|||||||
the build tag before deploying any binaries.
|
the build tag before deploying any binaries.
|
||||||
*/
|
*/
|
||||||
package gl
|
package gl
|
||||||
|
|
||||||
|
//go:generate go run gendebug.go -o gldebug.go
|
||||||
|
@ -12,16 +12,20 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"flag"
|
||||||
"go/ast"
|
"go/ast"
|
||||||
"go/format"
|
"go/format"
|
||||||
"go/parser"
|
"go/parser"
|
||||||
"go/printer"
|
"go/printer"
|
||||||
"go/token"
|
"go/token"
|
||||||
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var outfile = flag.String("o", "", "result will be written to the file instead of stdout.")
|
||||||
|
|
||||||
var fset = new(token.FileSet)
|
var fset = new(token.FileSet)
|
||||||
|
|
||||||
func typeString(t ast.Expr) string {
|
func typeString(t ast.Expr) string {
|
||||||
@ -46,18 +50,23 @@ func typePrinterArg(t, name string) string {
|
|||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func die(err error) {
|
||||||
|
fmt.Fprintf(os.Stderr, err.Error())
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
f, err := parser.ParseFile(fset, "consts.go", nil, parser.ParseComments)
|
f, err := parser.ParseFile(fset, "consts.go", nil, parser.ParseComments)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
die(err)
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
entries := enum(f)
|
entries := enum(f)
|
||||||
|
|
||||||
f, err = parser.ParseFile(fset, "gl.go", nil, parser.ParseComments)
|
f, err = parser.ParseFile(fset, "gl.go", nil, parser.ParseComments)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
die(err)
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
@ -193,18 +202,23 @@ func main() {
|
|||||||
b, err := format.Source(buf.Bytes())
|
b, err := format.Source(buf.Bytes())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Stdout.Write(buf.Bytes())
|
os.Stdout.Write(buf.Bytes())
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
die(err)
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Stdout.Write(b)
|
if *outfile == "" {
|
||||||
|
os.Stdout.Write(b)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := ioutil.WriteFile(*outfile, b, 0666); err != nil {
|
||||||
|
die(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const preamble = `// Copyright 2014 The Go Authors. All rights reserved.
|
const preamble = `// Copyright 2014 The Go Authors. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
// Generated from gl.go. DO NOT EDIT.
|
// Generated from gl.go using go generate. DO NOT EDIT.
|
||||||
// See doc.go for details.
|
// See doc.go for details.
|
||||||
|
|
||||||
// +build gldebug
|
// +build gldebug
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
// Generated from gl.go. DO NOT EDIT.
|
// Generated from gl.go using go generate. DO NOT EDIT.
|
||||||
// See doc.go for details.
|
// See doc.go for details.
|
||||||
|
|
||||||
// +build gldebug
|
// +build gldebug
|
||||||
|
Loading…
x
Reference in New Issue
Block a user