-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbazel_wrapper
executable file
·128 lines (99 loc) · 4.33 KB
/
bazel_wrapper
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/env bash
# Do not edit this file directly.
# It was auto-generated by: code/programs/reflexivity/reflexive_refresh
set -euo pipefail
# This is the front-end script that bootstraps and calls bazel.
# Any build commands will go through this script.
# it is expected to behave the same as the bazel command itself (with bootstraping capability / extra features).
# We may also consider bazelisk, but bazelisk would likely need bootstrapped as well.
# Regardless, we'll always want some kind of bare bones shell script to get/call other build tools.
url=https://github.com/bazelbuild/bazelisk/releases/download/v1.18.0/bazelisk-linux-amd64
sha256=ce52caa51ef9e509fb6b7e5ad892e5cf10feb0794b0aed4d2f36adb00a1a2779
# paths to place bazel related artifacts.
# CONSIDER(thickey): should we really install bazel in the user's home directory?
# Are we sure they will even have a home repo? Would it be better to install it inside the repo itself?
# I think this is fine for now. We'll see if any problems arise.
# It may be recomended to have bazel write its cache to the home directory anyway.
cache_root="${HOME}/.cache"
install_dir="${cache_root}/bazel/${sha256}"
bazel="${install_dir}/bazel"
if [[ -n "${BAZEL_PATH_OVERRIDE-}" ]]; then
bazel=${BAZEL_PATH_OVERRIDE}
fi
function robust_download() {
while [ 1 ]; do
wget "${url}" -O "${in_progress_download}" --retry-connrefused --waitretry=1 --read-timeout=20 --timeout=15 -t 0
if [ $? = 0 ]; then break; fi;
sleep 1s;
done;
}
function bootstrap_bazel() {
if [[ ! -f "${bazel}" ]]; then
ensure_barebone_binaries
pre_bazel_download_setup_env
download_bazel
post_bazel_download_verify
fi
}
function ensure_command_exists() {
command -v $1 >/dev/null 2>&1 || { echo >&2 "I require $1 but it's not installed. Aborting."; exit 1; }
}
function ensure_barebone_binaries() {
# Check for some bootstraping necessities
# If these bare-bone requirements don't exist, I considered installing them for the user automatically.
# For example, one of the online CIs, does not have wget when it spins up.
# That seems hard to figure out due to the different systems and package managers.
# For now, we can handle these kinds of dependencies prior to running this script.
# For example, most CI services have some kind of pre-install phase. where you can install system packages.
# We should try to build all of these tools from source as well
ensure_command_exists command
ensure_command_exists echo
ensure_command_exists exit
ensure_command_exists mkdir
ensure_command_exists rm
ensure_command_exists chmod
ensure_command_exists trap
ensure_command_exists tty
ensure_command_exists wget
ensure_command_exists sha256sum
# Bazel runtime dependencies
# Do you need some kind of Java tooling installed for bazel first? If so, add it here!
# I think sfortson mentioned that he had to install bazel first. The CIs seem to be fine, but sam was on arch linux
# I'm not sure if bazel's thing is truely stand-alone or what. you might need the jvm first.
# No, bazel comes bundled with a minimal jvm. We should be fine.
# We assume no runtime dependencies for running bazel
}
function pre_bazel_download_setup_env() {
# Say that we are missing bazel, and will install it
echo "INFO: Required bazel version not found."
echo "downloading to ${bazel}..." >&2
# Setup install directory
mkdir -p "${install_dir}"
# delete it on failure
# deleting it on failure is quite annoying and causes many re-fetches.
# trap 'rm -rf "${install_dir}"' ERR INT TERM
}
function download_bazel() {
# Download bazel
in_progress_download="${install_dir}/in_progress_download"
if tty -s; then
robust_download
else
wget "${url}" -O "${in_progress_download}" --no-verbose
fi
}
function post_bazel_download_verify() {
# Check that our download is valid
echo "${sha256} ${in_progress_download}" | sha256sum --check >&2
chmod +x "${in_progress_download}"
mv "${in_progress_download}" "${bazel}"
trap - ERR INT TERM
}
bootstrap_bazel
# If Inside Emacs Bazel tries to be helpful say it's "entering a
# directory" but that actually confuses emacs because then it starts
# looking for files inside the runfiles tree.
unset INSIDE_EMACS
# Run the real bazel that we boostrapped
cd source;
"${bazel}" "$@"