You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/11/28 00:37:50 UTC

[GitHub] ccollins476ad closed pull request #247: Include git hash and build date in version output

ccollins476ad closed pull request #247: Include git hash and build date in version output
URL: https://github.com/apache/mynewt-newt/pull/247
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/build.sh b/build.sh
index b56f0e43..0219fe41 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 0dc8808f..940e048a 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 0fd9f272..61f24651 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)
 }
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services