#!/bin/sh
# Process the logs in a certain directory and construct the HTML pages
# summarizing them
#
# We only construct the new html pages if either
# * No HTML files exist yet
# * .force exists in this directory (set by pdispatch when a log is
# removed by package build success)
# * A new log file has appeared since the last run.
#
# Individual summary data for the logs is saved between runs instead of
# being recomputed each time. Removing the old data for logs that
# no longer exist is the responsibility of the dopackages script when
# starting a new build.
# echo 'processlogs: at '`date`', begin'
arch=$1
# establish which directory the logfiles live in (leave out for
# backwards compatibility)
buildlogdir=$(realpath .)
if [ "$2" != "" ]; then
buildlogdir="$2"
fi
baselogdir=$(basename ${buildlogdir})
# establish which directory INDEX lives in (leave out for
# backwards compatibility)
indexlogdir=$(realpath .)
if [ "$3" != "" ]; then
indexlogdir="$3";
fi
# allow this script to be run from anywhere in the tree
scriptdir=$(dirname $0)
errorscript=$scriptdir/processonelog
# Figure out which arch we're building for
pbc=${PORTBUILD_CHECKOUT:-/a/portbuild}
pbd=${PORTBUILD_DATA:-/a/portbuild}
. ${pbc}/admin/conf/admin.conf
. ${pbc}/conf/server.conf
. ${pbd}/${arch}/portbuild.conf
# get the list of buildlogs.
cd ${buildlogdir}
if [ -e .force -o \! -e index.html ]; then
rm -f .force
force=1
else
force=0
fi
alllogs=$(find . -maxdepth 1 -type f \( -name '*.log' -o -name '*.log.bz2' \) | sed -e 's,^./,,' 2>/dev/null)
if [ -e .stamp -a ${#alllogs} -eq 0 ]; then
exit
fi
# create a name for the tempfile
of=.index.html
# XXX temporary
test -f .logs && rm -f .logs
mkdir -p .logs
#
# Read the log-files and write summaries to .logs in the format
# $filename|$portname|$affected|$logsize|$dir|$maintainer|\
# $reason|$tag|$broken|$datetime
#
echo "processlogs: at $(date), begin processing log files for ${arch} in ${baselogdir}"
rm -f .logs/.all
set -- ${alllogs}
gotnew=0
while [ $# -ge 1 ]; do
log=$1
shift
if [ ${log%.log.bz2} != ${log} -a -e ${log%.bz2} ]; then
# We have both a .log.bz2 and a .log, assume the former is stale
rm -f ${log}
continue
fi
# basename with .log and .log.bz2 stripped
base=${log%.bz2}
base=${log%.log}
if [ ${log} -nt .stamp -o ! -e .logs/${base} ]; then
# Save to the base name so the data persists after the log is
# compressed
${errorscript} ${log} ${indexlogdir} > .logs/${base}
gotnew=1
fi
cat .logs/${base} >> .logs/.all
done
touch .stamp
n_logs=0
if [ -e .logs/.all ]; then
n_logs=$(cat .logs/.all | wc -l)
fi
echo "processlogs: at "`date`", end processing log files for ${arch} in ${baselogdir}"
if [ ${force} -eq 0 -a ${gotnew} -eq 0 ]; then
# Nothing new to do
exit
fi
header() {
echo "
Package building errors" >$of
echo "" >>$of
echo "Package building errors
" >>$of
echo "View by " >>$of
echo "[ port " >>$of
echo "| maintainer " >>$of
echo "| category " >>$of
echo "| error " >>$of
echo "| builddate " >>$of
echo "]
" >>$of
if [ ${n_logs} = "0" ]; then
echo "No errors (yet)" >>$of
else
if [ -s .updated ]; then
echo "ports update finished at: $(cat .updated)
" >> $of
fi
latest=$(ls -rtTl *.log *.log.bz2 2> /dev/null | tail -1 | awk '{printf("%s %s %s %s\n",$6,$7,$8,$9)}')
echo "Timestamp of newest log: $latest
" >> $of
echo "\"Aff.\" is number of ports that depend on this one
" >> $of
echo "\"[B]\" indicates port is marked BROKEN (Note: BROKEN ports are not frequently rebuilt so they may not be listed here)
" >> $of
echo "${n_logs} errors
" >> $of
echo "" >>$of
echo "$1
" >>$of
fi
}
footer() {
echo "
" >>$of
echo "" >>$of
echo "" >>$of
}
# Now reread the .logs/.all file and create the reports.
# echo 'processlogs: at '`date`', create default output'
#
# Create "default" output, sorted on portname
#
header "Port | Aff. | Size | ${VCS} | Maintainer | Reason | Build date | "
if [ ${n_logs} -gt 0 ]; then
sort .logs/.all | while read line; do
IFS="|"
set -- ${line}
unset IFS
affby=$3
size=$4
portname=$5
maintainer=$6
reason=$7
datestamp=${10}
echo "" >> $of
echo "| $2 | " >> $of
test "${affby}" = "0" -o "${affby}" = "-1" && affby=" "
echo "${affby} | " >> $of
echo "$size Kb | " >> $of
if [ "$portname" != "" -a "$portname" != "NONE" ] ; then
portname="$portname"
else
portname='?'
fi
echo "$portname | " >> $of
if [ "$maintainer" != "" -a "$maintainer" != "NONE" ] ; then
maintainer="$maintainer"
else
maintainer='?'
fi
echo "$maintainer | " >> $of
echo "" >> $of
test "$9" = "broken" && echo "[B]" >> $of
echo "$reason" >> $of
echo " | " >> $of
datestamp=`echo ${datestamp} | sed -e "s/_/ /g"`
if [ "$datestamp" == "" -o "$datestamp" == "NONE" ] ; then
datestamp='?'
fi
echo "$datestamp | " >> $of
echo "
" >> $of
done
fi
footer ""
mv -f $of index.html
# echo 'processlogs: at '`date`', create output sorted by category'
#
# Create output by category
#
header "${VCS} | Aff. | Size | Port | Maintainer | Reason | Build date | "
if [ ${n_logs} -gt 0 ]; then
sort -t \| +4 .logs/.all | while read line; do
IFS="|"
set -- ${line}
unset IFS
affby=$3
size=$4
portname=$5
maintainer=$6
reason=$7
datestamp=${10}
echo "" >> $of
if [ "$portname" != "" -a "$portname" != "NONE" ] ; then
portname="$portname"
else
portname='?'
fi
echo "| $portname | " >> $of
test "${affby}" = "0" -o "${affby}" = "-1" && affby=" "
echo "${affby} | " >> $of
echo "$size Kb | " >> $of
echo "$2 | " >> $of
if [ "$maintainer" != "" -a "$maintainer" != "NONE" ] ; then
maintainer="$maintainer"
else
maintainer='?'
fi
echo "$maintainer | " >> $of
echo "" >> $of
test "$9" = "broken" && echo "[B]" >> $of
echo "$reason" >> $of
echo " | " >> $of
datestamp=`echo ${datestamp} | sed -e "s/_/ /g"`
if [ "$datestamp" == "" -o "$datestamp" == "NONE" ] ; then
datestamp='?'
fi
echo "$datestamp | " >> $of
echo "
" >> $of
done
fi
footer ""
mv -f $of index-category.html
# echo 'processlogs: at '`date`', create output sorted by maintainer'
#
# Create output by maintainer
#
header "Maintainer | Port | Aff. | Size | ${VCS} | Reason | Build date | "
if [ ${n_logs} -gt 0 ]; then
sort -t \| +5 .logs/.all | while read line; do
IFS="|"
set -- ${line}
unset IFS
affby=$3
size=$4
portname=$5
maintainer=$6
reason=$7
datestamp=${10}
echo "" >> $of
if [ "$maintainer" != "" -a "$maintainer" != "NONE" ] ; then
maintainer="$maintainer"
else
maintainer='?'
fi
echo "| $maintainer | " >> $of
echo "$2 | " >> $of
test "${affby}" = "0" -o "${affby}" = "-1" && affby=" "
echo "${affby} | " >> $of
echo "$size Kb | " >> $of
if [ "$portname" != "" -a "$portname" != "NONE" ] ; then
portname="$portname"
else
portname='?'
fi
echo "$portname | " >> $of
echo "" >> $of
test "$9" = "broken" && echo "[B]" >> $of
echo "$reason" >> $of
echo " | " >> $of
datestamp=`echo ${datestamp} | sed -e "s/_/ /g"`
if [ "$datestamp" == "" -o "$datestamp" == "NONE" ] ; then
datestamp='?'
fi
echo "$datestamp | " >> $of
echo "
" >> $of
done
fi
footer ""
mv -f $of index-maintainer.html
# echo 'processlogs: at '`date`', create output sorted by error'
#
# Create output by error
#
header "Reason | Port | Aff. | Size | ${VCS} | Maintainer | Build date | "
if [ ${n_logs} -gt 0 ]; then
sort -t \| +7 .logs/.all | while read line; do
IFS="|"
set -- ${line}
unset IFS
affby=$3
size=$4
portname=$5
maintainer=$6
reason=$7
datestamp=${10}
echo "" >> $of
echo "| " >> $of
test "$9" = "broken" && echo "[B]" >> $of
echo "$reason" >> $of
echo " | " >> $of
echo "$2 | " >> $of
test "${affby}" = "0" -o "${affby}" = "-1" && affby=" "
echo "${affby} | " >> $of
echo "$size Kb | " >> $of
if [ "$portname" != "" -a "$portname" != "NONE" ] ; then
portname="$portname"
else
portname='?'
fi
echo "$portname | " >> $of
if [ "$maintainer" != "" -a "$maintainer" != "NONE" ] ; then
maintainer="$maintainer"
else
maintainer='?'
fi
echo "$maintainer | " >> $of
datestamp=`echo ${datestamp} | sed -e "s/_/ /g"`
if [ "$datestamp" == "" -o "$datestamp" == "NONE" ] ; then
datestamp='?'
fi
echo "$datestamp | " >> $of
echo "
" >> $of
done
fi
footer ""
mv -f $of index-reason.html
# echo 'processlogs: at '`date`', create output sorted by builddate'
#
# Create output by builddate
#
header "Build date | Port | Aff. | Size | ${VCS} | Maintainer | Reason | "
if [ ${n_logs} -gt 0 ]; then
sort -t \| +9 .logs/.all | while read line; do
IFS="|"
set -- ${line}
unset IFS
affby=$3
size=$4
portname=$5
maintainer=$6
reason=$7
datestamp=${10}
echo "" >> $of
datestamp=`echo ${datestamp} | sed -e "s/_/ /g"`
if [ "$datestamp" == "" -o "$datestamp" == "NONE" ] ; then
datestamp='?'
fi
echo "| $datestamp | " >> $of
echo "$2 | " >> $of
test "${affby}" = "0" -o "${affby}" = "-1" && affby=" "
echo "${affby} | " >> $of
echo "$size Kb | " >> $of
if [ "$portname" != "" -a "$portname" != "NONE" ] ; then
portname="$portname"
else
portname='?'
fi
echo "$portname | " >> $of
if [ "$maintainer" != "" -a "$maintainer" != "NONE" ] ; then
maintainer="$maintainer"
else
maintainer='?'
fi
echo "$maintainer | " >> $of
echo "" >> $of
test "$9" = "broken" && echo "[B]" >> $of
echo "$reason" >> $of
echo " | " >> $of
echo "
" >> $of
done
fi
footer ""
mv -f $of index-builddate.html
# echo 'processlogs: at '`date`', create maintainer list'
#
# Get list of maintainers.
if [ ${n_logs} -gt 0 ]; then
cut -f 6 -d \| .logs/.all | sort -fu > maintainers
else
cat /dev/null > maintainers
fi
# echo 'processlogs: at '`date`', done'