apex_comparison_tests.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 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. trap cleanup EXIT
  40. ###########
  41. # Run Soong
  42. ###########
  43. export UNBUNDLED_BUILD_SDKS_FROM_SOURCE=true # don't rely on prebuilts
  44. export TARGET_BUILD_APPS="com.android.adbd com.android.tzdata build.bazel.examples.apex.minimal"
  45. packages/modules/common/build/build_unbundled_mainline_module.sh \
  46. --product "$TARGET_PRODUCT" \
  47. --dist_dir "$SOONG_OUTPUT_DIR"
  48. ######################
  49. # Run bp2build / Bazel
  50. ######################
  51. build/soong/soong_ui.bash --make-mode BP2BUILD_VERBOSE=1 --skip-soong-tests bp2build
  52. BAZEL_OUT="$(call_bazel info --config=bp2build output_path)"
  53. call_bazel build --config=bp2build --config=ci --config=android \
  54. //packages/modules/adb/apex:com.android.adbd \
  55. //system/timezone/apex:com.android.tzdata \
  56. //build/bazel/examples/apex/minimal:build.bazel.examples.apex.minimal
  57. BAZEL_ADBD="$(realpath $(call_bazel cquery --config=bp2build --config=android --config=ci --output=files //packages/modules/adb/apex:com.android.adbd))"
  58. BAZEL_TZDATA="$(realpath $(call_bazel cquery --config=bp2build --config=android --config=ci --output=files //system/timezone/apex:com.android.tzdata))"
  59. BAZEL_MINIMAL="$(realpath $(call_bazel cquery --config=bp2build --config=android --config=ci --output=files //build/bazel/examples/apex/minimal:build.bazel.examples.apex.minimal))"
  60. # # Build debugfs separately, as it's not a dep of apexer, but needs to be an explicit arg.
  61. call_bazel build --config=bp2build --config=linux_x86_64 //external/e2fsprogs/debugfs //system/apex/tools:deapexer
  62. DEBUGFS_PATH="$(realpath $(call_bazel cquery --config=bp2build --config=linux_x86_64 --config=ci --output=files //external/e2fsprogs/debugfs))"
  63. DEAPEXER="bazel-bin/system/apex/tools/deapexer"
  64. DEAPEXER="$DEAPEXER --debugfs_path=$DEBUGFS_PATH"
  65. #######
  66. # Tests
  67. #######
  68. function compare_deapexer_list() {
  69. local BAZEL_APEX=$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 SOONG_LIST="$OUTPUT_DIR/soong.list"
  74. local BAZEL_LIST="$OUTPUT_DIR/bazel.list"
  75. $DEAPEXER list "$SOONG_APEX" > "$SOONG_LIST"
  76. $DEAPEXER list "$BAZEL_APEX" > "$BAZEL_LIST"
  77. if cmp -s "$SOONG_LIST" "$BAZEL_LIST"
  78. then
  79. echo "ok: $APEX"
  80. else
  81. echo "contents of $APEX are different between Soong and Bazel:"
  82. echo
  83. echo expected
  84. echo
  85. cat "$SOONG_LIST"
  86. echo
  87. echo got
  88. echo
  89. cat "$BAZEL_LIST"
  90. exit 1
  91. fi
  92. }
  93. compare_deapexer_list "${BAZEL_ADBD}" com.android.adbd.apex
  94. compare_deapexer_list "${BAZEL_TZDATA}" com.android.tzdata.apex
  95. compare_deapexer_list "${BAZEL_MINIMAL}" build.bazel.examples.apex.minimal.apex