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') |
Tobias Werth | 9075514 | 2019-02-03 07:28:11 -0800 | [diff] [blame] | 27 | # 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 Werth | a87451a | 2019-01-29 07:03:58 -0800 | [diff] [blame] | 30 | fi |
Tobias Werth | 218e8f6 | 2018-12-13 04:44:35 -0800 | [diff] [blame] | 31 | fulljdk=$1 |
Tobias Werth | 218e8f6 | 2018-12-13 04:44:35 -0800 | [diff] [blame] | 32 | out=$3 |
Jason Furmanek | 04e073e | 2020-05-28 05:48:09 -0700 | [diff] [blame] | 33 | ARCH=`uname -p` |
Ruixin Bao | e14a6f2 | 2020-08-21 06:17:24 -0700 | [diff] [blame] | 34 | if [[ "${ARCH}" == 'ppc64le' ]] || [[ "${ARCH}" == 's390x' ]]; then |
Jason Furmanek | 04e073e | 2020-05-28 05:48:09 -0700 | [diff] [blame] | 35 | FULL_JDK_DIR="jdk*" |
| 36 | DOCS="" |
| 37 | else |
| 38 | FULL_JDK_DIR="zulu*" |
| 39 | DOCS="DISCLAIMER readme.txt" |
| 40 | fi |
Tobias Werth | 218e8f6 | 2018-12-13 04:44:35 -0800 | [diff] [blame] | 41 | |
| 42 | UNAME=$(uname -s | tr 'A-Z' 'a-z') |
| 43 | |
| 44 | if [[ "$UNAME" =~ msys_nt* ]]; then |
| 45 | set -x |
Tobias Werth | 9c91a81 | 2019-02-02 07:13:58 -0800 | [diff] [blame] | 46 | mkdir "tmp.$$" |
| 47 | cd "tmp.$$" |
| 48 | unzip "../$fulljdk" |
Jason Furmanek | 04e073e | 2020-05-28 05:48:09 -0700 | [diff] [blame] | 49 | cd $FULL_JDK_DIR |
Tobias Werth | 218e8f6 | 2018-12-13 04:44:35 -0800 | [diff] [blame] | 50 | ./bin/jlink --module-path ./jmods/ --add-modules "$modules" \ |
| 51 | --vm=server --strip-debug --no-man-pages \ |
| 52 | --output reduced |
Jason Furmanek | 04e073e | 2020-05-28 05:48:09 -0700 | [diff] [blame] | 53 | cp $DOCS legal/java.base/ASSEMBLY_EXCEPTION \ |
twerth | 060441f | 2018-12-20 04:46:27 -0800 | [diff] [blame] | 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 | cp bin/dt_socket.dll bin/jdwp.dll reduced/bin |
Tobias Werth | 218e8f6 | 2018-12-13 04:44:35 -0800 | [diff] [blame] | 57 | zip -r -9 ../reduced.zip reduced/ |
Tobias Werth | 9c91a81 | 2019-02-02 07:13:58 -0800 | [diff] [blame] | 58 | cd ../.. |
| 59 | mv "tmp.$$/reduced.zip" "$out" |
| 60 | rm -rf "tmp.$$" |
Tobias Werth | 218e8f6 | 2018-12-13 04:44:35 -0800 | [diff] [blame] | 61 | else |
philwo | 9f7fe69 | 2019-06-27 06:53:12 -0700 | [diff] [blame] | 62 | # 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 Furmanek | 04e073e | 2020-05-28 05:48:09 -0700 | [diff] [blame] | 66 | cd $FULL_JDK_DIR |
Tobias Werth | 218e8f6 | 2018-12-13 04:44:35 -0800 | [diff] [blame] | 67 | ./bin/jlink --module-path ./jmods/ --add-modules "$modules" \ |
| 68 | --vm=server --strip-debug --no-man-pages \ |
| 69 | --output reduced |
Jason Furmanek | 04e073e | 2020-05-28 05:48:09 -0700 | [diff] [blame] | 70 | cp $DOCS legal/java.base/ASSEMBLY_EXCEPTION \ |
twerth | 060441f | 2018-12-20 04:46:27 -0800 | [diff] [blame] | 71 | reduced/ |
Tobias Werth | 290e49b | 2019-01-16 05:04:40 -0800 | [diff] [blame] | 72 | # 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 Werth | 218e8f6 | 2018-12-13 04:44:35 -0800 | [diff] [blame] | 78 | GZIP=-9 tar -zcf ../reduced.tgz reduced |
| 79 | cd .. |
| 80 | mv reduced.tgz "$out" |
| 81 | fi |