blob: 1641291424de650efa358a2d1bcb8c87add3b3ea [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
Martin Stjernholm73cccc42020-02-24 17:18:38 +000019
Jooyung Han77d84bd2020-03-31 15:44:53 +090020# to use relative paths
21cd $(dirname $0)
Jooyung Han81538a72020-02-20 19:54:16 +090022
Jooyung Han77d84bd2020-03-31 15:44:53 +090023# when executed directly from commandline, build dependencies
24if [[ $(basename $0) == "rundiff.sh" ]]; then
25 if [ -z $ANDROID_BUILD_TOP ]; then
26 echo "You need to source and lunch before you can use this script"
27 exit 1
28 fi
29 $ANDROID_BUILD_TOP/build/soong/soong_ui.bash --make-mode linkerconfig conv_apex_manifest
Jooyung Hanfcaa89a2020-03-20 18:20:23 +090030else
31 # workaround to use host tools(conv_apex_manifest, linkerconfig) on build server
32 unzip -qqo linkerconfig_diff_test_host_tools.zip -d tools
33 export PATH=$(realpath tools)/bin:$PATH
34 export LD_LIBRARY_PATH=$(realpath tools)/lib64:$LD_LIBRARY_PATH
Jooyung Han77d84bd2020-03-31 15:44:53 +090035fi
Jooyung Han81538a72020-02-20 19:54:16 +090036
Jooyung Han0441fd32020-03-31 16:14:56 +090037# $1: tmp root
38# $2: apex
39function activate() {
40 cp -r ./testdata/root/apex/$2 $1/apex
41}
Jooyung Han81538a72020-02-20 19:54:16 +090042
Jooyung Han77d84bd2020-03-31 15:44:53 +090043# $1: target output directory
44function run_linkerconfig_to {
Jooyung Han0441fd32020-03-31 16:14:56 +090045 # delete old output
46 rm -rf $1
47
Jooyung Han0441fd32020-03-31 16:14:56 +090048 TMP_ROOT=$(mktemp -d -t linkerconfig-root-XXXXXXXX)
Jooyung Han0441fd32020-03-31 16:14:56 +090049
Jooyung Hanfcaa89a2020-03-20 18:20:23 +090050 ./testdata/prepare_root.sh --in testdata/root --out $TMP_ROOT
Jooyung Han0441fd32020-03-31 16:14:56 +090051 mkdir -p $1/stage0
52 linkerconfig -v R -r $TMP_ROOT -t $1/stage0
53
Jooyung Hanfcaa89a2020-03-20 18:20:23 +090054 ./testdata/prepare_root.sh --bootstrap --in testdata/root --out $TMP_ROOT
Jooyung Han0441fd32020-03-31 16:14:56 +090055 mkdir -p $1/stage1
56 linkerconfig -v R -r $TMP_ROOT -t $1/stage1
57
Jooyung Hanfcaa89a2020-03-20 18:20:23 +090058 ./testdata/prepare_root.sh --all --in testdata/root --out $TMP_ROOT
Jooyung Han0441fd32020-03-31 16:14:56 +090059 mkdir -p $1/stage2
60 linkerconfig -v R -r $TMP_ROOT -t $1/stage2
Jooyung Han81538a72020-02-20 19:54:16 +090061
Jooyung Han0441fd32020-03-31 16:14:56 +090062 mkdir -p $1/product-enabled
63 linkerconfig -v R -p R -r $TMP_ROOT -t $1/product-enabled
64
Jooyung Han71b4bf32020-04-02 15:40:41 +090065 rm -iRf $TMP_ROOT/apex/com.android.vndk.vR
66 mkdir -p $1/legacy
67 linkerconfig -r $TMP_ROOT -t $1/legacy
68
Jooyung Han77d84bd2020-03-31 15:44:53 +090069 # clean up testdata root
70 rm -rf $TMP_ROOT
71}
Jooyung Han81538a72020-02-20 19:54:16 +090072
Jooyung Han77d84bd2020-03-31 15:44:53 +090073# update golden_output
74if [[ $1 == "--update" ]]; then
75 run_linkerconfig_to ./testdata/golden_output
76 echo "Updated"
77 exit 0
78fi
Jooyung Han81538a72020-02-20 19:54:16 +090079
Jooyung Han77d84bd2020-03-31 15:44:53 +090080echo "Running linkerconfig diff test..."
81
82run_linkerconfig_to ./testdata/output
83if diff -ruN ./testdata/golden_output ./testdata/output ; then
84 echo "No changes."
Jooyung Han81538a72020-02-20 19:54:16 +090085else
86 echo
87 echo "------------------------------------------------------------------------------------------"
88 echo "if change looks fine, run following:"
Jooyung Han77d84bd2020-03-31 15:44:53 +090089 echo " \$ANDROID_BUILD_TOP/system/linkerconfig/rundiff.sh --update"
Jooyung Han81538a72020-02-20 19:54:16 +090090 echo "------------------------------------------------------------------------------------------"
Jooyung Han77d84bd2020-03-31 15:44:53 +090091 # fail
92 exit 1
93fi