Skip to content

Commit 3fe7dee

Browse files
andyscottjohnynek
authored andcommitted
Pin Bazel versions (#812)
* Pin Bazel versions * ensure one set of jobs is named test * Keep the original build structure * fix version for windows * add ci stopgap to scripts used in ci * fix ci errors * adjust for buildkite * remove unused param * Tweak travis image config * use sh language * libxml2-utils * use apt addon * Add notes about updating bazel versions
1 parent 8a5ca6b commit 3fe7dee

File tree

5 files changed

+133
-37
lines changed

5 files changed

+133
-37
lines changed

.travis.yml

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,67 @@
1-
# trusty beta image has jdk8, gcc4.8.4
2-
dist: trusty
1+
dist: xenial
32
sudo: required
4-
# xcode8 has jdk8
5-
osx_image: xcode8
6-
# Not technically required but suppresses 'Ruby' in Job status message.
73
language: sh
4+
osx_image: xcode10.1
5+
6+
addons:
7+
apt:
8+
packages:
9+
- libxml2-utils
810

911
cache:
1012
directories:
1113
- .bazel_cache
14+
- ~/.bazel_binaries
1215

1316
os:
1417
- linux
1518
- osx
1619
- windows
1720

21+
###
22+
#
23+
# Want to update/change bazel versions?
24+
#
25+
# 1. Update the bazel_version case statement in
26+
# ./tools/bazel to include hashes for the bazel version
27+
# you're targeting.
28+
#
29+
# 2. either
30+
# - If you're updating the default bazel version, change
31+
# default_bazel_version in ./tools/bazel.
32+
# or
33+
# - If you want to add an additional bazel version to the build
34+
# matrix, set BAZEL_VERSION=<desired-version> along side
35+
# TEST_SCRIPT below.
36+
#
37+
# 3. If you need to update the Windows version, adjust
38+
# the windows specific install code below.
39+
#
40+
###
41+
1842
env:
1943
# Linting is broken. Disable until fixed.
2044
# See https://github.com/bazelbuild/rules_scala/pull/622
2145
# we want to test the last release
22-
#- V=0.16.1 TEST_SCRIPT=test_lint.sh
23-
- V=0.28.0 TEST_SCRIPT=test_rules_scala
24-
#- V=0.14.1 TEST_SCRIPT=test_intellij_aspect.sh
25-
- V=0.28.0 TEST_SCRIPT=test_reproducibility
46+
#- TEST_SCRIPT=test_lint.sh
47+
- TEST_SCRIPT=test_rules_scala
48+
#- TEST_SCRIPT=test_intellij_aspect.sh
49+
- TEST_SCRIPT=test_reproducibility
2650

2751

2852
before_install:
2953
- |
3054
if [[ "${TRAVIS_OS_NAME}" == "windows" ]]; then
3155
choco install jdk8 -params 'installdir=c:\\java8'
32-
choco install bazel --version ${V}
33-
else
34-
if [[ "${TRAVIS_OS_NAME}" == "osx" ]]; then
35-
OS=darwin
36-
else
37-
sudo sysctl kernel.unprivileged_userns_clone=1
38-
sudo add-apt-repository -y ppa:openjdk-r/ppa
39-
sudo apt-get update -q
40-
sudo apt-get install openjdk-8-jdk -y
41-
sudo apt-get install libxml2-utils -y
42-
OS=linux
43-
fi
44-
45-
if [[ $V =~ .*rc[0-9]+.* ]]; then
46-
PRE_RC=$(expr "$V" : '\([0-9.]*\)rc.*')
47-
RC_PRC=$(expr "$V" : '[0-9.]*\(rc.*\)')
48-
URL="https://storage.googleapis.com/bazel/${PRE_RC}/${RC_PRC}/bazel-${V}-installer-${OS}-x86_64.sh"
49-
else
50-
URL="https://github.com/bazelbuild/bazel/releases/download/${V}/bazel-${V}-installer-${OS}-x86_64.sh"
51-
fi
52-
wget -O install.sh "${URL}"
53-
chmod +x install.sh
54-
./install.sh --user
55-
rm -f install.sh
56+
choco install bazel --version 0.28.0
5657
fi
5758
- cat .bazelrc.travis >> .bazelrc
5859

5960
script:
6061
- |
6162
if [[ "${TRAVIS_OS_NAME}" == "windows" ]]; then
6263
powershell -Command 'Set-ExecutionPolicy RemoteSigned -scope CurrentUser'
63-
powershell -File ./${TEST_SCRIPT}.ps1
64+
BAZEL_VERSION=host powershell -File ./${TEST_SCRIPT}.ps1
6465
else
6566
bash ./${TEST_SCRIPT}.sh ci
6667
fi

test_reproducibility.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
set -e
44

5+
if ! bazel_loc="$(type -p 'bazel')" || [[ -z "$bazel_loc" ]]; then
6+
export PATH="$(cd "$(dirname "$0")"; pwd)"/tools:$PATH
7+
echo 'Using ./tools/bazel directly for bazel calls'
8+
fi
9+
510
md5_util() {
611
if [[ "$OSTYPE" == "darwin"* ]]; then
712
_md5_util="md5"

test_rules_scala.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
set -e
44

5+
if ! bazel_loc="$(type -p 'bazel')" || [[ -z "$bazel_loc" ]]; then
6+
export PATH="$(cd "$(dirname "$0")"; pwd)"/tools:$PATH
7+
echo 'Using ./tools/bazel directly for bazel calls'
8+
fi
9+
510
test_disappearing_class() {
611
git checkout test_expect_failure/disappearing_class/ClassProvider.scala
712
bazel build test_expect_failure/disappearing_class:uses_class
@@ -1138,4 +1143,4 @@ $runner test_scalac_jvm_flags_from_scala_toolchain_fails
11381143
$runner test_scalac_jvm_flags_work_with_scalapb
11391144
$runner test_scala_test_jvm_flags_on_target_overrides_toolchain_passes
11401145
$runner test_scala_test_jvm_flags_from_scala_toolchain_passes
1141-
$runner test_scala_test_jvm_flags_from_scala_toolchain_fails
1146+
$runner test_scala_test_jvm_flags_from_scala_toolchain_fails

test_runner.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ run_test_ci() {
1212
local TEST_ARG=$@
1313
local log_file=output_$$.log
1414
echo "running test $TEST_ARG"
15-
$TEST_ARG &>$log_file &
15+
eval $TEST_ARG &>$log_file &
1616
local test_pid=$!
1717
SECONDS=0
1818
test_pulse_printer $! $TIMOUT $TEST_ARG &
@@ -83,4 +83,4 @@ get_test_runner() {
8383
exit 1
8484
fi
8585
echo "run_test_${test_env}"
86-
}
86+
}

tools/bazel

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
default_bazel_version='0.28.1'
5+
6+
if [ "$BUILDKITE" = true ]; then
7+
bazel_version='host'
8+
else
9+
case $(uname -s) in
10+
Darwin|Linux)
11+
# shellcheck disable=SC2153
12+
if [ -z "$BAZEL_VERSION" ]; then
13+
bazel_version="$default_bazel_version"
14+
else
15+
bazel_version="$BAZEL_VERSION"
16+
fi
17+
;;
18+
*)
19+
# windows, presumably
20+
bazel_version='host'
21+
;;
22+
esac
23+
fi
24+
25+
case "$bazel_version" in
26+
'host')
27+
bazel_version=$("$BAZEL_REAL" version | awk '/Build label/ {print $3}' | cut -d '-' -f 1)
28+
bazel="$BAZEL_REAL"
29+
;;
30+
'0.28.1')
31+
darwin_sha='5d50ae13ba01a224ddf54cfd818289bee5b38e551cca22bffc79b89f377d2095'
32+
linux_sha='a2a7e4cb38d7bc774a5bbfab4d45293f5f2158eb6caf0128792cc1148732a4e6'
33+
;;
34+
*)
35+
echo "The requested Bazel version '$bazel_version' is not supported"
36+
exit 1
37+
;;
38+
esac
39+
40+
if [ -z "$bazel" ]; then
41+
bazel_bin_loc=~/.bazel_binaries
42+
bazel=$bazel_bin_loc/$bazel_version/bin/bazel-real
43+
44+
if ! [ -f "$bazel" ]; then
45+
case $(uname -s) in
46+
Darwin)
47+
platform='darwin'
48+
sha=$darwin_sha
49+
;;
50+
Linux)
51+
platform='linux'
52+
sha=$linux_sha
53+
;;
54+
*)
55+
echo 'Your OS is not supported for automatic bazel installs.'
56+
exit 1
57+
;;
58+
esac
59+
remote_source=https://github.com/bazelbuild/bazel/releases/download
60+
installer_name="bazel-$bazel_version-installer-$platform-x86_64.sh"
61+
url="$remote_source/$bazel_version/$installer_name"
62+
(
63+
tmp_dir=$(mktemp -d)
64+
# shellcheck disable=SC2064
65+
trap "rm -rf $tmp_dir" EXIT
66+
cd "$tmp_dir"
67+
(>&2 echo "downloading installer from")
68+
(>&2 echo "$url")
69+
curl -o installer.sh -L "$url"
70+
generated_sha=$(shasum -a 256 installer.sh | awk '{print $1}')
71+
if [ "$generated_sha" != "$sha" ]; then
72+
echo "Sha 256 does not match, expected: $sha"
73+
echo "But found $generated_sha"
74+
echo "Recommend you: update the sha to the expected"
75+
echo "and then re-run this script"
76+
exit 1
77+
fi
78+
mkdir -p $bazel_bin_loc
79+
chmod +x installer.sh
80+
./installer.sh --base="$bazel_bin_loc"/"$bazel_version" --bin="$bazel_bin_loc"/"$bazel_version"/bin_t
81+
) >&2
82+
fi
83+
fi
84+
85+
exec "$bazel" "$@"

0 commit comments

Comments
 (0)