• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3# Copyright (C) 2022 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
17set -euo pipefail
18
19# Soong/Bazel integration test for building unbundled apexes in the real source tree.
20#
21# These tests build artifacts from head and compares their contents.
22
23if [ ! -e "build/make/core/Makefile" ]; then
24  echo "$0 must be run from the top of the Android source tree."
25  exit 1
26fi
27
28############
29# Test Setup
30############
31
32OUTPUT_DIR="$(mktemp -d tmp.XXXXXX)"
33SOONG_OUTPUT_DIR="$OUTPUT_DIR/soong"
34BAZEL_OUTPUT_DIR="$OUTPUT_DIR/bazel"
35
36export TARGET_PRODUCT="module_arm"
37[ "$#" -eq 1 ] && export TARGET_PRODUCT="$1"
38
39function call_bazel() {
40  build/bazel/bin/bazel --output_base="$BAZEL_OUTPUT_DIR" $@
41}
42
43function cleanup {
44  # call bazel clean because some bazel outputs don't have w bits.
45  call_bazel clean
46  rm -rf "${OUTPUT_DIR}"
47}
48trap cleanup EXIT
49
50###########
51# Run Soong
52###########
53export UNBUNDLED_BUILD_SDKS_FROM_SOURCE=true # don't rely on prebuilts
54export TARGET_BUILD_APPS="com.android.adbd com.android.tzdata build.bazel.examples.apex.minimal"
55packages/modules/common/build/build_unbundled_mainline_module.sh \
56  --product "$TARGET_PRODUCT" \
57  --dist_dir "$SOONG_OUTPUT_DIR"
58
59######################
60# Run bp2build / Bazel
61######################
62build/soong/soong_ui.bash --make-mode BP2BUILD_VERBOSE=1 --skip-soong-tests bp2build
63
64BAZEL_OUT="$(call_bazel info --config=bp2build output_path)"
65
66call_bazel build --config=bp2build --config=ci --config=android \
67  //packages/modules/adb/apex:com.android.adbd \
68  //system/timezone/apex:com.android.tzdata \
69  //build/bazel/examples/apex/minimal:build.bazel.examples.apex.minimal
70BAZEL_ADBD="$(realpath $(call_bazel cquery --config=bp2build --config=android --config=ci --output=files //packages/modules/adb/apex:com.android.adbd))"
71BAZEL_TZDATA="$(realpath $(call_bazel cquery --config=bp2build --config=android --config=ci --output=files //system/timezone/apex:com.android.tzdata))"
72BAZEL_MINIMAL="$(realpath $(call_bazel cquery --config=bp2build --config=android --config=ci --output=files //build/bazel/examples/apex/minimal:build.bazel.examples.apex.minimal))"
73
74# # Build debugfs separately, as it's not a dep of apexer, but needs to be an explicit arg.
75call_bazel build --config=bp2build --config=linux_x86_64 //external/e2fsprogs/debugfs //system/apex/tools:deapexer
76DEBUGFS_PATH="$(realpath $(call_bazel cquery --config=bp2build --config=linux_x86_64 --config=ci --output=files //external/e2fsprogs/debugfs))"
77DEAPEXER="bazel-bin/system/apex/tools/deapexer"
78DEAPEXER="$DEAPEXER --debugfs_path=$DEBUGFS_PATH"
79
80#######
81# Tests
82#######
83
84function compare_deapexer_list() {
85  local BAZEL_APEX=$1; shift
86  local APEX=$1; shift
87
88  # Compare the outputs of `deapexer list`, which lists the contents of the apex filesystem image.
89  local SOONG_APEX="$SOONG_OUTPUT_DIR/$APEX"
90
91  local SOONG_LIST="$OUTPUT_DIR/soong.list"
92  local BAZEL_LIST="$OUTPUT_DIR/bazel.list"
93
94  $DEAPEXER list "$SOONG_APEX" > "$SOONG_LIST"
95  $DEAPEXER list "$BAZEL_APEX" > "$BAZEL_LIST"
96
97  if cmp -s "$SOONG_LIST" "$BAZEL_LIST"
98  then
99    echo "ok: $APEX"
100  else
101    echo "contents of $APEX are different between Soong and Bazel:"
102    echo
103    echo expected
104    echo
105    cat "$SOONG_LIST"
106    echo
107    echo got
108    echo
109    cat "$BAZEL_LIST"
110    exit 1
111  fi
112}
113
114compare_deapexer_list "${BAZEL_ADBD}" com.android.adbd.apex
115compare_deapexer_list "${BAZEL_TZDATA}" com.android.tzdata.apex
116compare_deapexer_list "${BAZEL_MINIMAL}" build.bazel.examples.apex.minimal.apex
117