#!/bin/bash GITEXEC=`which git` GITPID=0 TMPSRVDIR="" # Trap SIGINT / SIGTERM # errex is used as the general error exit trap errex SIGINT SIGTERM function errex { echo -e "\nERROR: Abnormal termination of gubllt script!" if [ $GITPID -ne 0 ]; then echo "... killing git daemon (ppid $GITPID)" kill -n 9 -- $(ps -o pid= --ppid $GITPID) fi if [ "x$TMPSRVDIR" != "x" ]; then if [ -d "$TMPSRVDIR" ]; then echo "... removing $TMPSRVDIR" rm -rf $TMPSRVDIR fi fi exit 255 } # procFN function # This function canonicalizes / simplifies path names given as argument 1 # - replace './' at the beginning of $1 with '$PWD/' # - replace '../' at the beginning of $1 with '$PWD/../' # - if there is no '/' at the beginning of $1, put '$PWD' in front of $1 # - replace each occurrence of '/something/../' with '/' # - replace each occurrence of '/./' with '/' procFN () { echo $1 | \ sed -e "s|^./|$PWD/|" \ -e "s|^../|$PWD/../|" \ -e "s|\(^[^/]\)|$PWD/\1|" \ -e ':loopA s|/[^/]*/../|/|; t loopA' \ -e ':loopB s|/./|/|; t loopB' } echo "gubllt --- GUB Local Lilypond Tester" # abort if not exactly 4 arguments are provided if [ $# -ne 4 ]; then echo "ERROR: invalid number of command line arguments!" echo "USAGE: gubllt gub_directory lilypond_repository_directory testbase test" echo " 'testbase' and 'test' must be valid braches or commit names" echo " in 'lilypond_repository_directory'" errex fi GUBDIR=`procFN $1` LILYREPODIR=`procFN $2` LILYTESTBASE=$3 LILYTESTVER=$4 echo "Trying to" echo " - build regression testbase for '$LILYTESTBASE' of local lilypond repository '$LILYREPODIR'" echo " - do a full build of lilypond version '$LILYTESTVER'" echo "with GUB located in '$GUBDIR'" # abort if a git-daemon is active ps ax | grep git-daemon | grep -v grep | grep git-daemon if [ $? -eq 0 ]; then echo "ERROR: A git-daemon is already running on this system!" errex fi # abort if GUBDIR parameter is invalid if [ ! -f "$GUBDIR/bin/gub" ]; then echo "ERROR: gub_directory parameter '$GUBDIR' invalid!" errex fi mkdir -p $GUBDIR/regtests $GUBDIR/target $GUBDIR/uploads # abort if LILYREPODIR parameter is invalid if [ ! -f "$LILYREPODIR/lily/lilypond-version.cc" ]; then echo "ERROR: lilypond_repository_directory '$LILYREPODIR' invalid!" errex fi # create temporary branches cd $LILYREPODIR git branch -f tmp-gubllt-test $LILYTESTBASE if [ $? -ne 0 ]; then echo "ERROR: could not create branch 'tmp-gubllt-test', maybe there is no branch/commit $LILYTESTBASE!" errex fi # create a temporary git server directory in GUBDIR, abort if this fails TMPSRVDIR=$(mktemp -d -t -p $GUBDIR/ gubllt-XXXXXXXXXX) if [ ! -d "$TMPSRVDIR" ]; then echo "ERROR: We failed to created the directory $TMPSRVDIR!" TMPSRVDIR="" errex else echo "INFO: Temporary git daemon directory is $TMPSRVDIR" fi # create the lilypong.git link in TMPSRVDIR ln -s $LILYREPODIR $TMPSRVDIR/lilypond.git # start git-daemon in the background $GITEXEC daemon --log-destination=none --export-all --reuseaddr --base-path=$TMPSRVDIR/ $TMPSRVDIR &> /dev/null & GITPID=$! echo "INFO: Started git daemon with PID $GITPID" # wait until git-daemon starts to provide its service ... abort if this does not occur within a reasonable time # it is assumed that every lilypond git repository has a valid branch master, so test for that. i=0 while [ $i -le 10 ] do ((i++)) echo Waiting for git daemon ... TESTOUT=`git ls-remote git://localhost/lilypond.git master 2>&1 | grep -o refs/heads/master` if [ "$TESTOUT" == "refs/heads/master" ]; then break; fi if [ $i -eq 10 ]; then echo "ERROR: Git daemon timed out!" errex fi sleep 1 done # try to build LILYTESTBASE regtest archive cd $GUBDIR rm -rf regtests/* uploads/* target/*/*/*lilypond* ./downloads/lilypond/git/refs/heads/localhost/lilypond.git/tmp-gubllt-test bin/gub --platform=linux-64 git://localhost/lilypond-test.git?branch=tmp-gubllt-test TESTOUT=`ls uploads/lilypond*.*.*-*.test-output.tar.bz2` if [ "x$TESTOUT" == "x" ]; then echo "ERROR: creating testbase regression test archive failed!" errex fi # now try a full gub build of LILYTESTVER cd $LILYREPODIR git branch -f tmp-gubllt-test $LILYTESTVER if [ $? -ne 0 ]; then echo "ERROR: could not create branch 'tmp-gubllt-test', maybe there is no branch/commit $LILYTESTVER!" errex fi cd $GUBDIR cp $TESTOUT regtests/lilypond-0.00.0-1.test-output.tar.bz2 touch regtests/ignore rm -rf uploads/* target/*/*/*lilypond* make LILYPOND_REPO_URL=git://localhost/lilypond.git LILYPOND_BRANCH=tmp-gubllt-test lilypond # kill our git daemon and remove our temporary git server directory kill -n 9 -- $(ps -o pid= --ppid $GITPID) rm -rf $TMPSRVDIR exit 0