Jooyung Han | 81538a7 | 2020-02-20 19:54:16 +0900 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Copyright (C) 2020 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 | |
Martin Stjernholm | 73cccc4 | 2020-02-24 17:18:38 +0000 | [diff] [blame] | 17 | set -e |
Jooyung Han | 0441fd3 | 2020-03-31 16:14:56 +0900 | [diff] [blame] | 18 | shopt -s extglob |
Jooyung Han | a8df505 | 2022-01-26 16:25:30 +0900 | [diff] [blame] | 19 | shopt -s globstar |
Martin Stjernholm | 73cccc4 | 2020-02-24 17:18:38 +0000 | [diff] [blame] | 20 | |
Jooyung Han | 77d84bd | 2020-03-31 15:44:53 +0900 | [diff] [blame] | 21 | # to use relative paths |
| 22 | cd $(dirname $0) |
Jooyung Han | 81538a7 | 2020-02-20 19:54:16 +0900 | [diff] [blame] | 23 | |
Jooyung Han | 77d84bd | 2020-03-31 15:44:53 +0900 | [diff] [blame] | 24 | # when executed directly from commandline, build dependencies |
| 25 | if [[ $(basename $0) == "rundiff.sh" ]]; then |
| 26 | if [ -z $ANDROID_BUILD_TOP ]; then |
| 27 | echo "You need to source and lunch before you can use this script" |
| 28 | exit 1 |
| 29 | fi |
| 30 | $ANDROID_BUILD_TOP/build/soong/soong_ui.bash --make-mode linkerconfig conv_apex_manifest |
Jooyung Han | fcaa89a | 2020-03-20 18:20:23 +0900 | [diff] [blame] | 31 | else |
| 32 | # workaround to use host tools(conv_apex_manifest, linkerconfig) on build server |
| 33 | unzip -qqo linkerconfig_diff_test_host_tools.zip -d tools |
| 34 | export PATH=$(realpath tools)/bin:$PATH |
| 35 | export LD_LIBRARY_PATH=$(realpath tools)/lib64:$LD_LIBRARY_PATH |
Jooyung Han | 77d84bd | 2020-03-31 15:44:53 +0900 | [diff] [blame] | 36 | fi |
Jooyung Han | 81538a7 | 2020-02-20 19:54:16 +0900 | [diff] [blame] | 37 | |
Jooyung Han | a8df505 | 2022-01-26 16:25:30 +0900 | [diff] [blame] | 38 | # $1: target libraries.txt file |
| 39 | # $2: list of libs. ex) a.so:b.so:c.so |
| 40 | function write_libraries_txt { |
| 41 | rm -rf $1 |
Justin Yun | 02e0367 | 2021-08-09 15:05:42 +0900 | [diff] [blame] | 42 | IFS=':' |
| 43 | for lib in $2; do |
Jooyung Han | a8df505 | 2022-01-26 16:25:30 +0900 | [diff] [blame] | 44 | echo $lib >> $1 |
Justin Yun | 02e0367 | 2021-08-09 15:05:42 +0900 | [diff] [blame] | 45 | done |
Justin Yun | 02e0367 | 2021-08-09 15:05:42 +0900 | [diff] [blame] | 46 | unset IFS |
| 47 | } |
| 48 | |
Jooyung Han | a8df505 | 2022-01-26 16:25:30 +0900 | [diff] [blame] | 49 | # Simulate build process |
| 50 | # $1: input tree (with *.json) |
| 51 | # $2: output tree (*.json files are converted into *.pb) |
| 52 | function build_root { |
| 53 | cp -R $1/* $2 |
| 54 | |
| 55 | for json in $2/**/linker.config.json; do |
| 56 | conv_linker_config proto -s $json -o ${json%.json}.pb |
| 57 | rm $json |
| 58 | done |
| 59 | for json in $2/**/apex_manifest.json; do |
| 60 | conv_apex_manifest proto $json -o ${json%.json}.pb |
| 61 | rm $json |
| 62 | done |
| 63 | } |
| 64 | |
Jooyung Han | 77d84bd | 2020-03-31 15:44:53 +0900 | [diff] [blame] | 65 | # $1: target output directory |
| 66 | function run_linkerconfig_to { |
Jooyung Han | 0441fd3 | 2020-03-31 16:14:56 +0900 | [diff] [blame] | 67 | # delete old output |
| 68 | rm -rf $1 |
| 69 | |
Jooyung Han | 0441fd3 | 2020-03-31 16:14:56 +0900 | [diff] [blame] | 70 | TMP_ROOT=$(mktemp -d -t linkerconfig-root-XXXXXXXX) |
Jooyung Han | a8df505 | 2022-01-26 16:25:30 +0900 | [diff] [blame] | 71 | # Build the root |
| 72 | build_root testdata/root $TMP_ROOT |
Jooyung Han | 0441fd3 | 2020-03-31 16:14:56 +0900 | [diff] [blame] | 73 | |
Jooyung Han | a8df505 | 2022-01-26 16:25:30 +0900 | [diff] [blame] | 74 | # Run linkerconfig with various configurations |
| 75 | |
| 76 | ./testdata/prepare_root.sh --root $TMP_ROOT |
Jooyung Han | 0441fd3 | 2020-03-31 16:14:56 +0900 | [diff] [blame] | 77 | mkdir -p $1/stage0 |
| 78 | linkerconfig -v R -r $TMP_ROOT -t $1/stage0 |
| 79 | |
Jooyung Han | a8df505 | 2022-01-26 16:25:30 +0900 | [diff] [blame] | 80 | ./testdata/prepare_root.sh --bootstrap --root $TMP_ROOT |
Jooyung Han | 0441fd3 | 2020-03-31 16:14:56 +0900 | [diff] [blame] | 81 | mkdir -p $1/stage1 |
| 82 | linkerconfig -v R -r $TMP_ROOT -t $1/stage1 |
| 83 | |
Jooyung Han | a8df505 | 2022-01-26 16:25:30 +0900 | [diff] [blame] | 84 | ./testdata/prepare_root.sh --all --root $TMP_ROOT |
Jooyung Han | 0441fd3 | 2020-03-31 16:14:56 +0900 | [diff] [blame] | 85 | mkdir -p $1/stage2 |
| 86 | linkerconfig -v R -r $TMP_ROOT -t $1/stage2 |
Jooyung Han | 81538a7 | 2020-02-20 19:54:16 +0900 | [diff] [blame] | 87 | |
Jooyung Han | a8df505 | 2022-01-26 16:25:30 +0900 | [diff] [blame] | 88 | # skip prepare_root in order to use the same apexs |
Jooyung Han | 0441fd3 | 2020-03-31 16:14:56 +0900 | [diff] [blame] | 89 | mkdir -p $1/product-enabled |
| 90 | linkerconfig -v R -p R -r $TMP_ROOT -t $1/product-enabled |
| 91 | |
Jooyung Han | a8df505 | 2022-01-26 16:25:30 +0900 | [diff] [blame] | 92 | # skip prepare_root in order to use the same apexs |
| 93 | # but with system/etc/vndkcorevariant.libraries.txt |
| 94 | vndk_core_variant_libs_file=$TMP_ROOT/system/etc/vndkcorevariant.libraries.txt |
| 95 | write_libraries_txt $vndk_core_variant_libs_file libevent.so:libexif.so:libfmq.so |
Justin Yun | 02e0367 | 2021-08-09 15:05:42 +0900 | [diff] [blame] | 96 | mkdir -p $1/vndk-in-system |
Justin Yun | 02e0367 | 2021-08-09 15:05:42 +0900 | [diff] [blame] | 97 | linkerconfig -v R -p R -r $TMP_ROOT -t $1/vndk-in-system |
Jooyung Han | a8df505 | 2022-01-26 16:25:30 +0900 | [diff] [blame] | 98 | # clean up |
| 99 | rm -if $vndk_core_variant_libs_file |
| 100 | vndk_core_variant_libs_file= |
Justin Yun | 02e0367 | 2021-08-09 15:05:42 +0900 | [diff] [blame] | 101 | |
Jooyung Han | a8df505 | 2022-01-26 16:25:30 +0900 | [diff] [blame] | 102 | ./testdata/prepare_root.sh --all --block com.android.art:com.android.vndk.vR --root $TMP_ROOT |
Jooyung Han | 2f659de | 2021-07-22 17:59:45 +0000 | [diff] [blame] | 103 | mkdir -p $1/guest |
| 104 | linkerconfig -v R -p R -r $TMP_ROOT -t $1/guest |
| 105 | |
Jooyung Han | a8df505 | 2022-01-26 16:25:30 +0900 | [diff] [blame] | 106 | # skip prepare_root in order to use the same apexes except VNDK |
Jooyung Han | 71b4bf3 | 2020-04-02 15:40:41 +0900 | [diff] [blame] | 107 | rm -iRf $TMP_ROOT/apex/com.android.vndk.vR |
| 108 | mkdir -p $1/legacy |
| 109 | linkerconfig -r $TMP_ROOT -t $1/legacy |
| 110 | |
Jooyung Han | 77d84bd | 2020-03-31 15:44:53 +0900 | [diff] [blame] | 111 | # clean up testdata root |
| 112 | rm -rf $TMP_ROOT |
| 113 | } |
Jooyung Han | 81538a7 | 2020-02-20 19:54:16 +0900 | [diff] [blame] | 114 | |
Jooyung Han | 77d84bd | 2020-03-31 15:44:53 +0900 | [diff] [blame] | 115 | # update golden_output |
| 116 | if [[ $1 == "--update" ]]; then |
| 117 | run_linkerconfig_to ./testdata/golden_output |
| 118 | echo "Updated" |
| 119 | exit 0 |
| 120 | fi |
Jooyung Han | 81538a7 | 2020-02-20 19:54:16 +0900 | [diff] [blame] | 121 | |
Jooyung Han | 77d84bd | 2020-03-31 15:44:53 +0900 | [diff] [blame] | 122 | echo "Running linkerconfig diff test..." |
| 123 | |
| 124 | run_linkerconfig_to ./testdata/output |
| 125 | if diff -ruN ./testdata/golden_output ./testdata/output ; then |
| 126 | echo "No changes." |
Jooyung Han | 81538a7 | 2020-02-20 19:54:16 +0900 | [diff] [blame] | 127 | else |
| 128 | echo |
| 129 | echo "------------------------------------------------------------------------------------------" |
| 130 | echo "if change looks fine, run following:" |
Jooyung Han | 77d84bd | 2020-03-31 15:44:53 +0900 | [diff] [blame] | 131 | echo " \$ANDROID_BUILD_TOP/system/linkerconfig/rundiff.sh --update" |
Jooyung Han | 81538a7 | 2020-02-20 19:54:16 +0900 | [diff] [blame] | 132 | echo "------------------------------------------------------------------------------------------" |
Jooyung Han | 77d84bd | 2020-03-31 15:44:53 +0900 | [diff] [blame] | 133 | # fail |
| 134 | exit 1 |
| 135 | fi |