blob: 667dde0b757dece0f2ce937cbf974306c5cca09d [file] [log] [blame]
Yu Liue0c4d352023-02-24 16:45:19 -08001#!/bin/bash
2
3# Copyright (C) 2023 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 -euo pipefail
18
19# Soong/Bazel integration test to build the mainline modules in mixed build and
20# compare the DCLA libs extracted from those modules to ensure they are identical.
21
22if [ ! -e "build/make/core/Makefile" ]; then
23 echo "$0 must be run from the top of the Android source tree."
24 exit 1
25fi
26
27TARGET_PRODUCTS=(
28 module_arm64
29 module_x86_64
30)
31
32MODULES=(
33 # These modules depend on the DCLA libs
34 com.android.adbd
35 com.android.art
36 com.android.art.debug
37 com.android.art.testing
38 com.android.btservices
39 com.android.conscrypt
40 com.android.i18n
41 com.android.media
42 com.android.media.swcodec
43 com.android.resolv
44 com.android.runtime
45 com.android.tethering
46)
47
Yu Liu09a8d452023-05-12 17:22:30 -070048BAZEL_TARGETS=(
49 //packages/modules/adb/apex:com.android.adbd
50 //frameworks/av/apex:com.android.media.swcodec
51)
52
Yu Liue0c4d352023-02-24 16:45:19 -080053DCLA_LIBS=(
54 libbase.so
55 libc++.so
56 libcrypto.so
57 libcutils.so
58)
59
60if [[ -z ${OUT_DIR+x} ]]; then
61 OUT_DIR="out"
62fi
63
64if [[ -z ${ANDROID_HOST_OUT+x} ]]; then
65 export ANDROID_HOST_OUT="out/host/linux-x86"
66fi
67
68######################
69# Build deapexer and debugfs
70######################
71DEAPEXER="${ANDROID_HOST_OUT}/bin/deapexer"
72DEBUGFS="${ANDROID_HOST_OUT}/bin/debugfs"
73if [[ ! -f "${DEAPEXER}" ]] || [[ ! -f "${DEBUGFS}" ]]; then
74 build/soong/soong_ui.bash --make-mode --skip-soong-tests deapexer debugfs
75fi
76
77DEAPEXER="${DEAPEXER} --debugfs_path=${DEBUGFS}"
78
79############
80# Test Setup
81############
82OUTPUT_DIR="$(mktemp -d tmp.XXXXXX)"
83
Yu Liu09a8d452023-05-12 17:22:30 -070084function call_bazel() {
85 build/bazel/bin/bazel $@
86}
87
Yu Liue0c4d352023-02-24 16:45:19 -080088function cleanup {
89 rm -rf "${OUTPUT_DIR}"
90}
91trap cleanup EXIT
92
93#######
94# Tests
95#######
96
97function extract_dcla_libs() {
98 local product=$1; shift
Yu Liu09a8d452023-05-12 17:22:30 -070099 local modules=("$@"); shift
100
101 for module in "${modules[@]}"; do
Yu Liue0c4d352023-02-24 16:45:19 -0800102 local apex="${OUTPUT_DIR}/${product}/${module}.apex"
103 local extract_dir="${OUTPUT_DIR}/${product}/${module}/extract"
104
105 $DEAPEXER extract "${apex}" "${extract_dir}"
106 done
107}
108
109function compare_dcla_libs() {
110 local product=$1; shift
Yu Liu09a8d452023-05-12 17:22:30 -0700111 local modules=("$@"); shift
Yu Liue0c4d352023-02-24 16:45:19 -0800112
113 for lib in "${DCLA_LIBS[@]}"; do
114 for arch in lib lib64; do
115 local prev_sha=""
Yu Liu09a8d452023-05-12 17:22:30 -0700116 for module in "${modules[@]}"; do
Yu Liue0c4d352023-02-24 16:45:19 -0800117 local file="${OUTPUT_DIR}/${product}/${module}/extract/${arch}/${lib}"
118 if [[ ! -f "${file}" ]]; then
119 # not all libs are present in a module
120 echo "file doesn't exist: ${file}"
121 continue
122 fi
123 sha=$(sha1sum ${file})
124 sha="${sha% *}"
125 if [ "${prev_sha}" == "" ]; then
126 prev_sha="${sha}"
Yu Liu09a8d452023-05-12 17:22:30 -0700127 elif [ "${sha}" != "${prev_sha}" ] && { [ "${lib}" != "libcrypto.so" ] || [[ "${module}" != *"com.android.tethering" ]]; }; then
Yu Liue0c4d352023-02-24 16:45:19 -0800128 echo "Test failed, ${lib} has different hash value"
129 exit 1
130 fi
131 done
132 done
133 done
134}
135
136export UNBUNDLED_BUILD_SDKS_FROM_SOURCE=true # don't rely on prebuilts
137export TARGET_BUILD_APPS="${MODULES[@]}"
138for product in "${TARGET_PRODUCTS[@]}"; do
139 ###########
140 # Build the mainline modules
141 ###########
142 packages/modules/common/build/build_unbundled_mainline_module.sh \
143 --product "${product}" \
144 --dist_dir "${OUTPUT_DIR}/${product}"
145
Yu Liu09a8d452023-05-12 17:22:30 -0700146 bazel_apexes=()
147 if [[ -n ${TEST_BAZEL+x} ]] && [ "${TEST_BAZEL}" = true ]; then
148 export TARGET_PRODUCT="${product/module/aosp}"
149 call_bazel build --config=bp2build --config=ci --config=android "${BAZEL_TARGETS[@]}"
150 for target in "${BAZEL_TARGETS[@]}"; do
151 apex_path="$(realpath $(call_bazel cquery --config=bp2build --config=android --config=ci --output=files $target))"
152 mkdir -p ${OUTPUT_DIR}/${product}
153 bazel_apex="bazel_$(basename $apex_path)"
154 mv $apex_path ${OUTPUT_DIR}/${product}/${bazel_apex}
155 bazel_apexes+=(${bazel_apex%".apex"})
156 done
157 fi
158
159 all_modeuls=(${MODULES[@]} ${bazel_apexes[@]})
160 extract_dcla_libs "${product}" "${all_modeuls[@]}"
161 compare_dcla_libs "${product}" "${all_modeuls[@]}"
Yu Liue0c4d352023-02-24 16:45:19 -0800162done
163
164echo "Test passed"