blob: ca63fdfe4aad8f3da3f93030f793c291bf41edf5 [file] [log] [blame]
MarkDacek53506362023-04-18 19:33:11 +00001#!/bin/bash
Lukacs T. Berki3b730c42021-04-08 13:21:13 +02002
Rupert Shuttleworth2a4fc3e2021-04-21 07:10:09 -04003set -o pipefail
4
Lukacs T. Berki3b730c42021-04-08 13:21:13 +02005# 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
Lukacs T. Berki3b730c42021-04-08 13:21:13 +020013function test_bazel_smoke {
14 setup
Lukacs T. Berki3b730c42021-04-08 13:21:13 +020015
Sam Delmerico73d6bcc2022-09-20 15:31:37 -040016 run_soong bp2build
17
18 run_bazel info --config=bp2build
Lukacs T. Berki3b730c42021-04-08 13:21:13 +020019}
20
Lukacs T. Berkic541cd22022-10-26 07:26:50 +000021function test_add_irrelevant_file {
22 setup
Lukacs T. Berkic541cd22022-10-26 07:26:50 +000023
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
Chris Parsonsb6e96902022-10-31 20:08:45 -040034 run_soong --bazel-mode-staging nothing
Lukacs T. Berkic541cd22022-10-26 07:26:50 +000035
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
Chris Parsonsb6e96902022-10-31 20:08:45 -040049 run_soong --bazel-mode-staging nothing
Lukacs T. Berkic541cd22022-10-26 07:26:50 +000050 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
MarkDacek9c094ca2023-03-16 19:15:19 +000066function 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
MarkDacekf47e1422023-04-19 16:47:36 +000091 unused=`run_soong --bazel-force-enabled-modules=unenabled-touch-file --ensure-allowlist-integrity nothing >/dev/null`
MarkDacek9c094ca2023-03-16 19:15:19 +000092
MarkDacek53506362023-04-18 19:33:11 +000093 if [[ $? -ne 1 ]]; then
MarkDacek9c094ca2023-03-16 19:15:19 +000094 fail "Expected failure due to force-enabling an unenabled module "
95 fi
96}
97
98
MarkDacek53506362023-04-18 19:33:11 +000099scan_and_run_tests