• 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.
13SOURCE_ROOT="$(dirname $0)/../../.."
14OUT_DIR=$(realpath ${OUT_DIR:-${SOURCE_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 DEVICE_ONLY_TARGETS
37
38declare -a host_targets
39host_targets+=( "${BUILD_TARGETS[@]}" )
40host_targets+=( "${TEST_TARGETS[@]}" )
41host_targets+=( "${HOST_ONLY_TEST_TARGETS[@]}" )
42
43build_and_test_for_host ${host_targets[@]}
44
45#########################################################################
46# Check that rule wrappers have the same providers as the rules they wrap
47#########################################################################
48
49source "$(dirname $0)/../rules/java/wrapper_test.sh"
50test_wrapper_providers
51
52###################
53# bp2build progress
54###################
55
56function get_soong_names_from_queryview() {
57  names=$( build/bazel/bin/bazel query --config=ci --config=queryview --output=xml "${@}" \
58    | awk -F'"' '$2 ~ /soong_module_name/ { print $4 }' \
59    | sort -u )
60  echo "${names[@]}"
61}
62
63# Generate bp2build progress reports and graphs for these modules into the dist
64# dir so that they can be downloaded from the CI artifact list.
65BP2BUILD_PROGRESS_MODULES=(
66  NetworkStackNext  # not updatable but will be
67  android_module_lib_stubs_current
68  android_stubs_current
69  android_system_server_stubs_current
70  android_system_stubs_current
71  android_test_stubs_current
72  build-tools  # host sdk
73  com.android.runtime  # not updatable but will be
74  core-lambda-stubs  # DefaultLambdaStubsPath, StableCorePlatformBootclasspathLibraries
75  core-public-stubs-system-modules
76  ext  # FrameworkLibraries
77  framework  # FrameworkLibraries
78  framework-minus-apex
79  framework-res # sdk dep Framework Res Module
80  legacy-core-platform-api-stubs-system-modules
81  legacy.core.platform.api.stubs
82  platform-tools  # host sdk
83  sdk
84  stable-core-platform-api-stubs-system-modules  # StableCorePlatformSystemModules
85  stable.core.platform.api.stubs # StableCorePlatformBootclasspathLibraries
86)
87
88# Query for some module types of interest so that we don't have to hardcode the
89# lists
90"${SOURCE_ROOT}/build/soong/soong_ui.bash" --make-mode BP2BUILD_VERBOSE=1 --skip-soong-tests queryview
91rm -f out/ninja_build
92
93# Only apexes/apps that specify updatable=1 are mainline modules, the other are
94# "just" apexes/apps. Often this is not specified in the process of becoming a
95# mainline module as enables a number of validations.
96# Ignore defaults and test rules.
97APEX_QUERY='attr(updatable, 1, //...) - kind("_defaults rule", //...) - kind("apex_test_ rule", //...)'
98APEX_VNDK_QUERY="kind(\"apex_vndk rule\", //...)"
99
100BP2BUILD_PROGRESS_MODULES+=( $(get_soong_names_from_queryview "${APEX_QUERY}"" + ""${APEX_VNDK_QUERY}" ) )
101
102bp2build_progress_script="//build/bazel/scripts/bp2build_progress:bp2build_progress"
103bp2build_progress_output_dir="${DIST_DIR}/bp2build-progress"
104mkdir -p "${bp2build_progress_output_dir}"
105
106report_args=""
107for m in "${BP2BUILD_PROGRESS_MODULES[@]}"; do
108  report_args="$report_args -m ""${m}"
109  if [[ "${m}" =~ (media.swcodec|neuralnetworks)$ ]]; then
110    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"
111  fi
112done
113
114build/bazel/bin/bazel run ${FLAGS} --config=linux_x86_64 "${bp2build_progress_script}" -- \
115  report ${report_args} \
116  --proto-file=$( realpath "${bp2build_progress_output_dir}" )"/bp2build-progress.pb" \
117  --out-file=$( realpath "${bp2build_progress_output_dir}" )"/progress_report.txt" \
118  --bp2build-metrics-location=$( realpath "${DIST_DIR}" )"/logs" \
119