From 0bf1413833ad78784771fefb468f080a53640136 Mon Sep 17 00:00:00 2001 From: John Cater Date: Wed, 28 Mar 2018 13:55:44 -0700 Subject: bazel-dev is a helper script which attempts to rebuild Bazel on every execution. Change-Id: Iaa5168ac8e6c13b0ac5dfc7340c0ccdfc0dcf132 Closes #4932. Change-Id: I023c83f7373d339c2725e5a4a4b00c9d1dc1a2eb PiperOrigin-RevId: 190828186 --- scripts/bazel-dev.sh | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 scripts/bazel-dev.sh (limited to 'scripts') diff --git a/scripts/bazel-dev.sh b/scripts/bazel-dev.sh new file mode 100644 index 0000000000..76ae52bdc6 --- /dev/null +++ b/scripts/bazel-dev.sh @@ -0,0 +1,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 [...]" +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" + +# 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 || 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 "$@" + -- cgit v1.2.3