1#!/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 48DCLA_LIBS=( 49 libbase.so 50 libc++.so 51 libcrypto.so 52 libcutils.so 53) 54 55if [[ -z ${OUT_DIR+x} ]]; then 56 OUT_DIR="out" 57fi 58 59if [[ -z ${ANDROID_HOST_OUT+x} ]]; then 60 export ANDROID_HOST_OUT="out/host/linux-x86" 61fi 62 63###################### 64# Build deapexer and debugfs 65###################### 66DEAPEXER="${ANDROID_HOST_OUT}/bin/deapexer" 67DEBUGFS="${ANDROID_HOST_OUT}/bin/debugfs" 68if [[ ! -f "${DEAPEXER}" ]] || [[ ! -f "${DEBUGFS}" ]]; then 69 build/soong/soong_ui.bash --make-mode --skip-soong-tests deapexer debugfs 70fi 71 72DEAPEXER="${DEAPEXER} --debugfs_path=${DEBUGFS}" 73 74############ 75# Test Setup 76############ 77OUTPUT_DIR="$(mktemp -d tmp.XXXXXX)" 78 79function cleanup { 80 rm -rf "${OUTPUT_DIR}" 81} 82trap cleanup EXIT 83 84####### 85# Tests 86####### 87 88function extract_dcla_libs() { 89 local product=$1; shift 90 for module in "${MODULES[@]}"; do 91 local apex="${OUTPUT_DIR}/${product}/${module}.apex" 92 local extract_dir="${OUTPUT_DIR}/${product}/${module}/extract" 93 94 $DEAPEXER extract "${apex}" "${extract_dir}" 95 done 96} 97 98function compare_dcla_libs() { 99 local product=$1; shift 100 101 for lib in "${DCLA_LIBS[@]}"; do 102 for arch in lib lib64; do 103 local prev_sha="" 104 for module in "${MODULES[@]}"; do 105 local file="${OUTPUT_DIR}/${product}/${module}/extract/${arch}/${lib}" 106 if [[ ! -f "${file}" ]]; then 107 # not all libs are present in a module 108 echo "file doesn't exist: ${file}" 109 continue 110 fi 111 sha=$(sha1sum ${file}) 112 sha="${sha% *}" 113 if [ "${prev_sha}" == "" ]; then 114 prev_sha="${sha}" 115 elif [ "${sha}" != "${prev_sha}" ] && { [ "${lib}" != "libcrypto.so" ] || [ "${module}" != "com.android.tethering" ]; }; then 116 echo "Test failed, ${lib} has different hash value" 117 exit 1 118 fi 119 done 120 done 121 done 122} 123 124export UNBUNDLED_BUILD_SDKS_FROM_SOURCE=true # don't rely on prebuilts 125export TARGET_BUILD_APPS="${MODULES[@]}" 126for product in "${TARGET_PRODUCTS[@]}"; do 127 ########### 128 # Build the mainline modules 129 ########### 130 packages/modules/common/build/build_unbundled_mainline_module.sh \ 131 --product "${product}" \ 132 --dist_dir "${OUTPUT_DIR}/${product}" 133 134 extract_dcla_libs "${product}" 135 compare_dcla_libs "${product}" 136done 137 138echo "Test passed" 139