1#!/bin/bash -e
2
3# Copyright 2020 Google Inc. 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
17printHelp() {
18    echo "**************************** Usage Instructions ****************************"
19    echo "This script is used to generate the Mainline modules used-by Java symbols."
20    echo ""
21    echo "To run this script use: ./gen_java_usedby_apex.sh \$BINARY_DEXDEPS_PATH \$OUTPUT_FILE_PATH \$JAR_AND_APK_LIST"
22    echo "For example: If all jar and apk files are '/myJar.jar /myApk.apk' and output write to /myModule.txt then the command would be:"
23    echo "./gen_java_usedby_apex.sh \$BINARY_DEXDEPS_PATH /myModule.txt /myJar.jar /myApk.apk"
24}
25
26genUsedByList() {
27  dexdeps="$1"
28  shift
29  out="$1"
30  shift
31  rm -f "$out"
32  touch "$out"
33  echo "<externals>" >> "$out"
34  for x in "$@"; do
35    "$dexdeps" "$x" >> "$out" || echo "</external>" >> "$out"
36  done
37  echo "</externals>" >> "$out"
38}
39
40if [[ "$1" == "help" ]]
41then
42  printHelp
43elif [[ "$#" -lt 2 ]]
44then
45  echo "Wrong argument length. Expecting at least 2 argument representing dexdeps path, output path, followed by a list of jar or apk files in the Mainline module."
46else
47  genUsedByList "$@"
48fi