blob: afeeb65a1c64fb4c48117731e2006b992813f77b [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.$$"
Benjamin Peterson19475d82023-03-17 04:54:49 -070048 unzip -q "../$fulljdk"
Jason Furmanek04e073e2020-05-28 05:48:09 -070049 cd $FULL_JDK_DIR
Andreas Fuchsc94572b2022-04-22 04:06:51 -070050 # We have to add this module explicitly because it is windows specific, it allows
51 # the usage of the Windows truststore
52 # e.g. -Djavax.net.ssl.trustStoreType=WINDOWS-ROOT
53 modules="$modules,jdk.crypto.mscapi"
Tobias Werth218e8f62018-12-13 04:44:35 -080054 ./bin/jlink --module-path ./jmods/ --add-modules "$modules" \
55 --vm=server --strip-debug --no-man-pages \
56 --output reduced
Jason Furmanek04e073e2020-05-28 05:48:09 -070057 cp $DOCS legal/java.base/ASSEMBLY_EXCEPTION \
twerth060441f2018-12-20 04:46:27 -080058 reduced/
Tobias Werth290e49b2019-01-16 05:04:40 -080059 # These are necessary for --host_jvm_debug to work.
60 cp bin/dt_socket.dll bin/jdwp.dll reduced/bin
Benjamin Peterson66c22f42022-11-18 07:02:30 -080061 zip -q -X -r ../reduced.zip reduced/
Tobias Werth9c91a812019-02-02 07:13:58 -080062 cd ../..
63 mv "tmp.$$/reduced.zip" "$out"
64 rm -rf "tmp.$$"
Tobias Werth218e8f62018-12-13 04:44:35 -080065else
philwo9f7fe692019-06-27 06:53:12 -070066 # The --no-same-owner flag instructs tar to not try to chown extracted files
67 # to the owner stored in the archive - it will try to do that when running as
68 # root, but fail when running inside Docker, so we explicitly disable it.
69 tar xf "$fulljdk" --no-same-owner
Jason Furmanek04e073e2020-05-28 05:48:09 -070070 cd $FULL_JDK_DIR
Tobias Werth218e8f62018-12-13 04:44:35 -080071 ./bin/jlink --module-path ./jmods/ --add-modules "$modules" \
72 --vm=server --strip-debug --no-man-pages \
73 --output reduced
Jason Furmanek04e073e2020-05-28 05:48:09 -070074 cp $DOCS legal/java.base/ASSEMBLY_EXCEPTION \
twerth060441f2018-12-20 04:46:27 -080075 reduced/
Tobias Werth290e49b2019-01-16 05:04:40 -080076 # These are necessary for --host_jvm_debug to work.
77 if [[ "$UNAME" =~ darwin ]]; then
78 cp lib/libdt_socket.dylib lib/libjdwp.dylib reduced/lib
79 else
80 cp lib/libdt_socket.so lib/libjdwp.so reduced/lib
81 fi
Benjamin Peterson66c22f42022-11-18 07:02:30 -080082 find reduced -exec touch -ht 198001010000 {} +
83 zip -q -X -r ../reduced.zip reduced/
Tobias Werth218e8f62018-12-13 04:44:35 -080084 cd ..
Benjamin Peterson66c22f42022-11-18 07:02:30 -080085 mv reduced.zip "$out"
Tobias Werth218e8f62018-12-13 04:44:35 -080086fi