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

set -e

bare_metal_bot_p ()
{
    if [ -f "/.dockerenv" ]; then
       return 1
    fi
    return 0
}

use_clang_p ()
{
    # The LLD buildbot needs clang for -fuse-ld=lld in stage 2
    # The libcxx bot needs a recent clang to compile tests that
    # require new C++ standard support.
    # Typically we've used clang when the default gcc has problems
    # otherwise gcc is used.
    case "$1" in
        *-libcxx*|linaro-tk1-01) return 0 ;;
        *-lld) return 0 ;;
        *-arm-quick|linaro-tk1-06) return 0 ;;
        *-arm-full-selfhost|linaro-tk1-05) return 0 ;;
        *-arm-full|linaro-tk1-08) return 0 ;;
        *-arm-global-isel|linaro-tk1-09) return 0 ;;
        *) return 1 ;;
    esac
}

# Use the oldest maintained clang release (latest - 1).
setup_clang_release()
{
    local bot_name="$1"

    # There is a 6.0.1 release but there aren't any AArch64 binaries available
    # so we use 6.0.0 for now.
    local release_num=6.0.0
    case "$(uname -m)" in
    aarch64)
	local clang_ver=clang+llvm-${release_num}-aarch64-linux-gnu
	;;
    *)
	local clang_ver=clang+llvm-${release_num}-armv7a-linux-gnueabihf
	;;
    esac

    # Download and install clang+llvm into /usr/local
    # Docker bots already have clang+llvm downloaded and installed in the image.
    if bare_metal_bot_p $bot_name; then
	(
	    cd /usr/local
	    wget -c --progress=dot:giga http://releases.llvm.org/${release_num}/$clang_ver.tar.xz
	    tar xf $clang_ver.tar.xz
	)
    fi
    cc=/usr/local/$clang_ver/bin/clang
    cxx=/usr/local/$clang_ver/bin/clang++
}

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

if use_clang_p $2 ; then
    setup_clang_release $2
else
    cc=gcc
    cxx=g++
fi

# 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)
	# LLD buildbot needs to find ld.lld for stage1 build. GCC does not
        # support -fuse-ld=lld.
	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-armv8-*) hw="${n_cores}-core ARMv8 provided by Packet.net (Type 2A2)" ;;
    linaro-thx1-*) hw="${n_cores}-core ThunderX1 provided by Packet.net (Type 2A)" ;;
    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

case "$2" in
    linaro-tk1-*)
	# 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
	;;
    *)
	# 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
	;;
esac
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