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