Add harbour for GZX
[harbours.git] / matrix.sh
blob36642038b65d064dc2bc312fbcce43db93757479
1 #!/bin/sh
4 # Copyright (c) 2013 Vojtech Horky
5 # All rights reserved.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
11 # - Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # - Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
16 # - The name of the author may not be used to endorse or promote products
17 # derived from this software without specific prior written permission.
19 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 HELENOS_ROOT="$1"
32 ARCHITECTURES="$2"
33 HARBOURS="$3"
34 PARALLELISM=8
36 HSCT_HOME=`which -- "$0" 2>/dev/null`
37 # Maybe, we are running Bash
38 [ -z "$HSCT_HOME" ] && HSCT_HOME=`which -- "$BASH_SOURCE" 2>/dev/null`
39 HSCT_HOME=`dirname -- "$HSCT_HOME"`
40 HSCT="$HSCT_HOME/hsct.sh"
42 msg() {
43 echo ">>>" "$@" >&2
45 msg2() {
46 echo " =>" "$@" >&2
48 msg3() {
49 echo " ->" "$@" >&2
52 log_tail() {
53 tail -n 5 "$1" | sed 's#.*# !!! &#'
56 tap_init() {
57 TAP_FILENAME="$1"
58 TAP_COUNTER=1
59 echo "1..$2" >"$TAP_FILENAME"
62 tap_ok() {
63 echo "ok $TAP_COUNTER $1" >>"$TAP_FILENAME"
64 TAP_COUNTER=$(( $TAP_COUNTER + 1 ))
67 tap_fail() {
68 echo "not ok $TAP_COUNTER $1" >>"$TAP_FILENAME"
69 if [ -n "$2$3" ]; then
71 echo " ---"
72 if [ -n "$2" ]; then
73 echo " message: |+"
74 echo " ------ Last 10 lines of $2 -------"
75 tail -n 10 "$2" \
76 | sed 's#^.*# &#' \
77 | sed 's/^\([\t ]*\)#/\1\\#/'
78 else
79 echo " message: $3"
81 echo " ..."
82 ) >>"$TAP_FILENAME"
84 TAP_COUNTER=$(( $TAP_COUNTER + 1 ))
87 tap_test() {
88 if [ "$1" -eq 0 ]; then
89 tap_ok "$2"
90 else
91 tap_fail "$2" "$3"
95 arch_human_readable() {
96 _arch=`echo "$1" | cut '-d-' -f 1`
97 _machine=`echo "$1" | cut '-d-' -f 2-`
98 [ "$_machine" = "$_arch" ] && _machine="";
99 echo "<span class=\"arch\">"
100 case "$_arch" in
101 ia32) echo "IA 32";;
102 ia64) echo "IA 64";;
103 amd64) echo "AMD 64";;
104 arm32) echo "ARM 32";;
105 mips32) echo "MIPS 32";;
106 mips64) echo "MIPS 64";;
107 ppc32) echo "PowerPC 32";;
108 sparc32) echo "SPARC 32";;
109 sparc64) echo "SPARC 64";;
110 *) echo "$_arch";;
111 esac
112 echo "</span>"
113 if [ -z "$_machine" ]; then
114 echo ""
115 else
116 echo "<br /><span class=\"machine\">"
118 case "$_machine" in
119 beagleboardxm) echo "BeagleBoard-xM";;
120 beaglebone) echo "BeagleBone";;
121 gta02) echo "GTA02";;
122 integratorcp) echo "Integrator/CP";;
123 raspberrypi) echo "Raspberry Pi";;
124 malta-be) echo "Malta (BE)";;
125 malta-le) echo "Malta (LE)";;
126 msim) echo "MSIM";;
127 i460gx) echo "i460GX";;
128 leon3) echo "LEON3";;
129 "") ;;
130 *) echo "$_machine";;
131 esac
132 [ -z "$_machine" ] || echo "</span>"
136 # Resolve correct ordering of all harbours
139 # Allow hide harbours temporarily by prefixing them with e.g. _underscore
140 ALL_HARBOURS=`ls $HSCT_HOME/[a-zA-Z]*/HARBOUR | sed 's#.*/\([^/]*\)/HARBOUR$#\1#'`
142 # Export dependencies to HARBOUR_DEPS_{harbour_name}
143 for harbour in $ALL_HARBOURS; do
144 deps=`cd $HSCT_HOME/$harbour/; . ./HARBOUR ; echo $shiptugs`
145 eval HARBOUR_DEPS_$harbour="\"$deps\""
146 done
149 # Determine the correct ordering
150 ALL_HARBOURS_CORRECT_ORDER=""
151 HARBOURS_NOT_RESOLVED="$ALL_HARBOURS"
153 while [ -n "$HARBOURS_NOT_RESOLVED" ]; do
154 not_resolved_yet=""
155 sed_remove="-e s:x:x:"
156 found_one=false
157 for harbour in $HARBOURS_NOT_RESOLVED; do
158 deps=`eval echo \\$HARBOUR_DEPS_$harbour`
159 if [ -z "$deps" ]; then
160 ALL_HARBOURS_CORRECT_ORDER="$ALL_HARBOURS_CORRECT_ORDER $harbour";
161 sed_remove="$sed_remove -e s:$harbour::g"
162 found_one=true
163 else
164 not_resolved_yet="$not_resolved_yet $harbour";
166 done
167 for harbour in $ALL_HARBOURS; do
168 deps=`eval echo \\$HARBOUR_DEPS_$harbour | sed $sed_remove`
169 eval HARBOUR_DEPS_$harbour="\"$deps\""
170 done
171 HARBOURS_NOT_RESOLVED="$not_resolved_yet"
172 if ! $found_one; then
173 echo "There is circular dependency!"
174 exit 1
176 done
178 ALL_HARBOURS="$ALL_HARBOURS_CORRECT_ORDER"
180 # -- End of correct ordering resolving
184 if [ -z "$HELENOS_ROOT" ]; then
185 RESULTS=true
186 BUILD=false
187 else
188 RESULTS=true
189 BUILD=true
193 if $BUILD; then
194 [ -z "$ARCHITECTURES" ] && exit 1
195 [ -z "$HARBOURS" ] && exit 1
197 if [ "$ARCHITECTURES" == "all" ]; then
198 ARCHITECTURES="amd64 arm32/beagleboardxm arm32/beaglebone arm32/gta02 arm32/integratorcp arm32/raspberrypi ia32 ia64/i460GX ia64/ski mips32/malta-be mips32/malta-le mips32/msim ppc32 sparc32/leon3 sparc64/niagara sparc64/ultra"
200 if [ "$HARBOURS" == "all" ]; then
201 HARBOURS="$ALL_HARBOURS"
202 # We know that the ordering is correct, i.e. we build dependent
203 # packages first.
204 # This speeds-up the build if a dependent package fails as we
205 # do not try to rebuild it with each package that depends on
206 # it.
207 BUILD_OPTS="--no-deps"
211 msg "Harbour status matrix generator."
212 if $BUILD; then
213 msg2 "HelenOS root is at $HELENOS_ROOT."
215 msg2 "Coastline builder is at $HSCT."
217 if $BUILD; then
218 msg "Matrix generation started."
219 msg2 "Removing old results..."
221 rm -rf matrix
222 mkdir -p matrix
223 mkdir -p mirror
225 rm -rf tap
226 mkdir -p tap
228 # Count number of harbours to produce correct TAP plans
229 HARBOUR_COUNT=0
230 for HARBOUR in $HARBOURS; do
231 HARBOUR_COUNT=$(( $HARBOUR_COUNT + 1 ))
232 done
234 mkdir -p build-fetch
235 echo $ARCHITECTURES | (
236 read ARCH OTHERS_IGNORED_XXX
238 cd build-fetch
239 echo "root = $HELENOS_ROOT" >hsct.conf
240 echo "arch = ia32" >>hsct.conf
241 echo "sources = ../mirror/" >>hsct.conf
242 # We can expect we build matrix on a machine with a
243 # reasonable network connection.
244 echo "wget_opts = -T 30 -t 3" >>hsct.conf
246 msg "Downloading all the sources..."
247 tap_init ../tap/00-fetch.tap $HARBOUR_COUNT
248 for HARBOUR in $HARBOURS; do
249 msg2 "Fetching for $HARBOUR..."
250 $HSCT fetch $HARBOUR >>$HARBOUR.fetch.log 2>&1
251 tap_test "$?" "$HARBOUR (fetch)" "$HARBOUR.fetch.log"
252 done
255 for ARCH in $ARCHITECTURES; do
256 ARCH_FILENAME="`echo $ARCH | tr '/' '-'`"
257 ARCH_DIR="build-$ARCH_FILENAME"
258 TARBALL_DIR="matrix/$ARCH_FILENAME"
259 msg ""
260 msg "Building for $ARCH (into $ARCH_DIR)."
261 msg ""
262 mkdir -p "$ARCH_DIR"
263 mkdir -p "$TARBALL_DIR"
265 cd $ARCH_DIR
267 tap_init ../tap/$ARCH_FILENAME.tap $(( $HARBOUR_COUNT + 1 ))
269 if ! [ -r hsct.conf ]; then
271 set -o errexit
272 msg2 "Preparing for first build..."
273 $HSCT init "$HELENOS_ROOT" "$ARCH" build &>init.log
274 echo "parallel = $PARALLELISM" >>hsct.conf
275 echo "sources = ../mirror/" >>hsct.conf
277 RC=$?
278 tap_test $RC "initialization ($ARCH)" "init.log"
279 if [ $RC -ne 0 ]; then
280 log_tail init.log
281 for HARBOUR in $HARBOURS; do
282 tap_fail "$HARBOUR ($ARCH)" "" "Initialization failed."
283 done
284 exit 1
288 for HARBOUR in $HARBOURS; do
290 set -o errexit
291 mkdir -p build
292 echo -n "" >build/$HARBOUR.log
294 msg2 "Building $HARBOUR..."
295 $HSCT build --no-fetch $BUILD_OPTS $HARBOUR >build/$HARBOUR.log 2>&1
297 msg3 "Packaging..."
298 $HSCT package $HARBOUR >>build/$HARBOUR.log 2>&1
300 msg3 "Creating the tarball..."
301 $HSCT archive $HARBOUR >>build/$HARBOUR.log 2>&1
303 cp archives/$HARBOUR.tar.xz ../$TARBALL_DIR/$ARCH_FILENAME-$HARBOUR.tar.xz
305 RC=$?
306 tap_test $RC "$HARBOUR ($ARCH)" "build/$HARBOUR.log"
307 if [ $RC -ne 0 ]; then
308 log_tail build/$HARBOUR.log
310 msg3 "Cleaning the build directory..."
311 rm -rf build/$HARBOUR/
312 cp build/$HARBOUR.log ../$TARBALL_DIR/$HARBOUR.txt
313 done
315 done
318 if $RESULTS; then
319 msg "Generating HTML results page."
320 ARCHS=`find matrix/* -type d | cut '-d/' -f 2-`
321 BUILD_HARBOURS=`find matrix/* -name '*.txt' | cut '-d/' -f 3 | cut '-d.' -f 1 | sort | uniq | paste '-sd '`
322 BUILD_HARBOURS_COUNT=`echo $BUILD_HARBOURS | wc -w`
323 COL_WIDTH=$(( 100 / ( $BUILD_HARBOURS_COUNT + 1 ) ))
324 FIRST_COL_WIDTH=$(( 100 - $BUILD_HARBOURS_COUNT * $COL_WIDTH ))
326 BUILD_HARBOURS_ORDERED=""
327 for HARBOUR in $ALL_HARBOURS; do
328 if ! echo " $BUILD_HARBOURS " | grep " $HARBOUR " -q; then
329 continue
331 BUILD_HARBOURS_ORDERED="$BUILD_HARBOURS_ORDERED $HARBOUR"
332 done
333 BUILD_HARBOURS="$BUILD_HARBOURS_ORDERED"
335 cat <<EOF_HTML_HEADER
336 <!DOCTYPE html>
337 <html>
338 <head>
339 <meta charset="utf-8">
340 <title>HelenOS coastline status matrix</title>
341 <style type="text/css">
342 BODY {
343 font-family: Verdana,Arial,sans-serif;
345 H1 {
346 text-align: center;
347 font-size: 200%;
348 color: #036;
350 A:link, A:visited {
351 color: #036;
353 A:hover {
354 background: #036;
355 color: white;
357 TABLE.coastline {
358 margin: auto;
359 width: 100%;
361 TABLE.coastline, TABLE.coastline TH, TABLE.coastline TD {
362 font-weight: normal;
363 border: 1px solid black;
364 border-collapse: collapse;
365 padding: 4px 2px;
366 background: #FFFAF0;
367 text-align: center;
368 line-height: 130%;
369 vertical-align: middle;
371 TABLE.coastline TH.package .version {
372 font-size: 80%;
374 TABLE.coastline TD.ok {
375 background: #cfc;
377 TABLE.coastline TD.fail {
378 background: #fcc;
380 TD.ok .msg {
381 color: #030;
383 TD.fail .msg {
384 color: #300;
386 TABLE.coastline A {
387 padding: 2px;
389 TABLE.coastline A:link, TABLE.coastline A:visited {
390 color: #036;
392 TABLE.coastline A:hover {
393 background: #036;
394 color: white;
396 </style>
397 </head>
398 <body>
399 <h1>HelenOS coastline status matrix</h1>
401 This matrix summarizes status of porting various packages to
402 <a href="http://www.helenos.org">HelenOS</a>
403 through
404 <a href="https://github.com/vhotspur/coastline">Coastline</a>.
405 The results here come from completely
406 <a href="http://vh.alisma.cz/blog/2013/03/30/introducing-helenos-coastline/">automated
407 process</a>
408 and it is possible that some failed packages <i>can</i> be installed through some
409 manual tweaks.
410 </p>
412 <table class="coastline">
413 <colgroup>
414 <col width="$FIRST_COL_WIDTH%" />
415 <col span="$ARCH_COUNT" width="$COL_WIDTH%" />
416 </colgroup>
417 <tr>
418 <th>&nbsp;</th>
419 EOF_HTML_HEADER
420 for HARBOUR in $BUILD_HARBOURS; do
421 echo "<th class=\"package\">"
422 echo "$HARBOUR <br />"
423 VERSION=`sed -n 's#^[ \t]*shipversion=\(.*\)$#\1#p' <$HSCT_HOME/$HARBOUR/HARBOUR 2>/dev/null | tr -d "'\""`
424 echo "<span class=\"version\">$VERSION</span>"
425 echo "</th>"
426 done
427 echo "</tr>"
429 for ARCH in $ARCHS; do
430 echo "<tr>"
432 echo "<th>"
433 arch_human_readable "$ARCH"
434 echo "</th>"
435 for HARBOUR in $BUILD_HARBOURS; do
436 if [ -e matrix/$ARCH/$ARCH-$HARBOUR.tar.xz ]; then
437 TD_CLASS="ok"
438 TD_MSG="OK"
439 TD_LINK="$ARCH/$ARCH-$HARBOUR.tar.xz"
440 TD_LINK_TEXT="Tarball"
441 else
442 TD_CLASS="fail"
443 TD_MSG="FAILED"
444 TD_LINK="$ARCH/$HARBOUR.txt"
445 TD_LINK_TEXT="Log"
447 echo "<td class=\"$TD_CLASS\">"
448 echo "<span class=\"msg\">$TD_MSG</span><br />"
449 echo "<a href=\"$TD_LINK\">$TD_LINK_TEXT</a>"
450 echo "</td>"
451 done
453 echo "</tr><!-- $ARCH -->"
454 done
455 cat <<EOF_HTML_FOOTER
456 </table>
457 </body>
458 </html>
459 EOF_HTML_FOOTER
460 ) >matrix/index.html