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 desugar.jar with the --bootclasspath_entry values passed in automatically.
19# (This avoids having to manually set a boot class path).
20#
21#
22# Script-specific args:
23#   --mode=[host|target]: Select between host or target bootclasspath (default target).
24#   --core-only:          Use only "core" bootclasspath (e.g. do not include framework).
25#   --show-commands:      Print the desugar command being executed.
26#   --help:               Print above list of args.
27#
28# All other args are forwarded to desugar.jar
29#
30
31DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
32TOP=$DIR/../..
33
34pushd "$TOP" >/dev/null # back to android root.
35
36out=${OUT_DIR:-out}
37desugar_jar=$out/host/linux-x86/framework/desugar.jar
38
39if ! [[ -f $desugar_jar ]]; then
40  echo "Error: Missing $desugar_jar; did you do a build?" >&2
41  exit 1
42fi
43
44desugar_jar=$(readlink -f "$desugar_jar") # absolute path to desugar jar
45popd >/dev/null
46
47bootjars_args=
48mode=target
49showcommands=n
50while true; do
51  case $1 in
52    --help)
53      echo "Usage: $0 [--mode=host|target] [--core-only] [--show-commands] <desugar args>"
54      exit 0
55      ;;
56    --mode=host)
57      bootjars_args="$bootjars_args --host"
58      ;;
59    --mode=target)
60      bootjars_args="$bootjars_args --target"
61      ;;
62    --mode=*)
63      echo "Unsupported $0 usage with --mode=$1" >&2
64      exit 1
65      ;;
66    --core-only)
67      bootjars_args="$bootjars_args --core"
68      ;;
69    --show-commands)
70      showcommands=y
71      ;;
72    *)
73      break
74      ;;
75  esac
76  shift
77done
78
79desugar_args=(--min_sdk_version=10000)
80boot_class_path_list=$($TOP/art/tools/bootjars.sh $bootjars_args --path)
81
82for path in $boot_class_path_list; do
83  desugar_args+=(--bootclasspath_entry="$path")
84done
85
86if [[ ${#desugar_args[@]} -eq 0 ]]; then
87  echo "FATAL: Missing bootjars.sh file path list" >&2
88  exit 1
89fi
90
91if [[ $showcommands == y ]]; then
92  echo java -jar "$desugar_jar" "${desugar_args[@]}" "$@"
93fi
94
95java -jar "$desugar_jar" "${desugar_args[@]}" "$@"
96