blob: 74e3f703dc697c5f0199d666e8032426bce735f0 [file] [log] [blame]
Jooyung Han81538a72020-02-20 19:54:16 +09001#!/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 Stjernholm73cccc42020-02-24 17:18:38 +000017set -e
Jooyung Han0441fd32020-03-31 16:14:56 +090018shopt -s extglob
Jooyung Hana8df5052022-01-26 16:25:30 +090019shopt -s globstar
Martin Stjernholm73cccc42020-02-24 17:18:38 +000020
Jooyung Han77d84bd2020-03-31 15:44:53 +090021# to use relative paths
22cd $(dirname $0)
Jooyung Han81538a72020-02-20 19:54:16 +090023
Jooyung Han77d84bd2020-03-31 15:44:53 +090024# when executed directly from commandline, build dependencies
25if [[ $(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 Hanfcaa89a2020-03-20 18:20:23 +090031else
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 Han77d84bd2020-03-31 15:44:53 +090036fi
Jooyung Han81538a72020-02-20 19:54:16 +090037
Jooyung Hana8df5052022-01-26 16:25:30 +090038# $1: target libraries.txt file
39# $2: list of libs. ex) a.so:b.so:c.so
40function write_libraries_txt {
41 rm -rf $1
Justin Yun02e03672021-08-09 15:05:42 +090042 IFS=':'
43 for lib in $2; do
Jooyung Hana8df5052022-01-26 16:25:30 +090044 echo $lib >> $1
Justin Yun02e03672021-08-09 15:05:42 +090045 done
Justin Yun02e03672021-08-09 15:05:42 +090046 unset IFS
47}
48
Jooyung Hana8df5052022-01-26 16:25:30 +090049# Simulate build process
50# $1: input tree (with *.json)
51# $2: output tree (*.json files are converted into *.pb)
52function 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 Han77d84bd2020-03-31 15:44:53 +090065# $1: target output directory
66function run_linkerconfig_to {
Jooyung Han0441fd32020-03-31 16:14:56 +090067 # delete old output
68 rm -rf $1
69
Jooyung Han0441fd32020-03-31 16:14:56 +090070 TMP_ROOT=$(mktemp -d -t linkerconfig-root-XXXXXXXX)
Jooyung Hana8df5052022-01-26 16:25:30 +090071 # Build the root
72 build_root testdata/root $TMP_ROOT
Jooyung Han0441fd32020-03-31 16:14:56 +090073
Jooyung Hana8df5052022-01-26 16:25:30 +090074 # Run linkerconfig with various configurations
75
76 ./testdata/prepare_root.sh --root $TMP_ROOT
Jooyung Han0441fd32020-03-31 16:14:56 +090077 mkdir -p $1/stage0
78 linkerconfig -v R -r $TMP_ROOT -t $1/stage0
79
Jooyung Hana8df5052022-01-26 16:25:30 +090080 ./testdata/prepare_root.sh --bootstrap --root $TMP_ROOT
Jooyung Han0441fd32020-03-31 16:14:56 +090081 mkdir -p $1/stage1
82 linkerconfig -v R -r $TMP_ROOT -t $1/stage1
83
Jooyung Hana8df5052022-01-26 16:25:30 +090084 ./testdata/prepare_root.sh --all --root $TMP_ROOT
Jooyung Han0441fd32020-03-31 16:14:56 +090085 mkdir -p $1/stage2
86 linkerconfig -v R -r $TMP_ROOT -t $1/stage2
Jooyung Han81538a72020-02-20 19:54:16 +090087
Jooyung Hana8df5052022-01-26 16:25:30 +090088 # skip prepare_root in order to use the same apexs
Jooyung Han0441fd32020-03-31 16:14:56 +090089 mkdir -p $1/product-enabled
90 linkerconfig -v R -p R -r $TMP_ROOT -t $1/product-enabled
91
Jooyung Hana8df5052022-01-26 16:25:30 +090092 # 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 Yun02e03672021-08-09 15:05:42 +090096 mkdir -p $1/vndk-in-system
Justin Yun02e03672021-08-09 15:05:42 +090097 linkerconfig -v R -p R -r $TMP_ROOT -t $1/vndk-in-system
Jooyung Hana8df5052022-01-26 16:25:30 +090098 # clean up
99 rm -if $vndk_core_variant_libs_file
100 vndk_core_variant_libs_file=
Justin Yun02e03672021-08-09 15:05:42 +0900101
Jooyung Hana8df5052022-01-26 16:25:30 +0900102 ./testdata/prepare_root.sh --all --block com.android.art:com.android.vndk.vR --root $TMP_ROOT
Jooyung Han2f659de2021-07-22 17:59:45 +0000103 mkdir -p $1/guest
104 linkerconfig -v R -p R -r $TMP_ROOT -t $1/guest
105
Jooyung Hana8df5052022-01-26 16:25:30 +0900106 # skip prepare_root in order to use the same apexes except VNDK
Jooyung Han71b4bf32020-04-02 15:40:41 +0900107 rm -iRf $TMP_ROOT/apex/com.android.vndk.vR
108 mkdir -p $1/legacy
109 linkerconfig -r $TMP_ROOT -t $1/legacy
110
Jooyung Han77d84bd2020-03-31 15:44:53 +0900111 # clean up testdata root
112 rm -rf $TMP_ROOT
113}
Jooyung Han81538a72020-02-20 19:54:16 +0900114
Jooyung Han77d84bd2020-03-31 15:44:53 +0900115# update golden_output
116if [[ $1 == "--update" ]]; then
117 run_linkerconfig_to ./testdata/golden_output
118 echo "Updated"
119 exit 0
120fi
Jooyung Han81538a72020-02-20 19:54:16 +0900121
Jooyung Han77d84bd2020-03-31 15:44:53 +0900122echo "Running linkerconfig diff test..."
123
124run_linkerconfig_to ./testdata/output
125if diff -ruN ./testdata/golden_output ./testdata/output ; then
126 echo "No changes."
Jooyung Han81538a72020-02-20 19:54:16 +0900127else
128 echo
129 echo "------------------------------------------------------------------------------------------"
130 echo "if change looks fine, run following:"
Jooyung Han77d84bd2020-03-31 15:44:53 +0900131 echo " \$ANDROID_BUILD_TOP/system/linkerconfig/rundiff.sh --update"
Jooyung Han81538a72020-02-20 19:54:16 +0900132 echo "------------------------------------------------------------------------------------------"
Jooyung Han77d84bd2020-03-31 15:44:53 +0900133 # fail
134 exit 1
135fi