From f24742a42c137a33332012a853105be44f4808bb Mon Sep 17 00:00:00 2001 From: Shaun Ruffell Date: Wed, 26 Sep 2012 15:54:04 -0500 Subject: [PATCH] build_tools: Allow Asterisk to report git SHAs in version string. Make git more attractive for managing work-in-progress. Especially convenient when a potential patch set needs to be tested on multiple platforms since one can use git to keep all the test environments in sync independent of a subversion server. Now the Asterisk version will show the exact git SHA5 that was used when building (still appended by "M" if there are local modifications) from a git clone of the Asterisk repository so the developer can more easily know what is actually under test. You will now get this: $ asterisk -V Asterisk GIT-1698298 Instead of this: $ asterisk -V Asterisk UNKNOWN__and_probably_unsupported This has zero impact for those not using git with the exception of an extra test in the configure script to gather git's path. This is necessary to prevent "sudo make install" from failing since git may not be in the path in make's shell environment. (issue ASTERISK-20483) --- Makefile | 2 +- build_tools/make_version | 72 +++++++++++++++++++++++++++++++++++++++++++++- configure | 44 +++++++++++++++++++++++++++- configure.ac | 1 + makeopts.in | 1 + 5 files changed, 117 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index b75221b..8cefe3f 100644 --- a/Makefile +++ b/Makefile @@ -226,7 +226,7 @@ ifeq ($(OSARCH),SunOS) _ASTCFLAGS+=-Wcast-align -DSOLARIS -I../include/solaris-compat -I/opt/ssl/include -I/usr/local/ssl/include -D_XPG4_2 -D__EXTENSIONS__ endif -ASTERISKVERSION:=$(shell GREP=$(GREP) AWK=$(AWK) build_tools/make_version .) +ASTERISKVERSION:=$(shell GREP=$(GREP) AWK=$(AWK) GIT=$(GIT) build_tools/make_version .) ifneq ($(wildcard .version),) ASTERISKVERSIONNUM:=$(shell $(AWK) -F. '{printf "%01d%02d%02d", $$1, $$2, $$3}' .version) diff --git a/build_tools/make_version b/build_tools/make_version index d81325f..d7ea424 100755 --- a/build_tools/make_version +++ b/build_tools/make_version @@ -1,8 +1,12 @@ #!/bin/sh +if [ -z ${GIT} ]; then + GIT="git" +fi + if [ -f ${1}/.version ]; then cat ${1}/.version -elif [ -d .svn ]; then +elif [ -d ${1}/.svn ]; then PARTS=`LANG=C svn info ${1} | ${GREP} URL | ${AWK} '{print $2;}' | sed -e 's:^.*/svn/asterisk/::' | sed -e 's:/: :g'` BRANCH=0 TEAM=0 @@ -84,6 +88,72 @@ elif [ -d .svn ]; then else echo SVN-${RESULT}-r${REV}${BASE:+-${BASE}} fi +elif [ -d ${1}/.git ]; then + if ! command -v ${GIT} >/dev/null 2>&1; then + echo "UNKNOWN__and_probably_unsupported" + exit 1 + fi + # If the first log commit messages indicates that this is checked into + # subversion, we'll just use the SVN- form of the revision. + MODIFIED="" + SVN_REV=`${GIT} log --pretty=full -1 | grep -F "git-svn-id:" | sed -e "s/.*\@\([^\s]*\)\s.*/\1/g"` + if [ -z "$SVN_REV" ]; then + VERSION=GIT-`${GIT} describe --long --always --tags --dirty=M 2> /dev/null` + if [ $? -ne 0 ]; then + if [ "`${GIT} ls-files -m | wc -l`" != "0" ]; then + MODIFIED="M" + fi + # Some older versions of git do not support all the above + # options. + VERSION=GIT-`${GIT} rev-parse --short --verify HEAD`${MODIFIED} + fi + echo ${VERSION} + else + PARTS=`LANG=C ${GIT} log --pretty=full | grep -F "git-svn-id:" | head -1 | awk '{print $2;}' | sed -e s:^.*/svn/$2/:: | sed -e 's:/: :g' | sed -e 's/@.*$//g'` + BRANCH=0 + TEAM=0 + + if [ "`${GIT} ls-files -m | wc -l`" != "0" ]; then + MODIFIED="M" + fi + + if [ "${PARTS}" = "trunk" ]; then + echo SVN-'trunk'-r${SVN_REV}${MODIFIED} + exit 0 + fi + + for PART in $PARTS + do + if [ ${BRANCH} != 0 ]; then + RESULT="${RESULT}-${PART}" + break + fi + + if [ ${TEAM} != 0 ]; then + RESULT="${RESULT}-${PART}" + continue + fi + + if [ "${PART}" = "branches" ]; then + BRANCH=1 + RESULT="branch" + continue + fi + + if [ "${PART}" = "tags" ]; then + BRANCH=1 + RESULT="tag" + continue + fi + + if [ "${PART}" = "team" ]; then + TEAM=1 + continue + fi + done + + echo SVN-${RESULT##-}-r${SVN_REV}${MODIFIED} + fi else echo "UNKNOWN__and_probably_unsupported" fi diff --git a/configure b/configure index db14c6d..9d8f2ac 100755 --- a/configure +++ b/configure @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.ac Revision: 373120 . +# From configure.ac Revision. # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.68 for asterisk trunk. # @@ -1075,6 +1075,7 @@ SHA1SUM LDCONFIG DOWNLOAD FETCH +GIT XMLSTARLET XMLLINT KPATHSEA @@ -7242,6 +7243,47 @@ $as_echo "no" >&6; } fi +# Extract the first word of "git", so it can be a program name with args. +set dummy git; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_GIT+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $GIT in + [\\/]* | ?:[\\/]*) + ac_cv_path_GIT="$GIT" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_path_GIT="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + test -z "$ac_cv_path_GIT" && ac_cv_path_GIT=":" + ;; +esac +fi +GIT=$ac_cv_path_GIT +if test -n "$GIT"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $GIT" >&5 +$as_echo "$GIT" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + if test "${WGET}" != ":" ; then DOWNLOAD=${WGET} else if test "${CURL}" != ":" ; then diff --git a/configure.ac b/configure.ac index b6fe5ee..19acac7 100644 --- a/configure.ac +++ b/configure.ac @@ -262,6 +262,7 @@ AC_PATH_PROG([CATDVI], [catdvi], :) AC_PATH_PROG([KPATHSEA], [kpsewhich], :) AC_PATH_PROG([XMLLINT], [xmllint], :) AC_PATH_PROG([XMLSTARLET], [xmlstarlet], :) +AC_PATH_PROG([GIT], [git], :) if test "${WGET}" != ":" ; then DOWNLOAD=${WGET} else if test "${CURL}" != ":" ; then diff --git a/makeopts.in b/makeopts.in index 25c23b3..dbd181e 100644 --- a/makeopts.in +++ b/makeopts.in @@ -36,6 +36,7 @@ MD5=@MD5@ SHA1SUM=@SHA1SUM@ OPENSSL=@OPENSSL@ LDCONFIG=@LDCONFIG@ +GIT=@GIT@ BUILD_PLATFORM=@BUILD_PLATFORM@ BUILD_CPU=@BUILD_CPU@ -- 1.7.9.5