-#!/bin/sh
+#!/bin/bash
-. "$(dirname $0)/common.sh"
+tree=
+if [ "$1" ]; then
+ tree=$1
+ shift
+fi
+
+# shellcheck source=common.sh
+. "$(dirname "$0")/common.sh"
set -e
-###ssh "$build_host" /bin/sh -e <<-EOF
-ssh root@"$build_host" unshare -n su $(id -u -n) <<-EOF
- set -e
+bparent=$(dirname "$build_dir")
+
+line=$(tail -n 1 "$SHA1_FILE")
+
+# strip everything after the first tab character
+stree=${line%% *}
+if [ "$tree" ]; then
+ if [ "$tree" != "$stree" ]; then
+ printf 'That is not the last tree merged (%s v %s)\n' "$tree" "$stree" 1>&2
+ exit 1
+ fi
+else
+ tree="$stree"
+fi
+obdir="$bparent/old/$tree"
+
+cmd="/bin/sh"
+if [ "$build_host" ]; then
+ cmd="ssh root@$build_host unshare -n su $(id -u -n)"
+fi
+
+log_regex='/^[[:space:]]+$/d
+/^[.[:digit:]]+user [.[:digit:]]+system [:.[:digit:]]+elapsed [[:digit:]]+%CPU \([[:digit:]]+avgtext\+[[:digit:]]+avgdata [[:digit:]]+maxresident\)k$/d
+/^[[:digit:]]+inputs\+[[:digit:]]+outputs \([[:digit:]]+major\+[[:digit:]]+minor\)pagefaults [[:digit:]]+swaps$/d
+/^Setup is [[:digit:]]+ bytes \(padded to [[:digit:]]+ bytes\)\.$/d
+/^System is [[:digit:]]+ kB$/d
+/^CRC [[:xdigit:]]+$/d
+/^Kernel: arch\/x86\/boot\/bzImage is ready \(#[[:digit:]]+\)$/d
+s/^(WARNING: (modpost: )?(drivers\/built-in|vmlinux)\.o\(\.[^+]*\+0x)[[:xdigit:]]+(\): Section mismatch in reference from .*)$/\1XXXX\4/
+/^Warning: Kernel ABI header at /d
+/^[[:space:]]+PERF_VERSION = /d
+s/^(Parsed description of) [[:digit:]]+ (helper function)/\1 X \2/
+s/^[[:xdigit:]]+([[:space:]]+R_PPC64_(ADDR64|REL32)[[:space:]].*)$/XXX\1/'
+
+$cmd <<-EOF
+
+ echo Building on \$(hostname)
echo \$PATH | grep -q "\$HOME/bin" || export PATH="\$HOME/bin:\$PATH"
export LANG=C
- cd "$build_dir"
-
- export CCACHE_DIR="${build_dir%/*}/.ccache"
- export TMPDIR="${build_dir%/*}/tmp"
-
- git reset --hard next
- touch .scmversion
-
- d=../powerpc_ppc64_defconfig
- [ -d \$d ] || mkdir \$d
- cross -n -N -a powerpc64 -k powerpc -c 4.8.1 O=\$d ppc64_defconfig
- cross -n -N -a powerpc64 -k powerpc -c 4.8.1 O=\$d -j64 -s
-
- d=../x86_64_allmodconfig
- [ -d \$d ] || mkdir \$d
- e=\$d.except
- cat >\$e <<REOF
- CONFIG_PROFILE_ALL_BRANCHES=n
- CONFIG_DEBUG_INFO=n
- CONFIG_X86_DECODER_SELFTEST=n
- CONFIG_MODULES=y
- REOF
- KCONFIG_ALLCONFIG=\$e cross -n -N -a x86_64 -c 4.8.1 O=\$d allmodconfig
- rm \$e
- cross -n -N -a x86_64 -c 4.8.1 O=\$d -j64 -s
+ cd "$build_dir" || exit 1
+
+ export CCACHE_DIR="$bparent/.ccache"
+ export TMPDIR="$bparent/tmp"
+
+ git reset --hard next || exit 1
+ touch .scmversion || exit 1
+
+ [ -d "$obdir" ] || mkdir -p "$obdir" || exit 1
+
+ sanitise_log() {
+ sed -E -e '$log_regex' | grep -vxFf $bparent/log-ignore
+ }
+
+ show_log() {
+ arch=\$1
+ conf=\$2
+ log=\$3
+
+ sep='======================================================================'
+
+ echo "\$sep"
+ echo " \$arch \$conf build OK - log follows"
+ echo "\$sep"
+ cat \$log
+ b=\$(basename \$log)
+ olen=0
+ if [ -f $obdir/\$b ]; then
+ olen=\$(sanitise_log <$obdir/\$b | wc -l)
+ fi
+ len=\$(sanitise_log <\$log | wc -l)
+ if [ \$len -gt \$olen ]; then
+ echo "\$sep"
+ echo " log \$b increased number of lines"
+ echo "\$sep"
+ linux-next-notify "\$arch \$conf log got bigger"
+ if [ -f $obdir/\$b ]; then
+ diff -u $obdir/\$b \$log 2>&1 | less
+ else
+ diff -u /dev/null \$log 2>&1 | less
+ fi
+ fi
+ if [ \$len -gt 0 ]; then
+ (sanitise_log <\$log; cat $bparent/log-ignore ) |
+ sort -u >$bparent/log-ignore.tmp
+ mv $bparent/log-ignore.tmp $bparent/log-ignore
+ fi
+ mv \$log $obdir/\$b
+ }
+
+ echo Building: x86_64 allmodconfig
+ d="$bparent/x86_64_allmodconfig"
+ [ -d \$d ] || mkdir \$d || exit 1
+ log_x86=\$d.log
+ make ARCH=x86_64 CROSS_COMPILE=x86_64-linux-gnu- O=\$d -s allmodconfig || exit 1
+ echo "Forking x86 build ..."
+ /usr/bin/time make ARCH=x86_64 CROSS_COMPILE=x86_64-linux-gnu- O=\$d -j100 -O -s > \$log_x86 2>&1 &
+ x86_64_pid=\$!
+
+ echo Building: perf
+ d="$bparent/perf"
+ [ -d \$d ] || mkdir \$d || exit 1
+ log_perf=\$d.log
+ # the -Wno-psabi is to suppress
+ # note: the layout of aggregates containing vectors with 8-byte alignment has changed in GCC 5
+ # warnings until at least gcc 12 when the warning will be removed
+ /usr/bin/time make -C tools/perf -f Makefile.perf -s -O -j40 O=\$d EXTRA_CFLAGS=-Wno-psabi > \$log_perf 2>&1
+ rc=\$?
+
+ if [ \$rc -ne 0 ]; then
+ echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
+ echo "ERROR: perf build failed - log follows"
+ echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
+ cat \$log_perf
+ kill \$x86_64_pid || true
+ killall make
+ rm .scmversion
+ exit 1
+ else
+ show_log native perf \$log_perf
+ fi
+
+ echo Building: powerpc ppc64_defconfig
+ d="$bparent/powerpc_ppc64_defconfig"
+ [ -d \$d ] || mkdir \$d || exit 1
+ log_ppc=\$d.log
+ make ARCH=powerpc O=\$d -s ppc64_defconfig || exit 1
+ /usr/bin/time make ARCH=powerpc O=\$d -j40 -O -s > \$log_ppc 2>&1
+ rc=\$?
+
+ if [ \$rc -ne 0 ]; then
+ echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
+ echo "ERROR: powerpc ppc64_defconfig build failed - log follows"
+ echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
+ cat \$log_ppc
+ kill \$x86_64_pid || true
+ killall make
+ rm .scmversion
+ exit 1
+ else
+ show_log powerpc ppc64_defconfig \$log_ppc
+ fi
+
+ echo Building: arm multi_v7_defconfig
+ d="$bparent/arm_multi_v7_defconfig"
+ [ -d \$d ] || mkdir \$d || exit 1
+ log_arm=\$d.log
+ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- O=\$d -s multi_v7_defconfig || exit 1
+ /usr/bin/time make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- O=\$d -j40 -O -s > \$log_arm 2>&1
+ rc=\$?
+
+ if [ \$rc -ne 0 ]; then
+ echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
+ echo "ERROR: arm multi_v7_defconfig build failed - log follows"
+ echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
+ cat \$log_arm
+ kill \$x86_64_pid || true
+ killall make
+ rm .scmversion
+ exit 1
+ else
+ show_log arm multi_v7_defconfig \$log_arm
+ fi
+
+ wait \$x86_64_pid
+ rc=\$?
+
+ if [ \$rc -ne 0 ]; then
+ echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
+ echo "ERROR: x86_64 allmodconfig build failed - log follows"
+ echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
+ cat \$log_x86
+ rm .scmversion
+ exit 1
+ else
+ show_log x86_64 allmodconfig \$log_x86
+ fi
+
+ rm .scmversion
EOF