blob: 7cc1d33199167c013a9ee4a774dcb701f84496e2 [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)
23OUT=$1
24EMBEDDED_TOOLS=$2
25DEPLOY_JAR=$3
26INSTALL_BASE_KEY=$4
hlopkoaaf64572019-06-14 02:33:56 -070027PLATFORMS_ARCHIVE=$5
Googler9cc03462019-11-05 00:22:26 -080028shift 5
Lukacs Berkieb851fe2015-10-19 10:52:31 +000029
Tobias Werth518c8b32019-07-01 08:44:48 -070030if [[ "$OUT" == *jdk_allmodules.zip ]]; then
31 DEV_BUILD=1
32else
33 DEV_BUILD=0
34fi
35
Lukacs Berkieb851fe2015-10-19 10:52:31 +000036TMP_DIR=${TMPDIR:-/tmp}
Laszlo Csomora9a0f692019-09-26 07:14:42 -070037ROOT="$(mktemp -d ${TMP_DIR%%/}/bazel.XXXXXXXX)"
38RECOMP="$ROOT/recomp"
39PACKAGE_DIR="$ROOT/pkg"
40DEPLOY_UNCOMP="$ROOT/deploy-uncompressed.jar"
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.
Laszlo Csomora9a0f692019-09-26 07:14:42 -070049 unzip -q -d $RECOMP ${DEPLOY_JAR}
50 cd $RECOMP
michajlo1193e692019-05-21 11:19:57 -070051
Tobias Werth518c8b32019-07-01 08:44:48 -070052 # Zero out timestamps and sort the entries to ensure determinism.
53 find . -type f -print0 | xargs -0 touch -t 198001010000.00
Laszlo Csomora9a0f692019-09-26 07:14:42 -070054 find . -type f | sort | zip -q0DX@ "$DEPLOY_UNCOMP"
michajlo1193e692019-05-21 11:19:57 -070055
Tobias Werth518c8b32019-07-01 08:44:48 -070056 # While we're in the deploy jar, grab the label and pack it into the final
57 # packaged distribution zip where it can be used to quickly determine version
58 # info.
59 bazel_label="$(\
60 (grep '^build.label=' build-data.properties | cut -d'=' -f2- | tr -d '\n') \
61 || echo -n 'no_version')"
62 echo -n "${bazel_label:-no_version}" > "${PACKAGE_DIR}/build-label.txt"
michajlo1193e692019-05-21 11:19:57 -070063
Laszlo Csomora9a0f692019-09-26 07:14:42 -070064 cd $WORKDIR
Tobias Werth518c8b32019-07-01 08:44:48 -070065
Laszlo Csomora9a0f692019-09-26 07:14:42 -070066 DEPLOY_JAR="$DEPLOY_UNCOMP"
Tobias Werth518c8b32019-07-01 08:44:48 -070067fi
Tobias Werthed9e98f2019-04-18 03:05:45 -070068
Klaus Aehlig25719822016-06-14 08:45:44 +000069if [ -n "${EMBEDDED_TOOLS}" ]; then
Lukacs Berkieb851fe2015-10-19 10:52:31 +000070 mkdir ${PACKAGE_DIR}/embedded_tools
Alexander Chungfc071422017-02-07 12:48:26 +000071 (cd ${PACKAGE_DIR}/embedded_tools && unzip -q "${WORKDIR}/${EMBEDDED_TOOLS}")
Lukacs Berkieb851fe2015-10-19 10:52:31 +000072fi
73
hlopkoaaf64572019-06-14 02:33:56 -070074# Unzip platforms.zip into platforms/, move files up from external/platforms
Googler9cc03462019-11-05 00:22:26 -080075# subdirectory, and create WORKSPACE if it doesn't exist.
76(
77 cd $PACKAGE_DIR
78 unzip -q -d platforms $WORKDIR/$PLATFORMS_ARCHIVE
79 cd platforms
80 mv external/platforms/* .
81 rmdir -p external/platforms
82 >> WORKSPACE
hlopkoaaf64572019-06-14 02:33:56 -070083)
hlopkoaaf64572019-06-14 02:33:56 -070084
Googler9cc03462019-11-05 00:22:26 -080085# Make a list of the files in the order we want them inside the final zip.
86(
87 cd $PACKAGE_DIR
88 # The server jar needs to be the first binary we extract.
89 # This is how the Bazel client knows which .jar to pass to the JVM.
90 echo A-server.jar
91 find . -type f | sort
92 # And install_base_key must be last.
93 echo install_base_key
94) > files.list
95
96# Move these after the 'find' above.
97cp $DEPLOY_JAR $PACKAGE_DIR/A-server.jar
98cp $INSTALL_BASE_KEY $PACKAGE_DIR/install_base_key
99
100# Zero timestamps.
101(cd $PACKAGE_DIR; xargs touch -t 198001010000.00) < files.list
102
Jingwen Chen7c15c032020-01-16 11:54:44 -0800103if [[ "$DEV_BUILD" -eq 1 ]]; then
104 # Create output zip with lowest compression, but fast.
105 ZIP_ARGS="-q1DX@"
106else
107 # Create output zip with highest compression, but slow.
108 ZIP_ARGS="-q9DX@"
109fi
110(cd $PACKAGE_DIR; zip $ZIP_ARGS $WORKDIR/$OUT) < files.list
111
Googler9cc03462019-11-05 00:22:26 -0800112