Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Copyright 2014 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 | |
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() { |
| 30 | [ -n "${1:-build}" ] && echo "Invalid command(s): $1" >&2 |
| 31 | echo "syntax: $0 [command[,command]* [BAZEL_BIN [BAZEL_SUM]]]" >&2 |
| 32 | echo " General purpose commands:" >&2 |
| 33 | echo " build = compile,tools,init (default)" >&2 |
| 34 | echo " compile = compile a Bazel binary for usage" >&2 |
| 35 | echo " tools = compile and install tooling for Bazel" >&2 |
| 36 | echo " init = initialize the base workspace" >&2 |
| 37 | echo " Commands for developers:" >&2 |
| 38 | echo " all = build,determinism,test" >&2 |
| 39 | echo " determinism = test for stability of Bazel builds" >&2 |
| 40 | echo " test = run the full test suite of Bazel" >&2 |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 41 | exit 1 |
| 42 | } |
| 43 | |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 44 | function parse_options() { |
| 45 | local keywords="(build|compile|tools|init|all|determinism|bootstrap|test)" |
| 46 | COMMANDS="${1:-build}" |
| 47 | [[ "${COMMANDS}" =~ ^$keywords(,$keywords)*$ ]] || usage "$@" |
| 48 | DO_COMPILE= |
| 49 | DO_TOOLS_COMPILATION= |
| 50 | DO_CHECKSUM= |
| 51 | DO_FULL_CHECKSUM=1 |
| 52 | DO_TESTS= |
| 53 | DO_BASE_WORKSPACE_INIT= |
| 54 | [[ "${COMMANDS}" =~ (compile|build|all) ]] && DO_COMPILE=1 |
| 55 | [[ "${COMMANDS}" =~ (tools|build|all) ]] && DO_TOOLS_COMPILATION=1 |
| 56 | [[ "${COMMANDS}" =~ (init|build|all) ]] && DO_BASE_WORKSPACE_INIT=1 |
| 57 | [[ "${COMMANDS}" =~ (bootstrap|determinism|all) ]] && DO_CHECKSUM=1 |
| 58 | [[ "${COMMANDS}" =~ (bootstrap) ]] && DO_FULL_CHECKSUM= |
| 59 | [[ "${COMMANDS}" =~ (test|all) ]] && DO_TESTS=1 |
| 60 | |
| 61 | BAZEL_BIN=${2:-"bazel-bin/src/bazel"} |
Damien Martin-Guillerez | 4f89281 | 2015-07-02 08:38:58 +0000 | [diff] [blame] | 62 | BAZEL_SUM=${3:-"x"} |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 63 | } |
| 64 | |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 65 | parse_options "${@}" |
Kristina Chodorow | 8c6b3bb | 2015-04-09 19:05:34 +0000 | [diff] [blame] | 66 | |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 67 | mkdir -p output |
| 68 | : ${BAZEL:=${2-}} |
Kristina Chodorow | ac27114 | 2015-03-06 16:00:46 +0000 | [diff] [blame] | 69 | |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 70 | # |
| 71 | # Create an initial binary so we can host ourself |
| 72 | # |
| 73 | if [ ! -x "${BAZEL}" ]; then |
| 74 | display "$INFO You can skip this first step by providing a path to the bazel binary as second argument:" |
| 75 | display "$INFO $0 ${COMMANDS} /path/to/bazel" |
| 76 | new_step 'Building Bazel from scratch' |
| 77 | source scripts/bootstrap/compile.sh |
| 78 | cp ${OUTPUT_DIR}/bazel output/bazel |
| 79 | BAZEL=$(pwd)/output/bazel |
Daniel Wagner-Hall | 13ba331 | 2015-03-20 05:45:45 +0000 | [diff] [blame] | 80 | fi |
| 81 | |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 82 | # |
| 83 | # Bootstrap bazel using the previous bazel binary = release binary |
| 84 | # |
Damien Martin-Guillerez | a377af0 | 2015-06-24 12:04:27 +0000 | [diff] [blame] | 85 | if [ "${EMBED_LABEL-x}" = "x" ]; then |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 86 | # Add a default label when unspecified |
| 87 | git_sha1=$(git_sha1) |
| 88 | EMBED_LABEL="head (@${git_sha1:-non-git})" |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 89 | fi |
| 90 | |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 91 | source scripts/bootstrap/bootstrap.sh |
| 92 | if [ $DO_COMPILE ]; then |
| 93 | new_step 'Building Bazel with Bazel' |
| 94 | display "." |
| 95 | bazel_bootstrap //src:bazel output/bazel 0755 1 |
| 96 | BAZEL=$(pwd)/output/bazel |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 97 | fi |
| 98 | |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 99 | # |
| 100 | # Bootstrap tools using the release binary |
| 101 | # |
| 102 | if [ $DO_TOOLS_COMPILATION ]; then |
| 103 | new_step 'Building Bazel tools' |
Googler | a4211f3 | 2015-07-14 18:02:00 +0000 | [diff] [blame] | 104 | bazel_bootstrap //third_party/ijar:ijar tools/jdk/ijar 0755 |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 105 | bazel_bootstrap //src/java_tools/singlejar:SingleJar_deploy.jar \ |
| 106 | tools/jdk/SingleJar_deploy.jar |
| 107 | bazel_bootstrap //src/java_tools/buildjar:JavaBuilder_deploy.jar \ |
| 108 | tools/jdk/JavaBuilder_deploy.jar |
Alex Humesky | d3f7eda | 2015-07-08 18:18:33 +0000 | [diff] [blame] | 109 | bazel_bootstrap //src/java_tools/buildjar/java/com/google/devtools/build/buildjar/genclass:GenClass_deploy.jar \ |
| 110 | tools/jdk/GenClass_deploy.jar |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 111 | if [[ $PLATFORM == "darwin" ]]; then |
Lukacs Berki | 0caf332 | 2015-07-21 08:47:08 +0000 | [diff] [blame] | 112 | bazel_bootstrap //src/tools/xcode-common/java/com/google/devtools/build/xcode/actoolzip:actoolzip_deploy.jar \ |
| 113 | tools/objc/precomp_actoolzip_deploy.jar |
| 114 | bazel_bootstrap //src/tools/xcode/ibtoolwrapper:ibtoolwrapper tools/objc/ibtoolwrapper 0755 |
| 115 | bazel_bootstrap //src/tools/xcode-common/java/com/google/devtools/build/xcode/swiftstdlibtoolzip:swiftstdlibtoolzip_deploy.jar \ |
| 116 | tools/objc/precomp_swiftstdlibtoolzip_deploy.jar |
| 117 | bazel_bootstrap //src/objc_tools/momczip:momczip_deploy.jar \ |
| 118 | tools/objc/precomp_momczip_deploy.jar |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 119 | bazel_bootstrap //src/objc_tools/bundlemerge:bundlemerge_deploy.jar \ |
| 120 | tools/objc/precomp_bundlemerge_deploy.jar |
| 121 | bazel_bootstrap //src/objc_tools/plmerge:plmerge_deploy.jar \ |
| 122 | tools/objc/precomp_plmerge_deploy.jar |
| 123 | bazel_bootstrap //src/objc_tools/xcodegen:xcodegen_deploy.jar \ |
| 124 | tools/objc/precomp_xcodegen_deploy.jar |
Googler | ad26d68 | 2015-06-18 17:13:05 +0000 | [diff] [blame] | 125 | bazel_bootstrap //src/tools/xcode/stdredirect:StdRedirect.dylib \ |
Googler | a4211f3 | 2015-07-14 18:02:00 +0000 | [diff] [blame] | 126 | tools/objc/StdRedirect.dylib 0755 |
| 127 | bazel_bootstrap //src/tools/xcode/realpath:realpath tools/objc/realpath 0755 |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 128 | fi |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 129 | fi |
| 130 | |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 131 | # |
| 132 | # Output is deterministic between two bootstrapped bazel binary using the actual tools and the |
| 133 | # released binary. |
| 134 | # |
| 135 | if [ $DO_CHECKSUM ]; then |
| 136 | new_step "Determinism test" |
Damien Martin-Guillerez | 4349f94 | 2015-06-24 13:28:08 +0000 | [diff] [blame] | 137 | if [ ! -f ${BAZEL_SUM:-x} ]; then |
| 138 | BAZEL_SUM=bazel-out/bazel_checksum |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 139 | log "First build" |
| 140 | bootstrap_test ${BAZEL} ${BAZEL_SUM} |
| 141 | else |
| 142 | BOOTSTRAP=${BAZEL} |
| 143 | fi |
| 144 | if [ "${BAZEL_SUM}" != "${OUTPUT_DIR}/bazel_checksum" ]; then |
| 145 | cp ${BAZEL_SUM} ${OUTPUT_DIR}/bazel_checksum |
| 146 | fi |
| 147 | if [ $DO_FULL_CHECKSUM ]; then |
| 148 | log "Second build" |
| 149 | bootstrap_test ${BOOTSTRAP} bazel-out/bazel_checksum |
| 150 | log "Comparing output" |
| 151 | (diff -U 0 ${OUTPUT_DIR}/bazel_checksum bazel-out/bazel_checksum >&2) \ |
| 152 | || fail "Differences detected in outputs!" |
| 153 | fi |
| 154 | fi |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 155 | |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 156 | # |
| 157 | # Tests |
| 158 | # |
| 159 | if [ $DO_TESTS ]; then |
| 160 | new_step "Running tests" |
| 161 | display "." |
Damien Martin-Guillerez | 338dc56 | 2015-06-23 17:15:12 +0000 | [diff] [blame] | 162 | [ -n "$JAVAC_VERSION" ] || get_java_version |
| 163 | if [[ ! "${BAZEL_TEST_FILTERS-}" =~ "-jdk8" ]] \ |
| 164 | && [ "8" -gt ${JAVAC_VERSION#*.} ]; then |
| 165 | display "$WARNING Your version of Java is lower than 1.8!" |
| 166 | display "$WARNING Deactivating Java 8 tests, please use a JDK 8 to fully" |
| 167 | display "$WARNING test Bazel." |
| 168 | if [ -n "${BAZEL_TEST_FILTERS-}" ]; then |
| 169 | BAZEL_TEST_FILTERS="${BAZEL_TEST_FILTERS},-jdk8" |
| 170 | else |
| 171 | BAZEL_TEST_FILTERS="-jdk8" |
| 172 | fi |
| 173 | fi |
Damien Martin-Guillerez | 50d124b | 2015-06-24 15:20:09 +0000 | [diff] [blame] | 174 | $BAZEL --bazelrc=${BAZELRC} --nomaster_bazelrc test \ |
Damien Martin-Guillerez | 338dc56 | 2015-06-23 17:15:12 +0000 | [diff] [blame] | 175 | --test_tag_filters="${BAZEL_TEST_FILTERS-}" \ |
Damien Martin-Guillerez | 7cf300e | 2015-06-16 12:31:03 +0000 | [diff] [blame] | 176 | --build_tests_only \ |
Damien Martin-Guillerez | d6f4808 | 2015-06-05 10:50:43 +0000 | [diff] [blame] | 177 | --javacopt="-source ${JAVA_VERSION} -target ${JAVA_VERSION}" \ |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 178 | -k --test_output=errors //src/... //third_party/ijar/... //scripts/... \ |
| 179 | || fail "Tests failed" |
Damien Martin-Guillerez | d6f4808 | 2015-06-05 10:50:43 +0000 | [diff] [blame] | 180 | fi |
| 181 | |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 182 | # |
| 183 | # Setup the base workspace |
| 184 | # |
| 185 | if [ $DO_BASE_WORKSPACE_INIT ]; then |
| 186 | new_step 'Setting up base workspace' |
| 187 | display "." |
| 188 | source scripts/bootstrap/init_workspace.sh |
Damien Martin-Guillerez | d6f4808 | 2015-06-05 10:50:43 +0000 | [diff] [blame] | 189 | fi |
| 190 | |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 191 | clear_log |
| 192 | display "Build successful! Binary is here: ${BAZEL}" |