]> git.ipfire.org Git - thirdparty/iw.git/commitdiff
iw: version.sh: update to get version with git correctly
authorYongqin Liu <yongqin.liu@linaro.org>
Tue, 3 May 2016 05:48:48 +0000 (13:48 +0800)
committerJohannes Berg <johannes.berg@intel.com>
Tue, 31 May 2016 09:49:35 +0000 (11:49 +0200)
update to get the version information from the
git repository where this file is located instead of the
the current directory where it is executed, otherwise if
there is .git directory in the current directory, it will
get the wrong version information.

And improved the version check since the tag information
may not be mirrored like what AOSP does now.

Signed-off-by: Yongqin Liu <yongqin.liu@linaro.org>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
version.sh

index 7ccd419ffc468b2806add4bfff43c325abb866a8..c8111a6391f4b1ab4af747d3ebd7c20350d77a7d 100755 (executable)
@@ -3,20 +3,38 @@
 VERSION="4.3"
 OUT="$1"
 
-if [ -d .git ] && head=`git rev-parse --verify HEAD 2>/dev/null`; then
-       git update-index --refresh --unmerged > /dev/null
-       descr=$(git describe --match=v*)
+# get the absolute path for the OUT file
+OUT_NAME=$(basename ${OUT})
+OUT_DIR=$(cd $(dirname ${OUT}); pwd)
+OUT="${OUT_DIR}/${OUT_NAME}"
+
+# the version check should be under the source directory
+# where this script is located, instead of the currect directory
+# where this script is excuted.
+SRC_DIR=$(dirname $0)
+SRC_DIR=$(cd ${SRC_DIR}; pwd)
+cd "${SRC_DIR}"
 
-       # on git builds check that the version number above
-       # is correct...
-       [ "${descr%%-*}" = "v$VERSION" ] || exit 2
+v=""
+if [ -d .git ] && head=`git rev-parse --verify HEAD 2>/dev/null`; then
+    git update-index --refresh --unmerged > /dev/null
+    descr=$(git describe --match=v* 2>/dev/null)
+    if [ $? -eq 0 ]; then
+        # on git builds check that the version number above
+        # is correct...
+        if [ "${descr%%-*}" = "v$VERSION" ]; then
+            v="${descr#v}"
+            if git diff-index --name-only HEAD | read dummy ; then
+                v="$v"-dirty
+            fi
+        fi
+    fi
+fi
 
-       v="${descr#v}"
-       if git diff-index --name-only HEAD | read dummy ; then
-               v="$v"-dirty
-       fi
-else
-       v="$VERSION"
+# set to the default version when failed to get the version
+# information with git
+if [ -z "${v}" ]; then
+    v="$VERSION"
 fi
 
 echo '#include "iw.h"' > "$OUT"