Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Copyright 2015 Google Inc. All rights reserved. |
| 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) |
| 21 | # BAZEL_ARGS: list of other arguments to pass to bazel (optional) |
| 22 | # BAZELRC: the rc file to use |
| 23 | |
| 24 | : ${BAZELRC:="/dev/null"} |
| 25 | : ${EMBED_LABEL:=""} |
| 26 | |
| 27 | EMBED_LABEL_ARG=() |
| 28 | if [ -n "${EMBED_LABEL}" ]; then |
| 29 | EMBED_LABEL_ARG=(--stamp --embed_label "${EMBED_LABEL}") |
| 30 | fi |
| 31 | |
| 32 | : ${JAVA_VERSION:="1.8"} |
| 33 | : ${BAZEL_ARGS="--singlejar_top=//src/java_tools/singlejar:bootstrap_deploy.jar \ |
| 34 | --javabuilder_top=//src/java_tools/buildjar:bootstrap_deploy.jar \ |
Alex Humesky | d3f7eda | 2015-07-08 18:18:33 +0000 | [diff] [blame] | 35 | --genclass_top=//src/java_tools/buildjar:bootstrap_genclass_deploy.jar \ |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 36 | --ijar_top=//third_party/ijar"} |
| 37 | |
| 38 | function bazel_bootstrap() { |
| 39 | local mode=${3:-"0644"} |
| 40 | if [[ ! ${BAZEL_SKIP_TOOL_COMPILATION-} =~ "$2" ]]; then |
| 41 | log "Building $2" |
| 42 | if [ -n "${4-}" ]; then |
Damien Martin-Guillerez | 50d124b | 2015-06-24 15:20:09 +0000 | [diff] [blame] | 43 | ${BAZEL} --nomaster_bazelrc --bazelrc=${BAZELRC} \ |
Damien Martin-Guillerez | 43b2ea7 | 2015-06-15 10:40:07 +0000 | [diff] [blame] | 44 | build ${BAZEL_ARGS} \ |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 45 | --javacopt="-source ${JAVA_VERSION} -target ${JAVA_VERSION}" \ |
| 46 | "${EMBED_LABEL_ARG[@]}" $1 |
| 47 | else |
Damien Martin-Guillerez | 50d124b | 2015-06-24 15:20:09 +0000 | [diff] [blame] | 48 | run_silent ${BAZEL} --nomaster_bazelrc --bazelrc=${BAZELRC} \ |
Damien Martin-Guillerez | 43b2ea7 | 2015-06-15 10:40:07 +0000 | [diff] [blame] | 49 | build ${BAZEL_ARGS} \ |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 50 | --javacopt="-source ${JAVA_VERSION} -target ${JAVA_VERSION}" \ |
| 51 | "${EMBED_LABEL_ARG[@]}" $1 |
| 52 | fi |
| 53 | local file=bazel-bin/${1##//} |
| 54 | cp -f ${file/:/\/} $2 |
| 55 | chmod ${mode} $2 |
| 56 | fi |
| 57 | } |
| 58 | |
| 59 | function md5_outputs() { |
| 60 | [ -n "${BAZEL_TEST_XTRACE:-}" ] && set +x # Avoid garbage in the output |
| 61 | # runfiles/MANIFEST & runfiles_manifest contain absolute path, ignore. |
| 62 | # ar on OS-X is non-deterministic, ignore .a files. |
| 63 | for i in $(find bazel-bin/ -type f -a \! -name MANIFEST -a \! -name '*.runfiles_manifest' -a \! -name '*.a'); do |
| 64 | md5_file $i |
| 65 | done |
| 66 | for i in $(find bazel-genfiles/ -type f); do |
| 67 | md5_file $i |
| 68 | done |
| 69 | [ -n "${BAZEL_TEST_XTRACE:-}" ] && set -x |
| 70 | } |
| 71 | |
| 72 | function get_outputs_sum() { |
| 73 | md5_outputs | sort -k 2 |
| 74 | } |
| 75 | |
| 76 | function bootstrap_test() { |
| 77 | local BAZEL_BIN=$1 |
| 78 | local BAZEL_SUM=$2 |
| 79 | [ -x "${BAZEL_BIN}" ] || fail "syntax: bootstrap bazel-binary" |
Damien Martin-Guillerez | 50d124b | 2015-06-24 15:20:09 +0000 | [diff] [blame] | 80 | run_silent ${BAZEL_BIN} --nomaster_bazelrc --bazelrc=${BAZELRC} clean \ |
Damien Martin-Guillerez | 841751e | 2015-06-19 12:20:48 +0000 | [diff] [blame] | 81 | --expunge || return $? |
Damien Martin-Guillerez | 50d124b | 2015-06-24 15:20:09 +0000 | [diff] [blame] | 82 | run_silent ${BAZEL_BIN} --nomaster_bazelrc --bazelrc=${BAZELRC} build \ |
Damien Martin-Guillerez | 43b2ea7 | 2015-06-15 10:40:07 +0000 | [diff] [blame] | 83 | --fetch --nostamp \ |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 84 | --javacopt="-source ${JAVA_VERSION} -target ${JAVA_VERSION}" \ |
| 85 | //src:bazel //src:tools || return $? |
| 86 | if [ -n "${BAZEL_SUM}" ]; then |
| 87 | cat bazel-genfiles/src/java.version >${BAZEL_SUM} |
| 88 | get_outputs_sum >> ${BAZEL_SUM} || return $? |
| 89 | fi |
| 90 | if [ -z "${BOOTSTRAP:-}" ]; then |
| 91 | tempdir |
| 92 | BOOTSTRAP=${NEW_TMPDIR}/bazel |
| 93 | cp -f bazel-bin/src/bazel $BOOTSTRAP |
| 94 | chmod +x $BOOTSTRAP |
| 95 | fi |
| 96 | } |