Merge pull request #424 from stickpro/issue-415

feat: Add version and commit information to easyjson generator
This commit is contained in:
Vasily Romanov
2025-09-15 21:14:26 +03:00
committed by GitHub
2 changed files with 16 additions and 1 deletions
+5 -1
View File
@@ -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 \
+11
View File
@@ -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)