Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pin Bazel versions #812

Merged
merged 13 commits into from
Aug 15, 2019
69 changes: 35 additions & 34 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,66 +1,67 @@
# trusty beta image has jdk8, gcc4.8.4
dist: trusty
dist: xenial
sudo: required
# xcode8 has jdk8
osx_image: xcode8
# Not technically required but suppresses 'Ruby' in Job status message.
language: sh
osx_image: xcode10.1

addons:
apt:
packages:
- libxml2-utils

cache:
directories:
- .bazel_cache
- ~/.bazel_binaries

os:
- linux
- osx
- windows

###
#
# Want to update/change bazel versions?
#
# 1. Update the bazel_version case statement in
# ./tools/bazel to include hashes for the bazel version
# you're targeting.
#
# 2. either
# - If you're updating the default bazel version, change
# default_bazel_version in ./tools/bazel.
# or
# - If you want to add an additional bazel version to the build
# matrix, set BAZEL_VERSION=<desired-version> along side
# TEST_SCRIPT below.
#
# 3. If you need to update the Windows version, adjust
# the windows specific install code below.
#
###

env:
# Linting is broken. Disable until fixed.
# See https://github.com/bazelbuild/rules_scala/pull/622
# we want to test the last release
#- V=0.16.1 TEST_SCRIPT=test_lint.sh
- V=0.28.0 TEST_SCRIPT=test_rules_scala
#- V=0.14.1 TEST_SCRIPT=test_intellij_aspect.sh
- V=0.28.0 TEST_SCRIPT=test_reproducibility
#- TEST_SCRIPT=test_lint.sh
- TEST_SCRIPT=test_rules_scala
#- TEST_SCRIPT=test_intellij_aspect.sh
- TEST_SCRIPT=test_reproducibility


before_install:
- |
if [[ "${TRAVIS_OS_NAME}" == "windows" ]]; then
choco install jdk8 -params 'installdir=c:\\java8'
choco install bazel --version ${V}
else
if [[ "${TRAVIS_OS_NAME}" == "osx" ]]; then
OS=darwin
else
sudo sysctl kernel.unprivileged_userns_clone=1
sudo add-apt-repository -y ppa:openjdk-r/ppa
sudo apt-get update -q
sudo apt-get install openjdk-8-jdk -y
sudo apt-get install libxml2-utils -y
OS=linux
fi

if [[ $V =~ .*rc[0-9]+.* ]]; then
PRE_RC=$(expr "$V" : '\([0-9.]*\)rc.*')
RC_PRC=$(expr "$V" : '[0-9.]*\(rc.*\)')
URL="https://storage.googleapis.com/bazel/${PRE_RC}/${RC_PRC}/bazel-${V}-installer-${OS}-x86_64.sh"
else
URL="https://github.com/bazelbuild/bazel/releases/download/${V}/bazel-${V}-installer-${OS}-x86_64.sh"
fi
wget -O install.sh "${URL}"
chmod +x install.sh
./install.sh --user
rm -f install.sh
choco install bazel --version 0.28.0
fi
- cat .bazelrc.travis >> .bazelrc

script:
- |
if [[ "${TRAVIS_OS_NAME}" == "windows" ]]; then
powershell -Command 'Set-ExecutionPolicy RemoteSigned -scope CurrentUser'
powershell -File ./${TEST_SCRIPT}.ps1
BAZEL_VERSION=host powershell -File ./${TEST_SCRIPT}.ps1
else
bash ./${TEST_SCRIPT}.sh ci
fi
5 changes: 5 additions & 0 deletions test_reproducibility.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

set -e

if ! bazel_loc="$(type -p 'bazel')" || [[ -z "$bazel_loc" ]]; then
export PATH="$(cd "$(dirname "$0")"; pwd)"/tools:$PATH
echo 'Using ./tools/bazel directly for bazel calls'
fi

md5_util() {
if [[ "$OSTYPE" == "darwin"* ]]; then
_md5_util="md5"
Expand Down
7 changes: 6 additions & 1 deletion test_rules_scala.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

set -e

if ! bazel_loc="$(type -p 'bazel')" || [[ -z "$bazel_loc" ]]; then
export PATH="$(cd "$(dirname "$0")"; pwd)"/tools:$PATH
echo 'Using ./tools/bazel directly for bazel calls'
fi

test_disappearing_class() {
git checkout test_expect_failure/disappearing_class/ClassProvider.scala
bazel build test_expect_failure/disappearing_class:uses_class
Expand Down Expand Up @@ -1138,4 +1143,4 @@ $runner test_scalac_jvm_flags_from_scala_toolchain_fails
$runner test_scalac_jvm_flags_work_with_scalapb
$runner test_scala_test_jvm_flags_on_target_overrides_toolchain_passes
$runner test_scala_test_jvm_flags_from_scala_toolchain_passes
$runner test_scala_test_jvm_flags_from_scala_toolchain_fails
$runner test_scala_test_jvm_flags_from_scala_toolchain_fails
4 changes: 2 additions & 2 deletions test_runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ run_test_ci() {
local TEST_ARG=$@
local log_file=output_$$.log
echo "running test $TEST_ARG"
$TEST_ARG &>$log_file &
eval $TEST_ARG &>$log_file &
local test_pid=$!
SECONDS=0
test_pulse_printer $! $TIMOUT $TEST_ARG &
Expand Down Expand Up @@ -83,4 +83,4 @@ get_test_runner() {
exit 1
fi
echo "run_test_${test_env}"
}
}
85 changes: 85 additions & 0 deletions tools/bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env bash
set -e

default_bazel_version='0.28.1'

if [ "$BUILDKITE" = true ]; then
bazel_version='host'
else
case $(uname -s) in
Darwin|Linux)
# shellcheck disable=SC2153
if [ -z "$BAZEL_VERSION" ]; then
bazel_version="$default_bazel_version"
else
bazel_version="$BAZEL_VERSION"
fi
;;
*)
# windows, presumably
bazel_version='host'
;;
esac
fi

case "$bazel_version" in
'host')
bazel_version=$("$BAZEL_REAL" version | awk '/Build label/ {print $3}' | cut -d '-' -f 1)
bazel="$BAZEL_REAL"
;;
'0.28.1')
andyscott marked this conversation as resolved.
Show resolved Hide resolved
darwin_sha='5d50ae13ba01a224ddf54cfd818289bee5b38e551cca22bffc79b89f377d2095'
linux_sha='a2a7e4cb38d7bc774a5bbfab4d45293f5f2158eb6caf0128792cc1148732a4e6'
;;
*)
echo "The requested Bazel version '$bazel_version' is not supported"
exit 1
;;
esac

if [ -z "$bazel" ]; then
bazel_bin_loc=~/.bazel_binaries
bazel=$bazel_bin_loc/$bazel_version/bin/bazel-real

if ! [ -f "$bazel" ]; then
case $(uname -s) in
Darwin)
platform='darwin'
sha=$darwin_sha
;;
Linux)
platform='linux'
sha=$linux_sha
;;
*)
echo 'Your OS is not supported for automatic bazel installs.'
exit 1
;;
esac
remote_source=https://github.com/bazelbuild/bazel/releases/download
installer_name="bazel-$bazel_version-installer-$platform-x86_64.sh"
url="$remote_source/$bazel_version/$installer_name"
(
tmp_dir=$(mktemp -d)
# shellcheck disable=SC2064
trap "rm -rf $tmp_dir" EXIT
cd "$tmp_dir"
(>&2 echo "downloading installer from")
(>&2 echo "$url")
curl -o installer.sh -L "$url"
generated_sha=$(shasum -a 256 installer.sh | awk '{print $1}')
if [ "$generated_sha" != "$sha" ]; then
echo "Sha 256 does not match, expected: $sha"
echo "But found $generated_sha"
echo "Recommend you: update the sha to the expected"
echo "and then re-run this script"
exit 1
fi
mkdir -p $bazel_bin_loc
chmod +x installer.sh
./installer.sh --base="$bazel_bin_loc"/"$bazel_version" --bin="$bazel_bin_loc"/"$bazel_version"/bin_t
) >&2
fi
fi

exec "$bazel" "$@"