2019-01-20 12:16:47 -08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2019-12-31 20:48:08 -08:00
|
|
|
set -euo pipefail
|
2019-01-20 12:16:47 -08:00
|
|
|
|
2019-11-21 11:36:36 -08:00
|
|
|
ROOT_DIR=$(cd "$(dirname "${BASH_SOURCE:-$0}")"; pwd)
|
|
|
|
|
2020-06-12 12:59:22 -07:00
|
|
|
version="3.2.0"
|
2019-12-31 20:48:08 -08:00
|
|
|
achitecture="${HOSTTYPE}"
|
2019-01-20 12:16:47 -08:00
|
|
|
platform="unknown"
|
2019-12-31 20:48:08 -08:00
|
|
|
case "${OSTYPE}" in
|
|
|
|
msys)
|
|
|
|
echo "Platform is Windows."
|
|
|
|
platform="windows"
|
|
|
|
# No installer for Windows
|
|
|
|
;;
|
|
|
|
darwin*)
|
|
|
|
echo "Platform is Mac OS X."
|
|
|
|
platform="darwin"
|
|
|
|
;;
|
|
|
|
linux*)
|
|
|
|
echo "Platform is Linux (or WSL)."
|
|
|
|
platform="linux"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unrecognized platform."
|
|
|
|
exit 1
|
|
|
|
esac
|
|
|
|
|
2020-03-30 16:29:54 -07:00
|
|
|
# Sanity check: Verify we have symlinks where we expect them, or Bazel can produce weird "missing input file" errors.
|
|
|
|
# This is most likely to occur on Windows, where symlinks are sometimes disabled by default.
|
|
|
|
{ git ls-files -s || true; } | {
|
|
|
|
missing_symlinks=()
|
|
|
|
while read -r mode digest sn path; do
|
|
|
|
if [ "${mode}" = 120000 ]; then
|
|
|
|
test -L "${path}" || missing_symlinks+=("${paths}")
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ ! 0 -eq "${#missing_symlinks[@]}" ]; then
|
|
|
|
echo "error: expected symlink: ${missing_symlinks[@]}" 1>&2
|
|
|
|
echo "For a correct build, please run 'git config --local core.symlinks true' and re-run git checkout." 1>&2
|
|
|
|
false
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-12-31 20:48:08 -08:00
|
|
|
if [ "${OSTYPE}" = "msys" ]; then
|
|
|
|
target="${MINGW_DIR-/usr}/bin/bazel.exe"
|
|
|
|
mkdir -p "${target%/*}"
|
2020-05-05 10:47:49 -07:00
|
|
|
curl -f -s -L -R -o "${target}" "https://github.com/bazelbuild/bazel/releases/download/${version}/bazel-${version}-${platform}-${achitecture}.exe"
|
|
|
|
tee /etc/profile.d/bazel.sh > /dev/null <<EOF; . /etc/profile.d/bazel.sh
|
|
|
|
export USE_CLANG_CL=1 # Clang front-end for Visual C++
|
|
|
|
EOF
|
2019-01-20 12:16:47 -08:00
|
|
|
else
|
2019-12-31 20:48:08 -08:00
|
|
|
target="./install.sh"
|
2020-05-05 10:47:49 -07:00
|
|
|
curl -f -s -L -R -o "${target}" "https://github.com/bazelbuild/bazel/releases/download/${version}/bazel-${version}-installer-${platform}-${achitecture}.sh"
|
2019-12-31 20:48:08 -08:00
|
|
|
chmod +x "${target}"
|
2020-06-15 17:27:17 -07:00
|
|
|
if [ "${CI-}" = true ]; then
|
2020-04-10 13:26:28 -07:00
|
|
|
sudo "${target}" > /dev/null # system-wide install for CI
|
|
|
|
command -V bazel 1>&2
|
|
|
|
else
|
|
|
|
"${target}" --user > /dev/null
|
|
|
|
fi
|
2019-12-31 20:48:08 -08:00
|
|
|
rm -f "${target}"
|
2019-01-20 12:16:47 -08:00
|
|
|
fi
|
|
|
|
|
2020-06-15 17:27:17 -07:00
|
|
|
for bazel_cfg in ${BAZEL_CONFIG-}; do
|
|
|
|
echo "build --config=${bazel_cfg}" >> ~/.bazelrc
|
|
|
|
done
|
2019-12-31 20:48:08 -08:00
|
|
|
if [ "${TRAVIS-}" = true ]; then
|
2020-06-15 17:27:17 -07:00
|
|
|
echo "build --config=ci-travis" >> ~/.bazelrc
|
|
|
|
|
|
|
|
# If we are in Travis, most of the compilation result will be cached.
|
|
|
|
# This means we are I/O bounded. By default, Bazel set the number of concurrent
|
|
|
|
# jobs to the the number cores on the machine, which are not efficient for
|
|
|
|
# network bounded cache downloading workload. Therefore we increase the number
|
|
|
|
# of jobs to 50
|
|
|
|
# NOTE: Normally --jobs should be under 'build:ci-travis' in .bazelrc, but we put
|
|
|
|
# it under 'build' here avoid conflicts with other --config options.
|
|
|
|
echo "build --jobs=50" >> ~/.bazelrc
|
2019-12-31 20:48:08 -08:00
|
|
|
fi
|
2020-06-15 17:27:17 -07:00
|
|
|
if [ "${GITHUB_ACTIONS-}" = true ]; then
|
|
|
|
echo "build --config=ci-github" >> ~/.bazelrc
|
2020-03-01 14:04:06 -08:00
|
|
|
fi
|
2020-06-15 17:27:17 -07:00
|
|
|
if [ "${CI-}" = true ]; then
|
|
|
|
echo "build --config=ci" >> ~/.bazelrc
|
2019-12-31 20:48:08 -08:00
|
|
|
# If we are in master build, we can write to the cache as well.
|
|
|
|
upload=0
|
|
|
|
if [ "${TRAVIS_PULL_REQUEST-false}" = false ]; then
|
|
|
|
if [ -n "${BAZEL_CACHE_CREDENTIAL_B64:+x}" ]; then
|
|
|
|
{
|
|
|
|
printf "%s" "${BAZEL_CACHE_CREDENTIAL_B64}" | base64 -d - >> "${HOME}/bazel_cache_credential.json"
|
|
|
|
} 2>&- # avoid printing secrets
|
|
|
|
upload=1
|
|
|
|
elif [ -n "${encrypted_1c30b31fe1ee_key:+x}" ]; then
|
|
|
|
{
|
|
|
|
openssl aes-256-cbc -K "${encrypted_1c30b31fe1ee_key}" \
|
|
|
|
-iv "${encrypted_1c30b31fe1ee_iv}" \
|
|
|
|
-in "${ROOT_DIR}/bazel_cache_credential.json.enc" \
|
|
|
|
-out "${HOME}/bazel_cache_credential.json" -d
|
|
|
|
} 2>&- # avoid printing secrets
|
|
|
|
if [ 0 -eq $? ]; then
|
|
|
|
upload=1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [ 0 -ne "${upload}" ]; then
|
2020-06-15 17:27:17 -07:00
|
|
|
translated_path=~/bazel_cache_credential.json
|
2019-12-31 20:48:08 -08:00
|
|
|
if [ "${OSTYPE}" = msys ]; then # On Windows, we need path translation
|
|
|
|
translated_path="$(cygpath -m -- "${translated_path}")"
|
|
|
|
fi
|
2020-06-15 17:27:17 -07:00
|
|
|
cat <<EOF >> ~/.bazelrc
|
2020-02-26 12:28:13 -08:00
|
|
|
build --google_credentials="${translated_path}"
|
|
|
|
EOF
|
2019-11-21 11:36:36 -08:00
|
|
|
else
|
2019-12-31 20:48:08 -08:00
|
|
|
echo "Using remote build cache in read-only mode." 1>&2
|
2020-06-15 17:27:17 -07:00
|
|
|
cat <<EOF >> ~/.bazelrc
|
2020-02-26 12:28:13 -08:00
|
|
|
build --remote_upload_local_results=false
|
|
|
|
EOF
|
2019-11-21 11:36:36 -08:00
|
|
|
fi
|
2019-07-10 22:03:45 +08:00
|
|
|
fi
|