aboutsummaryrefslogtreecommitdiff
path: root/tcwg-base/tcwg-llvmbot/run.sh
blob: 3aa5cb2a8518430c8ff63a8258bc13500bb601a2 (plain)
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
#!/bin/bash

set -e

bare_metal_bot_p ()
{
    case "$1" in
	"linaro-tk1-"*) return 0 ;;
	"linaro-apm-02"|"linaro-apm-05") return 1 ;;
	"linaro-apm-"*) return 0 ;;
	*) return 1 ;;
    esac
}

if [ x"$1" = x"start.sh" ]; then
    cat /start.sh
    exit 0
fi

if ! [ -f ~buildslave/buildslave/buildbot.tac ]; then
    # Connect to silent master.
    # Reconnecting to main master should be done by hand.
    sudo -i -u buildslave buildslave create-slave --umask=022 ~buildslave/buildslave "$@"
fi

case "$(uname -m)" in
    aarch64)
	clang_ver=clang+llvm-6.0.0-aarch64-linux-gnu
	;;
    *)
	clang_ver=clang+llvm-6.0.0-armv7a-linux-gnueabihf
	;;
esac

if bare_metal_bot_p "$2"; then
    # Download and install clang+llvm into /usr/local for bare-metal
    # bots.
    (
	cd /usr/local
	wget -c --progress=dot:giga http://releases.llvm.org/6.0.0/$clang_ver.tar.xz
	tar xf $clang_ver.tar.xz
    )
fi

case "$2" in
    *-libcxx*|linaro-tk1-01|linaro-apm-03)
	# Libcxx bots need to be compiled with *recent* clang.
	cc=/usr/local/$clang_ver/bin/clang
	cxx=/usr/local/$clang_ver/bin/clang++
	;;
    *-lld|linaro-apm-04)
	# LLD bots need to be compiled with clang.
	# ??? Adding testStage1=False to LLD bot might enable it to not depend on clang.
	cc=/usr/bin/clang
	cxx=/usr/bin/clang++
	;;
    *-arm-quick|linaro-tk1-06)
	cc=/usr/bin/clang
	cxx=/usr/bin/clang++
	;;
    *-arm-full-selfhost|linaro-tk1-05)
	# ??? *-arm-full-selfhost bot doesn't look like it depends on clang.
	cc=/usr/bin/clang
	cxx=/usr/bin/clang++
	;;
    *-arm-full|linaro-tk1-08)
	# ??? For now we preserve host compiler configuration from non-docker bots.
	cc=/usr/bin/clang
	cxx=/usr/bin/clang++
	;;
    *-arm-global-isel|linaro-tk1-09)
	# ??? For now we preserve host compiler configuration from non-docker bots.
	cc=/usr/bin/clang
	cxx=/usr/bin/clang++
	;;
    *)
	cc=gcc
	cxx=g++
	;;
esac

# With default PATH /usr/local/bin/cc and /usr/local/bin/c++ are detected as
# system compilers.  No danger in ccaching results of system compiler since
# we always start with a clean cache in a new container.
cat > /usr/local/bin/cc <<EOF
#!/bin/sh
exec ccache $cc "\$@"
EOF
chmod +x /usr/local/bin/cc
cat > /usr/local/bin/c++ <<EOF
#!/bin/sh
exec ccache $cxx "\$@"
EOF
chmod +x /usr/local/bin/c++

case "$2" in
    *-lld|linaro-apm-04)
	# LLD buildbot needs to find ld.lld for stage1 build.
	ln -f -s /usr/bin/ld.bfd /usr/local/bin/ld.lld
	;;
    *)
	rm -f /usr/local/bin/ld.lld
	;;
esac

cat <<EOF | sudo -i -u buildslave tee ~buildslave/buildslave/info/admin
Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org>
EOF

n_cores=$(nproc --all)
case "$2" in
    linaro-apm-*) hw="APM Mustang ${n_cores}-core X-Gene" ;;
    linaro-armv8-*) hw="${n_cores}-core ARMv8 provided by Packet.net (Type 2A2)" ;;
    linaro-tk1-*) hw="NVIDIA TK1 ${n_cores}-core Cortex-A15" ;;
esac

if [ -f /sys/fs/cgroup/memory/memory.limit_in_bytes ]; then
    mem_limit=$((($(cat /sys/fs/cgroup/memory/memory.limit_in_bytes) + 512*1024*1024) / (1024*1024*1024)))
else
    mem_limit=$((($(cat /proc/meminfo | grep MemTotal | sed -e "s/[^0-9]\+\([0-9]\+\)[^0-9]\+/\1/") + 512*1024) / (1024*1024)))
fi
cat <<EOF | sudo -i -u buildslave tee ~buildslave/buildslave/info/host
$hw; RAM ${mem_limit}GB

OS: $(lsb_release -ds)
Kernel: $(uname -rv)
Compiler: $(cc --version | head -n 1)
Linker: $(ld --version | head -n 1)
C Library: $(ldd --version | head -n 1)
EOF

if bare_metal_bot_p "$2"; then
    # TK1s have CPU hot-plug, so ninja might detect smaller number of cores
    # available for parallelism.  Explicitly set "default" parallelism.
    cat > /usr/local/bin/ninja <<EOF
#!/bin/sh
exec /usr/bin/ninja -j$n_cores "\$@"
EOF
else
    # Throttle ninja on system load, system memory and container memory limit.
    # When running with "-l 2*N_CORES -m 50 -M 50" ninja will not start new jobs
    # if system or container memory utilization is beyond 50% or when load is
    # above double the core count.  Ninja will also stall up to 5 seconds (-D 5000)
    # before starting a new job to avoid rapid increase of resource usage.
    cat > /usr/local/bin/ninja <<EOF
#!/bin/sh
exec /usr/local/bin/ninja.bin -j$n_cores -l $((2*$n_cores)) -m 50 -M 50 -D 5000 "\$@"
EOF
fi
chmod +x /usr/local/bin/ninja

sudo -i -u buildslave buildslave restart ~buildslave/buildslave

if bare_metal_bot_p "$2"; then
    exit 0
fi

exec /usr/sbin/sshd -D