Yu Liu | e0c4d35 | 2023-02-24 16:45:19 -0800 | [diff] [blame] | 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 | |
| 17 | set -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 | |
| 22 | if [ ! -e "build/make/core/Makefile" ]; then |
| 23 | echo "$0 must be run from the top of the Android source tree." |
| 24 | exit 1 |
| 25 | fi |
| 26 | |
| 27 | TARGET_PRODUCTS=( |
| 28 | module_arm64 |
| 29 | module_x86_64 |
| 30 | ) |
| 31 | |
| 32 | MODULES=( |
| 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 Liu | 09a8d45 | 2023-05-12 17:22:30 -0700 | [diff] [blame^] | 48 | BAZEL_TARGETS=( |
| 49 | //packages/modules/adb/apex:com.android.adbd |
| 50 | //frameworks/av/apex:com.android.media.swcodec |
| 51 | ) |
| 52 | |
Yu Liu | e0c4d35 | 2023-02-24 16:45:19 -0800 | [diff] [blame] | 53 | DCLA_LIBS=( |
| 54 | libbase.so |
| 55 | libc++.so |
| 56 | libcrypto.so |
| 57 | libcutils.so |
| 58 | ) |
| 59 | |
| 60 | if [[ -z ${OUT_DIR+x} ]]; then |
| 61 | OUT_DIR="out" |
| 62 | fi |
| 63 | |
| 64 | if [[ -z ${ANDROID_HOST_OUT+x} ]]; then |
| 65 | export ANDROID_HOST_OUT="out/host/linux-x86" |
| 66 | fi |
| 67 | |
| 68 | ###################### |
| 69 | # Build deapexer and debugfs |
| 70 | ###################### |
| 71 | DEAPEXER="${ANDROID_HOST_OUT}/bin/deapexer" |
| 72 | DEBUGFS="${ANDROID_HOST_OUT}/bin/debugfs" |
| 73 | if [[ ! -f "${DEAPEXER}" ]] || [[ ! -f "${DEBUGFS}" ]]; then |
| 74 | build/soong/soong_ui.bash --make-mode --skip-soong-tests deapexer debugfs |
| 75 | fi |
| 76 | |
| 77 | DEAPEXER="${DEAPEXER} --debugfs_path=${DEBUGFS}" |
| 78 | |
| 79 | ############ |
| 80 | # Test Setup |
| 81 | ############ |
| 82 | OUTPUT_DIR="$(mktemp -d tmp.XXXXXX)" |
| 83 | |
Yu Liu | 09a8d45 | 2023-05-12 17:22:30 -0700 | [diff] [blame^] | 84 | function call_bazel() { |
| 85 | build/bazel/bin/bazel $@ |
| 86 | } |
| 87 | |
Yu Liu | e0c4d35 | 2023-02-24 16:45:19 -0800 | [diff] [blame] | 88 | function cleanup { |
| 89 | rm -rf "${OUTPUT_DIR}" |
| 90 | } |
| 91 | trap cleanup EXIT |
| 92 | |
| 93 | ####### |
| 94 | # Tests |
| 95 | ####### |
| 96 | |
| 97 | function extract_dcla_libs() { |
| 98 | local product=$1; shift |
Yu Liu | 09a8d45 | 2023-05-12 17:22:30 -0700 | [diff] [blame^] | 99 | local modules=("$@"); shift |
| 100 | |
| 101 | for module in "${modules[@]}"; do |
Yu Liu | e0c4d35 | 2023-02-24 16:45:19 -0800 | [diff] [blame] | 102 | 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 | |
| 109 | function compare_dcla_libs() { |
| 110 | local product=$1; shift |
Yu Liu | 09a8d45 | 2023-05-12 17:22:30 -0700 | [diff] [blame^] | 111 | local modules=("$@"); shift |
Yu Liu | e0c4d35 | 2023-02-24 16:45:19 -0800 | [diff] [blame] | 112 | |
| 113 | for lib in "${DCLA_LIBS[@]}"; do |
| 114 | for arch in lib lib64; do |
| 115 | local prev_sha="" |
Yu Liu | 09a8d45 | 2023-05-12 17:22:30 -0700 | [diff] [blame^] | 116 | for module in "${modules[@]}"; do |
Yu Liu | e0c4d35 | 2023-02-24 16:45:19 -0800 | [diff] [blame] | 117 | 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 Liu | 09a8d45 | 2023-05-12 17:22:30 -0700 | [diff] [blame^] | 127 | elif [ "${sha}" != "${prev_sha}" ] && { [ "${lib}" != "libcrypto.so" ] || [[ "${module}" != *"com.android.tethering" ]]; }; then |
Yu Liu | e0c4d35 | 2023-02-24 16:45:19 -0800 | [diff] [blame] | 128 | echo "Test failed, ${lib} has different hash value" |
| 129 | exit 1 |
| 130 | fi |
| 131 | done |
| 132 | done |
| 133 | done |
| 134 | } |
| 135 | |
| 136 | export UNBUNDLED_BUILD_SDKS_FROM_SOURCE=true # don't rely on prebuilts |
| 137 | export TARGET_BUILD_APPS="${MODULES[@]}" |
| 138 | for 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 Liu | 09a8d45 | 2023-05-12 17:22:30 -0700 | [diff] [blame^] | 146 | 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 Liu | e0c4d35 | 2023-02-24 16:45:19 -0800 | [diff] [blame] | 162 | done |
| 163 | |
| 164 | echo "Test passed" |