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 | |
Klaus Aehlig | f009901 | 2016-09-28 12:13:17 +0000 | [diff] [blame] | 19 | PROTO_FILES=$(ls src/main/protobuf/*.proto src/main/java/com/google/devtools/build/lib/buildeventstream/proto/*.proto) |
Klaus Aehlig | 76eb2a4 | 2018-01-19 02:44:58 -0800 | [diff] [blame] | 20 | LIBRARY_JARS=$(find third_party -name '*.jar' | grep -Fv JavaBuilder | grep -Fv third_party/guava | grep -Fv third_party/guava | grep -ve 'third_party/grpc/grpc.*jar' | tr "\n" " ") |
Carl Mastrangelo | 38ff396 | 2018-03-07 08:52:04 -0800 | [diff] [blame] | 21 | GRPC_JAVA_VERSION=1.10.0 |
Androbin | ef381e5 | 2017-12-14 07:24:27 -0800 | [diff] [blame] | 22 | GRPC_LIBRARY_JARS=$(find third_party/grpc -name '*.jar' | grep -e ".*${GRPC_JAVA_VERSION}.*jar" | tr "\n" " ") |
philwo | bed8c5f | 2018-07-25 04:44:15 -0700 | [diff] [blame] | 23 | GUAVA_VERSION=25.1 |
Androbin | ef381e5 | 2017-12-14 07:24:27 -0800 | [diff] [blame] | 24 | 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] | 25 | LIBRARY_JARS="${LIBRARY_JARS} ${GRPC_LIBRARY_JARS} ${GUAVA_JARS}" |
Nathan Harmata | 8a47590 | 2016-11-23 19:08:12 +0000 | [diff] [blame] | 26 | |
| 27 | # tl;dr - error_prone_core contains a copy of an older version of guava, so we |
| 28 | # need to make sure the newer version of guava always appears first on the |
| 29 | # classpath. |
| 30 | # |
| 31 | # Please read the comment in third_party/BUILD for more details. |
| 32 | LIBRARY_JARS_ARRAY=($LIBRARY_JARS) |
Greg Steuck | fce20d79 | 2018-06-04 23:10:39 -0700 | [diff] [blame] | 33 | for i in $(eval echo {0..$((${#LIBRARY_JARS_ARRAY[@]} - 1))}) |
Nathan Harmata | 8a47590 | 2016-11-23 19:08:12 +0000 | [diff] [blame] | 34 | do |
Damien Martin-Guillerez | b46631b | 2017-01-20 13:27:26 +0000 | [diff] [blame] | 35 | [[ "${LIBRARY_JARS_ARRAY[$i]}" =~ ^"third_party/error_prone/error_prone_core-".*\.jar$ ]] && ERROR_PRONE_INDEX=$i |
| 36 | [[ "${LIBRARY_JARS_ARRAY[$i]}" =~ ^"third_party/guava/guava-".*\.jar$ ]] && GUAVA_INDEX=$i |
Nathan Harmata | 8a47590 | 2016-11-23 19:08:12 +0000 | [diff] [blame] | 37 | done |
| 38 | [ "${ERROR_PRONE_INDEX:+present}" = "present" ] || { echo "no error prone jar"; echo "${LIBRARY_JARS_ARRAY[@]}"; exit 1; } |
| 39 | [ "${GUAVA_INDEX:+present}" = "present" ] || { echo "no guava jar"; exit 1; } |
| 40 | if [ "$ERROR_PRONE_INDEX" -lt "$GUAVA_INDEX" ]; then |
| 41 | TEMP_FOR_SWAP="${LIBRARY_JARS_ARRAY[$ERROR_PRONE_INDEX]}" |
| 42 | LIBRARY_JARS_ARRAY[$ERROR_PRONE_INDEX]="${LIBRARY_JARS_ARRAY[$GUAVA_INDEX]}" |
| 43 | LIBRARY_JARS_ARRAY[$GUAVA_INDEX]="$TEMP_FOR_SWAP" |
Androbin | 9c78a79 | 2017-11-29 01:31:47 -0800 | [diff] [blame] | 44 | LIBRARY_JARS="${LIBRARY_JARS_ARRAY[*]}" |
Nathan Harmata | 8a47590 | 2016-11-23 19:08:12 +0000 | [diff] [blame] | 45 | fi |
| 46 | |
Damien Martin-Guillerez | e700e72 | 2016-06-30 15:06:39 +0200 | [diff] [blame] | 47 | DIRS=$(echo src/{java_tools/singlejar/java/com/google/devtools/build/zip,main/java,tools/xcode-common/java/com/google/devtools/build/xcode/{common,util}} third_party/java/dd_plist/java ${OUTPUT_DIR}/src) |
dmarting | f0b8295 | 2017-09-19 14:54:30 +0200 | [diff] [blame] | 48 | EXCLUDE_FILES="src/main/java/com/google/devtools/build/lib/server/GrpcServerImpl.java src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/testing/*" |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 49 | |
Alexander Chung | fc07142 | 2017-02-07 12:48:26 +0000 | [diff] [blame] | 50 | mkdir -p "${OUTPUT_DIR}/classes" |
| 51 | mkdir -p "${OUTPUT_DIR}/src" |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 52 | |
| 53 | # May be passed in from outside. |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 54 | ZIPOPTS="$ZIPOPTS" |
| 55 | |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 56 | unset JAVA_TOOL_OPTIONS |
| 57 | unset _JAVA_OPTIONS |
| 58 | |
| 59 | LDFLAGS=${LDFLAGS:-""} |
| 60 | |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 61 | MSYS_DLLS="" |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 62 | |
Harsh Vardhan | fe04cfd | 2017-03-21 15:27:12 +0000 | [diff] [blame] | 63 | function get_minor_java_version() { |
| 64 | get_java_version |
hlopko | 3566474 | 2017-05-29 17:03:07 +0200 | [diff] [blame] | 65 | java_minor_version=$(echo $JAVA_VERSION | sed 's/[^.][^.]*\.//' | sed 's/\..*$//') |
| 66 | javac_minor_version=$(echo $JAVAC_VERSION | sed 's/[^.][^.]*\.//' | sed 's/\..*$//') |
Harsh Vardhan | fe04cfd | 2017-03-21 15:27:12 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 69 | # Check that javac -version returns a upper version than $JAVA_VERSION. |
Harsh Vardhan | fe04cfd | 2017-03-21 15:27:12 +0000 | [diff] [blame] | 70 | get_minor_java_version |
| 71 | [ ${java_minor_version} -le ${javac_minor_version} ] || \ |
Damien Martin-Guillerez | 338dc56 | 2015-06-23 17:15:12 +0000 | [diff] [blame] | 72 | 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] | 73 | |
| 74 | JAR="${JAVA_HOME}/bin/jar" |
| 75 | |
| 76 | # Compiles java classes. |
| 77 | function java_compilation() { |
| 78 | local name=$1 |
| 79 | local directories=$2 |
Lukacs Berki | e21e592 | 2016-04-12 12:22:20 +0000 | [diff] [blame] | 80 | local excludes=$3 |
| 81 | local library_jars=$4 |
| 82 | local output=$5 |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 83 | |
Laszlo Csomor | 5402993 | 2016-12-19 15:43:31 +0000 | [diff] [blame] | 84 | local classpath=${library_jars// /$PATHSEP}${PATHSEP}$5 |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 85 | local sourcepath=${directories// /$PATHSEP} |
| 86 | |
| 87 | tempdir |
| 88 | local tmp="${NEW_TMPDIR}" |
| 89 | local paramfile="${tmp}/param" |
Lukacs Berki | e21e592 | 2016-04-12 12:22:20 +0000 | [diff] [blame] | 90 | local filelist="${tmp}/filelist" |
| 91 | local excludefile="${tmp}/excludefile" |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 92 | touch $paramfile |
| 93 | |
| 94 | mkdir -p "${output}/classes" |
| 95 | |
| 96 | # Compile .java files (incl. generated ones) using javac |
| 97 | log "Compiling $name code..." |
Lukacs Berki | e21e592 | 2016-04-12 12:22:20 +0000 | [diff] [blame] | 98 | find ${directories} -name "*.java" | sort > "$filelist" |
| 99 | # Quotes around $excludes intentionally omitted in the for statement so that |
| 100 | # it's split on spaces |
| 101 | (for i in $excludes; do |
| 102 | echo $i |
| 103 | done) | sort > "$excludefile" |
| 104 | |
| 105 | comm -23 "$filelist" "$excludefile" > "$paramfile" |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 106 | |
| 107 | if [ ! -z "$BAZEL_DEBUG_JAVA_COMPILATION" ]; then |
| 108 | echo "directories=${directories}" >&2 |
| 109 | echo "classpath=${classpath}" >&2 |
| 110 | echo "sourcepath=${sourcepath}" >&2 |
| 111 | echo "libraries=${library_jars}" >&2 |
| 112 | echo "output=${output}/classes" >&2 |
| 113 | echo "List of compiled files:" >&2 |
| 114 | cat "$paramfile" >&2 |
| 115 | fi |
| 116 | |
Googler | 09222fa | 2018-06-14 08:06:32 -0700 | [diff] [blame] | 117 | # Use BAZEL_JAVAC_OPTS to pass additional arguments to javac, e.g., |
| 118 | # export BAZEL_JAVAC_OPTS="-J-Xmx2g -J-Xms200m" |
| 119 | # Useful if your system chooses too small of a max heap for javac. |
| 120 | # We intentionally rely on shell word splitting to allow multiple |
| 121 | # additional arguments to be passed to javac. |
Julio Merino | 5909d9d | 2016-02-25 21:44:31 +0000 | [diff] [blame] | 122 | run "${JAVAC}" -classpath "${classpath}" -sourcepath "${sourcepath}" \ |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 123 | -d "${output}/classes" -source "$JAVA_VERSION" -target "$JAVA_VERSION" \ |
Googler | 09222fa | 2018-06-14 08:06:32 -0700 | [diff] [blame] | 124 | -encoding UTF-8 ${BAZEL_JAVAC_OPTS} "@${paramfile}" |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 125 | |
| 126 | log "Extracting helper classes for $name..." |
| 127 | for f in ${library_jars} ; do |
Julio Merino | 5909d9d | 2016-02-25 21:44:31 +0000 | [diff] [blame] | 128 | run unzip -qn ${f} -d "${output}/classes" |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 129 | done |
| 130 | } |
| 131 | |
| 132 | # Create the deploy JAR |
| 133 | function create_deploy_jar() { |
| 134 | local name=$1 |
| 135 | local mainClass=$2 |
| 136 | local output=$3 |
| 137 | shift 3 |
| 138 | local packages="" |
| 139 | for i in $output/classes/*; do |
| 140 | local package=$(basename $i) |
| 141 | if [[ "$package" != "META-INF" ]]; then |
| 142 | packages="$packages -C $output/classes $package" |
| 143 | fi |
| 144 | done |
| 145 | |
| 146 | log "Creating $name.jar..." |
| 147 | echo "Main-Class: $mainClass" > $output/MANIFEST.MF |
Julio Merino | 5909d9d | 2016-02-25 21:44:31 +0000 | [diff] [blame] | 148 | run "$JAR" cmf $output/MANIFEST.MF $output/$name.jar $packages "$@" |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 149 | } |
| 150 | |
Klaus Aehlig | 967a0a3 | 2016-12-02 15:08:25 +0000 | [diff] [blame] | 151 | HOW_TO_BOOTSTRAP=' |
| 152 | |
| 153 | -------------------------------------------------------------------------------- |
| 154 | NOTE: This failure is likely occuring if you are trying to bootstrap bazel from |
| 155 | a developer checkout. Those checkouts do not include the generated output of |
| 156 | the protoc compiler (as we prefer not to version generated files). |
| 157 | |
| 158 | * To build a developer version of bazel, do |
| 159 | |
| 160 | bazel build //src:bazel |
| 161 | |
| 162 | * To bootstrap your first bazel binary, please download a dist archive from our |
| 163 | release page at https://github.com/bazelbuild/bazel/releases and run |
| 164 | compile.sh on the unpacked archive. |
| 165 | |
| 166 | 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] | 167 | at https://docs.bazel.build/install-compile-source.html |
Klaus Aehlig | 967a0a3 | 2016-12-02 15:08:25 +0000 | [diff] [blame] | 168 | For a rationale, why the bootstrap process is organized in this way, see |
| 169 | https://bazel.build/designs/2016/10/11/distribution-artifact.html |
| 170 | -------------------------------------------------------------------------------- |
| 171 | |
| 172 | ' |
| 173 | |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 174 | if [ -z "${BAZEL_SKIP_JAVA_COMPILATION}" ]; then |
Klaus Aehlig | d700dff5 | 2016-11-23 16:53:22 +0000 | [diff] [blame] | 175 | |
| 176 | if [ -d derived/src/java ] |
| 177 | then |
| 178 | log "Using pre-generated java proto files" |
| 179 | mkdir -p "${OUTPUT_DIR}/src" |
| 180 | cp -r derived/src/java/* "${OUTPUT_DIR}/src" |
| 181 | else |
| 182 | |
| 183 | [ -n "${PROTOC}" ] \ |
Klaus Aehlig | 967a0a3 | 2016-12-02 15:08:25 +0000 | [diff] [blame] | 184 | || 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] | 185 | |
| 186 | [ -n "${GRPC_JAVA_PLUGIN}" ] \ |
Klaus Aehlig | 967a0a3 | 2016-12-02 15:08:25 +0000 | [diff] [blame] | 187 | || 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] | 188 | |
| 189 | [[ -x "${PROTOC-}" ]] \ |
| 190 | || fail "Protobuf compiler not found in ${PROTOC-}" |
| 191 | |
| 192 | [[ -x "${GRPC_JAVA_PLUGIN-}" ]] \ |
| 193 | || fail "gRPC Java plugin not found in ${GRPC_JAVA_PLUGIN-}" |
| 194 | |
| 195 | log "Compiling Java stubs for protocol buffers..." |
| 196 | for f in $PROTO_FILES ; do |
Olivier Chafik | 98be14f | 2017-11-29 07:34:49 -0800 | [diff] [blame] | 197 | run "${PROTOC}" \ |
| 198 | -I. \ |
| 199 | -Isrc/main/protobuf/ \ |
Klaus Aehlig | d700dff5 | 2016-11-23 16:53:22 +0000 | [diff] [blame] | 200 | -Isrc/main/java/com/google/devtools/build/lib/buildeventstream/proto/ \ |
| 201 | --java_out=${OUTPUT_DIR}/src \ |
| 202 | --plugin=protoc-gen-grpc="${GRPC_JAVA_PLUGIN-}" \ |
| 203 | --grpc_out=${OUTPUT_DIR}/src "$f" |
| 204 | done |
| 205 | fi |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 206 | |
Lukacs Berki | e21e592 | 2016-04-12 12:22:20 +0000 | [diff] [blame] | 207 | java_compilation "Bazel Java" "$DIRS" "$EXCLUDE_FILES" "$LIBRARY_JARS" "${OUTPUT_DIR}" |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 208 | |
| 209 | # help files: all non java and BUILD files in src/main/java. |
| 210 | for i in $(find src/main/java -type f -a \! -name '*.java' -a \! -name 'BUILD' | sed 's|src/main/java/||'); do |
| 211 | mkdir -p $(dirname ${OUTPUT_DIR}/classes/$i) |
| 212 | cp src/main/java/$i ${OUTPUT_DIR}/classes/$i |
| 213 | done |
| 214 | |
John Cater | 32c5add | 2018-03-19 08:51:46 -0700 | [diff] [blame] | 215 | # Create the bazel_tools repository. |
| 216 | BAZEL_TOOLS_REPO=${OUTPUT_DIR}/embedded_tools |
| 217 | mkdir -p ${BAZEL_TOOLS_REPO} |
| 218 | cat <<EOF >${BAZEL_TOOLS_REPO}/WORKSPACE |
| 219 | workspace(name = 'bazel_tools') |
| 220 | EOF |
| 221 | link_dir ${PWD}/src ${BAZEL_TOOLS_REPO}/src |
| 222 | link_dir ${PWD}/third_party ${BAZEL_TOOLS_REPO}/third_party |
| 223 | link_dir ${PWD}/tools ${BAZEL_TOOLS_REPO}/tools |
| 224 | |
| 225 | # Set up @bazel_tools//platforms properly |
| 226 | mkdir -p ${BAZEL_TOOLS_REPO}/platforms |
| 227 | cp tools/platforms/platforms.BUILD ${BAZEL_TOOLS_REPO}/platforms/BUILD |
| 228 | |
Damien Martin-Guillerez | 12c68aa | 2016-01-15 13:18:11 +0000 | [diff] [blame] | 229 | # Overwrite tools.WORKSPACE, this is only for the bootstrap binary |
Klaus Aehlig | 286cfdd | 2016-10-17 16:47:55 +0000 | [diff] [blame] | 230 | 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] | 231 | 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] | 232 | local_repository(name = 'bazel_tools', path = '${BAZEL_TOOLS_REPO}') |
Damien Martin-Guillerez | be5b2eb | 2016-03-02 16:08:07 +0000 | [diff] [blame] | 233 | bind(name = "cc_toolchain", actual = "@bazel_tools//tools/cpp:default-toolchain") |
| 234 | EOF |
Damien Martin-Guillerez | 12c68aa | 2016-01-15 13:18:11 +0000 | [diff] [blame] | 235 | |
michajlo | 7131b2c | 2018-04-09 09:25:50 -0700 | [diff] [blame] | 236 | create_deploy_jar "libblaze" "com.google.devtools.build.lib.bazel.Bazel" \ |
Han-Wen Nienhuys | a4b6182 | 2015-11-09 13:55:44 +0000 | [diff] [blame] | 237 | ${OUTPUT_DIR} |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 238 | fi |
| 239 | |
Damien Martin-Guillerez | daffc35 | 2016-01-18 15:20:32 +0000 | [diff] [blame] | 240 | log "Creating Bazel install base..." |
| 241 | ARCHIVE_DIR=${OUTPUT_DIR}/archive |
| 242 | mkdir -p ${ARCHIVE_DIR}/_embedded_binaries |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 243 | |
Damien Martin-Guillerez | dceee0e | 2016-01-18 11:57:26 +0000 | [diff] [blame] | 244 | # Dummy build-runfiles |
Damien Martin-Guillerez | daffc35 | 2016-01-18 15:20:32 +0000 | [diff] [blame] | 245 | cat <<'EOF' >${ARCHIVE_DIR}/_embedded_binaries/build-runfiles${EXE_EXT} |
Klaus Aehlig | 6992e68 | 2016-08-05 12:27:21 +0000 | [diff] [blame] | 246 | #!/bin/sh |
Lukacs Berki | 25f3569 | 2016-08-04 10:38:36 +0000 | [diff] [blame] | 247 | mkdir -p $2 |
Damien Martin-Guillerez | dceee0e | 2016-01-18 11:57:26 +0000 | [diff] [blame] | 248 | cp $1 $2/MANIFEST |
| 249 | EOF |
Damien Martin-Guillerez | daffc35 | 2016-01-18 15:20:32 +0000 | [diff] [blame] | 250 | chmod 0755 ${ARCHIVE_DIR}/_embedded_binaries/build-runfiles${EXE_EXT} |
Damien Martin-Guillerez | d47a8ef | 2015-06-10 11:54:50 +0000 | [diff] [blame] | 251 | |
Laszlo Csomor | d40c78a | 2016-12-20 10:22:17 +0000 | [diff] [blame] | 252 | function build_jni() { |
| 253 | local -r output_dir=$1 |
| 254 | |
Laszlo Csomor | d0d7ef0 | 2017-04-26 10:48:00 +0200 | [diff] [blame] | 255 | if [ "${PLATFORM}" = "windows" ]; then |
Laszlo Csomor | d40c78a | 2016-12-20 10:22:17 +0000 | [diff] [blame] | 256 | # We need JNI on Windows because some filesystem operations are not (and |
| 257 | # cannot be) implemented in native Java. |
| 258 | log "Building Windows JNI library..." |
| 259 | |
| 260 | local -r jni_lib_name="windows_jni.dll" |
| 261 | local -r output="${output_dir}/${jni_lib_name}" |
| 262 | local -r tmp_output="${NEW_TMPDIR}/jni/${jni_lib_name}" |
| 263 | mkdir -p "$(dirname "$tmp_output")" |
| 264 | mkdir -p "$(dirname "$output")" |
| 265 | |
| 266 | # Keep this `find` command in sync with the `srcs` of |
Laszlo Csomor | 9409109 | 2017-07-04 05:45:40 -0400 | [diff] [blame] | 267 | # //src/main/native/windows:windows_jni |
Laszlo Csomor | 17770e5 | 2017-06-29 17:43:05 +0200 | [diff] [blame] | 268 | local srcs=$(find src/main/native/windows -name '*.cc' -o -name '*.h') |
Laszlo Csomor | d40c78a | 2016-12-20 10:22:17 +0000 | [diff] [blame] | 269 | [ -n "$srcs" ] || fail "Could not find sources for Windows JNI library" |
| 270 | |
| 271 | # 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] | 272 | src/main/native/windows/build_windows_jni.sh "$tmp_output" ${srcs} |
Laszlo Csomor | d40c78a | 2016-12-20 10:22:17 +0000 | [diff] [blame] | 273 | |
| 274 | cp "$tmp_output" "$output" |
| 275 | chmod 0555 "$output" |
| 276 | |
| 277 | JNI_FLAGS="-Dio.bazel.EnableJni=1 -Djava.library.path=${output_dir}" |
Laszlo Csomor | d0d7ef0 | 2017-04-26 10:48:00 +0200 | [diff] [blame] | 278 | else |
Laszlo Csomor | d40c78a | 2016-12-20 10:22:17 +0000 | [diff] [blame] | 279 | # We don't need JNI on other platforms. |
| 280 | JNI_FLAGS="-Dio.bazel.EnableJni=0" |
Laszlo Csomor | d0d7ef0 | 2017-04-26 10:48:00 +0200 | [diff] [blame] | 281 | fi |
Laszlo Csomor | d40c78a | 2016-12-20 10:22:17 +0000 | [diff] [blame] | 282 | } |
| 283 | |
Laszlo Csomor | 03f78f5 | 2017-06-14 15:46:05 +0200 | [diff] [blame] | 284 | # Computes the value of the bazel.windows_unix_root JVM flag. |
| 285 | # Prints the JVM flag verbatim on Windows, ready to be passed to the JVM. |
| 286 | # Prints an empty string on other platforms. |
| 287 | function windows_unix_root_jvm_flag() { |
| 288 | if [ "${PLATFORM}" != "windows" ]; then |
| 289 | echo "" |
| 290 | return |
| 291 | fi |
| 292 | [ -n "${BAZEL_SH}" ] || fail "\$BAZEL_SH is not defined" |
| 293 | if [ "$(basename "$BAZEL_SH")" = "bash.exe" ]; then |
| 294 | local result="$(dirname "$BAZEL_SH")" |
| 295 | if [ "$(basename "$result")" = "bin" ]; then |
| 296 | result="$(dirname "$result")" |
| 297 | if [ "$(basename "$result")" = "usr" ]; then |
| 298 | result="$(dirname "$result")" |
| 299 | fi |
| 300 | # Print the JVM flag. Replace backslashes with forward slashes so the JVM |
| 301 | # and the shell won't believe that backslashes are escaping characters. |
| 302 | echo "-Dbazel.windows_unix_root=${result//\\//}" |
| 303 | return |
| 304 | fi |
| 305 | fi |
| 306 | fail "\$BAZEL_SH=${BAZEL_SH}, must end with \"bin\\bash.exe\" or \"usr\\bin\\bash.exe\"" |
| 307 | } |
| 308 | |
Laszlo Csomor | d40c78a | 2016-12-20 10:22:17 +0000 | [diff] [blame] | 309 | build_jni "${ARCHIVE_DIR}/_embedded_binaries" |
| 310 | |
Damien Martin-Guillerez | daffc35 | 2016-01-18 15:20:32 +0000 | [diff] [blame] | 311 | cp src/main/tools/jdk.BUILD ${ARCHIVE_DIR}/_embedded_binaries/jdk.BUILD |
| 312 | cp $OUTPUT_DIR/libblaze.jar ${ARCHIVE_DIR} |
Chris Parsons | 381850e | 2016-08-31 17:04:17 +0000 | [diff] [blame] | 313 | |
| 314 | # TODO(b/28965185): Remove when xcode-locator is no longer required in embedded_binaries. |
| 315 | log "Compiling xcode-locator..." |
| 316 | if [[ $PLATFORM == "darwin" ]]; then |
| 317 | run /usr/bin/xcrun clang -fobjc-arc -framework CoreServices -framework Foundation -o ${ARCHIVE_DIR}/_embedded_binaries/xcode-locator tools/osx/xcode_locator.m |
| 318 | else |
| 319 | cp tools/osx/xcode_locator_stub.sh ${ARCHIVE_DIR}/_embedded_binaries/xcode-locator |
| 320 | fi |
Chris Parsons | f488818 | 2016-01-08 00:42:14 +0000 | [diff] [blame] | 321 | |
Laszlo Csomor | d0d7ef0 | 2017-04-26 10:48:00 +0200 | [diff] [blame] | 322 | function get_cwd() { |
| 323 | local result=${PWD} |
| 324 | [ "$PLATFORM" = "windows" ] && result="$(cygpath -m "$result")" |
| 325 | echo "$result" |
| 326 | } |
| 327 | |
Laszlo Csomor | 9f7180f | 2016-09-27 13:07:43 +0000 | [diff] [blame] | 328 | function run_bazel_jar() { |
| 329 | local command=$1 |
| 330 | shift |
Yun Peng | 8efd282 | 2017-03-09 13:15:41 +0000 | [diff] [blame] | 331 | local client_env=() |
Damien Martin-Guillerez | 755669f | 2017-05-08 12:27:38 -0400 | [diff] [blame] | 332 | # Propagate all environment variables to bootstrapped Bazel. |
hlopko | 200479a | 2017-05-09 07:10:35 -0400 | [diff] [blame] | 333 | # 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] | 334 | 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] | 335 | for varname in $env_vars; do |
Dmitry Lomov | 31fab29 | 2017-03-07 18:33:08 +0000 | [diff] [blame] | 336 | eval value=\$$varname |
Laszlo Csomor | 0a936d1 | 2017-05-31 09:47:43 +0200 | [diff] [blame] | 337 | if [ "${PLATFORM}" = "windows" ] && echo "$varname" | grep -q -i "^\(path\|tmp\|temp\|tempdir\|systemroot\)$" ; then |
| 338 | varname="$(echo "$varname" | tr [:lower:] [:upper:])" |
| 339 | fi |
Yun Peng | 8efd282 | 2017-03-09 13:15:41 +0000 | [diff] [blame] | 340 | if [ "${value}" ]; then |
| 341 | client_env=("${client_env[@]}" --client_env="${varname}=${value}") |
Dmitry Lomov | 31fab29 | 2017-03-07 18:33:08 +0000 | [diff] [blame] | 342 | fi |
| 343 | done |
| 344 | |
Dmitry Lomov | f9f2e10 | 2016-01-29 14:26:46 +0000 | [diff] [blame] | 345 | "${JAVA_HOME}/bin/java" \ |
Philipp Wollermann | 74cb8c7 | 2016-07-15 14:01:37 +0000 | [diff] [blame] | 346 | -XX:+HeapDumpOnOutOfMemoryError -Xverify:none -Dfile.encoding=ISO-8859-1 \ |
Carmi Grushko | 4068a1d | 2016-06-22 18:43:13 +0000 | [diff] [blame] | 347 | -XX:HeapDumpPath=${OUTPUT_DIR} \ |
Laszlo Csomor | 03f78f5 | 2017-06-14 15:46:05 +0200 | [diff] [blame] | 348 | $(windows_unix_root_jvm_flag) \ |
Damien Martin-Guillerez | daffc35 | 2016-01-18 15:20:32 +0000 | [diff] [blame] | 349 | -Djava.util.logging.config.file=${OUTPUT_DIR}/javalog.properties \ |
Laszlo Csomor | d40c78a | 2016-12-20 10:22:17 +0000 | [diff] [blame] | 350 | ${JNI_FLAGS} \ |
Damien Martin-Guillerez | daffc35 | 2016-01-18 15:20:32 +0000 | [diff] [blame] | 351 | -jar ${ARCHIVE_DIR}/libblaze.jar \ |
| 352 | --batch \ |
| 353 | --install_base=${ARCHIVE_DIR} \ |
| 354 | --output_base=${OUTPUT_DIR}/out \ |
Klaus Aehlig | c2499c4 | 2018-02-27 05:47:21 -0800 | [diff] [blame] | 355 | --output_user_root=${OUTPUT_DIR}/user_root \ |
Damien Martin-Guillerez | daffc35 | 2016-01-18 15:20:32 +0000 | [diff] [blame] | 356 | --install_md5= \ |
cushon | 849df36 | 2018-05-14 01:51:45 -0700 | [diff] [blame] | 357 | --default_system_javabase="${JAVA_HOME}" \ |
Laszlo Csomor | d0d7ef0 | 2017-04-26 10:48:00 +0200 | [diff] [blame] | 358 | --workspace_directory="$(get_cwd)" \ |
Kristina Chodorow | 4873e56 | 2016-06-20 14:17:50 +0000 | [diff] [blame] | 359 | --nofatal_event_bus_exceptions \ |
Klaus Aehlig | 276a8cd | 2016-07-11 12:06:07 +0000 | [diff] [blame] | 360 | ${BAZEL_DIR_STARTUP_OPTIONS} \ |
Laszlo Csomor | 50f6bba | 2016-09-26 14:10:25 +0000 | [diff] [blame] | 361 | ${BAZEL_BOOTSTRAP_STARTUP_OPTIONS:-} \ |
Laszlo Csomor | 9f7180f | 2016-09-27 13:07:43 +0000 | [diff] [blame] | 362 | $command \ |
Damien Martin-Guillerez | 51a204a | 2016-02-08 14:59:59 +0000 | [diff] [blame] | 363 | --ignore_unsupported_sandboxing \ |
Damien Martin-Guillerez | daffc35 | 2016-01-18 15:20:32 +0000 | [diff] [blame] | 364 | --startup_time=329 --extract_data_time=523 \ |
Klaus Aehlig | 7038d3f | 2016-03-16 15:41:22 +0000 | [diff] [blame] | 365 | --rc_source=/dev/null --isatty=1 \ |
Philipp Wollermann | 4c55898 | 2017-07-27 18:01:12 +0200 | [diff] [blame] | 366 | --build_python_zip \ |
Yun Peng | 8efd282 | 2017-03-09 13:15:41 +0000 | [diff] [blame] | 367 | "${client_env[@]}" \ |
Laszlo Csomor | d0d7ef0 | 2017-04-26 10:48:00 +0200 | [diff] [blame] | 368 | --client_cwd="$(get_cwd)" \ |
Damien Martin-Guillerez | daffc35 | 2016-01-18 15:20:32 +0000 | [diff] [blame] | 369 | "${@}" |
| 370 | } |