• 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
19shopt -s globstar
20
21# to use relative paths
22cd $(dirname $0)
23
24# 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
31else
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
36fi
37
38# $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
42  IFS=':'
43  for lib in $2; do
44    echo $lib >> $1
45  done
46  unset IFS
47}
48
49# 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
65# $1: target output directory
66function run_linkerconfig_to {
67  # delete old output
68  rm -rf $1
69
70  TMP_ROOT=$(mktemp -d -t linkerconfig-root-XXXXXXXX)
71  # Build the root
72  build_root testdata/root $TMP_ROOT
73
74  # Run linkerconfig with various configurations
75
76  ./testdata/prepare_root.sh --root $TMP_ROOT
77  mkdir -p $1/stage0
78  linkerconfig -v R -r $TMP_ROOT -t $1/stage0
79
80  ./testdata/prepare_root.sh --bootstrap --root $TMP_ROOT
81  mkdir -p $1/stage1
82  linkerconfig -v R -r $TMP_ROOT -t $1/stage1
83
84  ./testdata/prepare_root.sh --all --root $TMP_ROOT
85  mkdir -p $1/stage2
86  linkerconfig -v R -r $TMP_ROOT -t $1/stage2
87
88  # skip prepare_root in order to use the same apexs
89  mkdir -p $1/product-enabled
90  linkerconfig -v R -p R -r $TMP_ROOT -t $1/product-enabled
91
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
96  mkdir -p $1/vndk-in-system
97  linkerconfig -v R -p R -r $TMP_ROOT -t $1/vndk-in-system
98  # clean up
99  rm -if $vndk_core_variant_libs_file
100  vndk_core_variant_libs_file=
101
102  ./testdata/prepare_root.sh --all --block com.android.art:com.android.vndk.vR --root $TMP_ROOT
103  mkdir -p $1/guest
104  linkerconfig -v R -p R -r $TMP_ROOT -t $1/guest
105
106  # skip prepare_root in order to use the same apexes except VNDK
107  rm -iRf $TMP_ROOT/apex/com.android.vndk.vR
108  mkdir -p $1/legacy
109  linkerconfig -r $TMP_ROOT -t $1/legacy
110
111  # clean up testdata root
112  rm -rf $TMP_ROOT
113}
114
115# update golden_output
116if [[ $1 == "--update" ]]; then
117  run_linkerconfig_to ./testdata/golden_output
118  echo "Updated"
119  exit 0
120fi
121
122echo "Running linkerconfig diff test..."
123
124run_linkerconfig_to ./testdata/output
125if diff -ruN ./testdata/golden_output ./testdata/output ; then
126  echo "No changes."
127else
128  echo
129  echo "------------------------------------------------------------------------------------------"
130  echo "if change looks fine, run following:"
131  echo "  \$ANDROID_BUILD_TOP/system/linkerconfig/rundiff.sh --update"
132  echo "------------------------------------------------------------------------------------------"
133  # fail
134  exit 1
135fi