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