Rupert Shuttleworth | 2a4fc3e | 2021-04-21 07:10:09 -0400 | [diff] [blame] | 1 | #!/bin/bash -eu |
| 2 | |
| 3 | set -o pipefail |
| 4 | |
| 5 | # Test that bp2build and Bazel can play nicely together |
| 6 | |
| 7 | source "$(dirname "$0")/lib.sh" |
| 8 | |
Rupert Shuttleworth | 413a7a9 | 2021-05-18 07:47:15 -0400 | [diff] [blame^] | 9 | readonly GENERATED_BUILD_FILE_NAME="BUILD.bazel" |
| 10 | |
Rupert Shuttleworth | 2a4fc3e | 2021-04-21 07:10:09 -0400 | [diff] [blame] | 11 | function test_bp2build_generates_all_buildfiles { |
| 12 | setup |
| 13 | create_mock_bazel |
| 14 | |
| 15 | mkdir -p foo/convertible_soong_module |
| 16 | cat > foo/convertible_soong_module/Android.bp <<'EOF' |
| 17 | genrule { |
| 18 | name: "the_answer", |
| 19 | cmd: "echo '42' > $(out)", |
| 20 | out: [ |
| 21 | "the_answer.txt", |
| 22 | ], |
| 23 | bazel_module: { |
| 24 | bp2build_available: true, |
| 25 | }, |
| 26 | } |
| 27 | EOF |
| 28 | |
| 29 | mkdir -p foo/unconvertible_soong_module |
| 30 | cat > foo/unconvertible_soong_module/Android.bp <<'EOF' |
| 31 | genrule { |
| 32 | name: "not_the_answer", |
| 33 | cmd: "echo '43' > $(out)", |
| 34 | out: [ |
| 35 | "not_the_answer.txt", |
| 36 | ], |
| 37 | bazel_module: { |
| 38 | bp2build_available: false, |
| 39 | }, |
| 40 | } |
| 41 | EOF |
| 42 | |
| 43 | run_bp2build |
| 44 | |
Rupert Shuttleworth | 413a7a9 | 2021-05-18 07:47:15 -0400 | [diff] [blame^] | 45 | if [[ ! -f "./out/soong/workspace/foo/convertible_soong_module/${GENERATED_BUILD_FILE_NAME}" ]]; then |
| 46 | fail "./out/soong/workspace/foo/convertible_soong_module/${GENERATED_BUILD_FILE_NAME} was not generated" |
Rupert Shuttleworth | 2a4fc3e | 2021-04-21 07:10:09 -0400 | [diff] [blame] | 47 | fi |
| 48 | |
Rupert Shuttleworth | 413a7a9 | 2021-05-18 07:47:15 -0400 | [diff] [blame^] | 49 | if [[ ! -f "./out/soong/workspace/foo/unconvertible_soong_module/${GENERATED_BUILD_FILE_NAME}" ]]; then |
| 50 | fail "./out/soong/workspace/foo/unconvertible_soong_module/${GENERATED_BUILD_FILE_NAME} was not generated" |
Rupert Shuttleworth | 2a4fc3e | 2021-04-21 07:10:09 -0400 | [diff] [blame] | 51 | fi |
| 52 | |
Rupert Shuttleworth | 413a7a9 | 2021-05-18 07:47:15 -0400 | [diff] [blame^] | 53 | if ! grep "the_answer" "./out/soong/workspace/foo/convertible_soong_module/${GENERATED_BUILD_FILE_NAME}"; then |
| 54 | fail "missing BUILD target the_answer in convertible_soong_module/${GENERATED_BUILD_FILE_NAME}" |
Rupert Shuttleworth | 2a4fc3e | 2021-04-21 07:10:09 -0400 | [diff] [blame] | 55 | fi |
| 56 | |
Rupert Shuttleworth | 413a7a9 | 2021-05-18 07:47:15 -0400 | [diff] [blame^] | 57 | if grep "not_the_answer" "./out/soong/workspace/foo/unconvertible_soong_module/${GENERATED_BUILD_FILE_NAME}"; then |
| 58 | fail "found unexpected BUILD target not_the_answer in unconvertible_soong_module/${GENERATED_BUILD_FILE_NAME}" |
Rupert Shuttleworth | 2a4fc3e | 2021-04-21 07:10:09 -0400 | [diff] [blame] | 59 | fi |
| 60 | |
Rupert Shuttleworth | 413a7a9 | 2021-05-18 07:47:15 -0400 | [diff] [blame^] | 61 | if ! grep "filegroup" "./out/soong/workspace/foo/unconvertible_soong_module/${GENERATED_BUILD_FILE_NAME}"; then |
| 62 | fail "missing filegroup in unconvertible_soong_module/${GENERATED_BUILD_FILE_NAME}" |
Rupert Shuttleworth | 2a4fc3e | 2021-04-21 07:10:09 -0400 | [diff] [blame] | 63 | fi |
| 64 | |
| 65 | # NOTE: We don't actually use the extra BUILD file for anything here |
| 66 | run_bazel build --package_path=out/soong/workspace //foo/... |
| 67 | |
| 68 | local the_answer_file="bazel-out/k8-fastbuild/bin/foo/convertible_soong_module/the_answer.txt" |
| 69 | if [[ ! -f "${the_answer_file}" ]]; then |
| 70 | fail "Expected '${the_answer_file}' to be generated, but was missing" |
| 71 | fi |
| 72 | if ! grep 42 "${the_answer_file}"; then |
| 73 | fail "Expected to find 42 in '${the_answer_file}'" |
| 74 | fi |
| 75 | } |
| 76 | |
| 77 | test_bp2build_generates_all_buildfiles |