Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Damien Martin-Guillerez | f88f4d8 | 2015-09-25 13:56:55 +0000 | [diff] [blame] | 3 | # Copyright 2014 The Bazel Authors. All rights reserved. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [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 | |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 17 | # This script bootstraps building a Bazel binary without Bazel then |
| 18 | # use this compiled Bazel to bootstrap Bazel itself. It can also |
| 19 | # be provided with a previous version of Bazel to bootstrap Bazel |
| 20 | # itself. |
| 21 | # The resulting binary can be found at output/bazel. |
David Mankin | 5cafe13 | 2015-05-28 20:20:56 +0000 | [diff] [blame] | 22 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 23 | set -o errexit |
| 24 | |
| 25 | cd "$(dirname "$0")" |
| 26 | |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 27 | source scripts/bootstrap/buildenv.sh |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 28 | |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 29 | function usage() { |
Kristina Chodorow | 84450b8 | 2016-01-28 15:16:02 +0000 | [diff] [blame] | 30 | [ -n "${1:-compile}" ] && echo "Invalid command(s): $1" >&2 |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 31 | echo "syntax: $0 [command[,command]* [BAZEL_BIN [BAZEL_SUM]]]" >&2 |
| 32 | echo " General purpose commands:" >&2 |
Kristina Chodorow | 84450b8 | 2016-01-28 15:16:02 +0000 | [diff] [blame] | 33 | echo " compile = compile the bazel binary (default)" >&2 |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 34 | echo " Commands for developers:" >&2 |
Kristina Chodorow | 84450b8 | 2016-01-28 15:16:02 +0000 | [diff] [blame] | 35 | echo " all = compile,determinism,test" >&2 |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 36 | echo " determinism = test for stability of Bazel builds" >&2 |
| 37 | echo " test = run the full test suite of Bazel" >&2 |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 38 | exit 1 |
| 39 | } |
| 40 | |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 41 | function parse_options() { |
Kristina Chodorow | 84450b8 | 2016-01-28 15:16:02 +0000 | [diff] [blame] | 42 | local keywords="(compile|all|determinism|bootstrap|test)" |
| 43 | COMMANDS="${1:-compile}" |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 44 | [[ "${COMMANDS}" =~ ^$keywords(,$keywords)*$ ]] || usage "$@" |
| 45 | DO_COMPILE= |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 46 | DO_CHECKSUM= |
| 47 | DO_FULL_CHECKSUM=1 |
| 48 | DO_TESTS= |
Kristina Chodorow | 84450b8 | 2016-01-28 15:16:02 +0000 | [diff] [blame] | 49 | [[ "${COMMANDS}" =~ (compile|all) ]] && DO_COMPILE=1 |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 50 | [[ "${COMMANDS}" =~ (bootstrap|determinism|all) ]] && DO_CHECKSUM=1 |
| 51 | [[ "${COMMANDS}" =~ (bootstrap) ]] && DO_FULL_CHECKSUM= |
| 52 | [[ "${COMMANDS}" =~ (test|all) ]] && DO_TESTS=1 |
| 53 | |
| 54 | BAZEL_BIN=${2:-"bazel-bin/src/bazel"} |
Damien Martin-Guillerez | 4f89281 | 2015-07-02 08:38:58 +0000 | [diff] [blame] | 55 | BAZEL_SUM=${3:-"x"} |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 56 | } |
| 57 | |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 58 | parse_options "${@}" |
Kristina Chodorow | 8c6b3bb | 2015-04-09 19:05:34 +0000 | [diff] [blame] | 59 | |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 60 | mkdir -p output |
| 61 | : ${BAZEL:=${2-}} |
Kristina Chodorow | ac27114 | 2015-03-06 16:00:46 +0000 | [diff] [blame] | 62 | |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 63 | # |
| 64 | # Create an initial binary so we can host ourself |
| 65 | # |
| 66 | if [ ! -x "${BAZEL}" ]; then |
| 67 | display "$INFO You can skip this first step by providing a path to the bazel binary as second argument:" |
| 68 | display "$INFO $0 ${COMMANDS} /path/to/bazel" |
| 69 | new_step 'Building Bazel from scratch' |
| 70 | source scripts/bootstrap/compile.sh |
Kristina Chodorow | dccd81f | 2016-02-01 17:42:07 +0000 | [diff] [blame] | 71 | # The DO_COMPILE flow will actually create the bazel binary and set BAZEL. |
| 72 | DO_COMPILE=1 |
Daniel Wagner-Hall | 13ba331 | 2015-03-20 05:45:45 +0000 | [diff] [blame] | 73 | fi |
| 74 | |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 75 | # |
| 76 | # Bootstrap bazel using the previous bazel binary = release binary |
| 77 | # |
Damien Martin-Guillerez | a377af0 | 2015-06-24 12:04:27 +0000 | [diff] [blame] | 78 | if [ "${EMBED_LABEL-x}" = "x" ]; then |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 79 | # Add a default label when unspecified |
| 80 | git_sha1=$(git_sha1) |
| 81 | EMBED_LABEL="head (@${git_sha1:-non-git})" |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 82 | fi |
| 83 | |
Damien Martin-Guillerez | 3d796fe | 2016-01-11 10:07:57 +0000 | [diff] [blame] | 84 | if [[ $PLATFORM == "darwin" ]] && \ |
| 85 | xcodebuild -showsdks 2> /dev/null | grep -q '\-sdk iphonesimulator'; then |
| 86 | EXTRA_BAZEL_ARGS="${EXTRA_BAZEL_ARGS-} --define IPHONE_SDK=1" |
Dmitry Lomov | ac6ed79 | 2015-12-22 19:24:00 +0000 | [diff] [blame] | 87 | fi |
Damien Martin-Guillerez | 3d796fe | 2016-01-11 10:07:57 +0000 | [diff] [blame] | 88 | source scripts/bootstrap/bootstrap.sh |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 89 | |
Lukacs Berki | 0d5d522 | 2015-10-12 13:24:44 +0000 | [diff] [blame] | 90 | if [ $DO_COMPILE ]; then |
| 91 | new_step 'Building Bazel with Bazel' |
| 92 | display "." |
Damien Martin-Guillerez | 50fce86 | 2016-01-18 11:30:10 +0000 | [diff] [blame] | 93 | log "Building output/bazel" |
Dmitry Lomov | 9d40a60 | 2016-02-15 16:15:03 +0000 | [diff] [blame] | 94 | bazel_build "src:bazel${EXE_EXT}" |
| 95 | cp -f "bazel-bin/src/bazel${EXE_EXT}" "output/bazel${EXE_EXT}" |
| 96 | chmod 0755 "output/bazel${EXE_EXT}" |
| 97 | BAZEL="$(pwd)/output/bazel${EXE_EXT}" |
Lukacs Berki | 0d5d522 | 2015-10-12 13:24:44 +0000 | [diff] [blame] | 98 | fi |
| 99 | |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 100 | # |
| 101 | # Output is deterministic between two bootstrapped bazel binary using the actual tools and the |
| 102 | # released binary. |
| 103 | # |
| 104 | if [ $DO_CHECKSUM ]; then |
| 105 | new_step "Determinism test" |
Damien Martin-Guillerez | 4349f94 | 2015-06-24 13:28:08 +0000 | [diff] [blame] | 106 | if [ ! -f ${BAZEL_SUM:-x} ]; then |
| 107 | BAZEL_SUM=bazel-out/bazel_checksum |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 108 | log "First build" |
| 109 | bootstrap_test ${BAZEL} ${BAZEL_SUM} |
| 110 | else |
| 111 | BOOTSTRAP=${BAZEL} |
| 112 | fi |
| 113 | if [ "${BAZEL_SUM}" != "${OUTPUT_DIR}/bazel_checksum" ]; then |
| 114 | cp ${BAZEL_SUM} ${OUTPUT_DIR}/bazel_checksum |
| 115 | fi |
| 116 | if [ $DO_FULL_CHECKSUM ]; then |
| 117 | log "Second build" |
| 118 | bootstrap_test ${BOOTSTRAP} bazel-out/bazel_checksum |
| 119 | log "Comparing output" |
| 120 | (diff -U 0 ${OUTPUT_DIR}/bazel_checksum bazel-out/bazel_checksum >&2) \ |
| 121 | || fail "Differences detected in outputs!" |
| 122 | fi |
| 123 | fi |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 124 | |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 125 | # |
| 126 | # Tests |
| 127 | # |
| 128 | if [ $DO_TESTS ]; then |
| 129 | new_step "Running tests" |
| 130 | display "." |
Lukacs Berki | 678ba23 | 2015-09-03 13:28:55 +0000 | [diff] [blame] | 131 | |
Damien Martin-Guillerez | b81f90c | 2015-09-04 15:52:26 +0000 | [diff] [blame] | 132 | ndk_target="$(get_bind_target //external:android_ndk_for_testing)" |
| 133 | sdk_target="$(get_bind_target //external:android_sdk_for_testing)" |
| 134 | if [ "$ndk_target" = "//:dummy" -o "$sdk_target" = "//:dummy" ]; then |
Lukacs Berki | 678ba23 | 2015-09-03 13:28:55 +0000 | [diff] [blame] | 135 | display "$WARNING Android SDK or NDK are not set in the WORKSPACE file. Android tests will not be run." |
| 136 | fi |
| 137 | |
Damien Martin-Guillerez | 338dc56 | 2015-06-23 17:15:12 +0000 | [diff] [blame] | 138 | [ -n "$JAVAC_VERSION" ] || get_java_version |
| 139 | if [[ ! "${BAZEL_TEST_FILTERS-}" =~ "-jdk8" ]] \ |
| 140 | && [ "8" -gt ${JAVAC_VERSION#*.} ]; then |
| 141 | display "$WARNING Your version of Java is lower than 1.8!" |
| 142 | display "$WARNING Deactivating Java 8 tests, please use a JDK 8 to fully" |
| 143 | display "$WARNING test Bazel." |
| 144 | if [ -n "${BAZEL_TEST_FILTERS-}" ]; then |
| 145 | BAZEL_TEST_FILTERS="${BAZEL_TEST_FILTERS},-jdk8" |
| 146 | else |
| 147 | BAZEL_TEST_FILTERS="-jdk8" |
| 148 | fi |
| 149 | fi |
Damien Martin-Guillerez | 50d124b | 2015-06-24 15:20:09 +0000 | [diff] [blame] | 150 | $BAZEL --bazelrc=${BAZELRC} --nomaster_bazelrc test \ |
Damien Martin-Guillerez | 338dc56 | 2015-06-23 17:15:12 +0000 | [diff] [blame] | 151 | --test_tag_filters="${BAZEL_TEST_FILTERS-}" \ |
Damien Martin-Guillerez | 7cf300e | 2015-06-16 12:31:03 +0000 | [diff] [blame] | 152 | --build_tests_only \ |
Damien Martin-Guillerez | 8e2adfb | 2016-01-19 09:01:11 +0000 | [diff] [blame] | 153 | --nolegacy_bazel_java_test \ |
Damien Martin-Guillerez | 3d796fe | 2016-01-11 10:07:57 +0000 | [diff] [blame] | 154 | ${EXTRA_BAZEL_ARGS} \ |
Damien Martin-Guillerez | d6f4808 | 2015-06-05 10:50:43 +0000 | [diff] [blame] | 155 | --javacopt="-source ${JAVA_VERSION} -target ${JAVA_VERSION}" \ |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 156 | -k --test_output=errors //src/... //third_party/ijar/... //scripts/... \ |
Oscar Boykin | b5d417d | 2016-02-12 21:16:13 +0000 | [diff] [blame] | 157 | //tools/build_defs/scala/test/... \ |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 158 | || fail "Tests failed" |
Damien Martin-Guillerez | d6f4808 | 2015-06-05 10:50:43 +0000 | [diff] [blame] | 159 | fi |
| 160 | |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 161 | clear_log |
| 162 | display "Build successful! Binary is here: ${BAZEL}" |