blob: f4f08d94cf4e9459456fdb0fd0a74da7f8a475ab [file] [log] [blame]
Tobias Werth218e8f62018-12-13 04:44:35 -08001#!/bin/bash
2
3# Copyright 2018 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
17# This script creates from the full JDK a minimized version that only contains
18# the specified JDK modules.
19
20set -euo pipefail
21
Tobias Wertha87451a2019-01-29 07:03:58 -080022if [ "$1" == "--allmodules" ]; then
23 shift
24 modules="ALL-MODULE-PATH"
25else
26 modules=$(cat "$2" | paste -sd "," - | tr -d '\r')
Tobias Werth90755142019-02-03 07:28:11 -080027 # We have to add this module explicitly because jdeps doesn't find the
28 # dependency on it but it is still necessary for TLSv1.3.
29 modules="$modules,jdk.crypto.ec"
Tobias Wertha87451a2019-01-29 07:03:58 -080030fi
Tobias Werth218e8f62018-12-13 04:44:35 -080031fulljdk=$1
Tobias Werth218e8f62018-12-13 04:44:35 -080032out=$3
Jason Furmanek04e073e2020-05-28 05:48:09 -070033ARCH=`uname -p`
Ruixin Baoe14a6f22020-08-21 06:17:24 -070034if [[ "${ARCH}" == 'ppc64le' ]] || [[ "${ARCH}" == 's390x' ]]; then
Jason Furmanek04e073e2020-05-28 05:48:09 -070035 FULL_JDK_DIR="jdk*"
36 DOCS=""
37else
38 FULL_JDK_DIR="zulu*"
39 DOCS="DISCLAIMER readme.txt"
40fi
Tobias Werth218e8f62018-12-13 04:44:35 -080041
42UNAME=$(uname -s | tr 'A-Z' 'a-z')
43
44if [[ "$UNAME" =~ msys_nt* ]]; then
45 set -x
Tobias Werth9c91a812019-02-02 07:13:58 -080046 mkdir "tmp.$$"
47 cd "tmp.$$"
48 unzip "../$fulljdk"
Jason Furmanek04e073e2020-05-28 05:48:09 -070049 cd $FULL_JDK_DIR
Tobias Werth218e8f62018-12-13 04:44:35 -080050 ./bin/jlink --module-path ./jmods/ --add-modules "$modules" \
51 --vm=server --strip-debug --no-man-pages \
52 --output reduced
Jason Furmanek04e073e2020-05-28 05:48:09 -070053 cp $DOCS legal/java.base/ASSEMBLY_EXCEPTION \
twerth060441f2018-12-20 04:46:27 -080054 reduced/
Tobias Werth290e49b2019-01-16 05:04:40 -080055 # These are necessary for --host_jvm_debug to work.
56 cp bin/dt_socket.dll bin/jdwp.dll reduced/bin
Tobias Werth218e8f62018-12-13 04:44:35 -080057 zip -r -9 ../reduced.zip reduced/
Tobias Werth9c91a812019-02-02 07:13:58 -080058 cd ../..
59 mv "tmp.$$/reduced.zip" "$out"
60 rm -rf "tmp.$$"
Tobias Werth218e8f62018-12-13 04:44:35 -080061else
philwo9f7fe692019-06-27 06:53:12 -070062 # The --no-same-owner flag instructs tar to not try to chown extracted files
63 # to the owner stored in the archive - it will try to do that when running as
64 # root, but fail when running inside Docker, so we explicitly disable it.
65 tar xf "$fulljdk" --no-same-owner
Jason Furmanek04e073e2020-05-28 05:48:09 -070066 cd $FULL_JDK_DIR
Tobias Werth218e8f62018-12-13 04:44:35 -080067 ./bin/jlink --module-path ./jmods/ --add-modules "$modules" \
68 --vm=server --strip-debug --no-man-pages \
69 --output reduced
Jason Furmanek04e073e2020-05-28 05:48:09 -070070 cp $DOCS legal/java.base/ASSEMBLY_EXCEPTION \
twerth060441f2018-12-20 04:46:27 -080071 reduced/
Tobias Werth290e49b2019-01-16 05:04:40 -080072 # These are necessary for --host_jvm_debug to work.
73 if [[ "$UNAME" =~ darwin ]]; then
74 cp lib/libdt_socket.dylib lib/libjdwp.dylib reduced/lib
75 else
76 cp lib/libdt_socket.so lib/libjdwp.so reduced/lib
77 fi
Tobias Werth218e8f62018-12-13 04:44:35 -080078 GZIP=-9 tar -zcf ../reduced.tgz reduced
79 cd ..
80 mv reduced.tgz "$out"
81fi