Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (C) 2017 The Android Open Source Project |
| 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 | # |
| 18 | # Calls javac with the -bootclasspath values passed in automatically. |
| 19 | # (This avoids having to manually set a boot class path). |
Igor Murashkin | 2de6e08 | 2018-02-28 15:25:23 -0800 | [diff] [blame] | 20 | # If $JAVAC is set, it will call that instead of 'javac'. |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 21 | # |
| 22 | # |
| 23 | # Script-specific args: |
Igor Murashkin | 2de6e08 | 2018-02-28 15:25:23 -0800 | [diff] [blame] | 24 | # --mode=[host|target|jvm]: |
| 25 | # Select between host,target,jvm bootclasspath (default target). |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 26 | # --core-only: Use only "core" bootclasspath (e.g. do not include framework). |
Igor Murashkin | 2de6e08 | 2018-02-28 15:25:23 -0800 | [diff] [blame] | 27 | # Ignored with --mode=jvm. |
| 28 | # --show-commands: Print the javac command being executed. |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 29 | # --help: Print above list of args. |
| 30 | # |
| 31 | # All other args are forwarded to javac |
| 32 | # |
| 33 | |
| 34 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 35 | TOP=$DIR/../.. |
| 36 | |
| 37 | if [[ -z $JAVAC ]]; then |
| 38 | JAVAC=javac |
| 39 | fi |
| 40 | |
| 41 | bootjars_args= |
| 42 | mode=target |
| 43 | showcommands=n |
| 44 | while true; do |
| 45 | case $1 in |
| 46 | --help) |
Igor Murashkin | 2de6e08 | 2018-02-28 15:25:23 -0800 | [diff] [blame] | 47 | echo "Usage: $0 [--mode=host|target|jvm] [--core-only] [--show-commands] <javac args>" |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 48 | exit 0 |
| 49 | ;; |
| 50 | --mode=host) |
| 51 | bootjars_args="$bootjars_args --host" |
Igor Murashkin | 2de6e08 | 2018-02-28 15:25:23 -0800 | [diff] [blame] | 52 | mode=host |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 53 | ;; |
| 54 | --mode=target) |
| 55 | bootjars_args="$bootjars_args --target" |
Igor Murashkin | 2de6e08 | 2018-02-28 15:25:23 -0800 | [diff] [blame] | 56 | mode=target |
| 57 | ;; |
| 58 | --mode=jvm) |
| 59 | mode=jvm |
| 60 | ;; |
| 61 | --mode=*) |
| 62 | echo "Unsupported $0 usage with --mode=$1" >&2 |
| 63 | exit 1 |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 64 | ;; |
| 65 | --core-only) |
| 66 | bootjars_args="$bootjars_args --core" |
| 67 | ;; |
| 68 | --show-commands) |
| 69 | showcommands=y |
| 70 | ;; |
| 71 | *) |
| 72 | break |
| 73 | ;; |
| 74 | esac |
| 75 | shift |
| 76 | done |
| 77 | |
Igor Murashkin | 2de6e08 | 2018-02-28 15:25:23 -0800 | [diff] [blame] | 78 | if [[ $mode == jvm ]]; then |
| 79 | # For --mode=jvm: |
| 80 | # Do not prepend a -bootclasspath, which will use the default bootclasspath instead. |
| 81 | javac_args=() |
| 82 | else |
| 83 | # For --mode=host or --mode=target, look up the correct -bootclasspath for libcore. |
| 84 | javac_bootclasspath=() |
| 85 | boot_class_path_list=$($TOP/art/tools/bootjars.sh $bootjars_args --path) |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 86 | |
Igor Murashkin | 2de6e08 | 2018-02-28 15:25:23 -0800 | [diff] [blame] | 87 | for path in $boot_class_path_list; do |
| 88 | javac_bootclasspath+=("$path") |
| 89 | done |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 90 | |
Igor Murashkin | 2de6e08 | 2018-02-28 15:25:23 -0800 | [diff] [blame] | 91 | if [[ ${#javac_bootclasspath[@]} -eq 0 ]]; then |
| 92 | echo "FATAL: Missing bootjars.sh file path list" >&2 |
| 93 | exit 1 |
| 94 | fi |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 95 | |
Igor Murashkin | 2de6e08 | 2018-02-28 15:25:23 -0800 | [diff] [blame] | 96 | function join_by { local IFS="$1"; shift; echo "$*"; } |
| 97 | bcp_arg="$(join_by ":" "${javac_bootclasspath[@]}")" |
| 98 | javac_args=(-bootclasspath "$bcp_arg") |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 99 | fi |
| 100 | |
Igor Murashkin | 1c843e9 | 2017-06-19 14:33:06 -0700 | [diff] [blame] | 101 | if [[ $showcommands == y ]]; then |
| 102 | echo ${JAVAC} "${javac_args[@]}" "$@" |
| 103 | fi |
| 104 | |
| 105 | ${JAVAC} "${javac_args[@]}" "$@" |