sophiez | 6bde0b5 | 2021-01-09 01:03:42 +0000 | [diff] [blame] | 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 | |
| 17 | # Generates NDK API txt file used by Mainline modules. NDK APIs would have value |
| 18 | # "UND" in Ndx column and have suffix "@LIB_NAME" in Name column. |
| 19 | # For example, current line llvm-readelf output is: |
| 20 | # 1: 00000000 0 FUNC GLOBAL DEFAULT UND dlopen@LIBC |
| 21 | # After the parse function below "dlopen" would be write to the output file. |
| 22 | printHelp() { |
| 23 | echo "**************************** Usage Instructions ****************************" |
| 24 | echo "This script is used to generate the Mainline modules backed-by NDK symbols." |
| 25 | echo "" |
Colin Cross | 69f0a24 | 2021-02-08 16:49:57 -0800 | [diff] [blame^] | 26 | echo "To run this script use: ./gen_ndk_backed_by_apex.sh \$OUTPUT_FILE_PATH \$NDK_LIB_NAME_LIST \$MODULE_LIB1 \$MODULE_LIB2..." |
| 27 | echo "For example: If output write to /backedby.txt then the command would be:" |
| 28 | echo "./gen_ndk_backed_by_apex.sh /backedby.txt /ndkLibList.txt lib1.so lib2.so" |
sophiez | 6bde0b5 | 2021-01-09 01:03:42 +0000 | [diff] [blame] | 29 | echo "If the module1 is backing lib1 then the backedby.txt would contains: " |
| 30 | echo "lib1" |
| 31 | } |
| 32 | |
Colin Cross | 69f0a24 | 2021-02-08 16:49:57 -0800 | [diff] [blame^] | 33 | contains() { |
| 34 | val="$1" |
| 35 | shift |
| 36 | for x in "$@"; do |
| 37 | if [ "$x" = "$val" ]; then |
| 38 | return 0 |
| 39 | fi |
| 40 | done |
| 41 | return 1 |
| 42 | } |
| 43 | |
| 44 | |
sophiez | 6bde0b5 | 2021-01-09 01:03:42 +0000 | [diff] [blame] | 45 | genBackedByList() { |
Colin Cross | 69f0a24 | 2021-02-08 16:49:57 -0800 | [diff] [blame^] | 46 | out="$1" |
| 47 | shift |
| 48 | ndk_list="$1" |
| 49 | shift |
| 50 | rm -f "$out" |
| 51 | touch "$out" |
sophiez | 6bde0b5 | 2021-01-09 01:03:42 +0000 | [diff] [blame] | 52 | while IFS= read -r line |
| 53 | do |
| 54 | soFileName=$(echo "$line" | sed 's/\(.*so\).*/\1/') |
| 55 | if [[ ! -z "$soFileName" && "$soFileName" != *"#"* ]] |
| 56 | then |
Colin Cross | 69f0a24 | 2021-02-08 16:49:57 -0800 | [diff] [blame^] | 57 | if contains "$soFileName" "$@"; then |
| 58 | echo "$soFileName" >> "$out" |
| 59 | fi |
sophiez | 6bde0b5 | 2021-01-09 01:03:42 +0000 | [diff] [blame] | 60 | fi |
Colin Cross | 69f0a24 | 2021-02-08 16:49:57 -0800 | [diff] [blame^] | 61 | done < "$ndk_list" |
sophiez | 6bde0b5 | 2021-01-09 01:03:42 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | if [[ "$1" == "help" ]] |
| 65 | then |
| 66 | printHelp |
Colin Cross | 69f0a24 | 2021-02-08 16:49:57 -0800 | [diff] [blame^] | 67 | elif [[ "$#" -lt 2 ]] |
sophiez | 6bde0b5 | 2021-01-09 01:03:42 +0000 | [diff] [blame] | 68 | then |
Colin Cross | 69f0a24 | 2021-02-08 16:49:57 -0800 | [diff] [blame^] | 69 | echo "Wrong argument length. Expecting at least 2 argument representing output path, path to ndk library list, followed by a list of libraries in the Mainline module." |
sophiez | 6bde0b5 | 2021-01-09 01:03:42 +0000 | [diff] [blame] | 70 | else |
Colin Cross | 69f0a24 | 2021-02-08 16:49:57 -0800 | [diff] [blame^] | 71 | genBackedByList "$@" |
sophiez | 6bde0b5 | 2021-01-09 01:03:42 +0000 | [diff] [blame] | 72 | fi |