blob: e3c189f1cbe9fcc1c3f45292debf15db93315774 [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
Yu Liu7301fc82023-05-02 11:39:10 -070058 libstagefright_flacdec.so
59 libutils.so
Yu Liue0c4d352023-02-24 16:45:19 -080060)
61
62if [[ -z ${OUT_DIR+x} ]]; then
63 OUT_DIR="out"
64fi
65
66if [[ -z ${ANDROID_HOST_OUT+x} ]]; then
67 export ANDROID_HOST_OUT="out/host/linux-x86"
68fi
69
70######################
71# Build deapexer and debugfs
72######################
73DEAPEXER="${ANDROID_HOST_OUT}/bin/deapexer"
74DEBUGFS="${ANDROID_HOST_OUT}/bin/debugfs"
75if [[ ! -f "${DEAPEXER}" ]] || [[ ! -f "${DEBUGFS}" ]]; then
76 build/soong/soong_ui.bash --make-mode --skip-soong-tests deapexer debugfs
77fi
78
79DEAPEXER="${DEAPEXER} --debugfs_path=${DEBUGFS}"
80
81############
82# Test Setup
83############
84OUTPUT_DIR="$(mktemp -d tmp.XXXXXX)"
85
Yu Liu09a8d452023-05-12 17:22:30 -070086function call_bazel() {
87 build/bazel/bin/bazel $@
88}
89
Yu Liue0c4d352023-02-24 16:45:19 -080090function cleanup {
91 rm -rf "${OUTPUT_DIR}"
92}
93trap cleanup EXIT
94
95#######
96# Tests
97#######
98
99function extract_dcla_libs() {
100 local product=$1; shift
Yu Liu09a8d452023-05-12 17:22:30 -0700101 local modules=("$@"); shift
102
103 for module in "${modules[@]}"; do
Yu Liue0c4d352023-02-24 16:45:19 -0800104 local apex="${OUTPUT_DIR}/${product}/${module}.apex"
105 local extract_dir="${OUTPUT_DIR}/${product}/${module}/extract"
106
107 $DEAPEXER extract "${apex}" "${extract_dir}"
108 done
109}
110
111function compare_dcla_libs() {
112 local product=$1; shift
Yu Liu09a8d452023-05-12 17:22:30 -0700113 local modules=("$@"); shift
Yu Liue0c4d352023-02-24 16:45:19 -0800114
115 for lib in "${DCLA_LIBS[@]}"; do
116 for arch in lib lib64; do
117 local prev_sha=""
Yu Liu09a8d452023-05-12 17:22:30 -0700118 for module in "${modules[@]}"; do
Yu Liue0c4d352023-02-24 16:45:19 -0800119 local file="${OUTPUT_DIR}/${product}/${module}/extract/${arch}/${lib}"
120 if [[ ! -f "${file}" ]]; then
121 # not all libs are present in a module
122 echo "file doesn't exist: ${file}"
123 continue
124 fi
125 sha=$(sha1sum ${file})
126 sha="${sha% *}"
127 if [ "${prev_sha}" == "" ]; then
128 prev_sha="${sha}"
Yu Liu09a8d452023-05-12 17:22:30 -0700129 elif [ "${sha}" != "${prev_sha}" ] && { [ "${lib}" != "libcrypto.so" ] || [[ "${module}" != *"com.android.tethering" ]]; }; then
Yu Liue0c4d352023-02-24 16:45:19 -0800130 echo "Test failed, ${lib} has different hash value"
131 exit 1
132 fi
133 done
134 done
135 done
136}
137
138export UNBUNDLED_BUILD_SDKS_FROM_SOURCE=true # don't rely on prebuilts
139export TARGET_BUILD_APPS="${MODULES[@]}"
140for product in "${TARGET_PRODUCTS[@]}"; do
141 ###########
142 # Build the mainline modules
143 ###########
144 packages/modules/common/build/build_unbundled_mainline_module.sh \
145 --product "${product}" \
146 --dist_dir "${OUTPUT_DIR}/${product}"
147
Yu Liu09a8d452023-05-12 17:22:30 -0700148 bazel_apexes=()
149 if [[ -n ${TEST_BAZEL+x} ]] && [ "${TEST_BAZEL}" = true ]; then
150 export TARGET_PRODUCT="${product/module/aosp}"
151 call_bazel build --config=bp2build --config=ci --config=android "${BAZEL_TARGETS[@]}"
152 for target in "${BAZEL_TARGETS[@]}"; do
153 apex_path="$(realpath $(call_bazel cquery --config=bp2build --config=android --config=ci --output=files $target))"
154 mkdir -p ${OUTPUT_DIR}/${product}
155 bazel_apex="bazel_$(basename $apex_path)"
156 mv $apex_path ${OUTPUT_DIR}/${product}/${bazel_apex}
157 bazel_apexes+=(${bazel_apex%".apex"})
158 done
159 fi
160
161 all_modeuls=(${MODULES[@]} ${bazel_apexes[@]})
162 extract_dcla_libs "${product}" "${all_modeuls[@]}"
163 compare_dcla_libs "${product}" "${all_modeuls[@]}"
Yu Liue0c4d352023-02-24 16:45:19 -0800164done
165
166echo "Test passed"