Repository: incubator-mynewt-newt
Updated Branches:
  refs/heads/master 580535792 -> 8abc4f2c2


Fix portability issues with newt build.sh script.

* Go version string may contain more than two parts (not necessarily
  limited to major.minor).
* Don't depend on non-standard realpath utility.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/850f4247
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/850f4247
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/850f4247

Branch: refs/heads/master
Commit: 850f4247e57c9c9367a954778ed089ef3867cc51
Parents: 5805357
Author: Christopher Collins <ccoll...@apache.org>
Authored: Mon Mar 21 11:49:11 2016 -0700
Committer: Christopher Collins <ccoll...@apache.org>
Committed: Mon Mar 21 11:49:11 2016 -0700

----------------------------------------------------------------------
 build.sh | 34 +++++++++++++++++++++++++++++-----
 1 file changed, 29 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/850f4247/build.sh
----------------------------------------------------------------------
diff --git a/build.sh b/build.sh
index d0b433c..6ed9051 100755
--- a/build.sh
+++ b/build.sh
@@ -1,22 +1,46 @@
 #!/bin/sh
-
 set -e
 
+### Function to do the task of the non-standard realpath utility.  This does
+### not expand links, however.
+expandpath() {
+    (
+        cd "$1" && pwd
+    )
+}
+
 ### Ensure >= go1.5 is installed.
 go_ver_str="$(go version | cut -d ' ' -f 3)"
 go_ver="${go_ver_str#go}"
-go_maj="${go_ver%.*}"
-go_min="${go_ver#*.}"
+
+oldIFS="$IFS"
+IFS='.'
+set -- $go_ver
+IFS="$oldIFS"
+go_maj="$1"
+go_min="$2"
+
+if [ "$go_maj" = "" ]
+then
+    printf "* Error: could not extract go version (version string: %s)\n" \
+        "$go_ver_str"
+    exit 1
+fi
+
+if [ "$go_min" = "" ]
+then
+    go_min=0
+fi
 
 if [ ! "$go_maj" -gt 1 ] && [ ! "$go_min" -ge 5 ]
 then
     printf "* Error: go 1.5 or later is required (detected version: %s)\n" \
-        "$go_maj"."$go_min"
+        "$go_maj"."$go_min".X
     exit 1
 fi
 
 ### Create a temporary go tree in /tmp.
-installdir="$(realpath "$(dirname "$0")")"
+installdir="$(expandpath "$(dirname "$0")")"
 godir="$(mktemp -d /tmp/mynewt.XXXXXXXXXX)"
 mynewtdir="$godir"/src/mynewt.apache.org
 repodir="$mynewtdir"/newt

Reply via email to