blob: 10bb651da2b12e6b39f8242a0de1f26507fad3f9 [file] [log] [blame]
Tobias Werthed9e98f2019-04-18 03:05:45 -07001#!/bin/bash
Lukacs Berkieb851fe2015-10-19 10:52:31 +00002#
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 Werthed9e98f2019-04-18 03:05:45 -070017set -euo pipefail
Philipp Wollermanna5afe952016-06-21 14:58:09 +000018
hlopkoaaf64572019-06-14 02:33:56 -070019# This script creates the Bazel archive that Bazel client unpacks and then
20# starts the server from.
Lukacs Berkieb851fe2015-10-19 10:52:31 +000021
22WORKDIR=$(pwd)
brandjonde1babe2020-11-17 14:19:23 -080023OUT=$1; shift
24EMBEDDED_TOOLS=$1; shift
25DEPLOY_JAR=$1; shift
26INSTALL_BASE_KEY=$1; shift
brandjonde1babe2020-11-17 14:19:23 -080027PLATFORMS_ARCHIVE=$1; shift
Lukacs Berkieb851fe2015-10-19 10:52:31 +000028
Tobias Werth518c8b32019-07-01 08:44:48 -070029if [[ "$OUT" == *jdk_allmodules.zip ]]; then
30 DEV_BUILD=1
31else
32 DEV_BUILD=0
33fi
34
Lukacs Berkieb851fe2015-10-19 10:52:31 +000035TMP_DIR=${TMPDIR:-/tmp}
Laszlo Csomora9a0f692019-09-26 07:14:42 -070036ROOT="$(mktemp -d ${TMP_DIR%%/}/bazel.XXXXXXXX)"
37RECOMP="$ROOT/recomp"
38PACKAGE_DIR="$ROOT/pkg"
39DEPLOY_UNCOMP="$ROOT/deploy-uncompressed.jar"
Yun Pengbddb1912022-11-02 06:28:16 -070040FILE_LIST="$ROOT/file.list"
Lukacs Berkieb851fe2015-10-19 10:52:31 +000041mkdir -p "${PACKAGE_DIR}"
Laszlo Csomora9a0f692019-09-26 07:14:42 -070042trap "rm -fr ${ROOT}" EXIT
Lukacs Berkieb851fe2015-10-19 10:52:31 +000043
44cp $* ${PACKAGE_DIR}
Tobias Werthed9e98f2019-04-18 03:05:45 -070045
Tobias Werth518c8b32019-07-01 08:44:48 -070046if [[ $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-Hall5be6e552023-09-08 13:13:16 -070049 mkdir -p $RECOMP
Laszlo Csomora9a0f692019-09-26 07:14:42 -070050 unzip -q -d $RECOMP ${DEPLOY_JAR}
51 cd $RECOMP
michajlo1193e692019-05-21 11:19:57 -070052
Tobias Werth518c8b32019-07-01 08:44:48 -070053 # Zero out timestamps and sort the entries to ensure determinism.
54 find . -type f -print0 | xargs -0 touch -t 198001010000.00
Laszlo Csomora9a0f692019-09-26 07:14:42 -070055 find . -type f | sort | zip -q0DX@ "$DEPLOY_UNCOMP"
michajlo1193e692019-05-21 11:19:57 -070056
Tobias Werth518c8b32019-07-01 08:44:48 -070057 # 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"
michajlo1193e692019-05-21 11:19:57 -070064
Laszlo Csomora9a0f692019-09-26 07:14:42 -070065 cd $WORKDIR
Tobias Werth518c8b32019-07-01 08:44:48 -070066
Laszlo Csomora9a0f692019-09-26 07:14:42 -070067 DEPLOY_JAR="$DEPLOY_UNCOMP"
Tobias Werth518c8b32019-07-01 08:44:48 -070068fi
Tobias Werthed9e98f2019-04-18 03:05:45 -070069
Klaus Aehlig25719822016-06-14 08:45:44 +000070if [ -n "${EMBEDDED_TOOLS}" ]; then
Lukacs Berkieb851fe2015-10-19 10:52:31 +000071 mkdir ${PACKAGE_DIR}/embedded_tools
Alexander Chungfc071422017-02-07 12:48:26 +000072 (cd ${PACKAGE_DIR}/embedded_tools && unzip -q "${WORKDIR}/${EMBEDDED_TOOLS}")
Lukacs Berkieb851fe2015-10-19 10:52:31 +000073fi
74
Googler9cc03462019-11-05 00:22:26 -080075(
76 cd $PACKAGE_DIR
Yun Peng30b21302023-06-19 03:28:53 -070077 tar -xf $WORKDIR/$PLATFORMS_ARCHIVE -C .
Xdng Yng60924fd2024-07-31 01:46:57 -070078 # "platforms" is a well-known module, so no need to tamper with anything here.
Yun Peng30b21302023-06-19 03:28:53 -070079)
80
Googler9cc03462019-11-05 00:22:26 -080081# 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 Pengbddb1912022-11-02 06:28:16 -070090) > $FILE_LIST
Googler9cc03462019-11-05 00:22:26 -080091
92# Move these after the 'find' above.
93cp $DEPLOY_JAR $PACKAGE_DIR/A-server.jar
94cp $INSTALL_BASE_KEY $PACKAGE_DIR/install_base_key
95
96# Zero timestamps.
Yun Pengbddb1912022-11-02 06:28:16 -070097(cd $PACKAGE_DIR; xargs touch -t 198001010000.00) < $FILE_LIST
Googler9cc03462019-11-05 00:22:26 -080098
Jingwen Chen7c15c032020-01-16 11:54:44 -080099if [[ "$DEV_BUILD" -eq 1 ]]; then
100 # Create output zip with lowest compression, but fast.
101 ZIP_ARGS="-q1DX@"
102else
103 # Create output zip with highest compression, but slow.
104 ZIP_ARGS="-q9DX@"
105fi
Yun Pengbddb1912022-11-02 06:28:16 -0700106(cd $PACKAGE_DIR; zip $ZIP_ARGS $WORKDIR/$OUT) < $FILE_LIST
Jingwen Chen7c15c032020-01-16 11:54:44 -0800107
Googler9cc03462019-11-05 00:22:26 -0800108