aboutsummaryrefslogtreecommitdiff
path: root/Tools/scripts/tindex
blob: deb6af315593360991b084c6ed1bc7fbbb5fd4fa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/bin/sh
#
# INDEX build tinderbox script.  Build an INDEX for all supported FreeBSD branches
# using the latest value of OSVERSION according to the src trees.  If the build
# fails, yowl about it on ${REPORT_ADDRESS}  If not, copy the index to www.freebsd.org so
# that 'make fetchindex' sees it.
#
# When INDEX is broken, assemble the list of committers who touched files
# on the most recent 'cvs update', and put those committers "on the hook".
# These committers all stay on the hook until INDEX is buildable again.
#
# MAINTAINER= erwin@FreeBSD.org
#

# --------------------------------------------------------
# Change these!

# Address for success/failure reports
REPORT_ADDRESS=root@localhost

# Address for script errors
ERROR_ADDRESS=root@localhost

# Where to scp the resulting indexes after build
SCP_DEST_HOST=root@localhost
SCP_DEST_TMP=/tmp
SCP_DEST_DIR=/usr/local/www/ports

# Location of ports tree and source trees
export BASEDIR=/local0/tmp/kris/tindex
export PORTSDIR=${BASEDIR}/ports
export SRCDIR6=${BASEDIR}/src.6
export SRCDIR7=${BASEDIR}/src.7
export SRCDIR8=${BASEDIR}/src.8

# Target architecture if not set in the environment
if [ "${ARCH}" = "" ]; then
	export ARCH=i386
fi

# SSH key to use for copying INDEXes to www host (if non-default)
export SSHKEY="-i /home/kris/.ssh/id_dsa-index"

# --------------------------------------------------------

blame() {
  # Find out who is responsible for current version of file $1

  # Fastest way to extract is from the CVS "FreeBSD" tag
  ident=$(ident $1 2>/dev/null | grep '$FreeBSD')
  who=$(echo $ident | awk '{print $6}')

  if [ -z "$ident" ]; then
    # No FreeBSD tag, fall back to slower method of parsing cvs logs.
    rev=$(cvs status $1 2>/dev/null | grep 'Working revision:' | awk '{print $3}')
    if [ "$rev" != "No" ]; then    # "No" means not under CVS control
      ident=$(cvs -Rq log -r$rev $1 | grep "^date:" | head -1 | sed 's,;,,g')
      who=$(echo $ident | awk '{print $5}')
    fi
  fi

  echo $who
}

indexfail() {
  BRANCH=$1

  # Leave a cookie behind so that we know when the index is fixed
  touch ${PORTSDIR}/broken.${BRANCH}

  (
    echo "INDEX build failed with errors:";
    len=$(wc -l index.out | awk '{print $1}')
    if [ "$len" -gt "40" ]; then
      head -20 index.out
      echo "[...]"
      tail -20 index.out
    else
      cat index.out
    fi

    len=$(wc -l index.err | awk '{print $1}')
    if [ "$len" -gt "40" ]; then
      head -20 index.err
      echo "[...]"
      tail -20 index.err
    else
      cat index.err
    fi

    # Find out which committers are on the hook

    commits=$(grep ^U ${PORTSDIR}/cvs.log | grep -v INDEX | awk '{print $2}')
    for i in ${commits}; do
	blame $i >> ${PORTSDIR}/hook
    done
    sort -u ${PORTSDIR}/hook > ${PORTSDIR}/hook.new
    mv ${PORTSDIR}/hook.new ${PORTSDIR}/hook
    echo
    echo "Committers on the hook:"
    tr -s '\n' ' ' < ${PORTSDIR}/hook
    echo
    echo 
    echo "Most recent CVS update was:";
    grep -v '/work$' cvs.log | grep -v '^\?'
  ) | mail -s "INDEX build failed for ${BRANCH}" ${REPORT_ADDRESS}
  exit 1
}

checkfixed() {
  BRANCH=$1

  # If the cookie exists that means that this is the first build for which the
  # INDEX succeeded, so announce this.
  if [ -e ${PORTSDIR}/broken.${BRANCH} ]; then
    rm -f ${PORTSDIR}/broken.${BRANCH}
    mail -s "INDEX now builds successfully on ${BRANCH}" ${REPORT_ADDRESS} < /dev/null
  fi
}

createtmpdir() {
    TMPDIR=`ssh ${SCP_DEST_HOST} "mktemp -qd ${SCP_DEST_TMP}/tindex.XXXXXX"`
    if [ $? -ne 0 ]; then
	echo "$0: Can't create temp file, exiting..."
	exit 1
    fi
}
    

# Sanitize the environment so that the indexes aren't customized by the
# local machine settinge
export __MAKE_CONF=/dev/null
export PORT_DBDIR=/nonexistent
export PKG_DBDIR=/nonexistent
export INDEX_PRISTINE=1
export INDEX_JOBS=4
export INDEX_QUIET=1

# First update the source trees to get current OSVERSION
cd ${SRCDIR6}/sys/sys
cvs -Rq update -PdA -r RELENG_6 param.h
OSVERSION6=$(awk '/^#define[[:blank:]]__FreeBSD_version/ {print $3}' < ${SRCDIR6}/sys/sys/param.h)

cd ${SRCDIR7}/sys/sys
cvs -Rq update -PdA -r RELENG_7 param.h
OSVERSION7=$(awk '/^#define[[:blank:]]__FreeBSD_version/ {print $3}' < ${SRCDIR7}/sys/sys/param.h)

cd ${SRCDIR8}/sys/sys
cvs -Rq update -PdA param.h
OSVERSION8=$(awk '/^#define[[:blank:]]__FreeBSD_version/ {print $3}' < ${SRCDIR8}/sys/sys/param.h)


cd ${PORTSDIR}
rm -f INDEX-6 INDEX-6.bz2 INDEX-7 INDEX-7.bz2 INDEX-8 INDEX-8.bz2 
(cvs -Rq update -PdA 2>1 ) > cvs.log
if grep -q ^C cvs.log ; then
  (echo "cvs update failed with conflicts:";
    grep ^C cvs.log) | mail -s "Ports cvsup failed" ${ERROR_ADDRESS}
    exit 1
fi
  
BRANCH=6.x
export OSVERSION=${OSVERSION6}
echo "Building INDEX for ${BRANCH} with OSVERSION=${OSVERSION}"
cd ${PORTSDIR}
((make index 2> index.err) > index.out) || indexfail ${BRANCH}
if [ -s index.err ]; then
	indexfail ${BRANCH}
fi
checkfixed ${BRANCH}

createtmpdir
bzip2 -kf ${PORTSDIR}/INDEX-6
scp -q ${SSHKEY} ${PORTSDIR}/INDEX-6 ${PORTSDIR}/INDEX-6.bz2 ${SCP_DEST_HOST}:${TMPDIR} || mail -s "Cannot copy INDEX-6 to temp dir" ${ERROR_ADDRESS}
ssh ${SCP_DEST_HOST} "/bin/mv ${TMPDIR}/INDEX-6 ${SCP_DEST_DIR}; /bin/mv ${TMPDIR}/INDEX-6.bz2 ${SCP_DEST_DIR}; rmdir ${TMPDIR}" || mail -s "Cannot move INDEX-6 to final dir" ${ERROR_ADDRESS}

BRANCH=7.x
export OSVERSION=${OSVERSION7}
echo "Building INDEX for ${BRANCH} with OSVERSION=${OSVERSION}"
cd ${PORTSDIR}
((make index 2> index.err) > index.out) || indexfail ${BRANCH}
if [ -s index.err ]; then
	indexfail ${BRANCH}
fi
checkfixed ${BRANCH}

createtmpdir
bzip2 -kf ${PORTSDIR}/INDEX-7
scp -q ${SSHKEY} ${PORTSDIR}/INDEX-7 ${PORTSDIR}/INDEX-7.bz2 ${SCP_DEST_HOST}:${TMPDIR} || mail -s "Cannot copy INDEX-7 to temp dir" ${ERROR_ADDRESS}
ssh ${SCP_DEST_HOST} "/bin/mv ${TMPDIR}/INDEX-7 ${SCP_DEST_DIR}; /bin/mv ${TMPDIR}/INDEX-7.bz2 ${SCP_DEST_DIR}; rmdir ${TMPDIR}" || mail -s "Cannot move INDEX-7 to final dir" ${ERROR_ADDRESS}

BRANCH=8.x
export OSVERSION=${OSVERSION8}
echo "Building INDEX for ${BRANCH} with OSVERSION=${OSVERSION}"
cd ${PORTSDIR}
((make index 2> index.err) > index.out) || indexfail ${BRANCH}
if [ -s index.err ]; then
	indexfail ${BRANCH}
fi
checkfixed ${BRANCH}

createtmpdir
bzip2 -kf ${PORTSDIR}/INDEX-8
scp -q ${SSHKEY} ${PORTSDIR}/INDEX-8 ${PORTSDIR}/INDEX-8.bz2 ${SCP_DEST_HOST}:${TMPDIR} || mail -s "Cannot copy INDEX-8 to temp dir" ${ERROR_ADDRESS}
ssh ${SCP_DEST_HOST} "/bin/mv ${TMPDIR}/INDEX-8 ${SCP_DEST_DIR}; /bin/mv ${TMPDIR}/INDEX-8.bz2 ${SCP_DEST_DIR}; rmdir ${TMPDIR}" || mail -s "Cannot move INDEX-8 to final dir" ${ERROR_ADDRESS}

# All indexes built successfully, clear the hook
rm -f ${PORTSDIR}/hook