apex_comparison_tests.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #!/bin/bash
  2. # Copyright (C) 2022 The Android Open Source Project
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. set -euo pipefail
  16. # Soong/Bazel integration test for building unbundled apexes in the real source tree.
  17. #
  18. # These tests build artifacts from head and compares their contents.
  19. if [ ! -e "build/make/core/Makefile" ]; then
  20. echo "$0 must be run from the top of the Android source tree."
  21. exit 1
  22. fi
  23. ############
  24. # Test Setup
  25. ############
  26. OUTPUT_DIR="$(mktemp -d)"
  27. SOONG_OUTPUT_DIR="$OUTPUT_DIR/soong"
  28. BAZEL_OUTPUT_DIR="$OUTPUT_DIR/bazel"
  29. function call_bazel() {
  30. build/bazel/bin/bazel --output_base="$BAZEL_OUTPUT_DIR" $@
  31. }
  32. function cleanup {
  33. # call bazel clean because some bazel outputs don't have w bits.
  34. call_bazel clean
  35. rm -rf "${OUTPUT_DIR}"
  36. }
  37. trap cleanup EXIT
  38. ###########
  39. # Run Soong
  40. ###########
  41. export UNBUNDLED_BUILD_SDKS_FROM_SOURCE=true # don't rely on prebuilts
  42. export TARGET_BUILD_APPS="com.android.adbd com.android.tzdata build.bazel.examples.apex.minimal"
  43. packages/modules/common/build/build_unbundled_mainline_module.sh \
  44. --product module_arm \
  45. --dist_dir "$SOONG_OUTPUT_DIR"
  46. ######################
  47. # Run bp2build / Bazel
  48. ######################
  49. build/soong/soong_ui.bash --make-mode BP2BUILD_VERBOSE=1 --skip-soong-tests bp2build
  50. BAZEL_OUT="$(call_bazel info --config=bp2build output_path)"
  51. export TARGET_PRODUCT="module_arm"
  52. call_bazel build --config=bp2build --config=ci --config=android \
  53. //packages/modules/adb/apex:com.android.adbd \
  54. //system/timezone/apex:com.android.tzdata \
  55. //build/bazel/examples/apex/minimal:build.bazel.examples.apex.minimal.apex
  56. # Build debugfs separately, as it's not a dep of apexer, but needs to be an explicit arg.
  57. call_bazel build --config=bp2build --config=linux_x86_64 //external/e2fsprogs/debugfs
  58. DEBUGFS_PATH="$BAZEL_OUT/linux_x86_64-fastbuild/bin/external/e2fsprogs/debugfs/debugfs"
  59. function run_deapexer() {
  60. call_bazel run --config=bp2build --config=linux_x86_64 //system/apex/tools:deapexer \
  61. -- \
  62. --debugfs_path="$DEBUGFS_PATH" \
  63. $@
  64. }
  65. #######
  66. # Tests
  67. #######
  68. function compare_deapexer_list() {
  69. local APEX_DIR=$1; shift
  70. local APEX=$1; shift
  71. # Compare the outputs of `deapexer list`, which lists the contents of the apex filesystem image.
  72. local SOONG_APEX="$SOONG_OUTPUT_DIR/$APEX"
  73. local BAZEL_APEX="$BAZEL_OUT/android_target-fastbuild/bin/$APEX_DIR/$APEX"
  74. local SOONG_LIST="$OUTPUT_DIR/soong.list"
  75. local BAZEL_LIST="$OUTPUT_DIR/bazel.list"
  76. run_deapexer list "$SOONG_APEX" > "$SOONG_LIST"
  77. run_deapexer list "$BAZEL_APEX" > "$BAZEL_LIST"
  78. if cmp -s "$SOONG_LIST" "$BAZEL_LIST"
  79. then
  80. echo "ok: $APEX"
  81. else
  82. echo "contents of $APEX are different between Soong and Bazel:"
  83. echo
  84. echo expected
  85. echo
  86. cat "$SOONG_LIST"
  87. echo
  88. echo got
  89. echo
  90. cat "$BAZEL_LIST"
  91. exit 1
  92. fi
  93. }
  94. compare_deapexer_list packages/modules/adb/apex com.android.adbd.apex
  95. compare_deapexer_list system/timezone/apex com.android.tzdata.apex
  96. compare_deapexer_list build/bazel/examples/apex/minimal build.bazel.examples.apex.minimal.apex