Initial Kokoro cbuild

This does a lot of somewhat hacky setup to get the Kokoro VM in our desired state. We'll move to custom VM images or docker containers eventually. All tests pass. Unfortunately, logs are not yet externally visible (coming soon).

Also includes a debug script I used to get things set up. It allows accessing the Kokoro VM by authorizing the provided SSH public key, printing the VMs IP, and then putting the process to sleep to keep the VM alive.

Closes #178

PiperOrigin-RevId: 284249331
diff --git a/kokoro/gcp_ubuntu/bazel_build.sh b/kokoro/gcp_ubuntu/bazel_build.sh
index 2c3216d..45768ee 100755
--- a/kokoro/gcp_ubuntu/bazel_build.sh
+++ b/kokoro/gcp_ubuntu/bazel_build.sh
@@ -16,13 +16,44 @@
 
 # Build the project with bazel using Kokoro.
 
-# Having separate build scripts with this indirection is recommended by the
-# Kokoro setup instructions.
-
 set -e
 
 set -x
 
+# TODO(b/145697435) Kokoro VMs have bad public keys. Delete when this is fixed.
+echo "Deleting corrupted ppa sources"
+sudo rm -rf /etc/apt/sources.list.d/nvidia-docker.list*
+# Make sure we don't run the old version of bazel the VM comes with.
+echo "Deleting old bazel version"
+sudo rm /usr/local/bin/bazel
+
+export BAZEL_VERSION=1.1.0
+echo "Installing bazel ${BAZEL_VERSION}"
+# https://docs.bazel.build/versions/master/install-ubuntu.html
+wget "https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-installer-linux-x86_64.sh"
+chmod +x "bazel-${BAZEL_VERSION}-installer-linux-x86_64.sh"
+./bazel-${BAZEL_VERSION}-installer-linux-x86_64.sh --user
+export PATH="${HOME}/bin:${PATH}"
+bazel --version
+
+echo "Installing clang 6.0"
+wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
+sudo apt-add-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-6.0 main"
+sudo apt-get update
+sudo apt-get install -y clang-6.0
+clang++-6.0 --version
+
+python3 -V
+
+echo "Preparing environment variables"
+export CXX=clang++-6.0
+export CC=clang-6.0
+export PYTHON_BIN="$(which python3)"
+
 # Kokoro checks out the repository here.
 cd ${KOKORO_ARTIFACTS_DIR}/github/iree
+echo "Checking out submodules"
+git submodule update --init --depth 1000 --jobs 8
+
+echo "Building and testing with bazel"
 ./build_tools/bazel_build.sh
diff --git a/kokoro/gcp_ubuntu/ssh_debug.sh b/kokoro/gcp_ubuntu/ssh_debug.sh
new file mode 100755
index 0000000..b333de4
--- /dev/null
+++ b/kokoro/gcp_ubuntu/ssh_debug.sh
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+# Copyright 2019 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# A script that allows accessing a Kokoro VM for debugging.
+# To use, set the SSH_PUBLIC_KEY variable to your SSH public key and then
+# run this on a Kokoro VM by setting it as the build file in the build
+# configuration for the relevant job (e.g.
+# https://github.com/google/iree/tree/master/iree/kokoro/gcp_ubuntu/continuous.cfg). After setup the VM
+# debug logs will print out the external IP address and you can SSH into
+# kbuilder@INSTANCE_EXTERNAL_IP.
+
+set -e
+
+set -x
+
+SSH_PUBLIC_KEY=""
+
+echo "${SSH_PUBLIC_KEY}" >> ~/.ssh/authorized_keys
+external_ip=$(curl -s -H "Metadata-Flavor: Google" http://metadata/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip)
+echo "INSTANCE_EXTERNAL_IP=${external_ip}"
+sleep 10000 # Keep the VM alive for a few hours