Skip to content

Commit

Permalink
modify generate version way
Browse files Browse the repository at this point in the history
  • Loading branch information
flike committed Mar 22, 2016
1 parent 358bd8f commit b9e7e94
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ all: build
build: kingshard

kingshard:
go build -ldflags "-X main.GitHash=`git rev-parse HEAD` -X main.BuildTime=`date '+%Y-%m-%d_%I:%M:%S%p'`" -o ./bin/kingshard ./cmd/kingshard

@bash genver.sh
go build -o ./bin/kingshard ./cmd/kingshard
clean:
@rm -rf bin

Expand Down
10 changes: 3 additions & 7 deletions cmd/kingshard/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,14 @@ import (

"github.com/flike/kingshard/config"
"github.com/flike/kingshard/core/golog"
"github.com/flike/kingshard/core/hack"
"github.com/flike/kingshard/proxy/server"
)

var configFile *string = flag.String("config", "/etc/ks.yaml", "kingshard config file")
var logLevel *string = flag.String("log-level", "", "log level [debug|info|warn|error], default error")
var version *bool = flag.Bool("v", false, "the version of kingshard")

var (
BuildTime = "2016-01-09 CST"
GitHash = "master"
)

const (
sqlLogName = "sql.log"
sysLogName = "sys.log"
Expand All @@ -57,8 +53,8 @@ func main() {
fmt.Print(banner)
runtime.GOMAXPROCS(runtime.NumCPU())
flag.Parse()
fmt.Printf("Git commit hash:%s\n", GitHash)
fmt.Printf("Build time:%s\n", BuildTime)
fmt.Printf("Git commit:%s\n", hack.Version)
fmt.Printf("Build time:%s\n", hack.Compile)
if *version {
return
}
Expand Down
6 changes: 6 additions & 0 deletions core/hack/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package hack

const (
Version = "2016-03-17 14:04:39 +0800 @358bd8f"
Compile = "2016-03-22 10:52:25 +0800 by go version go1.6 darwin/amd64"
)
17 changes: 17 additions & 0 deletions genver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

version=`git log --date=iso --pretty=format:"%cd @%h" -1`
if [ $? -ne 0 ]; then
version="not a git repo"
fi

compile=`date +"%F %T %z"`" by "`go version`

cat << EOF | gofmt > core/hack/version.go
package hack
const (
Version = "$version"
Compile = "$compile"
)
EOF

0 comments on commit b9e7e94

Please sign in to comment.