summaryrefslogtreecommitdiffstats
path: root/gnu/llvm/libcxx/utils/docker
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/llvm/libcxx/utils/docker')
-rw-r--r--gnu/llvm/libcxx/utils/docker/debian9/Dockerfile.base45
-rw-r--r--gnu/llvm/libcxx/utils/docker/debian9/Dockerfile.buildbot26
-rw-r--r--gnu/llvm/libcxx/utils/docker/debian9/Dockerfile.clang19
-rw-r--r--gnu/llvm/libcxx/utils/docker/debian9/Dockerfile.compiler_zoo33
-rw-r--r--gnu/llvm/libcxx/utils/docker/debian9/Dockerfile.gcc18
-rw-r--r--gnu/llvm/libcxx/utils/docker/docker-compose.yml46
-rwxr-xr-xgnu/llvm/libcxx/utils/docker/scripts/build_gcc_version.sh108
-rwxr-xr-xgnu/llvm/libcxx/utils/docker/scripts/build_llvm_version.sh106
-rwxr-xr-xgnu/llvm/libcxx/utils/docker/scripts/docker_start_buildbots.sh8
-rwxr-xr-xgnu/llvm/libcxx/utils/docker/scripts/docker_update_bot.sh25
-rwxr-xr-xgnu/llvm/libcxx/utils/docker/scripts/install_clang_packages.sh81
-rwxr-xr-xgnu/llvm/libcxx/utils/docker/scripts/run_buildbot.sh102
12 files changed, 617 insertions, 0 deletions
diff --git a/gnu/llvm/libcxx/utils/docker/debian9/Dockerfile.base b/gnu/llvm/libcxx/utils/docker/debian9/Dockerfile.base
new file mode 100644
index 00000000000..6ad85fdb275
--- /dev/null
+++ b/gnu/llvm/libcxx/utils/docker/debian9/Dockerfile.base
@@ -0,0 +1,45 @@
+#===- libcxx/utils/docker/debian9/Dockerfile --------------------------------------------------===//
+#
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+#
+#===-------------------------------------------------------------------------------------------===//
+
+# Setup the base builder image with the packages we'll need to build GCC and Clang from source.
+FROM launcher.gcr.io/google/debian9:latest AS builder-base
+LABEL maintainer "libc++ Developers"
+
+RUN apt-get update && \
+ apt-get install -y --no-install-recommends \
+ ca-certificates \
+ gnupg \
+ build-essential \
+ wget \
+ subversion \
+ unzip \
+ automake \
+ python \
+ cmake \
+ ninja-build \
+ curl \
+ git \
+ gcc-multilib \
+ g++-multilib \
+ libc6-dev \
+ bison \
+ flex \
+ libtool \
+ autoconf \
+ binutils-dev \
+ binutils-gold \
+ software-properties-common \
+ gnupg \
+ apt-transport-https \
+ sudo \
+ systemd \
+ sysvinit-utils \
+ systemd-sysv && \
+ update-alternatives --install "/usr/bin/ld" "ld" "/usr/bin/ld.gold" 20 && \
+ update-alternatives --install "/usr/bin/ld" "ld" "/usr/bin/ld.bfd" 10 && \
+ rm -rf /var/lib/apt/lists/*
diff --git a/gnu/llvm/libcxx/utils/docker/debian9/Dockerfile.buildbot b/gnu/llvm/libcxx/utils/docker/debian9/Dockerfile.buildbot
new file mode 100644
index 00000000000..c48f59a0b2f
--- /dev/null
+++ b/gnu/llvm/libcxx/utils/docker/debian9/Dockerfile.buildbot
@@ -0,0 +1,26 @@
+
+#===-------------------------------------------------------------------------------------------===//
+# buildslave
+#===-------------------------------------------------------------------------------------------===//
+FROM ericwf/builder-base:latest AS buildbot
+
+# Copy over the GCC and Clang installations
+COPY --from=ericwf/gcc-5:latest /opt/gcc-5 /opt/gcc-5
+COPY --from=ericwf/gcc-tot:latest /opt/gcc-tot /opt/gcc-tot
+COPY --from=ericwf/llvm-4:latest /opt/llvm-4.0 /opt/llvm-4.0
+
+RUN ln -s /opt/gcc-5/bin/gcc /usr/local/bin/gcc-4.9 && \
+ ln -s /opt/gcc-5/bin/g++ /usr/local/bin/g++-4.9
+
+RUN apt-get update && \
+ apt-get install -y --no-install-recommends \
+ bash-completion \
+ vim \
+ sudo \
+ buildbot-slave \
+ && rm -rf /var/lib/apt/lists/*
+
+ADD scripts/install_clang_packages.sh /tmp/install_clang_packages.sh
+RUN /tmp/install_clang_packages.sh && rm /tmp/install_clang_packages.sh
+
+RUN git clone https://git.llvm.org/git/libcxx.git /libcxx
diff --git a/gnu/llvm/libcxx/utils/docker/debian9/Dockerfile.clang b/gnu/llvm/libcxx/utils/docker/debian9/Dockerfile.clang
new file mode 100644
index 00000000000..68e39bcd28f
--- /dev/null
+++ b/gnu/llvm/libcxx/utils/docker/debian9/Dockerfile.clang
@@ -0,0 +1,19 @@
+#===- libcxx/utils/docker/debian9/Dockerfile --------------------------------------------------===//
+#
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+#
+#===-------------------------------------------------------------------------------------------===//
+
+# Build GCC versions
+FROM ericwf/builder-base:latest
+LABEL maintainer "libc++ Developers"
+
+ARG install_prefix
+ARG branch
+
+# Build additional LLVM versions
+
+ADD scripts/build_llvm_version.sh /tmp/build_llvm_version.sh
+RUN /tmp/build_llvm_version.sh --install "$install_prefix" --branch "$branch"
diff --git a/gnu/llvm/libcxx/utils/docker/debian9/Dockerfile.compiler_zoo b/gnu/llvm/libcxx/utils/docker/debian9/Dockerfile.compiler_zoo
new file mode 100644
index 00000000000..640d24ae561
--- /dev/null
+++ b/gnu/llvm/libcxx/utils/docker/debian9/Dockerfile.compiler_zoo
@@ -0,0 +1,33 @@
+#===- libcxx/utils/docker/debian9/Dockerfile --------------------------------------------------===//
+#
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+#
+#===-------------------------------------------------------------------------------------------===//
+
+#===-------------------------------------------------------------------------------------------===//
+# compiler-zoo
+#===-------------------------------------------------------------------------------------------===//
+FROM ericwf/libcxx-buildbot-base:latest AS compiler-zoo
+LABEL maintainer "libc++ Developers"
+
+# Copy over the GCC and Clang installations
+COPY --from=ericwf/compilers:latest /opt/gcc-4.8.5 /opt/gcc-4.8.5
+COPY --from=ericwf/compilers:latest /opt/gcc-4.9.4 /opt/gcc-4.9.4
+COPY --from=ericwf/compilers:latest /opt/gcc-5 /opt/gcc-5
+COPY --from=ericwf/compilers:latest /opt/gcc-6 /opt/gcc-6
+COPY --from=ericwf/compilers:latest /opt/gcc-7 /opt/gcc-7
+COPY --from=ericwf/compilers:latest /opt/gcc-8 /opt/gcc-8
+COPY --from=ericwf/compilers_tot:latest /opt/gcc-tot /opt/gcc-tot
+
+COPY --from=ericwf/compilers:latest /opt/llvm-3.6 /opt/llvm-3.6
+COPY --from=ericwf/compilers:latest /opt/llvm-3.7 /opt/llvm-3.7
+COPY --from=ericwf/compilers:latest /opt/llvm-3.8 /opt/llvm-3.8
+COPY --from=ericwf/compilers:latest /opt/llvm-3.9 /opt/llvm-3.9
+COPY --from=ericwf/compilers:latest /opt/llvm-4.0 /opt/llvm-4.0
+COPY --from=ericwf/compilers:latest /opt/llvm-5.0 /opt/llvm-5.0
+COPY --from=ericwf/compilers:latest /opt/llvm-6.0 /opt/llvm-6.0
+COPY --from=ericwf/compilers:latest /opt/llvm-7.0 /opt/llvm-7.0
+COPY --from=ericwf/compilers:latest /opt/llvm-8.0 /opt/llvm-8.0
+COPY --from=ericwf/compilers_tot:latest /opt/llvm-tot /opt/llvm-tot
diff --git a/gnu/llvm/libcxx/utils/docker/debian9/Dockerfile.gcc b/gnu/llvm/libcxx/utils/docker/debian9/Dockerfile.gcc
new file mode 100644
index 00000000000..5a12074d0d3
--- /dev/null
+++ b/gnu/llvm/libcxx/utils/docker/debian9/Dockerfile.gcc
@@ -0,0 +1,18 @@
+#===- libcxx/utils/docker/debian9/Dockerfile --------------------------------------------------===//
+#
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+#
+#===-------------------------------------------------------------------------------------------===//
+
+# Build GCC versions
+FROM ericwf/builder-base:latest
+LABEL maintainer "libc++ Developers"
+
+ARG install_prefix
+ARG branch
+ARG cherry_pick=""
+
+ADD scripts/build_gcc_version.sh /tmp/build_gcc_version.sh
+RUN /tmp/build_gcc_version.sh --install "$install_prefix" --branch "$branch" --cherry-pick "$cherry_pick"
diff --git a/gnu/llvm/libcxx/utils/docker/docker-compose.yml b/gnu/llvm/libcxx/utils/docker/docker-compose.yml
new file mode 100644
index 00000000000..1202a827b2d
--- /dev/null
+++ b/gnu/llvm/libcxx/utils/docker/docker-compose.yml
@@ -0,0 +1,46 @@
+version: '3.4'
+services:
+ builder-base:
+ build:
+ context: .
+ dockerfile: debian9/Dockerfile.base
+ target: builder-base
+ image: ericwf/builder-base:latest
+ gcc-tot:
+ build:
+ context: .
+ dockerfile: debian9/Dockerfile.gcc
+ args:
+ install_prefix: /opt/gcc-tot
+ branch: master
+ image: ericwf/gcc-tot:latest
+ gcc-5:
+ build:
+ context: .
+ dockerfile: debian9/Dockerfile.gcc
+ args:
+ install_prefix: /opt/gcc-5
+ branch: gcc-5_5_0-release
+ image: ericwf/gcc-5:latest
+ llvm-4:
+ build:
+ context: .
+ dockerfile: debian9/Dockerfile.clang
+ args:
+ install_prefix: /opt/llvm-4.0
+ branch: release/4.x
+ image: ericwf/llvm-4:latest
+ llvm-tot:
+ build:
+ context: .
+ dockerfile: debian9/Dockerfile.clang
+ args:
+ install_prefix: /opt/llvm-tot
+ branch: master
+ image: ericwf/llvm-tot:latest
+ buildbot:
+ build:
+ context: .
+ dockerfile: debian9/Dockerfile.buildbot
+ target: buildbot
+ image: ericwf/libcxx-buildbot-base:latest
diff --git a/gnu/llvm/libcxx/utils/docker/scripts/build_gcc_version.sh b/gnu/llvm/libcxx/utils/docker/scripts/build_gcc_version.sh
new file mode 100755
index 00000000000..68aa4c67e3e
--- /dev/null
+++ b/gnu/llvm/libcxx/utils/docker/scripts/build_gcc_version.sh
@@ -0,0 +1,108 @@
+#!/usr/bin/env bash
+#===- libcxx/utils/docker/scripts/build-gcc.sh ----------------------------===//
+#
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+#
+#===-----------------------------------------------------------------------===//
+
+set -e
+
+function show_usage() {
+ cat << EOF
+Usage: build_gcc_version.sh [options]
+
+Run autoconf with the specified arguments. Used inside docker container.
+
+Available options:
+ -h|--help show this help message
+ --branch the branch of gcc you want to build.
+ --cherry-pick a commit hash to apply to the GCC sources.
+ --install destination directory where to install the targets.
+Required options: --install and --branch
+
+All options after '--' are passed to CMake invocation.
+EOF
+}
+
+GCC_INSTALL_DIR=""
+GCC_BRANCH=""
+CHERRY_PICK=""
+
+while [[ $# -gt 0 ]]; do
+ case "$1" in
+ --install)
+ shift
+ GCC_INSTALL_DIR="$1"
+ shift
+ ;;
+ --branch)
+ shift
+ GCC_BRANCH="$1"
+ shift
+ ;;
+ --cherry-pick)
+ shift
+ CHERRY_PICK="$1"
+ shift
+ ;;
+ -h|--help)
+ show_usage
+ exit 0
+ ;;
+ *)
+ echo "Unknown option: $1"
+ exit 1
+ esac
+done
+
+if [ "$GCC_INSTALL_DIR" == "" ]; then
+ echo "No install directory. Please specify the --install argument."
+ exit 1
+fi
+
+if [ "$GCC_BRANCH" == "" ]; then
+ echo "No branch specified. Please specify the --branch argument."
+ exit 1
+fi
+
+set -x
+
+NPROC=`nproc`
+TMP_ROOT="$(mktemp -d -p /tmp)"
+GCC_SOURCE_DIR="$TMP_ROOT/gcc"
+GCC_BUILD_DIR="$TMP_ROOT/build"
+
+echo "Cloning source directory for branch $GCC_BRANCH"
+git clone --branch "$GCC_BRANCH" --single-branch --depth=1 git://gcc.gnu.org/git/gcc.git $GCC_SOURCE_DIR
+
+pushd "$GCC_SOURCE_DIR"
+if [ "$CHERRY_PICK" != "" ]; then
+ git fetch origin trunk --unshallow # Urg, we have to get the entire history. This will take a while.
+ git cherry-pick --no-commit -X theirs "$CHERRY_PICK"
+fi
+./contrib/download_prerequisites
+popd
+
+
+mkdir "$GCC_BUILD_DIR"
+pushd "$GCC_BUILD_DIR"
+
+# Run the build as specified in the build arguments.
+echo "Running configuration"
+$GCC_SOURCE_DIR/configure --prefix=$GCC_INSTALL_DIR \
+ --disable-bootstrap --disable-libgomp --disable-libitm \
+ --disable-libvtv --disable-libcilkrts --disable-libmpx \
+ --disable-liboffloadmic --disable-libcc1 --enable-languages=c,c++
+
+echo "Running build with $NPROC threads"
+make -j$NPROC
+echo "Installing to $GCC_INSTALL_DIR"
+make install -j$NPROC
+popd
+
+# Cleanup.
+rm -rf "$TMP_ROOT"
+
+echo "Done" \ No newline at end of file
diff --git a/gnu/llvm/libcxx/utils/docker/scripts/build_llvm_version.sh b/gnu/llvm/libcxx/utils/docker/scripts/build_llvm_version.sh
new file mode 100755
index 00000000000..613a7babd33
--- /dev/null
+++ b/gnu/llvm/libcxx/utils/docker/scripts/build_llvm_version.sh
@@ -0,0 +1,106 @@
+#!/usr/bin/env bash
+#===- libcxx/utils/docker/scripts/build_install_llvm_version_default.sh -----------------------===//
+#
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+#
+#===-------------------------------------------------------------------------------------------===//
+
+set -e
+
+function show_usage() {
+ cat << EOF
+Usage: build_install_llvm.sh [options] -- [cmake-args]
+
+Run cmake with the specified arguments. Used inside docker container.
+Passes additional -DCMAKE_INSTALL_PREFIX and puts the build results into
+the directory specified by --to option.
+
+Available options:
+ -h|--help show this help message
+ --install destination directory where to install the targets.
+ --branch the branch or tag of LLVM to build
+Required options: --install, and --version.
+
+All options after '--' are passed to CMake invocation.
+EOF
+}
+
+LLVM_BRANCH=""
+CMAKE_ARGS=""
+LLVM_INSTALL_DIR=""
+
+while [[ $# -gt 0 ]]; do
+ case "$1" in
+ --install)
+ shift
+ LLVM_INSTALL_DIR="$1"
+ shift
+ ;;
+ --branch)
+ shift
+ LLVM_BRANCH="$1"
+ shift
+ ;;
+ --)
+ shift
+ CMAKE_ARGS="$*"
+ shift $#
+ ;;
+ -h|--help)
+ show_usage
+ exit 0
+ ;;
+ *)
+ echo "Unknown option: $1"
+ exit 1
+ esac
+done
+
+
+if [ "$LLVM_INSTALL_DIR" == "" ]; then
+ echo "No install directory. Please specify the --install argument."
+ exit 1
+fi
+
+if [ "$LLVM_BRANCH" == "" ]; then
+ echo "No install directory. Please specify the --branch argument."
+ exit 1
+fi
+
+if [ "$CMAKE_ARGS" == "" ]; then
+ CMAKE_ARGS="-DCMAKE_BUILD_TYPE=RELEASE '-DCMAKE_C_FLAGS=-gline-tables-only' '-DCMAKE_CXX_FLAGS=-gline-tables-only' -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_INSTALL_TOOLCHAIN_ONLY=ON"
+fi
+
+set -x
+
+TMP_ROOT="$(mktemp -d -p /tmp)"
+LLVM_SOURCE_DIR="$TMP_ROOT/llvm-project"
+LLVM_BUILD_DIR="$TMP_ROOT/build"
+LLVM="$LLVM_SOURCE_DIR/llvm"
+
+git clone --branch $LLVM_BRANCH --single-branch --depth=1 https://github.com/llvm/llvm-project.git $LLVM_SOURCE_DIR
+
+pushd "$LLVM_SOURCE_DIR"
+
+# Setup the source-tree using the old style layout
+ln -s $LLVM_SOURCE_DIR/libcxx $LLVM/projects/libcxx
+ln -s $LLVM_SOURCE_DIR/libcxxabi $LLVM/projects/libcxxabi
+ln -s $LLVM_SOURCE_DIR/compiler-rt $LLVM/projects/compiler-rt
+ln -s $LLVM_SOURCE_DIR/clang $LLVM/tools/clang
+ln -s $LLVM_SOURCE_DIR/clang-tools-extra $LLVM/tools/clang/tools/extra
+
+popd
+
+# Configure and build
+mkdir "$LLVM_BUILD_DIR"
+pushd "$LLVM_BUILD_DIR"
+cmake -GNinja "-DCMAKE_INSTALL_PREFIX=$LLVM_INSTALL_DIR" $CMAKE_ARGS $LLVM
+ninja install
+popd
+
+# Cleanup
+rm -rf "$TMP_ROOT/"
+
+echo "Done"
diff --git a/gnu/llvm/libcxx/utils/docker/scripts/docker_start_buildbots.sh b/gnu/llvm/libcxx/utils/docker/scripts/docker_start_buildbots.sh
new file mode 100755
index 00000000000..f47ddcd2481
--- /dev/null
+++ b/gnu/llvm/libcxx/utils/docker/scripts/docker_start_buildbots.sh
@@ -0,0 +1,8 @@
+#!/usr/bin/env bash
+set -x
+
+# Update the libc++ sources in the image in order to use the most recent version of
+# run_buildbots.sh
+cd /libcxx
+git pull
+/libcxx/utils/docker/scripts/run_buildbot.sh "$@"
diff --git a/gnu/llvm/libcxx/utils/docker/scripts/docker_update_bot.sh b/gnu/llvm/libcxx/utils/docker/scripts/docker_update_bot.sh
new file mode 100755
index 00000000000..10ff483bb4e
--- /dev/null
+++ b/gnu/llvm/libcxx/utils/docker/scripts/docker_update_bot.sh
@@ -0,0 +1,25 @@
+#!/usr/bin/env bash
+
+set -x
+
+cd /libcxx
+git pull
+
+
+#pushd /tmp
+#curl -sSO https://dl.google.com/cloudagents/install-monitoring-agent.sh
+#bash install-monitoring-agent.sh
+#curl -sSO https://dl.google.com/cloudagents/install-logging-agent.sh
+#bash install-logging-agent.sh --structured
+#popd
+
+
+apt-get update -y
+apt-get upgrade -y
+
+apt-get install sudo -y
+
+systemctl set-property buildslave.service TasksMax=100000
+
+systemctl daemon-reload
+service buildslave restart
diff --git a/gnu/llvm/libcxx/utils/docker/scripts/install_clang_packages.sh b/gnu/llvm/libcxx/utils/docker/scripts/install_clang_packages.sh
new file mode 100755
index 00000000000..94c98d6ad74
--- /dev/null
+++ b/gnu/llvm/libcxx/utils/docker/scripts/install_clang_packages.sh
@@ -0,0 +1,81 @@
+#!/usr/bin/env bash
+#===- libcxx/utils/docker/scripts/install_clang_package.sh -----------------===//
+#
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+#
+#===-----------------------------------------------------------------------===//
+
+set -e
+
+function show_usage() {
+ cat << EOF
+Usage: install_clang_package.sh [options]
+
+Install
+Available options:
+ -h|--help show this help message
+ --version the numeric version of the package to use.
+EOF
+}
+
+VERSION="9"
+
+while [[ $# -gt 0 ]]; do
+ case "$1" in
+ --version)
+ shift
+ VERSION="$1"
+ shift
+ ;;
+ -h|--help)
+ show_usage
+ exit 0
+ ;;
+ *)
+ echo "Unknown option: $1"
+ exit 1
+ esac
+done
+
+set -x
+
+curl -fsSL https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
+add-apt-repository -s "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs) main"
+apt-get update
+apt-get upgrade -y
+apt-get install -y --no-install-recommends "clang-$VERSION"
+
+# FIXME(EricWF): Remove this once the clang packages are no longer broken.
+if [ -f "/usr/local/bin/clang" ]; then
+ echo "clang already exists"
+ exit 1
+else
+ CC_BINARY="$(which clang-$VERSION)"
+ ln -s "$CC_BINARY" "/usr/local/bin/clang"
+fi
+if [ -f "/usr/local/bin/clang++" ]; then
+ echo "clang++ already exists"
+ exit 1
+else
+ CXX_BINARY="$(which clang++-$VERSION)"
+ ln -s "$CXX_BINARY" "/usr/local/bin/clang++"
+fi
+
+echo "Testing clang version..."
+clang --version
+
+echo "Testing clang++ version..."
+clang++ --version
+
+# Figure out the libc++ and libc++abi package versions that we want.
+if [ "$VERSION" == "" ]; then
+ VERSION="$(apt-cache search 'libc\+\+-[0-9]-dev' | awk '{print $1}' | awk -F- '{print $2}')"
+ echo "Installing version '$VERSION'"
+fi
+
+apt-get purge -y "libc++-$VERSION-dev" "libc++abi-$VERSION-dev"
+apt-get install -y --no-install-recommends "libc++-$VERSION-dev" "libc++abi-$VERSION-dev"
+
+echo "Done"
diff --git a/gnu/llvm/libcxx/utils/docker/scripts/run_buildbot.sh b/gnu/llvm/libcxx/utils/docker/scripts/run_buildbot.sh
new file mode 100755
index 00000000000..ce86e10e5a7
--- /dev/null
+++ b/gnu/llvm/libcxx/utils/docker/scripts/run_buildbot.sh
@@ -0,0 +1,102 @@
+#!/usr/bin/env bash
+set -x
+
+readonly BOT_ROOT=/b
+readonly BOT_ROOT_NAME=$1
+readonly BOT_PASS=$2
+
+#pushd /tmp
+#curl -sSO https://dl.google.com/cloudagents/install-monitoring-agent.sh
+#bash install-monitoring-agent.sh
+#curl -sSO https://dl.google.com/cloudagents/install-logging-agent.sh
+#bash install-logging-agent.sh --structured
+#popd
+
+apt-get update -y
+apt-get upgrade -y
+
+apt-get install sudo -y
+
+systemctl set-property buildslave.service TasksMax=100000
+
+function setup_numbered_bot() {
+ local BOT_NAME=$1
+ local BOT_DIR=$2
+ mkdir -p $BOT_DIR
+
+ buildslave stop $BOT_DIR
+ chown buildbot:buildbot $BOT_DIR
+ rm -rf $BOT_DIR/*
+
+ buildslave create-slave --allow-shutdown=signal "$BOT_DIR" "lab.llvm.org:9990" "$BOT_NAME" "$BOT_PASS"
+
+ echo "Eric Fiselier <ericwf@google.com>" > $BOT_DIR/info/admin
+
+ echo "Connecting as $1"
+ {
+ uname -a | head -n1
+ cmake --version | head -n1
+ g++ --version | head -n1
+ ld --version | head -n1
+ date
+ lscpu
+ } > $BOT_DIR/info/host
+
+
+#echo "SLAVE_RUNNER=/usr/bin/buildslave
+#SLAVE_ENABLED[1]=\"1\"
+#SLAVE_NAME[1]=\"$BOT_NAME\"
+#SLAVE_USER[1]=\"buildbot\"
+#SLAVE_BASEDIR[1]=\"$BOT_DIR\"
+#SLAVE_OPTIONS[1]=\"\"
+#SLAVE_PREFIXCMD[1]=\"\"" > $BOT_DIR/buildslave.cfg
+
+ ls $BOT_DIR/
+ cat $BOT_DIR/buildbot.tac
+}
+
+function try_start_builder {
+ local N=$1
+ local BOT_DIR="$BOT_ROOT/b$N"
+ local BOT_NAME="$BOT_ROOT_NAME$N"
+
+ systemctl daemon-reload
+ service buildslave restart
+ setup_numbered_bot "$BOT_NAME" "$BOT_DIR"
+
+ systemctl daemon-reload
+ service buildslave restart
+
+ chown -R buildbot:buildbot $BOT_DIR/
+ sudo -u buildbot /usr/bin/buildslave start $BOT_DIR/
+
+ sleep 30
+ cat $BOT_DIR/twistd.log
+ if grep --quiet "slave is ready" $BOT_DIR/twistd.log; then
+ return 0
+ fi
+ if grep --quiet "configuration update complete" $BOT_DIR/twistd.log; then
+ return 0
+ fi
+ if grep "rejecting duplicate slave" $BOT_DIR/twistd.log; then
+ return 1
+ fi
+ echo "Unknown error"
+ cat $BOT_DIR/twistd.log
+ exit 1
+}
+
+for N in `shuf -i 1-5`
+do
+ if try_start_builder $N; then
+ break
+ fi
+ echo "failed to start any buildbot"
+ shutdown now
+done
+
+# GCE can restart instance after 24h in the middle of the build.
+# Gracefully restart before that happen.
+sleep 72000
+while pkill -SIGHUP buildslave; do sleep 5; done;
+shutdown now