Skip to content

Commit 58eb6f5

Browse files
authored
Merge pull request #424 from stickpro/issue-415
feat: Add version and commit information to easyjson generator
2 parents fe2707c + ffa0b23 commit 58eb6f5

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
VERSION := $(shell git describe --tags --always --dirty)
2+
COMMIT := $(shell git rev-parse --short HEAD)
3+
14
all: test
25

36
clean:
@@ -6,7 +9,8 @@ clean:
69
rm -rf benchmark/*_easyjson.go
710

811
build:
9-
go build -o ./bin/easyjson ./easyjson
12+
go build -ldflags="-s -w -X 'main.Version=$(VERSION)' -X 'main.Commit=$(COMMIT)'" -o ./bin/easyjson ./easyjson
13+
1014

1115
generate: build
1216
bin/easyjson -stubs \

easyjson/main.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ import (
1616
"github.com/mailru/easyjson/parser"
1717
)
1818

19+
var (
20+
Version = "dev" //
21+
Commit = "none"
22+
)
23+
1924
var buildTags = flag.String("build_tags", "", "build tags to add to generated file")
2025
var genBuildFlags = flag.String("gen_build_flags", "", "build flags when running the generator while bootstrapping")
2126
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
3136
var processPkg = flag.Bool("pkg", false, "process the whole package instead of just the given file")
3237
var disallowUnknownFields = flag.Bool("disallow_unknown_fields", false, "return error if any unknown field in json appeared")
3338
var skipMemberNameUnescaping = flag.Bool("disable_members_unescape", false, "don't perform unescaping of member names to improve performance")
39+
var showVersion = flag.Bool("version", false, "print version and exit")
3440

3541
func generate(fname string) (err error) {
3642
fInfo, err := os.Stat(fname)
@@ -98,6 +104,11 @@ func main() {
98104

99105
files := flag.Args()
100106

107+
if *showVersion {
108+
fmt.Printf("easyjson generator\nversion: %s\ncommit: %s\n", Version, Commit)
109+
os.Exit(0)
110+
}
111+
101112
gofile := os.Getenv("GOFILE")
102113
if *processPkg {
103114
gofile = filepath.Dir(gofile)

0 commit comments

Comments
 (0)