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" |
Yun Peng | bddb191 | 2022-11-02 06:28:16 -0700 | [diff] [blame] | 40 | FILE_LIST="$ROOT/file.list" |
Lukacs Berki | eb851fe | 2015-10-19 10:52:31 +0000 | [diff] [blame] | 41 | mkdir -p "${PACKAGE_DIR}" |
Laszlo Csomor | a9a0f69 | 2019-09-26 07:14:42 -0700 | [diff] [blame] | 42 | trap "rm -fr ${ROOT}" EXIT |
Lukacs Berki | eb851fe | 2015-10-19 10:52:31 +0000 | [diff] [blame] | 43 | |
| 44 | cp $* ${PACKAGE_DIR} |
Tobias Werth | ed9e98f | 2019-04-18 03:05:45 -0700 | [diff] [blame] | 45 | |
Tobias Werth | 518c8b3 | 2019-07-01 08:44:48 -0700 | [diff] [blame] | 46 | if [[ $DEV_BUILD -eq 0 ]]; then |
| 47 | # Unpack the deploy jar for postprocessing and for "re-compressing" to save |
| 48 | # ~10% of final binary size. |
Daniel Wagner-Hall | 5be6e55 | 2023-09-08 13:13:16 -0700 | [diff] [blame] | 49 | mkdir -p $RECOMP |
Laszlo Csomor | a9a0f69 | 2019-09-26 07:14:42 -0700 | [diff] [blame] | 50 | unzip -q -d $RECOMP ${DEPLOY_JAR} |
| 51 | cd $RECOMP |
michajlo | 1193e69 | 2019-05-21 11:19:57 -0700 | [diff] [blame] | 52 | |
Tobias Werth | 518c8b3 | 2019-07-01 08:44:48 -0700 | [diff] [blame] | 53 | # Zero out timestamps and sort the entries to ensure determinism. |
| 54 | find . -type f -print0 | xargs -0 touch -t 198001010000.00 |
Laszlo Csomor | a9a0f69 | 2019-09-26 07:14:42 -0700 | [diff] [blame] | 55 | find . -type f | sort | zip -q0DX@ "$DEPLOY_UNCOMP" |
michajlo | 1193e69 | 2019-05-21 11:19:57 -0700 | [diff] [blame] | 56 | |
Tobias Werth | 518c8b3 | 2019-07-01 08:44:48 -0700 | [diff] [blame] | 57 | # While we're in the deploy jar, grab the label and pack it into the final |
| 58 | # packaged distribution zip where it can be used to quickly determine version |
| 59 | # info. |
| 60 | bazel_label="$(\ |
| 61 | (grep '^build.label=' build-data.properties | cut -d'=' -f2- | tr -d '\n') \ |
| 62 | || echo -n 'no_version')" |
| 63 | echo -n "${bazel_label:-no_version}" > "${PACKAGE_DIR}/build-label.txt" |
michajlo | 1193e69 | 2019-05-21 11:19:57 -0700 | [diff] [blame] | 64 | |
Laszlo Csomor | a9a0f69 | 2019-09-26 07:14:42 -0700 | [diff] [blame] | 65 | cd $WORKDIR |
Tobias Werth | 518c8b3 | 2019-07-01 08:44:48 -0700 | [diff] [blame] | 66 | |
Laszlo Csomor | a9a0f69 | 2019-09-26 07:14:42 -0700 | [diff] [blame] | 67 | DEPLOY_JAR="$DEPLOY_UNCOMP" |
Tobias Werth | 518c8b3 | 2019-07-01 08:44:48 -0700 | [diff] [blame] | 68 | fi |
Tobias Werth | ed9e98f | 2019-04-18 03:05:45 -0700 | [diff] [blame] | 69 | |
Klaus Aehlig | 2571982 | 2016-06-14 08:45:44 +0000 | [diff] [blame] | 70 | if [ -n "${EMBEDDED_TOOLS}" ]; then |
Lukacs Berki | eb851fe | 2015-10-19 10:52:31 +0000 | [diff] [blame] | 71 | mkdir ${PACKAGE_DIR}/embedded_tools |
Alexander Chung | fc07142 | 2017-02-07 12:48:26 +0000 | [diff] [blame] | 72 | (cd ${PACKAGE_DIR}/embedded_tools && unzip -q "${WORKDIR}/${EMBEDDED_TOOLS}") |
Lukacs Berki | eb851fe | 2015-10-19 10:52:31 +0000 | [diff] [blame] | 73 | fi |
| 74 | |
Googler | 9cc0346 | 2019-11-05 00:22:26 -0800 | [diff] [blame] | 75 | ( |
| 76 | cd $PACKAGE_DIR |
Yun Peng | 30b2130 | 2023-06-19 03:28:53 -0700 | [diff] [blame] | 77 | tar -xf $WORKDIR/$PLATFORMS_ARCHIVE -C . |
Xdng Yng | 60924fd | 2024-07-31 01:46:57 -0700 | [diff] [blame] | 78 | # "platforms" is a well-known module, so no need to tamper with anything here. |
Yun Peng | 30b2130 | 2023-06-19 03:28:53 -0700 | [diff] [blame] | 79 | ) |
| 80 | |
Googler | 9cc0346 | 2019-11-05 00:22:26 -0800 | [diff] [blame] | 81 | # Make a list of the files in the order we want them inside the final zip. |
| 82 | ( |
| 83 | cd $PACKAGE_DIR |
| 84 | # The server jar needs to be the first binary we extract. |
| 85 | # This is how the Bazel client knows which .jar to pass to the JVM. |
| 86 | echo A-server.jar |
| 87 | find . -type f | sort |
| 88 | # And install_base_key must be last. |
| 89 | echo install_base_key |
Yun Peng | bddb191 | 2022-11-02 06:28:16 -0700 | [diff] [blame] | 90 | ) > $FILE_LIST |
Googler | 9cc0346 | 2019-11-05 00:22:26 -0800 | [diff] [blame] | 91 | |
| 92 | # Move these after the 'find' above. |
| 93 | cp $DEPLOY_JAR $PACKAGE_DIR/A-server.jar |
| 94 | cp $INSTALL_BASE_KEY $PACKAGE_DIR/install_base_key |
| 95 | |
| 96 | # Zero timestamps. |
Yun Peng | bddb191 | 2022-11-02 06:28:16 -0700 | [diff] [blame] | 97 | (cd $PACKAGE_DIR; xargs touch -t 198001010000.00) < $FILE_LIST |
Googler | 9cc0346 | 2019-11-05 00:22:26 -0800 | [diff] [blame] | 98 | |
Jingwen Chen | 7c15c03 | 2020-01-16 11:54:44 -0800 | [diff] [blame] | 99 | if [[ "$DEV_BUILD" -eq 1 ]]; then |
| 100 | # Create output zip with lowest compression, but fast. |
| 101 | ZIP_ARGS="-q1DX@" |
| 102 | else |
| 103 | # Create output zip with highest compression, but slow. |
| 104 | ZIP_ARGS="-q9DX@" |
| 105 | fi |
Yun Peng | bddb191 | 2022-11-02 06:28:16 -0700 | [diff] [blame] | 106 | (cd $PACKAGE_DIR; zip $ZIP_ARGS $WORKDIR/$OUT) < $FILE_LIST |
Jingwen Chen | 7c15c03 | 2020-01-16 11:54:44 -0800 | [diff] [blame] | 107 | |
Googler | 9cc0346 | 2019-11-05 00:22:26 -0800 | [diff] [blame] | 108 | |