2
0
mirror of synced 2025-02-22 22:38:18 +00:00

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:
Hana (Hyang-Ah) Kim 2014-12-09 12:26:00 -05:00 committed by Hyang-Ah Hana Kim
parent 81f7d26930
commit daf6d8060b
3 changed files with 25 additions and 9 deletions

View File

@ -33,3 +33,5 @@ The gldebug tracing has very high overhead, so make sure to remove
the build tag before deploying any binaries.
*/
package gl
//go:generate go run gendebug.go -o gldebug.go

View File

@ -12,16 +12,20 @@ package main
import (
"bytes"
"fmt"
"flag"
"go/ast"
"go/format"
"go/parser"
"go/printer"
"go/token"
"io/ioutil"
"log"
"os"
"strconv"
)
var outfile = flag.String("o", "", "result will be written to the file instead of stdout.")
var fset = new(token.FileSet)
func typeString(t ast.Expr) string {
@ -46,18 +50,23 @@ func typePrinterArg(t, name string) string {
return name
}
func die(err error) {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
}
func main() {
flag.Parse()
f, err := parser.ParseFile(fset, "consts.go", nil, parser.ParseComments)
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
die(err)
}
entries := enum(f)
f, err = parser.ParseFile(fset, "gl.go", nil, parser.ParseComments)
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
die(err)
}
buf := new(bytes.Buffer)
@ -193,18 +202,23 @@ func main() {
b, err := format.Source(buf.Bytes())
if err != nil {
os.Stdout.Write(buf.Bytes())
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
die(err)
}
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.
// Use of this source code is governed by a BSD-style
// 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.
// +build gldebug

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// 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.
// +build gldebug