File: bazel-dev.sh

package info (click to toggle)
bazel-bootstrap 4.2.3%2Bds-11
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 85,704 kB
  • sloc: java: 721,717; sh: 55,859; cpp: 35,360; python: 12,139; xml: 295; objc: 269; makefile: 113; ansic: 106; ruby: 3
file content (70 lines) | stat: -rwxr-xr-x 2,072 bytes parent folder | download | duplicates (3)
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
#!/bin/bash
#
# Copyright 2018 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

set -eu

USAGE="$0 [<bazel arguments>...]"
DESCRIPTION='
  Rebuilds a development version of Bazel, if necessary, and then runs the
  given Bazel command using that binary.'

function usage() {
  echo "$USAGE" "$DESCRIPTION" >&2
}

# Configuration params. Export these in your bashrc to set personal defaults.

# The source of Bazel code.
BAZEL_REPO=${BAZEL_REPO:-https://github.com/bazelbuild/bazel}
# Where to keep the Bazel repository. If you make changes here, be warned that
# this script may overwrite or lose them.
BAZEL_DIR=${BAZEL_DIR:-$HOME/os-bazel}
# Bazel to use to build local bazel binaries.
BAZEL_BINARY=${BAZEL_BINARY:-$(which bazel)}

# The location of the resulting binary.
BAZEL_DEV="$BAZEL_DIR/bazel-bin/src/bazel-dev"

# First, check whether a rebuild is needed.
REBUILD=0
# If there is no built development Bazel, build it.
if [ ! -x "$BAZEL_DEV" ]; then
  REBUILD=1
fi
# If the current directory isn't the bazel working dir, always try to rebuild.
if [ "$(pwd)" != "$BAZEL_DIR" ]; then
  REBUILD=1
fi

# Perform a rebuild.
if [ "$REBUILD" == 1 ]; then
  echo -e "\033[31mBuilding dev version of bazel...\033[0m"
  (
    cd "$BAZEL_DIR"
    result=0
    ${BAZEL_BINARY} build //src:bazel-dev || result=$?
    if [[ $result != 0 ]]; then
      echo -e "\033[31mError building dev version of bazel.\033[0m"
      exit $result
    fi
  )
fi

# Execute bazel command.
echo -e "\e[31mExecuting bazel-dev...\e[0m"
exec $BAZEL_DEV "$@"