Tobias Werth | ed9e98f | 2019-04-18 03:05:45 -0700 | [diff] [blame] | 1 | #!/bin/bash |
Lukacs Berki | eb851fe | 2015-10-19 10:52:31 +0000 | [diff] [blame] | 2 | # |
| 3 | # Copyright 2015 The Bazel Authors. 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 | |
Tobias Werth | ed9e98f | 2019-04-18 03:05:45 -0700 | [diff] [blame] | 17 | set -euo pipefail |
Philipp Wollermann | a5afe95 | 2016-06-21 14:58:09 +0000 | [diff] [blame] | 18 | |
hlopko | aaf6457 | 2019-06-14 02:33:56 -0700 | [diff] [blame] | 19 | # This script creates the Bazel archive that Bazel client unpacks and then |
| 20 | # starts the server from. |
Lukacs Berki | eb851fe | 2015-10-19 10:52:31 +0000 | [diff] [blame] | 21 | |
| 22 | WORKDIR=$(pwd) |
brandjon | de1babe | 2020-11-17 14:19:23 -0800 | [diff] [blame] | 23 | OUT=$1; shift |
| 24 | EMBEDDED_TOOLS=$1; shift |
| 25 | DEPLOY_JAR=$1; shift |
| 26 | INSTALL_BASE_KEY=$1; shift |
brandjon | de1babe | 2020-11-17 14:19:23 -0800 | [diff] [blame] | 27 | PLATFORMS_ARCHIVE=$1; shift |
Lukacs Berki | eb851fe | 2015-10-19 10:52:31 +0000 | [diff] [blame] | 28 | |
Tobias Werth | 518c8b3 | 2019-07-01 08:44:48 -0700 | [diff] [blame] | 29 | if [[ "$OUT" == *jdk_allmodules.zip ]]; then |
| 30 | DEV_BUILD=1 |
| 31 | else |
| 32 | DEV_BUILD=0 |
| 33 | fi |
| 34 | |
Lukacs Berki | eb851fe | 2015-10-19 10:52:31 +0000 | [diff] [blame] | 35 | TMP_DIR=${TMPDIR:-/tmp} |
Laszlo Csomor | a9a0f69 | 2019-09-26 07:14:42 -0700 | [diff] [blame] | 36 | ROOT="$(mktemp -d ${TMP_DIR%%/}/bazel.XXXXXXXX)" |
| 37 | RECOMP="$ROOT/recomp" |
| 38 | PACKAGE_DIR="$ROOT/pkg" |
| 39 | DEPLOY_UNCOMP="$ROOT/deploy-uncompressed.jar" |
Lukacs Berki | eb851fe | 2015-10-19 10:52:31 +0000 | [diff] [blame] | 40 | mkdir -p "${PACKAGE_DIR}" |
Laszlo Csomor | a9a0f69 | 2019-09-26 07:14:42 -0700 | [diff] [blame] | 41 | trap "rm -fr ${ROOT}" EXIT |
Lukacs Berki | eb851fe | 2015-10-19 10:52:31 +0000 | [diff] [blame] | 42 | |
| 43 | cp $* ${PACKAGE_DIR} |
Tobias Werth | ed9e98f | 2019-04-18 03:05:45 -0700 | [diff] [blame] | 44 | |
Tobias Werth | 518c8b3 | 2019-07-01 08:44:48 -0700 | [diff] [blame] | 45 | if [[ $DEV_BUILD -eq 0 ]]; then |
| 46 | # Unpack the deploy jar for postprocessing and for "re-compressing" to save |
| 47 | # ~10% of final binary size. |
Laszlo Csomor | a9a0f69 | 2019-09-26 07:14:42 -0700 | [diff] [blame] | 48 | unzip -q -d $RECOMP ${DEPLOY_JAR} |
| 49 | cd $RECOMP |
michajlo | 1193e69 | 2019-05-21 11:19:57 -0700 | [diff] [blame] | 50 | |
Tobias Werth | 518c8b3 | 2019-07-01 08:44:48 -0700 | [diff] [blame] | 51 | # Zero out timestamps and sort the entries to ensure determinism. |
| 52 | find . -type f -print0 | xargs -0 touch -t 198001010000.00 |
Laszlo Csomor | a9a0f69 | 2019-09-26 07:14:42 -0700 | [diff] [blame] | 53 | find . -type f | sort | zip -q0DX@ "$DEPLOY_UNCOMP" |
michajlo | 1193e69 | 2019-05-21 11:19:57 -0700 | [diff] [blame] | 54 | |
Tobias Werth | 518c8b3 | 2019-07-01 08:44:48 -0700 | [diff] [blame] | 55 | # While we're in the deploy jar, grab the label and pack it into the final |
| 56 | # packaged distribution zip where it can be used to quickly determine version |
| 57 | # info. |
| 58 | bazel_label="$(\ |
| 59 | (grep '^build.label=' build-data.properties | cut -d'=' -f2- | tr -d '\n') \ |
| 60 | || echo -n 'no_version')" |
| 61 | echo -n "${bazel_label:-no_version}" > "${PACKAGE_DIR}/build-label.txt" |
michajlo | 1193e69 | 2019-05-21 11:19:57 -0700 | [diff] [blame] | 62 | |
Laszlo Csomor | a9a0f69 | 2019-09-26 07:14:42 -0700 | [diff] [blame] | 63 | cd $WORKDIR |
Tobias Werth | 518c8b3 | 2019-07-01 08:44:48 -0700 | [diff] [blame] | 64 | |
Laszlo Csomor | a9a0f69 | 2019-09-26 07:14:42 -0700 | [diff] [blame] | 65 | DEPLOY_JAR="$DEPLOY_UNCOMP" |
Tobias Werth | 518c8b3 | 2019-07-01 08:44:48 -0700 | [diff] [blame] | 66 | fi |
Tobias Werth | ed9e98f | 2019-04-18 03:05:45 -0700 | [diff] [blame] | 67 | |
Klaus Aehlig | 2571982 | 2016-06-14 08:45:44 +0000 | [diff] [blame] | 68 | if [ -n "${EMBEDDED_TOOLS}" ]; then |
Lukacs Berki | eb851fe | 2015-10-19 10:52:31 +0000 | [diff] [blame] | 69 | mkdir ${PACKAGE_DIR}/embedded_tools |
Alexander Chung | fc07142 | 2017-02-07 12:48:26 +0000 | [diff] [blame] | 70 | (cd ${PACKAGE_DIR}/embedded_tools && unzip -q "${WORKDIR}/${EMBEDDED_TOOLS}") |
Lukacs Berki | eb851fe | 2015-10-19 10:52:31 +0000 | [diff] [blame] | 71 | fi |
| 72 | |
hlopko | aaf6457 | 2019-06-14 02:33:56 -0700 | [diff] [blame] | 73 | # Unzip platforms.zip into platforms/, move files up from external/platforms |
Googler | 96e0110 | 2021-01-13 16:09:08 -0800 | [diff] [blame] | 74 | # subdirectory if required, and create WORKSPACE if it doesn't exist. |
Googler | 9cc0346 | 2019-11-05 00:22:26 -0800 | [diff] [blame] | 75 | ( |
| 76 | cd $PACKAGE_DIR |
| 77 | unzip -q -d platforms $WORKDIR/$PLATFORMS_ARCHIVE |
| 78 | cd platforms |
Googler | 093057f | 2021-02-12 08:12:26 -0800 | [diff] [blame] | 79 | # Platform files may be located under external/platform or platform depending |
| 80 | # on the external repository source layout. Take them out if it's the case. |
Yun Peng | 6181a3c | 2021-10-28 03:11:19 -0700 | [diff] [blame] | 81 | # Note that, when enabling Bzlmod, the canonical repo name for platforms is platforms.<version>, |
| 82 | # therefore, we use wildcard (platform*) to make sure it always work. |
| 83 | if ls external/platforms*/ >/dev/null 2>&1; then |
Googler | 093057f | 2021-02-12 08:12:26 -0800 | [diff] [blame] | 84 | # --experimental_sibling_repository_layout=false |
Yun Peng | 6181a3c | 2021-10-28 03:11:19 -0700 | [diff] [blame] | 85 | mv external/platforms*/* . |
| 86 | rmdir -p external/platforms* |
Googler | 093057f | 2021-02-12 08:12:26 -0800 | [diff] [blame] | 87 | else |
| 88 | # --experimental_sibling_repository_layout=true |
Yun Peng | 6181a3c | 2021-10-28 03:11:19 -0700 | [diff] [blame] | 89 | mv platforms*/* . |
| 90 | rmdir -p platforms* |
Googler | 96e0110 | 2021-01-13 16:09:08 -0800 | [diff] [blame] | 91 | fi |
Googler | 9cc0346 | 2019-11-05 00:22:26 -0800 | [diff] [blame] | 92 | >> WORKSPACE |
hlopko | aaf6457 | 2019-06-14 02:33:56 -0700 | [diff] [blame] | 93 | ) |
hlopko | aaf6457 | 2019-06-14 02:33:56 -0700 | [diff] [blame] | 94 | |
Googler | 9cc0346 | 2019-11-05 00:22:26 -0800 | [diff] [blame] | 95 | # Make a list of the files in the order we want them inside the final zip. |
| 96 | ( |
| 97 | cd $PACKAGE_DIR |
| 98 | # The server jar needs to be the first binary we extract. |
| 99 | # This is how the Bazel client knows which .jar to pass to the JVM. |
| 100 | echo A-server.jar |
| 101 | find . -type f | sort |
| 102 | # And install_base_key must be last. |
| 103 | echo install_base_key |
| 104 | ) > files.list |
| 105 | |
| 106 | # Move these after the 'find' above. |
| 107 | cp $DEPLOY_JAR $PACKAGE_DIR/A-server.jar |
| 108 | cp $INSTALL_BASE_KEY $PACKAGE_DIR/install_base_key |
| 109 | |
| 110 | # Zero timestamps. |
| 111 | (cd $PACKAGE_DIR; xargs touch -t 198001010000.00) < files.list |
| 112 | |
Jingwen Chen | 7c15c03 | 2020-01-16 11:54:44 -0800 | [diff] [blame] | 113 | if [[ "$DEV_BUILD" -eq 1 ]]; then |
| 114 | # Create output zip with lowest compression, but fast. |
| 115 | ZIP_ARGS="-q1DX@" |
| 116 | else |
| 117 | # Create output zip with highest compression, but slow. |
| 118 | ZIP_ARGS="-q9DX@" |
| 119 | fi |
| 120 | (cd $PACKAGE_DIR; zip $ZIP_ARGS $WORKDIR/$OUT) < files.list |
| 121 | |
Googler | 9cc0346 | 2019-11-05 00:22:26 -0800 | [diff] [blame] | 122 | |