blob: 57b5332863f1417b1e3ecf8599a2acc7661b4d59 [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
Damien Martin-Guillerez04d46ab2016-04-13 19:27:56 +000032: ${JAVA_VERSION:="1.8"}
33
Damien Martin-Guillerez0ad9f5e2016-04-20 13:58:08 +000034if [ "${JAVA_VERSION}" = "1.7" ]; then
László Csomor3c0c2622017-02-13 15:46:28 +000035 _BAZEL_ARGS="--java_toolchain=//src/java_tools/buildjar:bootstrap_toolchain_jdk7 \
Liam Miller-Cushon12c5ae62016-04-22 20:02:10 +000036 --host_java_toolchain=//src/java_tools/buildjar:bootstrap_toolchain_jdk7 \
Lukacs Berki88eca6e2017-01-20 15:28:28 +000037 --spawn_strategy=standalone \
Liam Miller-Cushon31e29d12017-01-12 08:54:06 +000038 --nojava_header_compilation \
Philipp Wollermann29a49822016-08-16 15:48:32 +000039 --define JAVA_VERSION=1.7 --ignore_unsupported_sandboxing \
Laszlo Csomor0a208242016-09-26 18:56:22 +000040 --compilation_mode=opt \
László Csomor3c0c2622017-02-13 15:46:28 +000041 ${EXTRA_BAZEL_ARGS:-}"
Damien Martin-Guillerez0ad9f5e2016-04-20 13:58:08 +000042else
László Csomor3c0c2622017-02-13 15:46:28 +000043 _BAZEL_ARGS="--java_toolchain=//src/java_tools/buildjar:bootstrap_toolchain \
Liam Miller-Cushon12c5ae62016-04-22 20:02:10 +000044 --host_java_toolchain=//src/java_tools/buildjar:bootstrap_toolchain \
Lukacs Berki88eca6e2017-01-20 15:28:28 +000045 --spawn_strategy=standalone \
Liam Miller-Cushon31e29d12017-01-12 08:54:06 +000046 --nojava_header_compilation \
Philipp Wollermann29a49822016-08-16 15:48:32 +000047 --strategy=Javac=worker --worker_quit_after_build --ignore_unsupported_sandboxing \
Laszlo Csomor0a208242016-09-26 18:56:22 +000048 --compilation_mode=opt \
László Csomor3c0c2622017-02-13 15:46:28 +000049 ${EXTRA_BAZEL_ARGS:-}"
Damien Martin-Guillerez0ad9f5e2016-04-20 13:58:08 +000050fi
Damien Martin-Guillerez5ed78952016-01-18 15:58:19 +000051
Damien Martin-Guillerezdaffc352016-01-18 15:20:32 +000052if [ -z "${BAZEL-}" ]; then
László Csomor3c0c2622017-02-13 15:46:28 +000053 function _run_bootstrapping_bazel() {
Laszlo Csomor9f7180f2016-09-27 13:07:43 +000054 local command=$1
55 shift
56 run_bazel_jar $command \
László Csomor3c0c2622017-02-13 15:46:28 +000057 ${_BAZEL_ARGS} --verbose_failures \
Laszlo Csomor9f7180f2016-09-27 13:07:43 +000058 --javacopt="-g -source ${JAVA_VERSION} -target ${JAVA_VERSION}" "${@}"
Damien Martin-Guillerezdaffc352016-01-18 15:20:32 +000059 }
60else
Laszlo Csomord0d7ef02017-04-26 10:48:00 +020061 function _run_bootstrapping_bazel() {
62 local command=$1
Laszlo Csomor9f7180f2016-09-27 13:07:43 +000063 shift
64 ${BAZEL} --bazelrc=${BAZELRC} ${BAZEL_DIR_STARTUP_OPTIONS} $command \
László Csomor3c0c2622017-02-13 15:46:28 +000065 ${_BAZEL_ARGS} --verbose_failures \
Laszlo Csomor9f7180f2016-09-27 13:07:43 +000066 --javacopt="-g -source ${JAVA_VERSION} -target ${JAVA_VERSION}" "${@}"
Damien Martin-Guillerezdaffc352016-01-18 15:20:32 +000067 }
68fi
69
Laszlo Csomor9f7180f2016-09-27 13:07:43 +000070function bazel_build() {
László Csomor3c0c2622017-02-13 15:46:28 +000071 _run_bootstrapping_bazel build "${EMBED_LABEL_ARG[@]}" "$@"
Laszlo Csomor9f7180f2016-09-27 13:07:43 +000072}
73
74function get_bazel_bin_path() {
László Csomor3c0c2622017-02-13 15:46:28 +000075 _run_bootstrapping_bazel info "bazel-bin" || echo "bazel-bin"
Laszlo Csomor9f7180f2016-09-27 13:07:43 +000076}