• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -eux
2# Verifies that bp2build-generated BUILD files result in successful Bazel
3# builds.
4#
5# This verification script is designed to be used for continuous integration
6# tests, though may also be used for manual developer verification.
7
8#######
9# Setup
10#######
11
12# Set the test output directories.
13AOSP_ROOT="$(dirname $0)/../../.."
14OUT_DIR=$(realpath ${OUT_DIR:-${AOSP_ROOT}/out})
15if [[ -z ${DIST_DIR+x} ]]; then
16  DIST_DIR="${OUT_DIR}/dist"
17  echo "DIST_DIR not set. Using ${OUT_DIR}/dist. This should only be used for manual developer testing."
18fi
19
20# Before you add flags to this list, cosnider adding it to the "ci" bazelrc
21# config instead of this list so that flags are not duplicated between scripts
22# and bazelrc, and bazelrc is the Bazel-native way of organizing flags.
23FLAGS=(
24  --config=bp2build
25  --config=ci
26)
27FLAGS="${FLAGS[@]}"
28
29source "$(dirname $0)/build_with_bazel.sh"
30source "$(dirname $0)/target_lists.sh"
31
32###############
33# Build and test targets for device target platform.
34###############
35
36build_for_device BUILD_TARGETS TEST_TARGETS
37
38declare -a host_targets
39host_targets+=( "${BUILD_TARGETS[@]}" )
40host_targets+=( "${TEST_TARGETS[@]}" )
41host_targets+=( "${HOST_INCOMPATIBLE_TARGETS[@]}" )
42host_targets+=( "${HOST_ONLY_TEST_TARGETS[@]}" )
43
44build_for_host ${host_targets[@]}
45
46#########################################################################
47# Check that rule wrappers have the same providers as the rules they wrap
48#########################################################################
49
50source "$(dirname $0)/../rules/java/wrapper_test.sh"
51test_wrapper_providers
52
53###################
54# bp2build progress
55###################
56
57function get_soong_names_from_queryview() {
58  names=$( build/bazel/bin/bazel query --config=ci --config=queryview --output=xml "${@}" \
59    | awk -F'"' '$2 ~ /soong_module_name/ { print $4 }' \
60    | sort -u )
61  echo "${names[@]}"
62}
63
64# Generate bp2build progress reports and graphs for these modules into the dist
65# dir so that they can be downloaded from the CI artifact list.
66BP2BUILD_PROGRESS_MODULES=(
67  NetworkStackNext  # not updatable but will be
68  android_module_lib_stubs_current
69  android_stubs_current
70  android_system_server_stubs_current
71  android_system_stubs_current
72  android_test_stubs_current
73  build-tools  # host sdk
74  com.android.runtime  # not updatable but will be
75  core-lambda-stubs  # DefaultLambdaStubsPath, StableCorePlatformBootclasspathLibraries
76  core-public-stubs-system-modules
77  ext  # FrameworkLibraries
78  framework  # FrameworkLibraries
79  framework-minus-apex
80  framework-res # sdk dep Framework Res Module
81  legacy-core-platform-api-stubs-system-modules
82  legacy.core.platform.api.stubs
83  platform-tools  # host sdk
84  sdk
85  stable-core-platform-api-stubs-system-modules  # StableCorePlatformSystemModules
86  stable.core.platform.api.stubs # StableCorePlatformBootclasspathLibraries
87)
88
89# Query for some module types of interest so that we don't have to hardcode the
90# lists
91"${AOSP_ROOT}/build/soong/soong_ui.bash" --make-mode BP2BUILD_VERBOSE=1 --skip-soong-tests queryview
92rm -f out/ninja_build
93
94# Only apexes/apps that specify updatable=1 are mainline modules, the other are
95# "just" apexes/apps. Often this is not specified in the process of becoming a
96# mainline module as enables a number of validations.
97# Ignore defaults and test rules.
98APEX_QUERY='attr(updatable, 1, //...) - kind("_defaults rule", //...) - kind("apex_test_ rule", //...)'
99APEX_VNDK_QUERY="kind(\"apex_vndk rule\", //...)"
100
101BP2BUILD_PROGRESS_MODULES+=( $(get_soong_names_from_queryview "${APEX_QUERY}"" + ""${APEX_VNDK_QUERY}" ) )
102
103bp2build_progress_script="//build/bazel/scripts/bp2build_progress:bp2build_progress"
104bp2build_progress_output_dir="${DIST_DIR}/bp2build-progress"
105mkdir -p "${bp2build_progress_output_dir}"
106
107report_args=""
108for m in "${BP2BUILD_PROGRESS_MODULES[@]}"; do
109  report_args="$report_args -m ""${m}"
110  if [[ "${m}" =~ (media.swcodec|neuralnetworks)$ ]]; then
111    build/bazel/bin/bazel run ${FLAGS} --config=linux_x86_64 "${bp2build_progress_script}" -- graph  -m "${m}" --out-file=$( realpath "${bp2build_progress_output_dir}" )"/${m}_graph.dot"
112  fi
113done
114
115build/bazel/bin/bazel run ${FLAGS} --config=linux_x86_64 "${bp2build_progress_script}" -- \
116  report ${report_args} \
117  --proto-file=$( realpath "${bp2build_progress_output_dir}" )"/bp2build-progress.pb" \
118  --out-file=$( realpath "${bp2build_progress_output_dir}" )"/progress_report.txt" \
119