mirror of
https://github.com/netbirdio/easyjson.git
synced 2026-05-22 18:44:42 -07:00
Merge pull request #424 from stickpro/issue-415
feat: Add version and commit information to easyjson generator
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
VERSION := $(shell git describe --tags --always --dirty)
|
||||
COMMIT := $(shell git rev-parse --short HEAD)
|
||||
|
||||
all: test
|
||||
|
||||
clean:
|
||||
@@ -6,7 +9,8 @@ clean:
|
||||
rm -rf benchmark/*_easyjson.go
|
||||
|
||||
build:
|
||||
go build -o ./bin/easyjson ./easyjson
|
||||
go build -ldflags="-s -w -X 'main.Version=$(VERSION)' -X 'main.Commit=$(COMMIT)'" -o ./bin/easyjson ./easyjson
|
||||
|
||||
|
||||
generate: build
|
||||
bin/easyjson -stubs \
|
||||
|
||||
@@ -16,6 +16,11 @@ import (
|
||||
"github.com/mailru/easyjson/parser"
|
||||
)
|
||||
|
||||
var (
|
||||
Version = "dev" //
|
||||
Commit = "none"
|
||||
)
|
||||
|
||||
var buildTags = flag.String("build_tags", "", "build tags to add to generated file")
|
||||
var genBuildFlags = flag.String("gen_build_flags", "", "build flags when running the generator while bootstrapping")
|
||||
var snakeCase = flag.Bool("snake_case", false, "use snake_case names instead of CamelCase by default")
|
||||
@@ -31,6 +36,7 @@ var specifiedName = flag.String("output_filename", "", "specify the filename of
|
||||
var processPkg = flag.Bool("pkg", false, "process the whole package instead of just the given file")
|
||||
var disallowUnknownFields = flag.Bool("disallow_unknown_fields", false, "return error if any unknown field in json appeared")
|
||||
var skipMemberNameUnescaping = flag.Bool("disable_members_unescape", false, "don't perform unescaping of member names to improve performance")
|
||||
var showVersion = flag.Bool("version", false, "print version and exit")
|
||||
|
||||
func generate(fname string) (err error) {
|
||||
fInfo, err := os.Stat(fname)
|
||||
@@ -98,6 +104,11 @@ func main() {
|
||||
|
||||
files := flag.Args()
|
||||
|
||||
if *showVersion {
|
||||
fmt.Printf("easyjson generator\nversion: %s\ncommit: %s\n", Version, Commit)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
gofile := os.Getenv("GOFILE")
|
||||
if *processPkg {
|
||||
gofile = filepath.Dir(gofile)
|
||||
|
||||
Reference in New Issue
Block a user