• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -eux
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# Verifies mixed builds does not run if neither --bazel-mode-dev nor --bazel-mode
18# is set.
19# This verification script is designed to be used for continuous integration
20# tests, though may also be used for manual developer verification.
21
22STARTUP_FLAGS=(
23  --max_idle_secs=5
24)
25
26# Before you add flags to this list, cosnider adding it to the "ci" bazelrc
27# config instead of this list so that flags are not duplicated between scripts
28# and bazelrc, and bazelrc is the Bazel-native way of organizing flags.
29FLAGS=(
30  --config=bp2build
31  --config=ci
32  --keep_going
33)
34
35function build_for_device() {
36  local -n build_targets=$1
37  local -n test_targets=$2
38  ###########
39  # Iterate over various products supported in the platform build.
40  ###########
41  product_prefix="aosp_"
42  for arch in arm arm64 x86 x86_64; do
43    # Re-run product config and bp2build for every TARGET_PRODUCT.
44    product=${product_prefix}${arch}
45    "${AOSP_ROOT}/build/soong/soong_ui.bash" --make-mode BP2BUILD_VERBOSE=1 TARGET_PRODUCT=${product} --skip-soong-tests bp2build dist
46    # Remove the ninja_build output marker file to communicate to buildbot that this is not a regular Ninja build, and its
47    # output should not be parsed as such.
48    rm -f out/ninja_build
49
50    # Dist the entire workspace of generated BUILD files, rooted from
51    # out/soong/bp2build. This is done early so it's available even if
52    # builds/tests fail. Currently the generated BUILD files can be different
53    # between products due to Soong plugins and non-deterministic codegeneration.
54    # We tar and gzip in separate steps because when using tar -z, you can't tell it to not include
55    # a timestamp in the gzip header.
56    tar c --mtime='1970-01-01' -C out/soong/bp2build . | gzip -n > "${DIST_DIR}/bp2build_generated_workspace_${product}.tar.gz"
57
58    local device_startup_flags=(
59      # Unique output bases per product to help with incremental builds across
60      # invocations of this script.
61      # e.g. the second invocation of this script for aosp_x86 would use the output_base
62      # of aosp_x86 from the first invocation.
63      --output_base="${OUT_DIR}/bazel/test_output_bases/${product}"
64    )
65    device_startup_flags+=( "${STARTUP_FLAGS[@]}" )
66
67    # Use a loop to prevent unnecessarily switching --platforms because that drops
68    # the Bazel analysis cache.
69    #
70    # 1. Build every target in $BUILD_TARGETS
71    build/bazel/bin/bazel ${device_startup_flags[@]} \
72      build ${FLAGS[@]} --config=android -- \
73      ${build_targets[@]}
74
75    # 2. Test every target that is compatible with an android target platform (e.g. analysis_tests, sh_tests, diff_tests).
76    build/bazel/bin/bazel ${device_startup_flags[@]} \
77      test ${FLAGS[@]} --build_tests_only --config=android -- \
78      ${test_targets[@]}
79
80    # 3. Dist mainline modules.
81    build/bazel/bin/bazel ${device_startup_flags[@]} \
82      run //build/bazel/ci/dist:mainline_modules ${FLAGS[@]} \
83      --config=android -- \
84      --dist_dir="${DIST_DIR}/mainline_modules_${arch}"
85  done
86}
87
88function build_for_host() {
89  targets=("$@")
90  # We can safely build and test all targets on the host linux config, and rely on
91  # incompatible target skipping for tests that cannot run on the host.
92  build/bazel/bin/bazel \
93    "${STARTUP_FLAGS[@]}" test ${FLAGS[@]} --build_tests_only=false \
94    -- ${targets[@]}
95}
96