mixed_mode_test.sh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/bin/bash
  2. set -o pipefail
  3. # This test exercises mixed builds where Soong and Bazel cooperate in building
  4. # Android.
  5. #
  6. # When the execroot is deleted, the Bazel server process will automatically
  7. # terminate itself.
  8. source "$(dirname "$0")/lib.sh"
  9. function test_bazel_smoke {
  10. setup
  11. run_soong bp2build
  12. run_bazel info --config=bp2build
  13. }
  14. function test_add_irrelevant_file {
  15. setup
  16. mkdir -p soong_tests/a/b
  17. touch soong_tests/a/b/c.txt
  18. cat > soong_tests/a/b/Android.bp <<'EOF'
  19. filegroup {
  20. name: "c",
  21. srcs: ["c.txt"],
  22. bazel_module: { bp2build_available: true },
  23. }
  24. EOF
  25. run_soong --bazel-mode-staging nothing
  26. if [[ ! -e out/soong/bp2build/soong_tests/a/b/BUILD.bazel ]]; then
  27. fail "BUILD.bazel not created"
  28. fi
  29. if [[ ! -e out/soong/build.ninja ]]; then
  30. fail "build.ninja not created"
  31. fi
  32. local mtime_build1=$(stat -c "%y" out/soong/bp2build/soong_tests/a/b/BUILD.bazel)
  33. local mtime_ninja1=$(stat -c "%y" out/soong/build.ninja)
  34. touch soong_tests/a/irrelevant.txt
  35. run_soong --bazel-mode-staging nothing
  36. local mtime_build2=$(stat -c "%y" out/soong/bp2build/soong_tests/a/b/BUILD.bazel)
  37. local mtime_ninja2=$(stat -c "%y" out/soong/build.ninja)
  38. if [[ "$mtime_build1" != "$mtime_build2" ]]; then
  39. fail "BUILD.bazel was generated"
  40. fi
  41. if [[ "$mtime_ninja1" != "$mtime_ninja2" ]]; then
  42. fail "build.ninja was regenerated"
  43. fi
  44. if [[ ! -e out/soong/workspace/soong_tests/a/irrelevant.txt ]]; then
  45. fail "new file was not symlinked"
  46. fi
  47. }
  48. function test_force_enabled_modules {
  49. setup
  50. # b/273910287 - test force enable modules
  51. mkdir -p soong_tests/a/b
  52. cat > soong_tests/a/b/Android.bp <<'EOF'
  53. genrule {
  54. name: "touch-file",
  55. out: ["fake-out.txt"],
  56. cmd: "touch $(out)",
  57. bazel_module: { bp2build_available: true },
  58. }
  59. genrule {
  60. name: "unenabled-touch-file",
  61. out: ["fake-out2.txt"],
  62. cmd: "touch $(out)",
  63. bazel_module: { bp2build_available: false },
  64. }
  65. EOF
  66. run_soong --bazel-mode-staging --bazel-force-enabled-modules=touch-file nothing
  67. local bazel_contained=`grep out/soong/.intermediates/soong_tests/a/b/touch-file/gen/fake-out.txt out/soong/build.ninja`
  68. if [[ $bazel_contained == '' ]]; then
  69. fail "Bazel actions not found for force-enabled module"
  70. fi
  71. unused=`run_soong --bazel-force-enabled-modules=unenabled-touch-file --ensure-allowlist-integrity nothing >/dev/null`
  72. if [[ $? -ne 1 ]]; then
  73. fail "Expected failure due to force-enabling an unenabled module "
  74. fi
  75. }
  76. scan_and_run_tests