blob: 03ea8298efb83e9ea542ae7123a1a68808936b6b [file] [log] [blame]
Igor Murashkin1c843e92017-06-19 14:33:06 -07001#!/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 Murashkin2de6e082018-02-28 15:25:23 -080020# If $JAVAC is set, it will call that instead of 'javac'.
Igor Murashkin1c843e92017-06-19 14:33:06 -070021#
22#
23# Script-specific args:
Igor Murashkin2de6e082018-02-28 15:25:23 -080024# --mode=[host|target|jvm]:
25# Select between host,target,jvm bootclasspath (default target).
Igor Murashkin1c843e92017-06-19 14:33:06 -070026# --core-only: Use only "core" bootclasspath (e.g. do not include framework).
Igor Murashkin2de6e082018-02-28 15:25:23 -080027# Ignored with --mode=jvm.
28# --show-commands: Print the javac command being executed.
Igor Murashkin1c843e92017-06-19 14:33:06 -070029# --help: Print above list of args.
30#
31# All other args are forwarded to javac
32#
33
34DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
35TOP=$DIR/../..
36
37if [[ -z $JAVAC ]]; then
38 JAVAC=javac
39fi
40
41bootjars_args=
42mode=target
43showcommands=n
44while true; do
45 case $1 in
46 --help)
Igor Murashkin2de6e082018-02-28 15:25:23 -080047 echo "Usage: $0 [--mode=host|target|jvm] [--core-only] [--show-commands] <javac args>"
Igor Murashkin1c843e92017-06-19 14:33:06 -070048 exit 0
49 ;;
50 --mode=host)
51 bootjars_args="$bootjars_args --host"
Igor Murashkin2de6e082018-02-28 15:25:23 -080052 mode=host
Igor Murashkin1c843e92017-06-19 14:33:06 -070053 ;;
54 --mode=target)
55 bootjars_args="$bootjars_args --target"
Igor Murashkin2de6e082018-02-28 15:25:23 -080056 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 Murashkin1c843e92017-06-19 14:33:06 -070064 ;;
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
76done
77
Igor Murashkin2de6e082018-02-28 15:25:23 -080078if [[ $mode == jvm ]]; then
79 # For --mode=jvm:
80 # Do not prepend a -bootclasspath, which will use the default bootclasspath instead.
81 javac_args=()
82else
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 Murashkin1c843e92017-06-19 14:33:06 -070086
Igor Murashkin2de6e082018-02-28 15:25:23 -080087 for path in $boot_class_path_list; do
88 javac_bootclasspath+=("$path")
89 done
Igor Murashkin1c843e92017-06-19 14:33:06 -070090
Igor Murashkin2de6e082018-02-28 15:25:23 -080091 if [[ ${#javac_bootclasspath[@]} -eq 0 ]]; then
92 echo "FATAL: Missing bootjars.sh file path list" >&2
93 exit 1
94 fi
Igor Murashkin1c843e92017-06-19 14:33:06 -070095
Igor Murashkin2de6e082018-02-28 15:25:23 -080096 function join_by { local IFS="$1"; shift; echo "$*"; }
97 bcp_arg="$(join_by ":" "${javac_bootclasspath[@]}")"
98 javac_args=(-bootclasspath "$bcp_arg")
Igor Murashkin1c843e92017-06-19 14:33:06 -070099fi
100
Igor Murashkin1c843e92017-06-19 14:33:06 -0700101if [[ $showcommands == y ]]; then
102 echo ${JAVAC} "${javac_args[@]}" "$@"
103fi
104
105${JAVAC} "${javac_args[@]}" "$@"