1#!/usr/bin/env bash
2# Copyright 2021 The TensorFlow Authors. All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15# ==============================================================================
16
17# Select bazel version.
18BAZEL_VERSION="3.7.2"
19
20set +e
21local_bazel_ver=$(bazel version 2>&1 | grep -i label | awk '{print $3}')
22
23if [[ "$local_bazel_ver" == "$BAZEL_VERSION" ]]; then
24  exit 0
25fi
26
27set -e
28
29# Install bazel.
30mkdir -p /bazel
31cd /bazel
32if [[ ! -f "bazel-$BAZEL_VERSION-installer-linux-x86_64.sh" ]]; then
33  curl -fSsL -O https://github.com/bazelbuild/bazel/releases/download/$BAZEL_VERSION/bazel-$BAZEL_VERSION-installer-linux-x86_64.sh
34fi
35chmod +x /bazel/bazel-*.sh
36/bazel/bazel-$BAZEL_VERSION-installer-linux-x86_64.sh
37rm -f /bazel/bazel-$BAZEL_VERSION-installer-linux-x86_64.sh
38
39# Enable bazel auto completion.
40echo "source /usr/local/lib/bazel/bin/bazel-complete.bash" >> ~/.bashrc
41