blob: c7fc3e3e75eed5b7c32bb416f269b1414ab05da0 [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"
Lukacs Berkieb851fe2015-10-19 10:52:31 +000040mkdir -p "${PACKAGE_DIR}"
Laszlo Csomora9a0f692019-09-26 07:14:42 -070041trap "rm -fr ${ROOT}" EXIT
Lukacs Berkieb851fe2015-10-19 10:52:31 +000042
43cp $* ${PACKAGE_DIR}
Tobias Werthed9e98f2019-04-18 03:05:45 -070044
Tobias Werth518c8b32019-07-01 08:44:48 -070045if [[ $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 Csomora9a0f692019-09-26 07:14:42 -070048 unzip -q -d $RECOMP ${DEPLOY_JAR}
49 cd $RECOMP
michajlo1193e692019-05-21 11:19:57 -070050
Tobias Werth518c8b32019-07-01 08:44:48 -070051 # Zero out timestamps and sort the entries to ensure determinism.
52 find . -type f -print0 | xargs -0 touch -t 198001010000.00
Laszlo Csomora9a0f692019-09-26 07:14:42 -070053 find . -type f | sort | zip -q0DX@ "$DEPLOY_UNCOMP"
michajlo1193e692019-05-21 11:19:57 -070054
Tobias Werth518c8b32019-07-01 08:44:48 -070055 # 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"
michajlo1193e692019-05-21 11:19:57 -070062
Laszlo Csomora9a0f692019-09-26 07:14:42 -070063 cd $WORKDIR
Tobias Werth518c8b32019-07-01 08:44:48 -070064
Laszlo Csomora9a0f692019-09-26 07:14:42 -070065 DEPLOY_JAR="$DEPLOY_UNCOMP"
Tobias Werth518c8b32019-07-01 08:44:48 -070066fi
Tobias Werthed9e98f2019-04-18 03:05:45 -070067
Klaus Aehlig25719822016-06-14 08:45:44 +000068if [ -n "${EMBEDDED_TOOLS}" ]; then
Lukacs Berkieb851fe2015-10-19 10:52:31 +000069 mkdir ${PACKAGE_DIR}/embedded_tools
Alexander Chungfc071422017-02-07 12:48:26 +000070 (cd ${PACKAGE_DIR}/embedded_tools && unzip -q "${WORKDIR}/${EMBEDDED_TOOLS}")
Lukacs Berkieb851fe2015-10-19 10:52:31 +000071fi
72
hlopkoaaf64572019-06-14 02:33:56 -070073# Unzip platforms.zip into platforms/, move files up from external/platforms
Googler96e01102021-01-13 16:09:08 -080074# subdirectory if required, and create WORKSPACE if it doesn't exist.
Googler9cc03462019-11-05 00:22:26 -080075(
76 cd $PACKAGE_DIR
77 unzip -q -d platforms $WORKDIR/$PLATFORMS_ARCHIVE
78 cd platforms
Googler093057f2021-02-12 08:12:26 -080079 # 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 Peng6181a3c2021-10-28 03:11:19 -070081 # 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
Googler093057f2021-02-12 08:12:26 -080084 # --experimental_sibling_repository_layout=false
Yun Peng6181a3c2021-10-28 03:11:19 -070085 mv external/platforms*/* .
86 rmdir -p external/platforms*
Googler093057f2021-02-12 08:12:26 -080087 else
88 # --experimental_sibling_repository_layout=true
Yun Peng6181a3c2021-10-28 03:11:19 -070089 mv platforms*/* .
90 rmdir -p platforms*
Googler96e01102021-01-13 16:09:08 -080091 fi
Googler9cc03462019-11-05 00:22:26 -080092 >> WORKSPACE
hlopkoaaf64572019-06-14 02:33:56 -070093)
hlopkoaaf64572019-06-14 02:33:56 -070094
Googler9cc03462019-11-05 00:22:26 -080095# 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.
107cp $DEPLOY_JAR $PACKAGE_DIR/A-server.jar
108cp $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 Chen7c15c032020-01-16 11:54:44 -0800113if [[ "$DEV_BUILD" -eq 1 ]]; then
114 # Create output zip with lowest compression, but fast.
115 ZIP_ARGS="-q1DX@"
116else
117 # Create output zip with highest compression, but slow.
118 ZIP_ARGS="-q9DX@"
119fi
120(cd $PACKAGE_DIR; zip $ZIP_ARGS $WORKDIR/$OUT) < files.list
121
Googler9cc03462019-11-05 00:22:26 -0800122