Skip to content

Commit

Permalink
version.sh: Ticket 411 (make loops, rerunning configure ad infinitum)
Browse files Browse the repository at this point in the history
version.h is dumped even when git is unavailable or broken
buildbot dislikes to fetch tags (git fetch --tags) => version.sh failure.
version.sh refused to create version.h when git is unavailable.

All those cases are hopefully fixed.

Signed-off-by: Sergei Trofimovich <[email protected]>
Signed-off-by: Slava Zanko <[email protected]>
  • Loading branch information
slavaz authored and Sergei Trofimovich committed Jun 20, 2009
1 parent 4a58bd3 commit d9a72ea
Showing 1 changed file with 39 additions and 36 deletions.
75 changes: 39 additions & 36 deletions maint/version.sh
Original file line number Diff line number Diff line change
@@ -1,44 +1,47 @@
#!/bin/sh

git --version >/dev/null || exit

curr_dir=$(pwd)

src_top_dir=
[ -d ${curr_dir}/.git ] && {
src_top_dir=${curr_dir}
} || {
curr_dir=$(dirname ${curr_dir})
[ -d ${curr_dir}/.git ] && {
src_top_dir=${curr_dir}
} || {
[ -z "$1" ] && exit
src_top_dir=$1
}
if [ -z "$1" ]
then
echo "usage: $0 <toplevel-source-dir>"
exit 1
fi

src_top_dir="$1"

VERSION_FILE="${src_top_dir}/version.h"
PREV_MC_VERSION="unknown"
CURR_MC_VERSION="${PREV_MC_VERSION}"

if [ -r ${VERSION_FILE} ]
then
PREV_MC_VERSION=`sed -rn 's/^#define MC_CURRENT_VERSION "(.*)"$/\1/p' "${VERSION_FILE}"`
CURR_MC_VERSION="${PREV_MC_VERSION}"
fi

mc_print_version(){

if [ ! -f "${VERSION_FILE}" \
-o "${PREV_MC_VERSION}" != "${CURR_MC_VERSION}" ]
then
cat >"${VERSION_FILE}" <<EOF
#ifndef MC_CURRENT_VERSION
/* This is an autogenerated file. Don't edit! */
#define MC_CURRENT_VERSION "${CURR_MC_VERSION}"
#endif
EOF
fi
exit
}
[ -z "${src_top_dir}" ] && exit


VERSION_FILE=${src_top_dir}/version.h

git_head=$(git --git-dir "${src_top_dir}/.git" rev-parse --verify HEAD 2>/dev/null)
[ -z "${git_head}" ] && exit

new_version="$(git --git-dir "${src_top_dir}/.git" describe 2>/dev/null)"
[ -z "${new_version}" ] && exit
[ -z "${git_head}" ] && mc_print_version

# try to store sha1
CURR_MC_VERSION="${git_head}"

saved_version=
[ -r ${VERSION_FILE} ] && {
saved_version=$(sed -rn 's/^#define MC_CURRENT_VERSION "(.*)"$/\1/p' ${VERSION_FILE})
}
new_version="$(git --git-dir "${src_top_dir}/.git" describe 2>/dev/null)"
[ -z "${new_version}" ] && mc_print_version

[ -z "${saved_version}" -o "${saved_version}" != "${new_version}" ] && {
cat >${VERSION_FILE} <<EOF
#ifndef MC_CURRENT_VERSION
/* This is an autogenerated file. Don't edit! */
#define MC_CURRENT_VERSION "${new_version}"
#endif
EOF
}
exit 0
# store pretty tagged version
CURR_MC_VERSION="${new_version}"
mc_print_version

0 comments on commit d9a72ea

Please sign in to comment.