• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
17set -e
18shopt -s extglob
19
20# to use relative paths
21cd $(dirname $0)
22
23# 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
30else
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
35fi
36
37# $1: tmp root
38# $2: apex
39function activate() {
40  cp -r ./testdata/root/apex/$2 $1/apex
41}
42
43# $1: target output directory
44function run_linkerconfig_to {
45  # delete old output
46  rm -rf $1
47
48  TMP_ROOT=$(mktemp -d -t linkerconfig-root-XXXXXXXX)
49
50  ./testdata/prepare_root.sh --in testdata/root --out $TMP_ROOT
51  mkdir -p $1/stage0
52  linkerconfig -v R -r $TMP_ROOT -t $1/stage0
53
54  ./testdata/prepare_root.sh --bootstrap --in testdata/root --out $TMP_ROOT
55  mkdir -p $1/stage1
56  linkerconfig -v R -r $TMP_ROOT -t $1/stage1
57
58  ./testdata/prepare_root.sh --all --in testdata/root --out $TMP_ROOT
59  mkdir -p $1/stage2
60  linkerconfig -v R -r $TMP_ROOT -t $1/stage2
61
62  mkdir -p $1/product-enabled
63  linkerconfig -v R -p R -r $TMP_ROOT -t $1/product-enabled
64
65  rm -iRf $TMP_ROOT/apex/com.android.vndk.vR
66  mkdir -p $1/legacy
67  linkerconfig -r $TMP_ROOT -t $1/legacy
68
69  # clean up testdata root
70  rm -rf $TMP_ROOT
71}
72
73# update golden_output
74if [[ $1 == "--update" ]]; then
75  run_linkerconfig_to ./testdata/golden_output
76  echo "Updated"
77  exit 0
78fi
79
80echo "Running linkerconfig diff test..."
81
82run_linkerconfig_to ./testdata/output
83if diff -ruN ./testdata/golden_output ./testdata/output ; then
84  echo "No changes."
85else
86  echo
87  echo "------------------------------------------------------------------------------------------"
88  echo "if change looks fine, run following:"
89  echo "  \$ANDROID_BUILD_TOP/system/linkerconfig/rundiff.sh --update"
90  echo "------------------------------------------------------------------------------------------"
91  # fail
92  exit 1
93fi