blob: 9c7cdbee60b2d57b70a83bfad6d24ae1998711e2 [file] [log] [blame]
Damien Martin-Guillerezd47a8ef2015-06-10 11:54:50 +00001#!/bin/bash
2
Damien Martin-Guillerezf88f4d82015-09-25 13:56:55 +00003# Copyright 2015 The Bazel Authors. All rights reserved.
Damien Martin-Guillerezd47a8ef2015-06-10 11:54:50 +00004#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# Use bazel to bootstrap various tools
18# Configuration:
19# BAZEL: path to the bazel binary
20# EMBED_LABEL: the label to embed in tools using --embed_label (optional)
Damien Martin-Guillerezd47a8ef2015-06-10 11:54:50 +000021# BAZELRC: the rc file to use
22
23: ${BAZELRC:="/dev/null"}
24: ${EMBED_LABEL:=""}
Klaus Aehlig48631ea2017-03-22 17:39:10 +000025: ${SOURCE_DATE_EPOCH:=""}
Damien Martin-Guillerezd47a8ef2015-06-10 11:54:50 +000026
27EMBED_LABEL_ARG=()
28if [ -n "${EMBED_LABEL}" ]; then
29 EMBED_LABEL_ARG=(--stamp --embed_label "${EMBED_LABEL}")
30fi
31
cushon63c92382022-01-18 10:57:53 -080032: ${JAVA_VERSION:="11"}
Damien Martin-Guillerez04d46ab2016-04-13 19:27:56 +000033
Fabian Meumertzheimbd63c612023-11-09 02:09:58 -080034# TODO: remove `--repo_env=BAZEL_HTTP_RULES_URLS_AS_DEFAULT_CANONICAL_ID=0` once all dependencies are
35# mirrored. See https://github.com/bazelbuild/bazel/pull/19549 for more context.
Yun Pengd2998a32020-04-24 01:32:40 -070036_BAZEL_ARGS="--spawn_strategy=standalone \
cushon032141d2018-04-25 13:01:05 -070037 --nojava_header_compilation \
38 --strategy=Javac=worker --worker_quit_after_build --ignore_unsupported_sandboxing \
39 --compilation_mode=opt \
Yun Peng136dae12023-09-08 12:39:10 -070040 --repository_cache=derived/repository_cache \
Fabian Meumertzheimbd63c612023-11-09 02:09:58 -080041 --repo_env=BAZEL_HTTP_RULES_URLS_AS_DEFAULT_CANONICAL_ID=0 \
Googlerf23440b2022-12-14 16:11:40 -080042 --extra_toolchains=//scripts/bootstrap:all \
Googlerb66b8c52023-08-04 01:46:42 -070043 --extra_toolchains=@bazel_tools//tools/python:autodetecting_toolchain \
Yun Peng136dae12023-09-08 12:39:10 -070044 --enable_bzlmod \
45 --check_direct_dependencies=error \
46 --lockfile_mode=update \
47 --override_repository=$(cat derived/maven/MAVEN_CANONICAL_REPO_NAME)=derived/maven \
Yun Pengd2998a32020-04-24 01:32:40 -070048 ${DIST_BOOTSTRAP_ARGS:-} \
cushon032141d2018-04-25 13:01:05 -070049 ${EXTRA_BAZEL_ARGS:-}"
Damien Martin-Guillerez5ed78952016-01-18 15:58:19 +000050
ilistd14fcf42020-12-14 05:15:06 -080051cp scripts/bootstrap/BUILD.bootstrap scripts/bootstrap/BUILD
52
Googlerb66b8c52023-08-04 01:46:42 -070053# Remove lines containing 'install_deps' to avoid loading @bazel_pip_dev_deps,
54# which requires fetching the python toolchain.
55sed -i.bak '/install_deps/d' WORKSPACE && rm WORKSPACE.bak
56
Damien Martin-Guillerezdaffc352016-01-18 15:20:32 +000057if [ -z "${BAZEL-}" ]; then
László Csomor3c0c2622017-02-13 15:46:28 +000058 function _run_bootstrapping_bazel() {
Laszlo Csomor9f7180f2016-09-27 13:07:43 +000059 local command=$1
60 shift
61 run_bazel_jar $command \
László Csomor3c0c2622017-02-13 15:46:28 +000062 ${_BAZEL_ARGS} --verbose_failures \
Laszlo Csomor9f7180f2016-09-27 13:07:43 +000063 --javacopt="-g -source ${JAVA_VERSION} -target ${JAVA_VERSION}" "${@}"
Damien Martin-Guillerezdaffc352016-01-18 15:20:32 +000064 }
65else
Laszlo Csomord0d7ef02017-04-26 10:48:00 +020066 function _run_bootstrapping_bazel() {
67 local command=$1
Laszlo Csomor9f7180f2016-09-27 13:07:43 +000068 shift
69 ${BAZEL} --bazelrc=${BAZELRC} ${BAZEL_DIR_STARTUP_OPTIONS} $command \
László Csomor3c0c2622017-02-13 15:46:28 +000070 ${_BAZEL_ARGS} --verbose_failures \
Laszlo Csomor9f7180f2016-09-27 13:07:43 +000071 --javacopt="-g -source ${JAVA_VERSION} -target ${JAVA_VERSION}" "${@}"
Damien Martin-Guillerezdaffc352016-01-18 15:20:32 +000072 }
73fi
74
Laszlo Csomor9f7180f2016-09-27 13:07:43 +000075function bazel_build() {
László Csomor3c0c2622017-02-13 15:46:28 +000076 _run_bootstrapping_bazel build "${EMBED_LABEL_ARG[@]}" "$@"
Laszlo Csomor9f7180f2016-09-27 13:07:43 +000077}
78
79function get_bazel_bin_path() {
László Csomor3c0c2622017-02-13 15:46:28 +000080 _run_bootstrapping_bazel info "bazel-bin" || echo "bazel-bin"
Laszlo Csomor9f7180f2016-09-27 13:07:43 +000081}