Blame synfig-core/build_tools/autorevision.sh

Carlos Lopez a09598
#!/bin/sh
Carlos Lopez a09598
Carlos Lopez a09598
# Copyright 2008 Paul Wise
Carlos Lopez a09598
# Copyright 2009 Konstantin Dmitriev
Carlos Lopez a09598
#
Carlos Lopez a09598
# This package is free software; you can redistribute it and/or
Carlos Lopez a09598
# modify it under the terms of the GNU General Public License as
Carlos Lopez a09598
# published by the Free Software Foundation; either version 2 of
Carlos Lopez a09598
# the License, or (at your option) any later version.
Carlos Lopez a09598
#
Carlos Lopez a09598
# This package is distributed in the hope that it will be useful,
Carlos Lopez a09598
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Carlos Lopez a09598
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Carlos Lopez a09598
# General Public License for more details.
Carlos Lopez a09598
Carlos Lopez a09598
get_git_id(){
Carlos Lopez a09598
	export SCM=git
fb6e5f
	export REVISION_ID=`cd "$1"; git log --no-color -1 | head -n 1 | cut -f 2 -d ' ' | cut -c -6`
Carlos Lopez a09598
	export BRANCH="`cd "$1"; git branch -a --no-color --contains HEAD | sed -e s/\*\ // | sed -e s/\(no\ branch\)// | tr '\n' ' ' | tr -s ' ' | sed s/^' '//`"
Carlos Lopez a09598
	if ( echo $BRANCH | egrep origin/master > /dev/null ); then
Carlos Lopez a09598
		#give a priority to master branch
Carlos Lopez a09598
		BRANCH='master'
Carlos Lopez a09598
	else
Carlos Lopez a09598
		BRANCH=`echo $BRANCH | cut -d ' ' -f 1`
Carlos Lopez a09598
		BRANCH=${BRANCH##*/}
Carlos Lopez a09598
	fi
Carlos Lopez a09598
	export REVISION=`git show --pretty=format:%ci HEAD |  head -c 10 | tr -d '-'`
Carlos Lopez a09598
	export COMPARE=`git rev-parse --git-dir`
Carlos Lopez a09598
	# The extra * at the end is for Modified
Carlos Lopez a09598
	#REVISION="$REVISION"`cd "$1"; [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"`
Carlos Lopez a09598
}
Carlos Lopez a09598
Carlos Lopez a09598
get_git_svn_id(){
Carlos Lopez a09598
	export SCM=git-svn
Carlos Lopez a09598
	export REVISION=`cd "$1"; git svn find-rev HEAD`
Carlos Lopez a09598
	export COMPARE="$1/.git/"
Carlos Lopez a09598
	if [ x = "x$REVISION" ] ; then
Carlos Lopez a09598
		# The extra M at the end is for Modified
Carlos Lopez a09598
		export REVISION=`cd "$1"; git svn find-rev \`git rev-list --max-count=1 --grep='git-svn-id: ' HEAD\``M
Carlos Lopez a09598
	else
Carlos Lopez a09598
		export REVISION="$REVISION"`cd "$1"; git diff --quiet HEAD || echo M`
Carlos Lopez a09598
	fi
Carlos Lopez a09598
}
Carlos Lopez a09598
Carlos Lopez a09598
get_svn_id(){
Carlos Lopez a09598
	export SCM=svn
Carlos Lopez a09598
	export REVISION=`cd "$1"; svnversion || svn info | sed -n 's/^Revision: \(.*\)/\1/p'`
Carlos Lopez a09598
}
Carlos Lopez a09598
Carlos Lopez a09598
Carlos Lopez a09598
HEADER="$2/autorevision.h"
Carlos Lopez a09598
SCM=none
Carlos Lopez a09598
Carlos Lopez a09598
Carlos Lopez a09598
if [ ! -f "$HEADER" ] ; then
Carlos Lopez a09598
	touch -t 197001010101 "$HEADER"
Carlos Lopez a09598
fi
Carlos Lopez a09598
Carlos Lopez a09598
Carlos Lopez a09598
# Extract the revision from SVN/git/etc
Carlos Lopez a09598
if git rev-parse --git-dir > /dev/null  2>&1 ; then
Carlos Lopez a09598
	get_git_id "."
Carlos Lopez a09598
elif [ -d "$1/.git/svn" ] ; then
Carlos Lopez a09598
	get_git_svn_id "$1"
Carlos Lopez a09598
elif [ -d "$1/../.git/svn" ] ; then
Carlos Lopez a09598
	get_git_svn_id "$1/.."
Carlos Lopez a09598
elif [ -d "$1/../../.git/svn" ] ; then
Carlos Lopez a09598
	get_git_svn_id "$1/../.."
Carlos Lopez a09598
elif [ -d "$1/.svn" ] ; then
Carlos Lopez a09598
	COMPARE="$1/.svn"
Carlos Lopez a09598
	get_svn_id "$1"
Carlos Lopez a09598
elif [ -d "$1/_svn" ] ; then
Carlos Lopez a09598
	COMPARE="$1/_svn"
Carlos Lopez a09598
	get_svn_id "$1"
Carlos Lopez a09598
fi
Carlos Lopez a09598
Carlos Lopez a09598
Carlos Lopez a09598
# Allow overriding both REVISION and DEVEL_VERSION
Carlos Lopez a09598
if [ -f "$2/autorevision.conf" ] ; then
Carlos Lopez a09598
	SCM=manual
Carlos Lopez a09598
	. "$2/autorevision.conf"
Carlos Lopez a09598
fi
Carlos Lopez a09598
Carlos Lopez a09598
Carlos Lopez a09598
# Abort if the header is newer
Carlos Lopez a09598
if [ "$COMPARE" -ot "$HEADER" ] ; then exit; fi
Carlos Lopez a09598
Carlos Lopez a09598
# Set the development version string
Carlos Lopez a09598
if [ x = "x$DEVEL_VERSION" ] ; then
Carlos Lopez a09598
	if [ x != "x$REVISION" ] ; then
Carlos Lopez a09598
		if [ $SCM = svn ] ; then
Carlos Lopez a09598
			DEVEL_VERSION="SVN r$REVISION"
Carlos Lopez a09598
		elif [ $SCM = git-svn ] ; then
Carlos Lopez a09598
			DEVEL_VERSION="SVN r$REVISION (via git)"
Carlos Lopez a09598
		elif [ $SCM = git ] ; then
Carlos Lopez a09598
			DEVEL_VERSION="Revision: ${REVISION}\\\\nBranch: ${BRANCH}\\\\nRevision ID: ${REVISION_ID}"
Carlos Lopez a09598
		elif [ $SCM = manual ] ; then
Carlos Lopez a09598
			DEVEL_VERSION="$REVISION (manually configured)"
Carlos Lopez a09598
		fi
Carlos Lopez a09598
	fi
Carlos Lopez a09598
fi
Carlos Lopez a09598
Carlos Lopez a09598
Carlos Lopez a09598
# Output the header
Carlos Lopez a09598
if [ x != "x$DEVEL_VERSION" ] ; then
Carlos Lopez a09598
	printf "#define DEVEL_VERSION \"$DEVEL_VERSION\"\n" > "$HEADER"
Carlos Lopez a09598
fi