generate_svn_version.sh 2.15 KB
Newer Older
1
#!/usr/bin/env bash
2

3 4 5 6 7 8
HEADER="svn_version.h"
TMPFILE="$HEADER.tmp"

echo "#ifndef SVN_VERSION_H" > $TMPFILE
echo "#define SVN_VERSION_H" >> $TMPFILE
echo "" >> $TMPFILE
9

10
if [ -d .git/svn ]; then
11
    CMD="git svn info"
12 13 14
elif [ -d .git ]; then
    GIT_LOG=`git log -n1 --pretty="format:%H"`
    HOST=`hostname`
15
    BRANCH=`git branch | sed -n 's/^\* *//p'`
16 17 18 19
    remote=`git config --get branch.$BRANCH.remote 2>/dev/null`
    if [ "$?" != "0" ]; then
        remote="origin"
    fi
20 21
    URL=`git config --get remote.$remote.url`
    DATE=`git log -n1 --pretty="format:%ct"`
22
    SERVER_VERSION=`git describe --abbrev=0 --match server_release/*` 
23 24 25 26 27 28
elif [ -d .svn ]; then
    CMD="svn info"
else
    CMD=""
fi

29
if [ "x$GIT_LOG" != "x" ]; then
lfield's avatar
lfield committed
30
    echo "#define SVN_VERSION \"$GIT_LOG [$URL] ($HOST:$PWD [$BRANCH]) [Server-Release: $SERVER_VERSION]\"" >> $TMPFILE
31 32 33 34 35 36 37
    echo "$GIT_LOG" | sed 's/^\(........\).*/#define GIT_REVISION 0x\1/' >> $TMPFILE
    echo "#define GIT_DATE $DATE" >> $TMPFILE
    test "x$URL" = "x" ||
        echo "$URL" |
            sed 's/.git$//;s%.*://%%;s/[^/]*@//;s/[^a-zA-Z0-9]/_/g;s/__*/_/g;
                 y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/;
                 s/^/#define REPOSITORY_/;s/$/ 1/' >> $TMPFILE
38
elif [ "x$CMD" != "x" ]; then
39
    LANG=C
40 41
    URL=`$CMD | awk '
                /^URL/ { url = $2; };
42
                /^Rev/ { rev = $2; };
43
                END { print "#define SVN_VERSION \"Repository: " url \
44 45 46
                            " Revision: " rev "\"" >> "'"$TMPFILE"'";
                      print "#define SVN_REPOSITORY \"" url "\"" >> "'"$TMPFILE"'";
                      print "#define SVN_REVISION " rev >> "'"$TMPFILE"'";
47
                      print url };'`
48
    echo $URL |
49 50 51
        sed 's%.*://%%;s/[^/]*@//;s/[^a-zA-Z0-9]/_/g;s/__*/_/g;
             y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/;
             s/^/#define REPOSITORY_/;s/$/ 1/' >> $TMPFILE
52
else
53 54
    echo "#include \"version.h\"" >> $TMPFILE
    echo "#define SVN_VERSION BOINC_VERSION_STRING" >> $TMPFILE
55 56
fi

57 58 59 60 61 62 63 64
echo "" >> $TMPFILE
echo "#endif" >> $TMPFILE

if cmp "$HEADER" "$TMPFILE" >/dev/null 2>&1; then
	rm -f "$TMPFILE"
else
	mv "$TMPFILE" "$HEADER"
fi