You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2018/11/28 00:37:52 UTC
[mynewt-newt] branch master updated: Include git hash and build
date in version output
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-newt.git
The following commit(s) were added to refs/heads/master by this push:
new 6207aa8 Include git hash and build date in version output
6207aa8 is described below
commit 6207aa8125377b362ddce3884db1d937708f8af3
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Mon Nov 26 15:16:11 2018 -0800
Include git hash and build date in version output
The hash and build date need to be specified at build time. This
has been added to the `build.sh` script.
---
build.sh | 14 +++++++++++++-
newt/newt.go | 5 ++++-
newt/newtutil/newtutil.go | 10 +++++++---
3 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/build.sh b/build.sh
index b56f0e4..0219fe4 100755
--- a/build.sh
+++ b/build.sh
@@ -67,12 +67,24 @@ dstfile="$installdir"/newt/newt
mkdir -p "$mynewtdir"
ln -s "$installdir" "$repodir"
+### Collect version information.
+GIT_HASH="$(git rev-parse --short HEAD)"
+GIT_DIRTY="$(git status --porcelain)"
+if [ ! -z "$GIT_DIRTY" ]; then
+ GIT_HASH=$GIT_HASH"-dirty"
+fi
+
+DATE="$(date +%F_%R)"
+
### Build newt.
(
cd "$newtdir"
printf "Building newt. This may take a minute...\n"
- GOPATH="$godir" GO15VENDOREXPERIMENT=1 go install
+ GOPATH="$godir" GO15VENDOREXPERIMENT=1 go install -ldflags " \
+ -X mynewt.apache.org/newt/newt/newtutil.NewtGitHash=$GIT_HASH \
+ -X mynewt.apache.org/newt/newt/newtutil.NewtDate=$DATE \
+ "
mv "$godir"/bin/newt "$dstfile"
diff --git a/newt/newt.go b/newt/newt.go
index 0dc8808..940e048 100644
--- a/newt/newt.go
+++ b/newt/newt.go
@@ -127,7 +127,10 @@ func newtCmd() *cobra.Command {
Long: versHelpText,
Example: versHelpEx,
Run: func(cmd *cobra.Command, args []string) {
- fmt.Printf("%s\n", newtutil.NewtVersionStr)
+ fmt.Printf("Apache Newt\n")
+ fmt.Printf(" Version: %s\n", newtutil.NewtVersionStr)
+ fmt.Printf(" Git Hash: %s\n", newtutil.NewtGitHash)
+ fmt.Printf("Build Date: %s\n", newtutil.NewtDate)
},
}
diff --git a/newt/newtutil/newtutil.go b/newt/newtutil/newtutil.go
index 0fd9f27..61f2465 100644
--- a/newt/newtutil/newtutil.go
+++ b/newt/newtutil/newtutil.go
@@ -31,8 +31,11 @@ import (
"mynewt.apache.org/newt/yaml"
)
-var NewtVersion Version = Version{1, 5, 9900}
-var NewtVersionStr string = "Apache Newt version: 1.6.0-dev"
+var NewtVersion = Version{1, 5, 9900}
+var NewtVersionStr = "1.6.0-dev"
+var NewtGitHash = "unknown"
+var NewtDate = "unknown"
+
var NewtBlinkyTag string = "master"
var NewtNumJobs int
var NewtForce bool
@@ -161,7 +164,8 @@ func BuildPackageString(repoName string, pkgName string) string {
}
func GeneratedPreamble() string {
- return fmt.Sprintf("/**\n * This file was generated by %s\n */\n\n",
+ return fmt.Sprintf(
+ "/**\n * This file was generated by Apache newt version: %s\n */\n\n",
NewtVersionStr)
}