Jingwen Chen | 26f0b21 | 2022-06-14 10:08:51 +0000 | [diff] [blame] | 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 | |
| 17 | set -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 | |
| 23 | if [ ! -e "build/make/core/Makefile" ]; then |
| 24 | echo "$0 must be run from the top of the Android source tree." |
| 25 | exit 1 |
| 26 | fi |
| 27 | |
| 28 | ############ |
| 29 | # Test Setup |
| 30 | ############ |
| 31 | |
Trevor Radcliffe | 59b3729 | 2023-05-22 17:55:18 +0000 | [diff] [blame] | 32 | OUTPUT_DIR="$(mktemp -d $(pwd)/tmp.XXXXXX)" |
Jingwen Chen | 26f0b21 | 2022-06-14 10:08:51 +0000 | [diff] [blame] | 33 | SOONG_OUTPUT_DIR="$OUTPUT_DIR/soong" |
| 34 | BAZEL_OUTPUT_DIR="$OUTPUT_DIR/bazel" |
| 35 | |
Wei Li | 94bf315 | 2022-12-05 15:26:36 -0800 | [diff] [blame] | 36 | export TARGET_PRODUCT="module_arm" |
| 37 | [ "$#" -eq 1 ] && export TARGET_PRODUCT="$1" |
| 38 | |
Sam Delmerico | b6d1b03 | 2022-08-08 12:07:16 -0400 | [diff] [blame] | 39 | function call_bazel() { |
Joe Onorato | ba29f38 | 2022-10-24 06:38:11 -0700 | [diff] [blame] | 40 | build/bazel/bin/bazel --output_base="$BAZEL_OUTPUT_DIR" $@ |
Sam Delmerico | b6d1b03 | 2022-08-08 12:07:16 -0400 | [diff] [blame] | 41 | } |
| 42 | |
Jingwen Chen | 26f0b21 | 2022-06-14 10:08:51 +0000 | [diff] [blame] | 43 | function cleanup { |
| 44 | # call bazel clean because some bazel outputs don't have w bits. |
| 45 | call_bazel clean |
| 46 | rm -rf "${OUTPUT_DIR}" |
| 47 | } |
Trevor Radcliffe | 59b3729 | 2023-05-22 17:55:18 +0000 | [diff] [blame] | 48 | |
| 49 | function deapexer() { |
| 50 | DEBUGFS_PATH="$(realpath $(call_bazel cquery --config=bp2build --config=linux_x86_64 --config=ci --output=files //external/e2fsprogs/debugfs))" |
| 51 | call_bazel run --config=bp2build //system/apex/tools:deapexer -- --debugfs_path=$DEBUGFS_PATH $@ |
| 52 | } |
| 53 | |
Jingwen Chen | 26f0b21 | 2022-06-14 10:08:51 +0000 | [diff] [blame] | 54 | trap cleanup EXIT |
| 55 | |
| 56 | ########### |
| 57 | # Run Soong |
| 58 | ########### |
| 59 | export UNBUNDLED_BUILD_SDKS_FROM_SOURCE=true # don't rely on prebuilts |
| 60 | export TARGET_BUILD_APPS="com.android.adbd com.android.tzdata build.bazel.examples.apex.minimal" |
| 61 | packages/modules/common/build/build_unbundled_mainline_module.sh \ |
Wei Li | 94bf315 | 2022-12-05 15:26:36 -0800 | [diff] [blame] | 62 | --product "$TARGET_PRODUCT" \ |
Jingwen Chen | 26f0b21 | 2022-06-14 10:08:51 +0000 | [diff] [blame] | 63 | --dist_dir "$SOONG_OUTPUT_DIR" |
| 64 | |
| 65 | ###################### |
| 66 | # Run bp2build / Bazel |
| 67 | ###################### |
| 68 | build/soong/soong_ui.bash --make-mode BP2BUILD_VERBOSE=1 --skip-soong-tests bp2build |
| 69 | |
Sam Delmerico | 73d6bcc | 2022-09-20 15:31:37 -0400 | [diff] [blame] | 70 | BAZEL_OUT="$(call_bazel info --config=bp2build output_path)" |
Jingwen Chen | 26f0b21 | 2022-06-14 10:08:51 +0000 | [diff] [blame] | 71 | |
Jingwen Chen | 60d8840 | 2022-09-07 11:03:33 +0000 | [diff] [blame] | 72 | call_bazel build --config=bp2build --config=ci --config=android \ |
Jingwen Chen | 26f0b21 | 2022-06-14 10:08:51 +0000 | [diff] [blame] | 73 | //packages/modules/adb/apex:com.android.adbd \ |
| 74 | //system/timezone/apex:com.android.tzdata \ |
Cole Faust | ebc01a3 | 2023-03-27 16:08:03 -0700 | [diff] [blame] | 75 | //build/bazel/examples/apex/minimal:build.bazel.examples.apex.minimal |
Cole Faust | b85d1a1 | 2022-11-08 18:14:01 -0800 | [diff] [blame] | 76 | BAZEL_ADBD="$(realpath $(call_bazel cquery --config=bp2build --config=android --config=ci --output=files //packages/modules/adb/apex:com.android.adbd))" |
| 77 | BAZEL_TZDATA="$(realpath $(call_bazel cquery --config=bp2build --config=android --config=ci --output=files //system/timezone/apex:com.android.tzdata))" |
Cole Faust | ebc01a3 | 2023-03-27 16:08:03 -0700 | [diff] [blame] | 78 | BAZEL_MINIMAL="$(realpath $(call_bazel cquery --config=bp2build --config=android --config=ci --output=files //build/bazel/examples/apex/minimal:build.bazel.examples.apex.minimal))" |
Jingwen Chen | 26f0b21 | 2022-06-14 10:08:51 +0000 | [diff] [blame] | 79 | |
Vinh Tran | cc1a017 | 2022-12-09 17:47:03 -0500 | [diff] [blame] | 80 | # # Build debugfs separately, as it's not a dep of apexer, but needs to be an explicit arg. |
Trevor Radcliffe | 59b3729 | 2023-05-22 17:55:18 +0000 | [diff] [blame] | 81 | call_bazel build --config=bp2build --config=linux_x86_64 //external/e2fsprogs/debugfs |
Jingwen Chen | 26f0b21 | 2022-06-14 10:08:51 +0000 | [diff] [blame] | 82 | |
| 83 | ####### |
| 84 | # Tests |
| 85 | ####### |
| 86 | |
| 87 | function compare_deapexer_list() { |
Cole Faust | b85d1a1 | 2022-11-08 18:14:01 -0800 | [diff] [blame] | 88 | local BAZEL_APEX=$1; shift |
Jingwen Chen | 26f0b21 | 2022-06-14 10:08:51 +0000 | [diff] [blame] | 89 | local APEX=$1; shift |
| 90 | |
| 91 | # Compare the outputs of `deapexer list`, which lists the contents of the apex filesystem image. |
| 92 | local SOONG_APEX="$SOONG_OUTPUT_DIR/$APEX" |
Jingwen Chen | 26f0b21 | 2022-06-14 10:08:51 +0000 | [diff] [blame] | 93 | |
| 94 | local SOONG_LIST="$OUTPUT_DIR/soong.list" |
| 95 | local BAZEL_LIST="$OUTPUT_DIR/bazel.list" |
| 96 | |
Trevor Radcliffe | 59b3729 | 2023-05-22 17:55:18 +0000 | [diff] [blame] | 97 | deapexer list "$SOONG_APEX" > "$SOONG_LIST" |
| 98 | deapexer list "$BAZEL_APEX" > "$BAZEL_LIST" |
Jingwen Chen | 26f0b21 | 2022-06-14 10:08:51 +0000 | [diff] [blame] | 99 | |
| 100 | if cmp -s "$SOONG_LIST" "$BAZEL_LIST" |
| 101 | then |
| 102 | echo "ok: $APEX" |
| 103 | else |
| 104 | echo "contents of $APEX are different between Soong and Bazel:" |
| 105 | echo |
| 106 | echo expected |
| 107 | echo |
| 108 | cat "$SOONG_LIST" |
| 109 | echo |
| 110 | echo got |
| 111 | echo |
| 112 | cat "$BAZEL_LIST" |
| 113 | exit 1 |
| 114 | fi |
| 115 | } |
| 116 | |
Cole Faust | b85d1a1 | 2022-11-08 18:14:01 -0800 | [diff] [blame] | 117 | compare_deapexer_list "${BAZEL_ADBD}" com.android.adbd.apex |
| 118 | compare_deapexer_list "${BAZEL_TZDATA}" com.android.tzdata.apex |
| 119 | compare_deapexer_list "${BAZEL_MINIMAL}" build.bazel.examples.apex.minimal.apex |