This is an automated email from the ASF dual-hosted git repository. ccollins pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-imgmod.git
commit 7a8a8a53755954bceb8b38637d1d612fa2ab1795 Author: Christopher Collins <ccoll...@apache.org> AuthorDate: Thu Feb 20 09:59:32 2020 -0800 Use Makefile to embed version string This allows us to include a git hash and build date in the `imgmod version` output. --- Makefile | 31 +++++++++++++++++++++++++++++++ imgmod.go | 8 ++++---- version/version.go | 13 +++++++++++++ 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..dd94567 --- /dev/null +++ b/Makefile @@ -0,0 +1,31 @@ +PKG := mynewt.apache.org/imgmod/version +VERSION:="0.0.3" +DATE := $(shell date -u +%F,%R) +COMMIT := $(shell git rev-parse --short HEAD) +ifneq ($(shell git status --porcelain),) + COMMIT_SUFFIX := "-dirty" +endif +GIT_STATE := ${COMMIT}${COMMIT_SUFFIX} + +GOOS?=linux +GOARCH?=amd64 + +GWARCH=${GOOS}-${GOARCH} + +all: + @echo "Usage:" + @echo " make binary GOOS=linux # Linux" + @echo " make binary GOOS=darwin # MacOS" + @echo " make binary GOOS=windows # Windows" + +.PHONY: version +version: + @echo ${VERSION} + +.PHONY: gitstate +gitstate: + @echo ${GIT_STATE} + +binary: + @GOOS=${GOOS} GOARCH=${GOARCH} GO111MODULE=on go build -ldflags \ + "-X ${PKG}.Version=${VERSION} -X ${PKG}.BuildDate=${DATE} -X ${PKG}.GitState=${GIT_STATE}" diff --git a/imgmod.go b/imgmod.go index b3e2bb0..e4b9982 100644 --- a/imgmod.go +++ b/imgmod.go @@ -20,16 +20,16 @@ package main import ( - "github.com/apache/mynewt-artifact/errors" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" + "github.com/apache/mynewt-artifact/errors" + "mynewt.apache.org/imgmod/cli" "mynewt.apache.org/imgmod/iutil" + "mynewt.apache.org/imgmod/version" ) -var imgmodVersion = "0.0.2" - func main() { imgmodHelpText := "" imgmodHelpEx := "" @@ -68,7 +68,7 @@ func main() { Long: versHelpText, Example: versHelpEx, Run: func(cmd *cobra.Command, args []string) { - iutil.Printf("%s\n", imgmodVersion) + iutil.Printf("imgmod %s\n", version.VersionStr()) }, } imgmodCmd.AddCommand(versCmd) diff --git a/version/version.go b/version/version.go new file mode 100644 index 0000000..811fc84 --- /dev/null +++ b/version/version.go @@ -0,0 +1,13 @@ +package version + +import "fmt" + +var ( + Version string = "unknown_version" + BuildDate string = "unknown_date" + GitState string = "unknown_git_state" +) + +func VersionStr() string { + return fmt.Sprintf("%s / %s / %s", Version, GitState, BuildDate) +}