blob: e3577107ff1e30e32431116f7223825cfd56ec4e [file] [log] [blame]
Rupert Shuttleworth2a4fc3e2021-04-21 07:10:09 -04001#!/bin/bash -eu
2
3set -o pipefail
4
5# Test that bp2build and Bazel can play nicely together
6
7source "$(dirname "$0")/lib.sh"
8
Rupert Shuttleworth413a7a92021-05-18 07:47:15 -04009readonly GENERATED_BUILD_FILE_NAME="BUILD.bazel"
10
Rupert Shuttleworth2a4fc3e2021-04-21 07:10:09 -040011function 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'
17genrule {
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 }
27EOF
28
29 mkdir -p foo/unconvertible_soong_module
30 cat > foo/unconvertible_soong_module/Android.bp <<'EOF'
31genrule {
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 }
41EOF
42
43 run_bp2build
44
Rupert Shuttleworth413a7a92021-05-18 07:47:15 -040045 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 Shuttleworth2a4fc3e2021-04-21 07:10:09 -040047 fi
48
Rupert Shuttleworth413a7a92021-05-18 07:47:15 -040049 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 Shuttleworth2a4fc3e2021-04-21 07:10:09 -040051 fi
52
Rupert Shuttleworth413a7a92021-05-18 07:47:15 -040053 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 Shuttleworth2a4fc3e2021-04-21 07:10:09 -040055 fi
56
Rupert Shuttleworth413a7a92021-05-18 07:47:15 -040057 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 Shuttleworth2a4fc3e2021-04-21 07:10:09 -040059 fi
60
Rupert Shuttleworth413a7a92021-05-18 07:47:15 -040061 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 Shuttleworth2a4fc3e2021-04-21 07:10:09 -040063 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
77test_bp2build_generates_all_buildfiles