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 | |
| 32 | OUTPUT_DIR="$(mktemp -d)" |
| 33 | SOONG_OUTPUT_DIR="$OUTPUT_DIR/soong" |
| 34 | BAZEL_OUTPUT_DIR="$OUTPUT_DIR/bazel" |
| 35 | |
| 36 | function cleanup { |
| 37 | # call bazel clean because some bazel outputs don't have w bits. |
| 38 | call_bazel clean |
| 39 | rm -rf "${OUTPUT_DIR}" |
| 40 | } |
| 41 | trap cleanup EXIT |
| 42 | |
| 43 | ########### |
| 44 | # Run Soong |
| 45 | ########### |
| 46 | export UNBUNDLED_BUILD_SDKS_FROM_SOURCE=true # don't rely on prebuilts |
| 47 | export TARGET_BUILD_APPS="com.android.adbd com.android.tzdata build.bazel.examples.apex.minimal" |
| 48 | packages/modules/common/build/build_unbundled_mainline_module.sh \ |
| 49 | --product module_arm \ |
| 50 | --dist_dir "$SOONG_OUTPUT_DIR" |
| 51 | |
| 52 | ###################### |
| 53 | # Run bp2build / Bazel |
| 54 | ###################### |
| 55 | build/soong/soong_ui.bash --make-mode BP2BUILD_VERBOSE=1 --skip-soong-tests bp2build |
| 56 | |
| 57 | function call_bazel() { |
| 58 | tools/bazel --output_base="$BAZEL_OUTPUT_DIR" $@ |
| 59 | } |
| 60 | BAZEL_OUT="$(call_bazel info output_path)" |
| 61 | |
| 62 | call_bazel build --config=bp2build --config=ci --config=android_arm \ |
| 63 | //packages/modules/adb/apex:com.android.adbd \ |
| 64 | //system/timezone/apex:com.android.tzdata \ |
| 65 | //build/bazel/examples/apex/minimal:build.bazel.examples.apex.minimal.apex |
| 66 | |
| 67 | # Build debugfs separately, as it's not a dep of apexer, but needs to be an explicit arg. |
| 68 | call_bazel build --config=bp2build --config=linux_x86_64 //external/e2fsprogs/debugfs |
| 69 | DEBUGFS_PATH="$BAZEL_OUT/linux_x86_64-fastbuild/bin/external/e2fsprogs/debugfs/debugfs" |
| 70 | |
| 71 | function run_deapexer() { |
| 72 | call_bazel run --config=bp2build --config=linux_x86_64 //system/apex/tools:deapexer \ |
| 73 | -- \ |
| 74 | --debugfs_path="$DEBUGFS_PATH" \ |
| 75 | $@ |
| 76 | } |
| 77 | |
| 78 | ####### |
| 79 | # Tests |
| 80 | ####### |
| 81 | |
| 82 | function compare_deapexer_list() { |
| 83 | local APEX_DIR=$1; shift |
| 84 | local APEX=$1; shift |
| 85 | |
| 86 | # Compare the outputs of `deapexer list`, which lists the contents of the apex filesystem image. |
| 87 | local SOONG_APEX="$SOONG_OUTPUT_DIR/$APEX" |
| 88 | local BAZEL_APEX="$BAZEL_OUT/android_arm-fastbuild/bin/$APEX_DIR/$APEX" |
| 89 | |
| 90 | local SOONG_LIST="$OUTPUT_DIR/soong.list" |
| 91 | local BAZEL_LIST="$OUTPUT_DIR/bazel.list" |
| 92 | |
| 93 | run_deapexer list "$SOONG_APEX" > "$SOONG_LIST" |
| 94 | run_deapexer list "$BAZEL_APEX" > "$BAZEL_LIST" |
| 95 | |
| 96 | if cmp -s "$SOONG_LIST" "$BAZEL_LIST" |
| 97 | then |
| 98 | echo "ok: $APEX" |
| 99 | else |
| 100 | echo "contents of $APEX are different between Soong and Bazel:" |
| 101 | echo |
| 102 | echo expected |
| 103 | echo |
| 104 | cat "$SOONG_LIST" |
| 105 | echo |
| 106 | echo got |
| 107 | echo |
| 108 | cat "$BAZEL_LIST" |
| 109 | exit 1 |
| 110 | fi |
| 111 | } |
| 112 | |
| 113 | compare_deapexer_list packages/modules/adb/apex com.android.adbd.apex |
| 114 | compare_deapexer_list system/timezone/apex com.android.tzdata.apex |
| 115 | compare_deapexer_list build/bazel/examples/apex/minimal build.bazel.examples.apex.minimal.apex |