gdb-buildbot/scripts/update-logs.sh
Sergio Durigan Junior 78ac2523c8 New method for storing log files.
This is a new method developed to store the log files for builds.  It
doesn't use git anymore, but instead uses a set of sqlite databases +
scripts + xz in order to make the files smaller and more organized.
Also, it is now possible to safely remove old build logs.
2016-11-10 01:45:57 -05:00

136 lines
2.9 KiB
Bash
Executable file

#!/bin/bash
set -e
umask u=rw,g=r,o=r
usage ()
{
cat > /dev/stderr <<EOF
$0 -- Update build logs for builder
Usage: $0 [-c|--commit COMMIT] [-b|--builder BUILDER] [--branch BRANCH] [-d|--base-directory DIR] [-t|--is-try-sched yes|no] [-h|--help]
EOF
}
err ()
{
local msg=$1
echo "ERROR: $msg" > /dev/stderr
exit 1
}
msg ()
{
local msg=$1
echo ">>> INFO: $msg"
}
while test "$1" != "" ; do
case "$1" in
"-c"|"--commit")
COMMIT=$2
shift 2
;;
"-b"|"--builder")
BUILDER=$2
shift 2
;;
"-d"|"--base-directory")
BASE_DIR=$2
shift 2
;;
"-h"|"--help")
usage
exit 0
;;
"-t"|"--is-try-sched")
IS_TRY_SCHED=$2
shift 2
;;
"--branch")
BRANCH=$2
shift 2
;;
*)
usage
exit 1
;;
esac
done
DIR=$BASE_DIR/$BUILDER/
if test ! -d $DIR ; then
msg "$DIR is not a valid directory. Creeating it..."
(umask 0022 && mkdir --verbose -p $DIR)
fi
cd $DIR
DB_NAME=$DIR/${BUILDER}.db
if test ! -f $DB_NAME ; then
msg "Database $DB_NAME does not exist. Creating it..."
sqlite3 $DB_NAME "CREATE TABLE logs(commitid TEXT, branch TEXT DEFAULT 'master', trysched BOOLEAN DEFAULT 0, timestamp TIMESTAMP PRIMARY KEY DEFAULT (strftime('%s', 'now')) NOT NULL)"
fi
COMMIT_2_DIG=`echo $COMMIT | sed 's/^\(..\).*$/\1/'`
CDIR=$COMMIT_2_DIG/$COMMIT/
ISTRY=0
if test "$IS_TRY_SCHED" = "yes" ; then
CDIR=try/${CDIR}
ISTRY=1
fi
CDIR_EXISTS=`sqlite3 $DB_NAME "SELECT commitid FROM logs WHERE commitid = '${COMMIT}'"`
if test -n "$CDIR_EXISTS" ; then
# If this is a try build, the user is doing a rebuild.
# If this is a normal build, someone triggered a rebuild.
# Either way, we need to delete the current log dir.
msg "Log dir $CDIR already exists. Deleting it so that we can update the logs..."
rm --verbose -rf $CDIR
fi
if test ! -d $CDIR ; then
msg "Creating directory structure $CDIR..."
(umask 0022 && mkdir --verbose -p $CDIR)
fi
cd $CDIR
TMP_DIR=$DIR/tmp/$COMMIT/
msg "Moving log files to $PWD..."
mv --verbose $TMP_DIR/* .
rmdir $TMP_DIR
msg "Compressing log files..."
find . -type f ! -name "*.xz" | xargs xz --verbose --compress
PREV_COMMIT=`sqlite3 $DB_NAME "SELECT commitid FROM logs WHERE branch = '$BRANCH' AND trysched = 0 ORDER BY timestamp DESC LIMIT 1"`
if test "$IS_TRY_SCHED" != "yes" ; then
PREV_2DIG=`echo $PREV_COMMIT | sed 's/^\(..\).*$/\1/'`
ln -s $DIR/$PREV_2DIG/$PREV_COMMIT PREVIOUS_COMMIT
ln -s $DIR/$CDIR $DIR/$PREV_2DIG/$PREV_COMMIT/NEXT_COMMIT
fi
msg "Update database..."
sqlite3 $DB_NAME "INSERT INTO logs(commitid, branch, trysched) VALUES('$COMMIT', '$BRANCH', $ISTRY)"
msg "Creating README.txt..."
cat > README.txt <<EOF
=== README ===
Logs for: $COMMIT
Branch tested: $BRANCH
Previous commit: $PREV_COMMIT
Patch: <http://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=${COMMIT}>
EOF
exit 0