Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Damien Martin-Guillerez | f88f4d8 | 2015-09-25 13:56:55 +0000 | [diff] [blame] | 3 | # Copyright 2015 The Bazel Authors. All rights reserved. |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 4 | # |
| 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-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 21 | # BAZELRC: the rc file to use |
| 22 | |
| 23 | : ${BAZELRC:="/dev/null"} |
| 24 | : ${EMBED_LABEL:=""} |
Klaus Aehlig | 48631ea | 2017-03-22 17:39:10 +0000 | [diff] [blame] | 25 | : ${SOURCE_DATE_EPOCH:=""} |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 26 | |
| 27 | EMBED_LABEL_ARG=() |
| 28 | if [ -n "${EMBED_LABEL}" ]; then |
| 29 | EMBED_LABEL_ARG=(--stamp --embed_label "${EMBED_LABEL}") |
| 30 | fi |
| 31 | |
Damien Martin-Guillerez | 04d46ab | 2016-04-13 19:27:56 +0000 | [diff] [blame] | 32 | : ${JAVA_VERSION:="1.8"} |
| 33 | |
cushon | 032141d | 2018-04-25 13:01:05 -0700 | [diff] [blame] | 34 | _BAZEL_ARGS="--java_toolchain=//src/java_tools/buildjar:bootstrap_toolchain \ |
| 35 | --host_java_toolchain=//src/java_tools/buildjar:bootstrap_toolchain \ |
| 36 | --spawn_strategy=standalone \ |
| 37 | --nojava_header_compilation \ |
| 38 | --strategy=Javac=worker --worker_quit_after_build --ignore_unsupported_sandboxing \ |
| 39 | --compilation_mode=opt \ |
Klaus Aehlig | d595703 | 2018-06-07 08:18:00 -0700 | [diff] [blame] | 40 | --distdir=derived/distdir \ |
cushon | 032141d | 2018-04-25 13:01:05 -0700 | [diff] [blame] | 41 | ${EXTRA_BAZEL_ARGS:-}" |
Damien Martin-Guillerez | 5ed7895 | 2016-01-18 15:58:19 +0000 | [diff] [blame] | 42 | |
Damien Martin-Guillerez | daffc35 | 2016-01-18 15:20:32 +0000 | [diff] [blame] | 43 | if [ -z "${BAZEL-}" ]; then |
László Csomor | 3c0c262 | 2017-02-13 15:46:28 +0000 | [diff] [blame] | 44 | function _run_bootstrapping_bazel() { |
Laszlo Csomor | 9f7180f | 2016-09-27 13:07:43 +0000 | [diff] [blame] | 45 | local command=$1 |
| 46 | shift |
| 47 | run_bazel_jar $command \ |
László Csomor | 3c0c262 | 2017-02-13 15:46:28 +0000 | [diff] [blame] | 48 | ${_BAZEL_ARGS} --verbose_failures \ |
Laszlo Csomor | 9f7180f | 2016-09-27 13:07:43 +0000 | [diff] [blame] | 49 | --javacopt="-g -source ${JAVA_VERSION} -target ${JAVA_VERSION}" "${@}" |
Damien Martin-Guillerez | daffc35 | 2016-01-18 15:20:32 +0000 | [diff] [blame] | 50 | } |
| 51 | else |
Laszlo Csomor | d0d7ef0 | 2017-04-26 10:48:00 +0200 | [diff] [blame] | 52 | function _run_bootstrapping_bazel() { |
| 53 | local command=$1 |
Laszlo Csomor | 9f7180f | 2016-09-27 13:07:43 +0000 | [diff] [blame] | 54 | shift |
| 55 | ${BAZEL} --bazelrc=${BAZELRC} ${BAZEL_DIR_STARTUP_OPTIONS} $command \ |
László Csomor | 3c0c262 | 2017-02-13 15:46:28 +0000 | [diff] [blame] | 56 | ${_BAZEL_ARGS} --verbose_failures \ |
Laszlo Csomor | 9f7180f | 2016-09-27 13:07:43 +0000 | [diff] [blame] | 57 | --javacopt="-g -source ${JAVA_VERSION} -target ${JAVA_VERSION}" "${@}" |
Damien Martin-Guillerez | daffc35 | 2016-01-18 15:20:32 +0000 | [diff] [blame] | 58 | } |
| 59 | fi |
| 60 | |
Laszlo Csomor | 9f7180f | 2016-09-27 13:07:43 +0000 | [diff] [blame] | 61 | function bazel_build() { |
László Csomor | 3c0c262 | 2017-02-13 15:46:28 +0000 | [diff] [blame] | 62 | _run_bootstrapping_bazel build "${EMBED_LABEL_ARG[@]}" "$@" |
Laszlo Csomor | 9f7180f | 2016-09-27 13:07:43 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | function get_bazel_bin_path() { |
László Csomor | 3c0c262 | 2017-02-13 15:46:28 +0000 | [diff] [blame] | 66 | _run_bootstrapping_bazel info "bazel-bin" || echo "bazel-bin" |
Laszlo Csomor | 9f7180f | 2016-09-27 13:07:43 +0000 | [diff] [blame] | 67 | } |