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 | |
Laszlo Csomor | f5525e8 | 2017-01-30 18:11:58 +0000 | [diff] [blame] | 25 | # Check that the bintools can be found, otherwise we would see very confusing |
| 26 | # error messages. |
Laszlo Csomor | e79a110 | 2017-10-06 16:45:05 +0200 | [diff] [blame] | 27 | # For example on Windows we would find "FIND.EXE" instead of "/usr/bin/find" |
| 28 | # when running "find". |
Klaus Aehlig | 27db2d8 | 2017-08-28 12:41:52 +0200 | [diff] [blame] | 29 | hash tr >&/dev/null || { |
| 30 | echo >&2 "ERROR: cannot locate GNU coreutils; check your PATH." |
L?szl? Csomor | 90ecf93 | 2017-12-06 06:53:13 -0800 | [diff] [blame] | 31 | echo >&2 " You may need to run the following command:" |
| 32 | echo >&2 " export PATH=\"/bin:/usr/bin:\$PATH\"" |
Laszlo Csomor | f5525e8 | 2017-01-30 18:11:58 +0000 | [diff] [blame] | 33 | exit 1 |
| 34 | } |
| 35 | |
Laszlo Csomor | e79a110 | 2017-10-06 16:45:05 +0200 | [diff] [blame] | 36 | # Ensure Python is on the PATH on Windows,otherwise we would see |
| 37 | # "LAUNCHER ERROR" messages from py_binary exe launchers. |
Laszlo Csomor | 4cb8cb8 | 2018-01-30 06:59:49 -0800 | [diff] [blame] | 38 | case "$(uname -s | tr "[:upper:]" "[:lower:]")" in |
Laszlo Csomor | e79a110 | 2017-10-06 16:45:05 +0200 | [diff] [blame] | 39 | msys*|mingw*|cygwin*) |
Laszlo Csomor | 4cb8cb8 | 2018-01-30 06:59:49 -0800 | [diff] [blame] | 40 | # Ensure Python is on the PATH, otherwise the bootstrapping fails later. |
Laszlo Csomor | e79a110 | 2017-10-06 16:45:05 +0200 | [diff] [blame] | 41 | which python.exe >&/dev/null || { |
| 42 | echo >&2 "ERROR: cannot locate python.exe; check your PATH." |
L?szl? Csomor | 90ecf93 | 2017-12-06 06:53:13 -0800 | [diff] [blame] | 43 | echo >&2 " You may need to run the following command, or something" |
| 44 | echo >&2 " similar, depending on where you installed Python:" |
| 45 | echo >&2 " export PATH=\"/c/Python27:\$PATH\"" |
Laszlo Csomor | e79a110 | 2017-10-06 16:45:05 +0200 | [diff] [blame] | 46 | exit 1 |
| 47 | } |
Laszlo Csomor | 4cb8cb8 | 2018-01-30 06:59:49 -0800 | [diff] [blame] | 48 | # Ensure TMPDIR uses the user-specified TMPDIR or TMP or TEMP. |
| 49 | # This is necessary to avoid overly longs paths during bootstrapping, see for |
| 50 | # example https://github.com/bazelbuild/bazel/issues/4536 |
| 51 | export TMPDIR="${TMPDIR:-${TMP:-${TEMP:-}}}" |
Laszlo Csomor | e79a110 | 2017-10-06 16:45:05 +0200 | [diff] [blame] | 52 | esac |
| 53 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 54 | cd "$(dirname "$0")" |
| 55 | |
Julio Merino | 5909d9d | 2016-02-25 21:44:31 +0000 | [diff] [blame] | 56 | # Set the default verbose mode in buildenv.sh so that we do not display command |
| 57 | # output unless there is a failure. We do this conditionally to offer the user |
| 58 | # a chance of overriding this in case they want to do so. |
| 59 | : ${VERBOSE:=no} |
| 60 | |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 61 | source scripts/bootstrap/buildenv.sh |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 62 | |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 63 | mkdir -p output |
dmarting | 03976a5 | 2017-08-29 12:42:58 +0200 | [diff] [blame] | 64 | : ${BAZEL:=} |
Kristina Chodorow | ac27114 | 2015-03-06 16:00:46 +0000 | [diff] [blame] | 65 | |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 66 | # |
| 67 | # Create an initial binary so we can host ourself |
| 68 | # |
| 69 | if [ ! -x "${BAZEL}" ]; then |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 70 | new_step 'Building Bazel from scratch' |
| 71 | source scripts/bootstrap/compile.sh |
Daniel Wagner-Hall | 13ba331 | 2015-03-20 05:45:45 +0000 | [diff] [blame] | 72 | fi |
| 73 | |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 74 | # |
| 75 | # Bootstrap bazel using the previous bazel binary = release binary |
| 76 | # |
Damien Martin-Guillerez | a377af0 | 2015-06-24 12:04:27 +0000 | [diff] [blame] | 77 | if [ "${EMBED_LABEL-x}" = "x" ]; then |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 78 | # Add a default label when unspecified |
| 79 | git_sha1=$(git_sha1) |
Damien Martin-Guillerez | 28e67b5 | 2016-03-14 11:01:31 +0000 | [diff] [blame] | 80 | EMBED_LABEL="$(get_last_version) (@${git_sha1:-non-git})" |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 81 | fi |
| 82 | |
Damien Martin-Guillerez | 3d796fe | 2016-01-11 10:07:57 +0000 | [diff] [blame] | 83 | if [[ $PLATFORM == "darwin" ]] && \ |
| 84 | xcodebuild -showsdks 2> /dev/null | grep -q '\-sdk iphonesimulator'; then |
Damien Martin-Guillerez | 1540d8f | 2016-09-07 11:49:39 +0000 | [diff] [blame] | 85 | EXTRA_BAZEL_ARGS="${EXTRA_BAZEL_ARGS-} --define IPHONE_SDK=1" |
Dmitry Lomov | ac6ed79 | 2015-12-22 19:24:00 +0000 | [diff] [blame] | 86 | fi |
Yun Peng | cb8a5e2 | 2017-03-08 14:30:49 +0000 | [diff] [blame] | 87 | |
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 | |
dmarting | 03976a5 | 2017-08-29 12:42:58 +0200 | [diff] [blame] | 90 | new_step 'Building Bazel with Bazel' |
| 91 | display "." |
| 92 | log "Building output/bazel" |
cpeyser | d852e48 | 2017-09-07 22:16:06 +0200 | [diff] [blame] | 93 | # We set host and target platform directly since the defaults in @bazel_tools |
| 94 | # have not yet been generated. |
Liam Miller-Cushon | 7c49bd9 | 2018-06-18 09:29:52 -0700 | [diff] [blame] | 95 | bazel_build "src:bazel_nojdk${EXE_EXT}" \ |
John Cater | 32c5add | 2018-03-19 08:51:46 -0700 | [diff] [blame] | 96 | --host_platform=@bazel_tools//platforms:host_platform \ |
| 97 | --platforms=@bazel_tools//platforms:target_platform \ |
dmarting | 03976a5 | 2017-08-29 12:42:58 +0200 | [diff] [blame] | 98 | || fail "Could not build Bazel" |
Liam Miller-Cushon | 7c49bd9 | 2018-06-18 09:29:52 -0700 | [diff] [blame] | 99 | bazel_bin_path="$(get_bazel_bin_path)/src/bazel_nojdk${EXE_EXT}" |
dmarting | 03976a5 | 2017-08-29 12:42:58 +0200 | [diff] [blame] | 100 | [ -e "$bazel_bin_path" ] \ |
| 101 | || fail "Could not find freshly built Bazel binary at '$bazel_bin_path'" |
| 102 | cp -f "$bazel_bin_path" "output/bazel${EXE_EXT}" \ |
| 103 | || fail "Could not copy '$bazel_bin_path' to 'output/bazel${EXE_EXT}'" |
| 104 | chmod 0755 "output/bazel${EXE_EXT}" |
| 105 | BAZEL="$(pwd)/output/bazel${EXE_EXT}" |
Damien Martin-Guillerez | d6f4808 | 2015-06-05 10:50:43 +0000 | [diff] [blame] | 106 | |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 107 | clear_log |
| 108 | display "Build successful! Binary is here: ${BAZEL}" |