1#!/bin/bash -eux 2 3source "$(dirname $0)/target_lists.sh" 4cd "$(dirname $0)/../../.." 5OUT_DIR=$(realpath ${OUT_DIR:-out}) 6DIST_DIR=$(realpath ${DIST_DIR:-out/dist}) 7 8 9read -ra PRODUCTS <<<"$(build/soong/soong_ui.bash --dumpvar-mode all_named_products)" 10 11FAILED_PRODUCTS=() 12PRODUCTS_WITH_BP2BUILD_DIFFS=() 13 14function report { 15 # Turn off -x so that we can see the printfs more clearly 16 set +x 17 # check if FAILED_PRODUCTS is not empty 18 if (( ${#FAILED_PRODUCTS[@]} )); then 19 printf "Failed products:\n" 20 printf '%s\n' "${FAILED_PRODUCTS[@]}" 21 22 # TODO(b/262192655): Support riscv64 products in Bazel. 23 # TODO(b/261023967): Don't fail the build until every product is OK and we want to prevent backsliding. 24 # exit 1 25 fi 26 if (( ${#PRODUCTS_WITH_BP2BUILD_DIFFS[@]} )); then 27 printf "\n\nProducts that produced different bp2build files from aosp_arm64:\n" 28 printf '%s\n' "${PRODUCTS_WITH_BP2BUILD_DIFFS[@]}" 29 30 # TODO(b/261023967): Don't fail the build until every product is OK and we want to prevent backsliding. 31 # exit 1 32 fi 33} 34 35trap report EXIT 36 37rm -rf "${DIST_DIR}/multiproduct_analysis" 38mkdir -p "${DIST_DIR}/multiproduct_analysis" 39 40# Create zip of the bp2build files for aosp_arm64. We'll check that all other products produce 41# identical bp2build files. 42# We have to run tar and gzip as separate commands because tar with -z doesn't provide an option 43# to not include a timestamp in the gzip header. (--mtime is only for the tar parts, not gzip) 44export TARGET_PRODUCT="aosp_arm64" 45build/soong/soong_ui.bash --make-mode --skip-soong-tests bp2build 46tar c --mtime='1970-01-01' -C out/soong/bp2build . | gzip -n > "${DIST_DIR}/multiproduct_analysis/reference_bp2build_files_aosp_arm64.tar.gz" 47 48total=${#PRODUCTS[@]} 49count=1 50 51for product in "${PRODUCTS[@]}"; do 52 echo "Product ${count}/${total}: ${product}" 53 54 # Ensure that all processes later use the same TARGET_PRODUCT. 55 export TARGET_PRODUCT="${product}" 56 57 # Re-run product config and bp2build for every TARGET_PRODUCT. 58 build/soong/soong_ui.bash --make-mode --skip-soong-tests bp2build 59 # Remove the ninja_build output marker file to communicate to buildbot that this is not a regular Ninja build, and its 60 # output should not be parsed as such. 61 rm -f out/ninja_build 62 63 rm -f out/multiproduct_analysis_current_bp2build_files.tar.gz 64 tar c --mtime='1970-01-01' -C out/soong/bp2build . | gzip -n > "${DIST_DIR}/multiproduct_analysis/bp2build_files_${product}.tar.gz" 65 if diff -q "${DIST_DIR}/multiproduct_analysis/bp2build_files_${product}.tar.gz" "${DIST_DIR}/multiproduct_analysis/reference_bp2build_files_aosp_arm64.tar.gz"; then 66 rm -f "${DIST_DIR}/multiproduct_analysis/bp2build_files_${product}.tar.gz" 67 else 68 PRODUCTS_WITH_BP2BUILD_DIFFS+=("${product}") 69 fi 70 71 STARTUP_FLAGS=( 72 # Keep the Bazel server alive, package cache hot and reduce excessive I/O 73 # and wall time by ensuring that max_idle_secs is longer than bp2build which 74 # runs in every loop. bp2build takes ~20 seconds to run, so set this to a 75 # minute to account for resource contention, but still ensure that the bazel 76 # server doesn't stick around after. 77 --max_idle_secs=60 78 ) 79 80 FLAGS=( 81 --config=bp2build 82 --config=ci 83 --nobuild 84 --keep_going 85 ) 86 87 build/bazel/bin/bazel ${STARTUP_FLAGS[@]} build ${FLAGS[@]} --config=linux_x86_64 -- ${BUILD_TARGETS} || \ 88 FAILED_PRODUCTS+=("${product} --config=linux_x86_64") 89 90 build/bazel/bin/bazel ${STARTUP_FLAGS[@]} build ${FLAGS[@]} --config=android -- ${BUILD_TARGETS} || \ 91 FAILED_PRODUCTS+=("${product} --config=android") 92 93 count=$((count+1)) 94done 95 96