• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/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
9function test_bp2build_generates_all_buildfiles {
10  setup
11  create_mock_bazel
12
13  mkdir -p foo/convertible_soong_module
14  cat > foo/convertible_soong_module/Android.bp <<'EOF'
15genrule {
16    name: "the_answer",
17    cmd: "echo '42' > $(out)",
18    out: [
19        "the_answer.txt",
20    ],
21    bazel_module: {
22        bp2build_available: true,
23    },
24  }
25EOF
26
27  mkdir -p foo/unconvertible_soong_module
28  cat > foo/unconvertible_soong_module/Android.bp <<'EOF'
29genrule {
30    name: "not_the_answer",
31    cmd: "echo '43' > $(out)",
32    out: [
33        "not_the_answer.txt",
34    ],
35    bazel_module: {
36        bp2build_available: false,
37    },
38  }
39EOF
40
41  run_bp2build
42
43  if [[ ! -f "./out/soong/workspace/foo/convertible_soong_module/BUILD" ]]; then
44    fail "./out/soong/workspace/foo/convertible_soong_module/BUILD was not generated"
45  fi
46
47  if [[ ! -f "./out/soong/workspace/foo/unconvertible_soong_module/BUILD" ]]; then
48    fail "./out/soong/workspace/foo/unconvertible_soong_module/BUILD was not generated"
49  fi
50
51  if ! grep "the_answer" "./out/soong/workspace/foo/convertible_soong_module/BUILD"; then
52    fail "missing BUILD target the_answer in convertible_soong_module/BUILD"
53  fi
54
55  if grep "not_the_answer" "./out/soong/workspace/foo/unconvertible_soong_module/BUILD"; then
56    fail "found unexpected BUILD target not_the_answer in unconvertible_soong_module/BUILD"
57  fi
58
59  if ! grep "filegroup" "./out/soong/workspace/foo/unconvertible_soong_module/BUILD"; then
60    fail "missing filegroup in unconvertible_soong_module/BUILD"
61  fi
62
63  # NOTE: We don't actually use the extra BUILD file for anything here
64  run_bazel build --package_path=out/soong/workspace //foo/...
65
66  local the_answer_file="bazel-out/k8-fastbuild/bin/foo/convertible_soong_module/the_answer.txt"
67  if [[ ! -f "${the_answer_file}" ]]; then
68    fail "Expected '${the_answer_file}' to be generated, but was missing"
69  fi
70  if ! grep 42 "${the_answer_file}"; then
71    fail "Expected to find 42 in '${the_answer_file}'"
72  fi
73}
74
75test_bp2build_generates_all_buildfiles
76