Tobias Werth | 218e8f6 | 2018-12-13 04:44:35 -0800 | [diff] [blame] | 1 | #!/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 | |
| 20 | set -euo pipefail |
| 21 | |
Tobias Werth | a87451a | 2019-01-29 07:03:58 -0800 | [diff] [blame] | 22 | if [ "$1" == "--allmodules" ]; then |
| 23 | shift |
| 24 | modules="ALL-MODULE-PATH" |
| 25 | else |
| 26 | modules=$(cat "$2" | paste -sd "," - | tr -d '\r') |
| 27 | fi |
Tobias Werth | 218e8f6 | 2018-12-13 04:44:35 -0800 | [diff] [blame] | 28 | fulljdk=$1 |
Tobias Werth | 218e8f6 | 2018-12-13 04:44:35 -0800 | [diff] [blame] | 29 | out=$3 |
| 30 | |
| 31 | UNAME=$(uname -s | tr 'A-Z' 'a-z') |
| 32 | |
| 33 | if [[ "$UNAME" =~ msys_nt* ]]; then |
| 34 | set -x |
| 35 | unzip "$fulljdk" |
| 36 | cd zulu* |
Tobias Werth | 218e8f6 | 2018-12-13 04:44:35 -0800 | [diff] [blame] | 37 | ./bin/jlink --module-path ./jmods/ --add-modules "$modules" \ |
| 38 | --vm=server --strip-debug --no-man-pages \ |
| 39 | --output reduced |
twerth | 060441f | 2018-12-20 04:46:27 -0800 | [diff] [blame] | 40 | cp DISCLAIMER readme.txt legal/java.base/ASSEMBLY_EXCEPTION \ |
| 41 | reduced/ |
Tobias Werth | 290e49b | 2019-01-16 05:04:40 -0800 | [diff] [blame] | 42 | # These are necessary for --host_jvm_debug to work. |
| 43 | cp bin/dt_socket.dll bin/jdwp.dll reduced/bin |
Tobias Werth | 218e8f6 | 2018-12-13 04:44:35 -0800 | [diff] [blame] | 44 | zip -r -9 ../reduced.zip reduced/ |
| 45 | cd .. |
| 46 | mv reduced.zip "$out" |
| 47 | else |
| 48 | tar xf "$fulljdk" |
| 49 | cd zulu* |
| 50 | ./bin/jlink --module-path ./jmods/ --add-modules "$modules" \ |
| 51 | --vm=server --strip-debug --no-man-pages \ |
| 52 | --output reduced |
twerth | 060441f | 2018-12-20 04:46:27 -0800 | [diff] [blame] | 53 | cp DISCLAIMER readme.txt legal/java.base/ASSEMBLY_EXCEPTION \ |
| 54 | reduced/ |
Tobias Werth | 290e49b | 2019-01-16 05:04:40 -0800 | [diff] [blame] | 55 | # These are necessary for --host_jvm_debug to work. |
| 56 | if [[ "$UNAME" =~ darwin ]]; then |
| 57 | cp lib/libdt_socket.dylib lib/libjdwp.dylib reduced/lib |
| 58 | else |
| 59 | cp lib/libdt_socket.so lib/libjdwp.so reduced/lib |
| 60 | fi |
Tobias Werth | 218e8f6 | 2018-12-13 04:44:35 -0800 | [diff] [blame] | 61 | GZIP=-9 tar -zcf ../reduced.tgz reduced |
| 62 | cd .. |
| 63 | mv reduced.tgz "$out" |
| 64 | fi |