apex_comparison_tests.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 $(pwd)/tmp.XXXXXX)"
  27. SOONG_OUTPUT_DIR="$OUTPUT_DIR/soong"
  28. BAZEL_OUTPUT_DIR="$OUTPUT_DIR/bazel"
  29. export TARGET_PRODUCT="module_arm"
  30. [ "$#" -eq 1 ] && export TARGET_PRODUCT="$1"
  31. function call_bazel() {
  32. build/bazel/bin/bazel --output_base="$BAZEL_OUTPUT_DIR" $@
  33. }
  34. function cleanup {
  35. # call bazel clean because some bazel outputs don't have w bits.
  36. call_bazel clean
  37. rm -rf "${OUTPUT_DIR}"
  38. }
  39. function deapexer() {
  40. DEBUGFS_PATH="$(realpath $(call_bazel cquery --config=bp2build --config=linux_x86_64 --config=ci --output=files //external/e2fsprogs/debugfs))"
  41. call_bazel run --config=bp2build //system/apex/tools:deapexer -- --debugfs_path=$DEBUGFS_PATH $@
  42. }
  43. trap cleanup EXIT
  44. ###########
  45. # Run Soong
  46. ###########
  47. export UNBUNDLED_BUILD_SDKS_FROM_SOURCE=true # don't rely on prebuilts
  48. export TARGET_BUILD_APPS="com.android.adbd com.android.tzdata build.bazel.examples.apex.minimal"
  49. packages/modules/common/build/build_unbundled_mainline_module.sh \
  50. --product "$TARGET_PRODUCT" \
  51. --dist_dir "$SOONG_OUTPUT_DIR"
  52. ######################
  53. # Run bp2build / Bazel
  54. ######################
  55. build/soong/soong_ui.bash --make-mode BP2BUILD_VERBOSE=1 --skip-soong-tests bp2build
  56. BAZEL_OUT="$(call_bazel info --config=bp2build output_path)"
  57. call_bazel build --config=bp2build --config=ci --config=android \
  58. //packages/modules/adb/apex:com.android.adbd \
  59. //system/timezone/apex:com.android.tzdata \
  60. //build/bazel/examples/apex/minimal:build.bazel.examples.apex.minimal
  61. BAZEL_ADBD="$(realpath $(call_bazel cquery --config=bp2build --config=android --config=ci --output=files //packages/modules/adb/apex:com.android.adbd))"
  62. BAZEL_TZDATA="$(realpath $(call_bazel cquery --config=bp2build --config=android --config=ci --output=files //system/timezone/apex:com.android.tzdata))"
  63. BAZEL_MINIMAL="$(realpath $(call_bazel cquery --config=bp2build --config=android --config=ci --output=files //build/bazel/examples/apex/minimal:build.bazel.examples.apex.minimal))"
  64. # # Build debugfs separately, as it's not a dep of apexer, but needs to be an explicit arg.
  65. call_bazel build --config=bp2build --config=linux_x86_64 //external/e2fsprogs/debugfs
  66. #######
  67. # Tests
  68. #######
  69. function compare_deapexer_list() {
  70. local BAZEL_APEX=$1; shift
  71. local APEX=$1; shift
  72. # Compare the outputs of `deapexer list`, which lists the contents of the apex filesystem image.
  73. local SOONG_APEX="$SOONG_OUTPUT_DIR/$APEX"
  74. local SOONG_LIST="$OUTPUT_DIR/soong.list"
  75. local BAZEL_LIST="$OUTPUT_DIR/bazel.list"
  76. deapexer list "$SOONG_APEX" > "$SOONG_LIST"
  77. 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 "${BAZEL_ADBD}" com.android.adbd.apex
  95. compare_deapexer_list "${BAZEL_TZDATA}" com.android.tzdata.apex
  96. compare_deapexer_list "${BAZEL_MINIMAL}" build.bazel.examples.apex.minimal.apex