blob: cfa7760a4c0af9f074bb1f8a61c6511d3ee532a8 [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
33
34UNAME=$(uname -s | tr 'A-Z' 'a-z')
35
36if [[ "$UNAME" =~ msys_nt* ]]; then
37 set -x
Tobias Werth9c91a812019-02-02 07:13:58 -080038 mkdir "tmp.$$"
39 cd "tmp.$$"
40 unzip "../$fulljdk"
Tobias Werth218e8f62018-12-13 04:44:35 -080041 cd zulu*
Tobias Werth218e8f62018-12-13 04:44:35 -080042 ./bin/jlink --module-path ./jmods/ --add-modules "$modules" \
43 --vm=server --strip-debug --no-man-pages \
44 --output reduced
twerth060441f2018-12-20 04:46:27 -080045 cp DISCLAIMER readme.txt legal/java.base/ASSEMBLY_EXCEPTION \
46 reduced/
Tobias Werth290e49b2019-01-16 05:04:40 -080047 # These are necessary for --host_jvm_debug to work.
48 cp bin/dt_socket.dll bin/jdwp.dll reduced/bin
Tobias Werth218e8f62018-12-13 04:44:35 -080049 zip -r -9 ../reduced.zip reduced/
Tobias Werth9c91a812019-02-02 07:13:58 -080050 cd ../..
51 mv "tmp.$$/reduced.zip" "$out"
52 rm -rf "tmp.$$"
Tobias Werth218e8f62018-12-13 04:44:35 -080053else
54 tar xf "$fulljdk"
55 cd zulu*
56 ./bin/jlink --module-path ./jmods/ --add-modules "$modules" \
57 --vm=server --strip-debug --no-man-pages \
58 --output reduced
twerth060441f2018-12-20 04:46:27 -080059 cp DISCLAIMER readme.txt legal/java.base/ASSEMBLY_EXCEPTION \
60 reduced/
Tobias Werth290e49b2019-01-16 05:04:40 -080061 # These are necessary for --host_jvm_debug to work.
62 if [[ "$UNAME" =~ darwin ]]; then
63 cp lib/libdt_socket.dylib lib/libjdwp.dylib reduced/lib
64 else
65 cp lib/libdt_socket.so lib/libjdwp.so reduced/lib
66 fi
Tobias Werth218e8f62018-12-13 04:44:35 -080067 GZIP=-9 tar -zcf ../reduced.tgz reduced
68 cd ..
69 mv reduced.tgz "$out"
70fi