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 | # Script for building bazel from scratch without bazel |
| 18 | |
Yun Peng | d2998a3 | 2020-04-24 01:32:40 -0700 | [diff] [blame] | 19 | if [ -d derived/jars ]; then |
Yun Peng | fcc7d4a | 2020-05-25 07:47:04 -0700 | [diff] [blame] | 20 | ADDITIONAL_JARS=derived/jars |
Yun Peng | d2998a3 | 2020-04-24 01:32:40 -0700 | [diff] [blame] | 21 | else |
Yun Peng | d83fc58 | 2020-09-03 02:03:22 -0700 | [diff] [blame] | 22 | DISTRIBUTION=${BAZEL_DISTRIBUTION:-debian} |
Yun Peng | fcc7d4a | 2020-05-25 07:47:04 -0700 | [diff] [blame] | 23 | ADDITIONAL_JARS="$(grep -o '".*\.jar"' tools/distributions/${DISTRIBUTION}/${DISTRIBUTION}_java.BUILD | sed 's/"//g' | sed 's|^|/usr/share/java/|g')" |
Yun Peng | d2998a3 | 2020-04-24 01:32:40 -0700 | [diff] [blame] | 24 | fi |
Yun Peng | 89cfb70 | 2020-05-25 06:55:22 -0700 | [diff] [blame] | 25 | |
| 26 | # Parse third_party/googleapis/BUILD.bazel to find the proto files we need to compile from googleapis |
| 27 | GOOGLE_API_PROTOS="$(grep -o '".*\.proto"' third_party/googleapis/BUILD.bazel | sed 's/"//g' | sed 's|^|third_party/googleapis/|g')" |
Dmitry Ivankov | 645093c | 2020-10-21 04:55:17 -0700 | [diff] [blame] | 28 | PROTO_FILES=$(find third_party/remoteapis ${GOOGLE_API_PROTOS} third_party/pprof src/main/protobuf src/main/java/com/google/devtools/build/lib/buildeventstream/proto src/main/java/com/google/devtools/build/skyframe src/main/java/com/google/devtools/build/lib/skyframe/proto src/main/java/com/google/devtools/build/lib/bazel/debug src/main/java/com/google/devtools/build/lib/starlarkdebug/proto src/main/java/com/google/devtools/build/lib/packages/metrics/package_metrics.proto -name "*.proto") |
Benjamin Peterson | 676d630 | 2020-10-16 06:45:10 -0700 | [diff] [blame] | 29 | LIBRARY_JARS=$(find $ADDITIONAL_JARS third_party -name '*.jar' | grep -Fv JavaBuilder | grep -Fv third_party/guava/guava | grep -ve 'third_party/grpc/grpc.*jar' | tr "\n" " ") |
Lauri Peltonen | 2df3d39 | 2021-02-26 04:37:48 -0800 | [diff] [blame] | 30 | GRPC_JAVA_VERSION=1.33.1 |
Androbin | ef381e5 | 2017-12-14 07:24:27 -0800 | [diff] [blame] | 31 | GRPC_LIBRARY_JARS=$(find third_party/grpc -name '*.jar' | grep -e ".*${GRPC_JAVA_VERSION}.*jar" | tr "\n" " ") |
Benjamin Peterson | 676d630 | 2020-10-16 06:45:10 -0700 | [diff] [blame] | 32 | GUAVA_VERSION=29.0 |
Androbin | ef381e5 | 2017-12-14 07:24:27 -0800 | [diff] [blame] | 33 | GUAVA_JARS=$(find third_party/guava -name '*.jar' | grep -e ".*${GUAVA_VERSION}.*jar" | tr "\n" " ") |
Damien Martin-Guillerez | d72bc57 | 2017-03-07 16:40:41 +0000 | [diff] [blame] | 34 | LIBRARY_JARS="${LIBRARY_JARS} ${GRPC_LIBRARY_JARS} ${GUAVA_JARS}" |
Nathan Harmata | 8a47590 | 2016-11-23 19:08:12 +0000 | [diff] [blame] | 35 | |
pcloudy | c20900e | 2020-04-29 12:01:56 -0700 | [diff] [blame] | 36 | DIRS=$(echo src/{java_tools/singlejar/java/com/google/devtools/build/zip,main/java} tools/java/runfiles ${OUTPUT_DIR}/src) |
Yun Peng | 83249e5 | 2020-05-25 08:54:24 -0700 | [diff] [blame] | 37 | # Exclude source files that are not needed for Bazel itself, which avoids dependencies like truth. |
michajlo | 4e11dc1 | 2020-09-11 06:16:01 -0700 | [diff] [blame] | 38 | EXCLUDE_FILES="src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/testing/* src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSetCodecTestUtils.java" |
cparsons | f7854a90 | 2018-11-07 12:48:52 -0800 | [diff] [blame] | 39 | # Exclude whole directories under the bazel src tree that bazel itself |
| 40 | # doesn't depend on. |
Yun Peng | 83249e5 | 2020-05-25 08:54:24 -0700 | [diff] [blame] | 41 | EXCLUDE_DIRS="src/main/java/com/google/devtools/build/skydoc src/main/java/com/google/devtools/build/docgen tools/java/runfiles/testing src/main/java/com/google/devtools/build/lib/skyframe/serialization/testutils src/main/java/com/google/devtools/common/options/testing" |
cparsons | f7854a90 | 2018-11-07 12:48:52 -0800 | [diff] [blame] | 42 | for d in $EXCLUDE_DIRS ; do |
| 43 | for f in $(find $d -type f) ; do |
| 44 | EXCLUDE_FILES+=" $f" |
| 45 | done |
| 46 | done |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 47 | |
Alexander Chung | fc07142 | 2017-02-07 12:48:26 +0000 | [diff] [blame] | 48 | mkdir -p "${OUTPUT_DIR}/classes" |
| 49 | mkdir -p "${OUTPUT_DIR}/src" |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 50 | |
| 51 | # May be passed in from outside. |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 52 | ZIPOPTS="$ZIPOPTS" |
| 53 | |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 54 | unset JAVA_TOOL_OPTIONS |
| 55 | unset _JAVA_OPTIONS |
| 56 | |
| 57 | LDFLAGS=${LDFLAGS:-""} |
| 58 | |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 59 | MSYS_DLLS="" |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 60 | |
Harsh Vardhan | fe04cfd | 2017-03-21 15:27:12 +0000 | [diff] [blame] | 61 | function get_minor_java_version() { |
| 62 | get_java_version |
hlopko | 3566474 | 2017-05-29 17:03:07 +0200 | [diff] [blame] | 63 | java_minor_version=$(echo $JAVA_VERSION | sed 's/[^.][^.]*\.//' | sed 's/\..*$//') |
| 64 | javac_minor_version=$(echo $JAVAC_VERSION | sed 's/[^.][^.]*\.//' | sed 's/\..*$//') |
Harsh Vardhan | fe04cfd | 2017-03-21 15:27:12 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 67 | # Check that javac -version returns a upper version than $JAVA_VERSION. |
Harsh Vardhan | fe04cfd | 2017-03-21 15:27:12 +0000 | [diff] [blame] | 68 | get_minor_java_version |
| 69 | [ ${java_minor_version} -le ${javac_minor_version} ] || \ |
Damien Martin-Guillerez | 338dc56 | 2015-06-23 17:15:12 +0000 | [diff] [blame] | 70 | fail "JDK version (${JAVAC_VERSION}) is lower than ${JAVA_VERSION}, please set \$JAVA_HOME." |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 71 | |
| 72 | JAR="${JAVA_HOME}/bin/jar" |
| 73 | |
Laszlo Csomor | 7523e2c | 2019-07-05 05:21:09 -0700 | [diff] [blame] | 74 | # Ensures unzip won't create paths longer than 259 chars (MAX_PATH) on Windows. |
| 75 | function check_unzip_wont_create_long_paths() { |
| 76 | output_path="$1" |
| 77 | jars="$2" |
| 78 | if [[ "${PLATFORM}" == "windows" ]]; then |
| 79 | log "Checking if helper classes can be extracted..." |
| 80 | max_path=$((259-${#output_path})) |
| 81 | # Do not quote $jars, we rely on it being split on spaces. |
| 82 | for f in $jars ; do |
| 83 | # Get the zip entries. Match lines with a date: they have the paths. |
| 84 | entries="$(unzip -l "$f" | grep '[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}' | awk '{print $4}')" |
| 85 | for e in $entries; do |
| 86 | if [[ ${#e} -gt $max_path ]]; then |
| 87 | fail "Cannot unzip \"$f\" because the output path is too long: extracting file \"$e\" under \"$output_path\" would create a path longer than 259 characters. To fix this, set a shorter TMP value and try again. Example: export TMP=/c/tmp/bzl" |
| 88 | fi |
| 89 | done |
| 90 | done |
| 91 | fi |
| 92 | } |
| 93 | |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 94 | # Compiles java classes. |
| 95 | function java_compilation() { |
| 96 | local name=$1 |
| 97 | local directories=$2 |
Lukacs Berki | e21e592 | 2016-04-12 12:22:20 +0000 | [diff] [blame] | 98 | local excludes=$3 |
| 99 | local library_jars=$4 |
| 100 | local output=$5 |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 101 | |
Laszlo Csomor | 5402993 | 2016-12-19 15:43:31 +0000 | [diff] [blame] | 102 | local classpath=${library_jars// /$PATHSEP}${PATHSEP}$5 |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 103 | local sourcepath=${directories// /$PATHSEP} |
| 104 | |
| 105 | tempdir |
| 106 | local tmp="${NEW_TMPDIR}" |
| 107 | local paramfile="${tmp}/param" |
Lukacs Berki | e21e592 | 2016-04-12 12:22:20 +0000 | [diff] [blame] | 108 | local filelist="${tmp}/filelist" |
| 109 | local excludefile="${tmp}/excludefile" |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 110 | touch $paramfile |
| 111 | |
| 112 | mkdir -p "${output}/classes" |
| 113 | |
| 114 | # Compile .java files (incl. generated ones) using javac |
| 115 | log "Compiling $name code..." |
Lukacs Berki | e21e592 | 2016-04-12 12:22:20 +0000 | [diff] [blame] | 116 | find ${directories} -name "*.java" | sort > "$filelist" |
| 117 | # Quotes around $excludes intentionally omitted in the for statement so that |
| 118 | # it's split on spaces |
| 119 | (for i in $excludes; do |
| 120 | echo $i |
| 121 | done) | sort > "$excludefile" |
| 122 | |
| 123 | comm -23 "$filelist" "$excludefile" > "$paramfile" |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 124 | |
| 125 | if [ ! -z "$BAZEL_DEBUG_JAVA_COMPILATION" ]; then |
| 126 | echo "directories=${directories}" >&2 |
| 127 | echo "classpath=${classpath}" >&2 |
| 128 | echo "sourcepath=${sourcepath}" >&2 |
| 129 | echo "libraries=${library_jars}" >&2 |
| 130 | echo "output=${output}/classes" >&2 |
| 131 | echo "List of compiled files:" >&2 |
| 132 | cat "$paramfile" >&2 |
| 133 | fi |
| 134 | |
Laszlo Csomor | 7523e2c | 2019-07-05 05:21:09 -0700 | [diff] [blame] | 135 | check_unzip_wont_create_long_paths "${output}/classes" "$library_jars" |
| 136 | |
Googler | 09222fa | 2018-06-14 08:06:32 -0700 | [diff] [blame] | 137 | # Use BAZEL_JAVAC_OPTS to pass additional arguments to javac, e.g., |
| 138 | # export BAZEL_JAVAC_OPTS="-J-Xmx2g -J-Xms200m" |
| 139 | # Useful if your system chooses too small of a max heap for javac. |
| 140 | # We intentionally rely on shell word splitting to allow multiple |
| 141 | # additional arguments to be passed to javac. |
Julio Merino | 5909d9d | 2016-02-25 21:44:31 +0000 | [diff] [blame] | 142 | run "${JAVAC}" -classpath "${classpath}" -sourcepath "${sourcepath}" \ |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 143 | -d "${output}/classes" -source "$JAVA_VERSION" -target "$JAVA_VERSION" \ |
Googler | 09222fa | 2018-06-14 08:06:32 -0700 | [diff] [blame] | 144 | -encoding UTF-8 ${BAZEL_JAVAC_OPTS} "@${paramfile}" |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 145 | |
| 146 | log "Extracting helper classes for $name..." |
| 147 | for f in ${library_jars} ; do |
Julio Merino | 5909d9d | 2016-02-25 21:44:31 +0000 | [diff] [blame] | 148 | run unzip -qn ${f} -d "${output}/classes" |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 149 | done |
| 150 | } |
| 151 | |
| 152 | # Create the deploy JAR |
| 153 | function create_deploy_jar() { |
| 154 | local name=$1 |
| 155 | local mainClass=$2 |
| 156 | local output=$3 |
| 157 | shift 3 |
| 158 | local packages="" |
| 159 | for i in $output/classes/*; do |
| 160 | local package=$(basename $i) |
| 161 | if [[ "$package" != "META-INF" ]]; then |
| 162 | packages="$packages -C $output/classes $package" |
| 163 | fi |
| 164 | done |
| 165 | |
| 166 | log "Creating $name.jar..." |
| 167 | echo "Main-Class: $mainClass" > $output/MANIFEST.MF |
Julio Merino | 5909d9d | 2016-02-25 21:44:31 +0000 | [diff] [blame] | 168 | run "$JAR" cmf $output/MANIFEST.MF $output/$name.jar $packages "$@" |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 169 | } |
| 170 | |
Klaus Aehlig | 967a0a3 | 2016-12-02 15:08:25 +0000 | [diff] [blame] | 171 | HOW_TO_BOOTSTRAP=' |
| 172 | |
| 173 | -------------------------------------------------------------------------------- |
| 174 | NOTE: This failure is likely occuring if you are trying to bootstrap bazel from |
| 175 | a developer checkout. Those checkouts do not include the generated output of |
| 176 | the protoc compiler (as we prefer not to version generated files). |
| 177 | |
| 178 | * To build a developer version of bazel, do |
| 179 | |
| 180 | bazel build //src:bazel |
| 181 | |
| 182 | * To bootstrap your first bazel binary, please download a dist archive from our |
| 183 | release page at https://github.com/bazelbuild/bazel/releases and run |
| 184 | compile.sh on the unpacked archive. |
| 185 | |
| 186 | The full install instructions to install a release version of bazel can be found |
dzc | 5596d3b | 2017-06-07 21:51:52 -0400 | [diff] [blame] | 187 | at https://docs.bazel.build/install-compile-source.html |
Klaus Aehlig | 967a0a3 | 2016-12-02 15:08:25 +0000 | [diff] [blame] | 188 | For a rationale, why the bootstrap process is organized in this way, see |
| 189 | https://bazel.build/designs/2016/10/11/distribution-artifact.html |
| 190 | -------------------------------------------------------------------------------- |
| 191 | |
| 192 | ' |
| 193 | |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 194 | if [ -z "${BAZEL_SKIP_JAVA_COMPILATION}" ]; then |
Klaus Aehlig | d700dff5 | 2016-11-23 16:53:22 +0000 | [diff] [blame] | 195 | |
| 196 | if [ -d derived/src/java ] |
| 197 | then |
| 198 | log "Using pre-generated java proto files" |
| 199 | mkdir -p "${OUTPUT_DIR}/src" |
| 200 | cp -r derived/src/java/* "${OUTPUT_DIR}/src" |
| 201 | else |
| 202 | |
| 203 | [ -n "${PROTOC}" ] \ |
Klaus Aehlig | 967a0a3 | 2016-12-02 15:08:25 +0000 | [diff] [blame] | 204 | || fail "Must specify PROTOC if not bootstrapping from the distribution artifact${HOW_TO_BOOTSTRAP}" |
Klaus Aehlig | d700dff5 | 2016-11-23 16:53:22 +0000 | [diff] [blame] | 205 | |
| 206 | [ -n "${GRPC_JAVA_PLUGIN}" ] \ |
Klaus Aehlig | 967a0a3 | 2016-12-02 15:08:25 +0000 | [diff] [blame] | 207 | || fail "Must specify GRPC_JAVA_PLUGIN if not bootstrapping from the distribution artifact${HOW_TO_BOOTSTRAP}" |
Klaus Aehlig | d700dff5 | 2016-11-23 16:53:22 +0000 | [diff] [blame] | 208 | |
| 209 | [[ -x "${PROTOC-}" ]] \ |
| 210 | || fail "Protobuf compiler not found in ${PROTOC-}" |
| 211 | |
| 212 | [[ -x "${GRPC_JAVA_PLUGIN-}" ]] \ |
| 213 | || fail "gRPC Java plugin not found in ${GRPC_JAVA_PLUGIN-}" |
| 214 | |
| 215 | log "Compiling Java stubs for protocol buffers..." |
| 216 | for f in $PROTO_FILES ; do |
Olivier Chafik | 98be14f | 2017-11-29 07:34:49 -0800 | [diff] [blame] | 217 | run "${PROTOC}" \ |
| 218 | -I. \ |
| 219 | -Isrc/main/protobuf/ \ |
Klaus Aehlig | d700dff5 | 2016-11-23 16:53:22 +0000 | [diff] [blame] | 220 | -Isrc/main/java/com/google/devtools/build/lib/buildeventstream/proto/ \ |
Googler | 94bf004 | 2020-03-05 09:02:03 -0800 | [diff] [blame] | 221 | -Isrc/main/java/com/google/devtools/build/lib/skyframe/proto/ \ |
janakr | 65970e5 | 2020-02-26 08:25:00 -0800 | [diff] [blame] | 222 | -Isrc/main/java/com/google/devtools/build/skyframe/ \ |
Yun Peng | d2998a3 | 2020-04-24 01:32:40 -0700 | [diff] [blame] | 223 | -Isrc/main/java/com/google/devtools/build/lib/bazel/debug/ \ |
laurentlb | 6e87c95 | 2020-04-28 11:44:05 -0700 | [diff] [blame] | 224 | -Isrc/main/java/com/google/devtools/build/lib/starlarkdebug/proto/ \ |
Yun Peng | d2998a3 | 2020-04-24 01:32:40 -0700 | [diff] [blame] | 225 | -Ithird_party/remoteapis/ \ |
| 226 | -Ithird_party/googleapis/ \ |
| 227 | -Ithird_party/pprof/ \ |
Klaus Aehlig | d700dff5 | 2016-11-23 16:53:22 +0000 | [diff] [blame] | 228 | --java_out=${OUTPUT_DIR}/src \ |
| 229 | --plugin=protoc-gen-grpc="${GRPC_JAVA_PLUGIN-}" \ |
| 230 | --grpc_out=${OUTPUT_DIR}/src "$f" |
| 231 | done |
Yun Peng | 89cfb70 | 2020-05-25 06:55:22 -0700 | [diff] [blame] | 232 | |
| 233 | # Recreate the derived directory |
| 234 | mkdir -p derived/src/java/build |
| 235 | mkdir -p derived/src/java/com |
| 236 | link_children ${OUTPUT_DIR}/src build derived/src/java |
| 237 | link_children ${OUTPUT_DIR}/src com derived/src/java |
Klaus Aehlig | d700dff5 | 2016-11-23 16:53:22 +0000 | [diff] [blame] | 238 | fi |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 239 | |
Lukacs Berki | e21e592 | 2016-04-12 12:22:20 +0000 | [diff] [blame] | 240 | java_compilation "Bazel Java" "$DIRS" "$EXCLUDE_FILES" "$LIBRARY_JARS" "${OUTPUT_DIR}" |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 241 | |
| 242 | # help files: all non java and BUILD files in src/main/java. |
| 243 | for i in $(find src/main/java -type f -a \! -name '*.java' -a \! -name 'BUILD' | sed 's|src/main/java/||'); do |
| 244 | mkdir -p $(dirname ${OUTPUT_DIR}/classes/$i) |
| 245 | cp src/main/java/$i ${OUTPUT_DIR}/classes/$i |
| 246 | done |
| 247 | |
John Cater | 32c5add | 2018-03-19 08:51:46 -0700 | [diff] [blame] | 248 | # Create the bazel_tools repository. |
| 249 | BAZEL_TOOLS_REPO=${OUTPUT_DIR}/embedded_tools |
| 250 | mkdir -p ${BAZEL_TOOLS_REPO} |
| 251 | cat <<EOF >${BAZEL_TOOLS_REPO}/WORKSPACE |
| 252 | workspace(name = 'bazel_tools') |
| 253 | EOF |
Laszlo Csomor | c84c40d | 2019-04-30 07:17:00 -0700 | [diff] [blame] | 254 | |
| 255 | mkdir -p "${BAZEL_TOOLS_REPO}/src/conditions" |
| 256 | link_file "${PWD}/src/conditions/BUILD.tools" \ |
| 257 | "${BAZEL_TOOLS_REPO}/src/conditions/BUILD" |
| 258 | link_children "${PWD}" src/conditions "${BAZEL_TOOLS_REPO}" |
| 259 | link_children "${PWD}" src "${BAZEL_TOOLS_REPO}" |
| 260 | |
John Cater | 32c5add | 2018-03-19 08:51:46 -0700 | [diff] [blame] | 261 | link_dir ${PWD}/third_party ${BAZEL_TOOLS_REPO}/third_party |
Laszlo Csomor | 3eec3fe | 2018-09-03 06:40:28 -0700 | [diff] [blame] | 262 | |
| 263 | # Create @bazel_tools//tools/cpp/runfiles |
| 264 | mkdir -p ${BAZEL_TOOLS_REPO}/tools/cpp/runfiles |
| 265 | link_file "${PWD}/tools/cpp/runfiles/runfiles_src.h" \ |
| 266 | "${BAZEL_TOOLS_REPO}/tools/cpp/runfiles/runfiles.h" |
| 267 | # Transform //tools/cpp/runfiles:runfiles_src.cc to |
| 268 | # @bazel_tools//tools/cpp/runfiles:runfiles.cc |
| 269 | # Keep this transformation logic in sync with the |
| 270 | # //tools/cpp/runfiles:srcs_for_embedded_tools genrule. |
| 271 | sed 's|^#include.*/runfiles_src.h.*|#include \"tools/cpp/runfiles/runfiles.h\"|' \ |
| 272 | "${PWD}/tools/cpp/runfiles/runfiles_src.cc" > \ |
| 273 | "${BAZEL_TOOLS_REPO}/tools/cpp/runfiles/runfiles.cc" |
| 274 | link_file "${PWD}/tools/cpp/runfiles/BUILD.tools" \ |
| 275 | "${BAZEL_TOOLS_REPO}/tools/cpp/runfiles/BUILD" |
John Cater | d93ebe1 | 2018-09-27 06:59:58 -0700 | [diff] [blame] | 276 | |
| 277 | # Create @bazel_tools//tools/sh |
| 278 | mkdir -p ${BAZEL_TOOLS_REPO}/tools/sh |
| 279 | link_file "${PWD}/tools/sh/sh_configure.bzl" "${BAZEL_TOOLS_REPO}/tools/sh/sh_configure.bzl" |
| 280 | link_file "${PWD}/tools/sh/sh_toolchain.bzl" "${BAZEL_TOOLS_REPO}/tools/sh/sh_toolchain.bzl" |
| 281 | link_file "${PWD}/tools/sh/BUILD.tools" "${BAZEL_TOOLS_REPO}/tools/sh/BUILD" |
| 282 | |
Ivo List | 504a5b7 | 2020-12-03 04:00:13 -0800 | [diff] [blame] | 283 | # Create @bazel_tools//tools/jdk |
| 284 | mkdir -p ${BAZEL_TOOLS_REPO}/tools/jdk |
| 285 | link_file "${PWD}/tools/jdk/BUILD.tools" "${BAZEL_TOOLS_REPO}/tools/jdk/BUILD" |
| 286 | link_children "${PWD}" tools/jdk "${BAZEL_TOOLS_REPO}" |
| 287 | |
Laszlo Csomor | 4d05f38 | 2018-11-22 07:53:57 -0800 | [diff] [blame] | 288 | # Create @bazel_tools//tools/java/runfiles |
| 289 | mkdir -p ${BAZEL_TOOLS_REPO}/tools/java/runfiles |
| 290 | link_file "${PWD}/tools/java/runfiles/Runfiles.java" "${BAZEL_TOOLS_REPO}/tools/java/runfiles/Runfiles.java" |
| 291 | link_file "${PWD}/tools/java/runfiles/Util.java" "${BAZEL_TOOLS_REPO}/tools/java/runfiles/Util.java" |
| 292 | link_file "${PWD}/tools/java/runfiles/BUILD.tools" "${BAZEL_TOOLS_REPO}/tools/java/runfiles/BUILD" |
| 293 | |
brandjon | c9f78b5 | 2019-03-05 12:20:12 -0800 | [diff] [blame] | 294 | # Create @bazel_tools/tools/python/BUILD |
| 295 | mkdir -p ${BAZEL_TOOLS_REPO}/tools/python |
| 296 | link_file "${PWD}/tools/python/BUILD.tools" "${BAZEL_TOOLS_REPO}/tools/python/BUILD" |
| 297 | |
John Cater | 1e00502 | 2020-07-20 07:50:49 -0700 | [diff] [blame] | 298 | # Create @bazel_tools/tools/android/BUILD |
| 299 | mkdir -p ${BAZEL_TOOLS_REPO}/tools/android |
| 300 | link_file "${PWD}/tools/android/BUILD.tools" "${BAZEL_TOOLS_REPO}/tools/android/BUILD" |
| 301 | link_children "${PWD}" tools/android "${BAZEL_TOOLS_REPO}" |
| 302 | |
Laszlo Csomor | 3eec3fe | 2018-09-03 06:40:28 -0700 | [diff] [blame] | 303 | # Create the rest of @bazel_tools//tools/... |
| 304 | link_children "${PWD}" tools/cpp "${BAZEL_TOOLS_REPO}" |
hlopko | bea9d25 | 2019-11-15 07:30:16 -0800 | [diff] [blame] | 305 | mv -f ${BAZEL_TOOLS_REPO}/tools/cpp/BUILD.tools ${BAZEL_TOOLS_REPO}/tools/cpp/BUILD |
brandjon | c9f78b5 | 2019-03-05 12:20:12 -0800 | [diff] [blame] | 306 | link_children "${PWD}" tools/python "${BAZEL_TOOLS_REPO}" |
Laszlo Csomor | 3eec3fe | 2018-09-03 06:40:28 -0700 | [diff] [blame] | 307 | link_children "${PWD}" tools "${BAZEL_TOOLS_REPO}" |
John Cater | 32c5add | 2018-03-19 08:51:46 -0700 | [diff] [blame] | 308 | |
| 309 | # Set up @bazel_tools//platforms properly |
| 310 | mkdir -p ${BAZEL_TOOLS_REPO}/platforms |
philwo | e67c961 | 2019-05-06 04:28:48 -0700 | [diff] [blame] | 311 | cp tools/platforms/BUILD.tools ${BAZEL_TOOLS_REPO}/platforms/BUILD |
John Cater | 32c5add | 2018-03-19 08:51:46 -0700 | [diff] [blame] | 312 | |
Damien Martin-Guillerez | 12c68aa | 2016-01-15 13:18:11 +0000 | [diff] [blame] | 313 | # Overwrite tools.WORKSPACE, this is only for the bootstrap binary |
Klaus Aehlig | 286cfdd | 2016-10-17 16:47:55 +0000 | [diff] [blame] | 314 | chmod u+w "${OUTPUT_DIR}/classes/com/google/devtools/build/lib/bazel/rules/tools.WORKSPACE" |
Damien Martin-Guillerez | be5b2eb | 2016-03-02 16:08:07 +0000 | [diff] [blame] | 315 | cat <<EOF >${OUTPUT_DIR}/classes/com/google/devtools/build/lib/bazel/rules/tools.WORKSPACE |
John Cater | 32c5add | 2018-03-19 08:51:46 -0700 | [diff] [blame] | 316 | local_repository(name = 'bazel_tools', path = '${BAZEL_TOOLS_REPO}') |
Damien Martin-Guillerez | be5b2eb | 2016-03-02 16:08:07 +0000 | [diff] [blame] | 317 | bind(name = "cc_toolchain", actual = "@bazel_tools//tools/cpp:default-toolchain") |
John Cater | 00f8d65 | 2019-08-01 14:21:54 -0700 | [diff] [blame] | 318 | local_config_platform(name = 'local_config_platform') |
Damien Martin-Guillerez | be5b2eb | 2016-03-02 16:08:07 +0000 | [diff] [blame] | 319 | EOF |
Damien Martin-Guillerez | 12c68aa | 2016-01-15 13:18:11 +0000 | [diff] [blame] | 320 | |
michajlo | 7131b2c | 2018-04-09 09:25:50 -0700 | [diff] [blame] | 321 | create_deploy_jar "libblaze" "com.google.devtools.build.lib.bazel.Bazel" \ |
Han-Wen Nienhuys | a4b6182 | 2015-11-09 13:55:44 +0000 | [diff] [blame] | 322 | ${OUTPUT_DIR} |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 323 | fi |
| 324 | |
Damien Martin-Guillerez | daffc35 | 2016-01-18 15:20:32 +0000 | [diff] [blame] | 325 | log "Creating Bazel install base..." |
| 326 | ARCHIVE_DIR=${OUTPUT_DIR}/archive |
Googler | 3a5b710 | 2019-11-07 13:53:48 -0800 | [diff] [blame] | 327 | mkdir -p ${ARCHIVE_DIR} |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 328 | |
hlopko | aaf6457 | 2019-06-14 02:33:56 -0700 | [diff] [blame] | 329 | # Prepare @platforms local repository |
Googler | 3a5b710 | 2019-11-07 13:53:48 -0800 | [diff] [blame] | 330 | link_dir ${PWD}/platforms ${ARCHIVE_DIR}/platforms |
hlopko | aaf6457 | 2019-06-14 02:33:56 -0700 | [diff] [blame] | 331 | |
lberki | 73b0808 | 2018-10-05 10:00:57 -0700 | [diff] [blame] | 332 | # Dummy build-runfiles (we can't compile C++ yet, so we can't have the real one) |
| 333 | if [ "${PLATFORM}" = "windows" ]; then |
| 334 | # We don't rely on runfiles trees on Windows |
Googler | 3a5b710 | 2019-11-07 13:53:48 -0800 | [diff] [blame] | 335 | cat <<'EOF' >${ARCHIVE_DIR}/build-runfiles${EXE_EXT} |
lberki | 73b0808 | 2018-10-05 10:00:57 -0700 | [diff] [blame] | 336 | #!/bin/sh |
| 337 | mkdir -p $2 |
| 338 | cp $1 $2/MANIFEST |
| 339 | EOF |
| 340 | else |
Googler | 3a5b710 | 2019-11-07 13:53:48 -0800 | [diff] [blame] | 341 | cat <<'EOF' >${ARCHIVE_DIR}/build-runfiles${EXE_EXT} |
Klaus Aehlig | 6992e68 | 2016-08-05 12:27:21 +0000 | [diff] [blame] | 342 | #!/bin/sh |
lberki | 988626e | 2018-10-05 07:14:50 -0700 | [diff] [blame] | 343 | # This is bash implementation of build-runfiles: reads space-separated paths |
| 344 | # from each line in the file in $1, then creates a symlink under $2 for the |
| 345 | # first element of the pair that points to the second element of the pair. |
| 346 | # |
| 347 | # bash is a terrible tool for this job, but in this case, that's the only one |
| 348 | # we have (we could hand-compile a little .jar file like we hand-compile the |
| 349 | # bootstrap version of Bazel, but we'd still need a shell wrapper around it, so |
| 350 | # it's not clear whether that would be a win over a few lines of Lovecraftian |
| 351 | # code) |
| 352 | MANIFEST="$1" |
| 353 | TREE="$2" |
| 354 | |
| 355 | rm -fr "$TREE" |
| 356 | mkdir -p "$TREE" |
| 357 | |
| 358 | # Read the lines in $MANIFEST. the usual "for VAR in $(cat FILE)" idiom won't do |
| 359 | # because the lines in FILE contain spaces. |
| 360 | while read LINE; do |
| 361 | # Split each line into two parts on the first space |
| 362 | SYMLINK_PATH="${LINE%% *}" |
| 363 | TARGET_PATH="${LINE#* }" |
| 364 | ABSOLUTE_SYMLINK_PATH="$TREE/$SYMLINK_PATH" |
| 365 | mkdir -p "$(dirname $ABSOLUTE_SYMLINK_PATH)" |
| 366 | ln -s "$TARGET_PATH" "$ABSOLUTE_SYMLINK_PATH" |
| 367 | done < "$MANIFEST" |
| 368 | |
| 369 | cp "$MANIFEST" "$TREE/MANIFEST" |
Damien Martin-Guillerez | dceee0e | 2016-01-18 11:57:26 +0000 | [diff] [blame] | 370 | EOF |
lberki | 73b0808 | 2018-10-05 10:00:57 -0700 | [diff] [blame] | 371 | fi |
| 372 | |
Googler | 3a5b710 | 2019-11-07 13:53:48 -0800 | [diff] [blame] | 373 | chmod 0755 ${ARCHIVE_DIR}/build-runfiles${EXE_EXT} |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 374 | |
Laszlo Csomor | d40c78a | 2016-12-20 10:22:17 +0000 | [diff] [blame] | 375 | function build_jni() { |
| 376 | local -r output_dir=$1 |
| 377 | |
Laszlo Csomor | d0d7ef0 | 2017-04-26 10:48:00 +0200 | [diff] [blame] | 378 | if [ "${PLATFORM}" = "windows" ]; then |
Laszlo Csomor | d40c78a | 2016-12-20 10:22:17 +0000 | [diff] [blame] | 379 | # We need JNI on Windows because some filesystem operations are not (and |
| 380 | # cannot be) implemented in native Java. |
| 381 | log "Building Windows JNI library..." |
| 382 | |
| 383 | local -r jni_lib_name="windows_jni.dll" |
| 384 | local -r output="${output_dir}/${jni_lib_name}" |
| 385 | local -r tmp_output="${NEW_TMPDIR}/jni/${jni_lib_name}" |
| 386 | mkdir -p "$(dirname "$tmp_output")" |
| 387 | mkdir -p "$(dirname "$output")" |
| 388 | |
| 389 | # Keep this `find` command in sync with the `srcs` of |
Laszlo Csomor | 9409109 | 2017-07-04 05:45:40 -0400 | [diff] [blame] | 390 | # //src/main/native/windows:windows_jni |
Laszlo Csomor | 17770e5 | 2017-06-29 17:43:05 +0200 | [diff] [blame] | 391 | local srcs=$(find src/main/native/windows -name '*.cc' -o -name '*.h') |
Laszlo Csomor | d40c78a | 2016-12-20 10:22:17 +0000 | [diff] [blame] | 392 | [ -n "$srcs" ] || fail "Could not find sources for Windows JNI library" |
| 393 | |
| 394 | # do not quote $srcs because we need to expand it to multiple args |
Laszlo Csomor | 9409109 | 2017-07-04 05:45:40 -0400 | [diff] [blame] | 395 | src/main/native/windows/build_windows_jni.sh "$tmp_output" ${srcs} |
Laszlo Csomor | d40c78a | 2016-12-20 10:22:17 +0000 | [diff] [blame] | 396 | |
| 397 | cp "$tmp_output" "$output" |
| 398 | chmod 0555 "$output" |
| 399 | |
jmmv | 50adefb | 2020-10-02 09:25:34 -0700 | [diff] [blame] | 400 | JNI_FLAGS="-Djava.library.path=${output_dir}" |
Laszlo Csomor | d0d7ef0 | 2017-04-26 10:48:00 +0200 | [diff] [blame] | 401 | else |
jmmv | 50adefb | 2020-10-02 09:25:34 -0700 | [diff] [blame] | 402 | # We don't need JNI on other platforms. The Java NIO file system fallback is |
| 403 | # sufficient. |
| 404 | true |
Laszlo Csomor | d0d7ef0 | 2017-04-26 10:48:00 +0200 | [diff] [blame] | 405 | fi |
Laszlo Csomor | d40c78a | 2016-12-20 10:22:17 +0000 | [diff] [blame] | 406 | } |
| 407 | |
Googler | 3a5b710 | 2019-11-07 13:53:48 -0800 | [diff] [blame] | 408 | build_jni "${ARCHIVE_DIR}" |
Laszlo Csomor | d40c78a | 2016-12-20 10:22:17 +0000 | [diff] [blame] | 409 | |
Damien Martin-Guillerez | daffc35 | 2016-01-18 15:20:32 +0000 | [diff] [blame] | 410 | cp $OUTPUT_DIR/libblaze.jar ${ARCHIVE_DIR} |
Chris Parsons | 381850e | 2016-08-31 17:04:17 +0000 | [diff] [blame] | 411 | |
| 412 | # TODO(b/28965185): Remove when xcode-locator is no longer required in embedded_binaries. |
| 413 | log "Compiling xcode-locator..." |
| 414 | if [[ $PLATFORM == "darwin" ]]; then |
Googler | 3a5b710 | 2019-11-07 13:53:48 -0800 | [diff] [blame] | 415 | run /usr/bin/xcrun --sdk macosx clang -mmacosx-version-min=10.9 -fobjc-arc -framework CoreServices -framework Foundation -o ${ARCHIVE_DIR}/xcode-locator tools/osx/xcode_locator.m |
Chris Parsons | 381850e | 2016-08-31 17:04:17 +0000 | [diff] [blame] | 416 | else |
Googler | 3a5b710 | 2019-11-07 13:53:48 -0800 | [diff] [blame] | 417 | cp tools/osx/xcode_locator_stub.sh ${ARCHIVE_DIR}/xcode-locator |
Chris Parsons | 381850e | 2016-08-31 17:04:17 +0000 | [diff] [blame] | 418 | fi |
Chris Parsons | f488818 | 2016-01-08 00:42:14 +0000 | [diff] [blame] | 419 | |
Laszlo Csomor | d0d7ef0 | 2017-04-26 10:48:00 +0200 | [diff] [blame] | 420 | function get_cwd() { |
| 421 | local result=${PWD} |
| 422 | [ "$PLATFORM" = "windows" ] && result="$(cygpath -m "$result")" |
| 423 | echo "$result" |
| 424 | } |
| 425 | |
Laszlo Csomor | 9f7180f | 2016-09-27 13:07:43 +0000 | [diff] [blame] | 426 | function run_bazel_jar() { |
| 427 | local command=$1 |
| 428 | shift |
Yun Peng | 8efd282 | 2017-03-09 13:15:41 +0000 | [diff] [blame] | 429 | local client_env=() |
Damien Martin-Guillerez | 755669f | 2017-05-08 12:27:38 -0400 | [diff] [blame] | 430 | # Propagate all environment variables to bootstrapped Bazel. |
hlopko | 200479a | 2017-05-09 07:10:35 -0400 | [diff] [blame] | 431 | # See https://stackoverflow.com/questions/41898503/loop-over-environment-variables-in-posix-sh |
Laszlo Csomor | 0a936d1 | 2017-05-31 09:47:43 +0200 | [diff] [blame] | 432 | local env_vars="$(awk 'END { for (name in ENVIRON) { if(name != "_" && name ~ /^[A-Za-z0-9_]*$/) print name; } }' </dev/null)" |
Nicolas Lopez | bcbdb87 | 2017-03-28 08:08:50 +0000 | [diff] [blame] | 433 | for varname in $env_vars; do |
Dmitry Lomov | 31fab29 | 2017-03-07 18:33:08 +0000 | [diff] [blame] | 434 | eval value=\$$varname |
pcloudy | 8c21b0b | 2018-09-19 07:19:09 -0700 | [diff] [blame] | 435 | if [ "${PLATFORM}" = "windows" ] && echo "$varname" | grep -q -i "^\(path\|tmp\|temp\|tempdir\|systemroot\|systemdrive\)$" ; then |
Laszlo Csomor | 0a936d1 | 2017-05-31 09:47:43 +0200 | [diff] [blame] | 436 | varname="$(echo "$varname" | tr [:lower:] [:upper:])" |
| 437 | fi |
Yun Peng | 8efd282 | 2017-03-09 13:15:41 +0000 | [diff] [blame] | 438 | if [ "${value}" ]; then |
| 439 | client_env=("${client_env[@]}" --client_env="${varname}=${value}") |
Dmitry Lomov | 31fab29 | 2017-03-07 18:33:08 +0000 | [diff] [blame] | 440 | fi |
| 441 | done |
| 442 | |
Dmitry Lomov | f9f2e10 | 2016-01-29 14:26:46 +0000 | [diff] [blame] | 443 | "${JAVA_HOME}/bin/java" \ |
Philipp Wollermann | 74cb8c7 | 2016-07-15 14:01:37 +0000 | [diff] [blame] | 444 | -XX:+HeapDumpOnOutOfMemoryError -Xverify:none -Dfile.encoding=ISO-8859-1 \ |
Carmi Grushko | 4068a1d | 2016-06-22 18:43:13 +0000 | [diff] [blame] | 445 | -XX:HeapDumpPath=${OUTPUT_DIR} \ |
Damien Martin-Guillerez | daffc35 | 2016-01-18 15:20:32 +0000 | [diff] [blame] | 446 | -Djava.util.logging.config.file=${OUTPUT_DIR}/javalog.properties \ |
Laszlo Csomor | d40c78a | 2016-12-20 10:22:17 +0000 | [diff] [blame] | 447 | ${JNI_FLAGS} \ |
Damien Martin-Guillerez | daffc35 | 2016-01-18 15:20:32 +0000 | [diff] [blame] | 448 | -jar ${ARCHIVE_DIR}/libblaze.jar \ |
| 449 | --batch \ |
| 450 | --install_base=${ARCHIVE_DIR} \ |
| 451 | --output_base=${OUTPUT_DIR}/out \ |
mschaller | 0992427 | 2020-04-07 20:50:28 -0700 | [diff] [blame] | 452 | --failure_detail_out=${OUTPUT_DIR}/failure_detail.rawproto \ |
Klaus Aehlig | c2499c4 | 2018-02-27 05:47:21 -0800 | [diff] [blame] | 453 | --output_user_root=${OUTPUT_DIR}/user_root \ |
Damien Martin-Guillerez | daffc35 | 2016-01-18 15:20:32 +0000 | [diff] [blame] | 454 | --install_md5= \ |
cushon | 849df36 | 2018-05-14 01:51:45 -0700 | [diff] [blame] | 455 | --default_system_javabase="${JAVA_HOME}" \ |
Laszlo Csomor | d0d7ef0 | 2017-04-26 10:48:00 +0200 | [diff] [blame] | 456 | --workspace_directory="$(get_cwd)" \ |
Kristina Chodorow | 4873e56 | 2016-06-20 14:17:50 +0000 | [diff] [blame] | 457 | --nofatal_event_bus_exceptions \ |
Klaus Aehlig | 276a8cd | 2016-07-11 12:06:07 +0000 | [diff] [blame] | 458 | ${BAZEL_DIR_STARTUP_OPTIONS} \ |
Laszlo Csomor | 50f6bba | 2016-09-26 14:10:25 +0000 | [diff] [blame] | 459 | ${BAZEL_BOOTSTRAP_STARTUP_OPTIONS:-} \ |
Laszlo Csomor | 9f7180f | 2016-09-27 13:07:43 +0000 | [diff] [blame] | 460 | $command \ |
Damien Martin-Guillerez | 51a204a | 2016-02-08 14:59:59 +0000 | [diff] [blame] | 461 | --ignore_unsupported_sandboxing \ |
Damien Martin-Guillerez | daffc35 | 2016-01-18 15:20:32 +0000 | [diff] [blame] | 462 | --startup_time=329 --extract_data_time=523 \ |
Klaus Aehlig | 7038d3f | 2016-03-16 15:41:22 +0000 | [diff] [blame] | 463 | --rc_source=/dev/null --isatty=1 \ |
Philipp Wollermann | 4c55898 | 2017-07-27 18:01:12 +0200 | [diff] [blame] | 464 | --build_python_zip \ |
Yun Peng | 8efd282 | 2017-03-09 13:15:41 +0000 | [diff] [blame] | 465 | "${client_env[@]}" \ |
Laszlo Csomor | d0d7ef0 | 2017-04-26 10:48:00 +0200 | [diff] [blame] | 466 | --client_cwd="$(get_cwd)" \ |
Damien Martin-Guillerez | daffc35 | 2016-01-18 15:20:32 +0000 | [diff] [blame] | 467 | "${@}" |
| 468 | } |