-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbazel
executable file
·121 lines (96 loc) · 3.26 KB
/
bazel
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
#!/bin/bash
# Update the WORKSPACE to point at new bazel versions
# https://github.com/bazelbuild/bazel
set -e
ORIGINAL_PWD=$PWD
TMPDIR="${TMPDIR:-/tmp}"
RND_UID="${USER}_$(date "+%s")_${RANDOM}"
function try_goto_cmd_location() {
BASH_LOC=${BASH_SOURCE[0]}
if [ ! -z "$BASH_LOC" ]; then
DIR_NAME=$(dirname "$BASH_LOC")
CMD_LOC="$( cd "$DIR_NAME" && pwd )"
if [ ! -z "$CMD_LOC" ]; then
cd $CMD_LOC
fi
fi
}
# If we are executed as a sub-process we won't be able to do this
# So we do it as a try
try_goto_cmd_location
set -e
findWorkspace() {
OLD_PWD=$PWD
if [ ! -f WORKSPACE ]; then
cd ..
if [ "$PWD" = "$OLD_PWD" ]; then
echo "Didn't find the workspace"
exit 1
fi
findWorkspace
fi
}
findWorkspace
REPO_ROOT=$PWD
cd $ORIGINAL_PWD
if [ "$(uname -s)" == "Linux" ]; then
export BAZEL_LAUNCHER_PLATFORM_NAME='linux'
elif [ "$(uname -s)" == "Darwin" ]; then
export BAZEL_LAUNCHER_PLATFORM_NAME='darwin'
else
"Your platform $(uname -s) is unsupported, sorry"
exit 1
fi
if [ -z "$BAZEL_REMOTE_SOURCE" ]; then
export BAZEL_REMOTE_SOURCE=https://github.com/bazelbuild/bazel/releases/download
fi
# we store the settings in the WORKSPACE
export BAZEL_VERSION=$(cat $REPO_ROOT/WORKSPACE | egrep '^BAZEL_VERSION\s*=\s*' | sed -e 's/.*=//g' -e 's/ //g' -e 's/"//g')
SHA_VARIABLE_NAME="BAZEL_INSTALLER_VERSION_${BAZEL_LAUNCHER_PLATFORM_NAME}_SHA"
# So we can compare what we download against an expected SHA 256
export BAZEL_INSTALLER_VERSION_SHA=$(cat $REPO_ROOT/WORKSPACE | egrep "^${SHA_VARIABLE_NAME}\s*=\s*" | sed -e 's/.*=//g' -e 's/ //g' -e 's/"//g')
export BAZEL_ZIP_PATH=$(cat $REPO_ROOT/WORKSPACE | egrep '^BAZEL_ZIP_PATH\s*=\s*' | sed -e 's/.*=//g' -e 's/ //g' -e 's/"//g')
if [ -z BAZEL_VERSION ]; then
echo "Must supply a BAZEL_VERSION in the workspace"
exit 1
fi
if [ -z "$BAZEL_INSTALLER_VERSION_SHA" ]; then
echo "Must supply a ${SHA_VARIABLE_NAME} in the workspace"
exit 1
fi
if [ -z "$BAZEL_BIN_LOC" ]; then
BAZEL_BIN_LOC=~/.bazel_binaries
fi
mkdir -p $BAZEL_BIN_LOC
export BAZEL_EXEC_PATH=$BAZEL_BIN_LOC/$BAZEL_VERSION/bin/bazel-real
if [ -f "$BAZEL_EXEC_PATH" ]; then
exec $BAZEL_EXEC_PATH "$@"
fi
export BUILD_DIR=${TMPDIR}/bazel_b_${RND_UID}
mkdir -p $BUILD_DIR
( # Opens a subshell
set -e
echo "Installing Bazel, this will take a few seconds depending on your internet connection speed."
cd $BUILD_DIR
INSTALLER_NAME="bazel-${BAZEL_VERSION}-installer-${BAZEL_LAUNCHER_PLATFORM_NAME}-x86_64.sh"
echo $PWD
if [ -z $BAZEL_INSTALLER_PATH ]; then
BAZEL_INSTALLER_PATH=$BAZEL_REMOTE_SOURCE/${BAZEL_VERSION}/$INSTALLER_NAME
fi
curl -O -L $BAZEL_INSTALLER_PATH
GENERATED_SHA_256=$(shasum -a 256 $INSTALLER_NAME | awk '{print $1}')
if [ "$GENERATED_SHA_256" != "$BAZEL_INSTALLER_VERSION_SHA" ]; then
echo "Sha 256 does not match, expected: $BAZEL_INSTALLER_VERSION_SHA"
echo "But found $GENERATED_SHA_256"
echo "Recommend you: update the sha to the expected"
echo "and then re-run this script"
exit 1
fi
chmod +x ${INSTALLER_NAME}
mkdir -p ${BAZEL_BIN_LOC}/${BAZEL_VERSION}/bin_t
./${INSTALLER_NAME} --base=${BAZEL_BIN_LOC}/${BAZEL_VERSION} --bin=${BAZEL_BIN_LOC}/${BAZEL_VERSION}/bin_t
)
rm -rf $BUILD_DIR
cd $ORIGINAL_PWD
ls -R ${BAZEL_BIN_LOC}
exec $BAZEL_EXEC_PATH "$@"