-
Notifications
You must be signed in to change notification settings - Fork 0
/
rundiff.sh
executable file
·202 lines (165 loc) · 5.39 KB
/
rundiff.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/bin/bash
# Copyright (C) 2020 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
shopt -s extglob
shopt -s globstar
# to use relative paths
cd $(dirname $0)
RUN_FROM_SERVER=0
# when executed directly from commandline, build dependencies
if [[ $(basename $0) == "rundiff.sh" ]]; then
if [ -z $ANDROID_BUILD_TOP ]; then
echo "You need to source and lunch before you can use this script"
exit 1
fi
$ANDROID_BUILD_TOP/build/soong/soong_ui.bash --make-mode linkerconfig conv_apex_manifest conv_linker_config
else
# workaround to use host tools on build server
export PATH=$(dirname $0):$PATH
RUN_FROM_SERVER=1
fi
# $1: target libraries.txt file
# $2: list of libs. ex) a.so:b.so:c.so
function write_libraries_txt {
rm -rf $1
IFS=':'
for lib in $2; do
echo $lib >> $1
done
unset IFS
}
# Simulate build process
# $1: input tree (with *.json)
# $2: output tree (*.json files are converted into *.pb)
function build_root {
cp -R $1/* $2
for json in $2/**/linker.config.json; do
conv_linker_config proto -s $json -o ${json%.json}.pb
rm $json
done
for json in $2/**/apex_manifest.json; do
conv_apex_manifest proto $json -o ${json%.json}.pb
rm $json
done
}
function run_linkerconfig_stage0 {
# prepare root
echo "Prepare root for stage 0"
TMP_PATH=$2/stage0
mkdir $TMP_PATH
build_root testdata/root $TMP_PATH
./testdata/prepare_root.sh --root $TMP_PATH
mkdir -p $1/stage0
echo "Running linkerconfig for stage 0"
linkerconfig -v R -r $TMP_PATH -t $1/stage0
echo "Stage 0 completed"
}
function run_linkerconfig_stage1 {
# prepare root
echo "Prepare root for stage 1"
TMP_PATH=$2/stage1
mkdir $TMP_PATH
build_root testdata/root $TMP_PATH
./testdata/prepare_root.sh --bootstrap --root $TMP_PATH
mkdir -p $1/stage1
echo "Running linkerconfig for stage 1"
linkerconfig -v R -r $TMP_PATH -t $1/stage1
echo "Stage 1 completed"
}
function run_linkerconfig_stage2 {
# prepare root
echo "Prepare root for stage 2"
TMP_PATH=$2/stage2
mkdir $TMP_PATH
build_root testdata/root $TMP_PATH
./testdata/prepare_root.sh --all --root $TMP_PATH
mkdir -p $1/stage2
echo "Running linkerconfig for stage 2"
linkerconfig -v R -r $TMP_PATH -t $1/stage2
# skip prepare_root in order to use the same apexs
mkdir -p $1/product-enabled
echo "Running linkerconfig for product-enabled"
linkerconfig -v R -p R -r $TMP_PATH -t $1/product-enabled
# skip prepare_root (reuse the previous setup)
mkdir -p $1/gen-only-a-single-apex
echo "Running linkerconfig for gen-only-a-single-apex"
linkerconfig -v R -r $TMP_PATH --apex com.vendor.service2 -t $1/gen-only-a-single-apex
# skip prepare_root in order to use the same apexs
# but with system/etc/vndkcorevariant.libraries.txt
vndk_core_variant_libs_file=$TMP_PATH/system/etc/vndkcorevariant.libraries.txt
write_libraries_txt $vndk_core_variant_libs_file libevent.so:libexif.so:libfmq.so
mkdir -p $1/vndk-in-system
echo "Running linkerconfig for vndk-in-system"
linkerconfig -v R -p R -r $TMP_PATH -t $1/vndk-in-system
# clean up
rm -if $vndk_core_variant_libs_file
vndk_core_variant_libs_file=
echo "Stage 2 completed"
}
function run_linkerconfig_others {
# prepare root
echo "Prepare root for stage others"
TMP_PATH=$2/others
mkdir $TMP_PATH
build_root testdata/root $TMP_PATH
./testdata/prepare_root.sh --all --block com.android.art:com.android.vndk.vR --root $TMP_PATH
mkdir -p $1/guest
echo "Running linkerconfig for guest"
linkerconfig -v R -p R -r $TMP_PATH -t $1/guest
# skip prepare_root in order to use the same apexes except VNDK
rm -iRf $TMP_PATH/apex/com.android.vndk.vR
mkdir -p $1/legacy
echo "Running linkerconfig for legacy"
linkerconfig -r $TMP_PATH -t $1/legacy
echo "Stage others completed"
}
# $1: target output directory
function run_linkerconfig_to {
# delete old output
rm -rf $1
TMP_ROOT=$(mktemp -d -t linkerconfig-root-XXXXXXXX)
run_linkerconfig_stage0 $1 $TMP_ROOT &
run_linkerconfig_stage1 $1 $TMP_ROOT &
run_linkerconfig_stage2 $1 $TMP_ROOT &
run_linkerconfig_others $1 $TMP_ROOT &
for job in `jobs -p`
do
wait $job
done
# Remove temp root if required
if [[ $RUN_FROM_SERVER -ne 1 ]]; then
rm -rf $TMP_ROOT
fi
}
# update golden_output
if [[ $1 == "--update" ]]; then
run_linkerconfig_to ./testdata/golden_output
echo "Updated"
exit 0
fi
echo "Running linkerconfig diff test..."
run_linkerconfig_to ./testdata/output
echo "Running diff from test output"
if diff -ruN ./testdata/golden_output ./testdata/output ; then
echo "No changes."
else
echo
echo "------------------------------------------------------------------------------------------"
echo "if change looks fine, run following:"
echo " \$ANDROID_BUILD_TOP/system/linkerconfig/rundiff.sh --update"
echo "------------------------------------------------------------------------------------------"
# fail
exit 1
fi