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 | |
Usta Shrestha | 572ecec | 2022-12-08 01:29:21 -0500 | [diff] [blame] | 11 | function test_bp2build_null_build { |
Jingwen Chen | 53dfa40 | 2021-08-12 09:37:14 +0000 | [diff] [blame] | 12 | setup |
Lukacs T. Berki | a1b9372 | 2021-09-02 17:23:06 +0200 | [diff] [blame] | 13 | run_soong bp2build |
Usta Shrestha | 2c9a5e3 | 2022-06-09 12:22:36 -0400 | [diff] [blame] | 14 | local -r output_mtime1=$(stat -c "%y" out/soong/bp2build_workspace_marker) |
Jingwen Chen | 53dfa40 | 2021-08-12 09:37:14 +0000 | [diff] [blame] | 15 | |
Lukacs T. Berki | a1b9372 | 2021-09-02 17:23:06 +0200 | [diff] [blame] | 16 | run_soong bp2build |
Usta Shrestha | 2c9a5e3 | 2022-06-09 12:22:36 -0400 | [diff] [blame] | 17 | local -r output_mtime2=$(stat -c "%y" out/soong/bp2build_workspace_marker) |
Jingwen Chen | 53dfa40 | 2021-08-12 09:37:14 +0000 | [diff] [blame] | 18 | |
| 19 | if [[ "$output_mtime1" != "$output_mtime2" ]]; then |
| 20 | fail "Output bp2build marker file changed on null build" |
| 21 | fi |
| 22 | } |
| 23 | |
Chris Parsons | 520e88b | 2023-02-09 17:54:00 -0500 | [diff] [blame] | 24 | # Tests that, if bp2build reruns due to a blueprint file changing, that |
| 25 | # BUILD files whose contents are unchanged are not regenerated. |
| 26 | function test_bp2build_unchanged { |
| 27 | setup |
| 28 | |
| 29 | mkdir -p pkg |
| 30 | touch pkg/x.txt |
| 31 | cat > pkg/Android.bp <<'EOF' |
| 32 | filegroup { |
| 33 | name: "x", |
| 34 | srcs: ["x.txt"], |
| 35 | bazel_module: {bp2build_available: true}, |
| 36 | } |
| 37 | EOF |
| 38 | |
| 39 | run_soong bp2build |
| 40 | local -r buildfile_mtime1=$(stat -c "%y" out/soong/bp2build/pkg/BUILD.bazel) |
| 41 | local -r marker_mtime1=$(stat -c "%y" out/soong/bp2build_workspace_marker) |
| 42 | |
| 43 | # Force bp2build to rerun by updating the timestamp of a blueprint file. |
| 44 | touch pkg/Android.bp |
| 45 | |
| 46 | run_soong bp2build |
| 47 | local -r buildfile_mtime2=$(stat -c "%y" out/soong/bp2build/pkg/BUILD.bazel) |
| 48 | local -r marker_mtime2=$(stat -c "%y" out/soong/bp2build_workspace_marker) |
| 49 | |
| 50 | if [[ "$marker_mtime1" == "$marker_mtime2" ]]; then |
| 51 | fail "Expected bp2build marker file to change" |
| 52 | fi |
| 53 | if [[ "$buildfile_mtime1" != "$buildfile_mtime2" ]]; then |
| 54 | fail "BUILD.bazel was updated even though contents are same" |
| 55 | fi |
Cole Faust | c9508aa | 2023-02-07 11:38:27 -0800 | [diff] [blame] | 56 | |
| 57 | # Force bp2build to rerun by updating the timestamp of the constants_exported_to_soong.bzl file. |
| 58 | touch build/bazel/constants_exported_to_soong.bzl |
| 59 | |
| 60 | run_soong bp2build |
| 61 | local -r buildfile_mtime3=$(stat -c "%y" out/soong/bp2build/pkg/BUILD.bazel) |
| 62 | local -r marker_mtime3=$(stat -c "%y" out/soong/bp2build_workspace_marker) |
| 63 | |
| 64 | if [[ "$marker_mtime2" == "$marker_mtime3" ]]; then |
| 65 | fail "Expected bp2build marker file to change" |
| 66 | fi |
| 67 | if [[ "$buildfile_mtime2" != "$buildfile_mtime3" ]]; then |
| 68 | fail "BUILD.bazel was updated even though contents are same" |
| 69 | fi |
Chris Parsons | 520e88b | 2023-02-09 17:54:00 -0500 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | # Tests that blueprint files that are deleted are not present when the |
| 73 | # bp2build tree is regenerated. |
| 74 | function test_bp2build_deleted_blueprint { |
| 75 | setup |
| 76 | |
| 77 | mkdir -p pkg |
| 78 | touch pkg/x.txt |
| 79 | cat > pkg/Android.bp <<'EOF' |
| 80 | filegroup { |
| 81 | name: "x", |
| 82 | srcs: ["x.txt"], |
| 83 | bazel_module: {bp2build_available: true}, |
| 84 | } |
| 85 | EOF |
| 86 | |
| 87 | run_soong bp2build |
| 88 | if [[ ! -e "./out/soong/bp2build/pkg/BUILD.bazel" ]]; then |
| 89 | fail "Expected pkg/BUILD.bazel to be generated" |
| 90 | fi |
| 91 | |
| 92 | rm pkg/Android.bp |
| 93 | |
| 94 | run_soong bp2build |
| 95 | if [[ -e "./out/soong/bp2build/pkg/BUILD.bazel" ]]; then |
| 96 | fail "Expected pkg/BUILD.bazel to be deleted" |
| 97 | fi |
| 98 | } |
| 99 | |
Usta Shrestha | 572ecec | 2022-12-08 01:29:21 -0500 | [diff] [blame] | 100 | function test_bp2build_null_build_with_globs { |
Jingwen Chen | 53dfa40 | 2021-08-12 09:37:14 +0000 | [diff] [blame] | 101 | setup |
| 102 | |
| 103 | mkdir -p foo/bar |
| 104 | cat > foo/bar/Android.bp <<'EOF' |
| 105 | filegroup { |
| 106 | name: "globs", |
| 107 | srcs: ["*.txt"], |
| 108 | } |
| 109 | EOF |
| 110 | touch foo/bar/a.txt foo/bar/b.txt |
| 111 | |
Lukacs T. Berki | a1b9372 | 2021-09-02 17:23:06 +0200 | [diff] [blame] | 112 | run_soong bp2build |
Usta Shrestha | 2c9a5e3 | 2022-06-09 12:22:36 -0400 | [diff] [blame] | 113 | local -r output_mtime1=$(stat -c "%y" out/soong/bp2build_workspace_marker) |
Jingwen Chen | 53dfa40 | 2021-08-12 09:37:14 +0000 | [diff] [blame] | 114 | |
Lukacs T. Berki | a1b9372 | 2021-09-02 17:23:06 +0200 | [diff] [blame] | 115 | run_soong bp2build |
Usta Shrestha | 2c9a5e3 | 2022-06-09 12:22:36 -0400 | [diff] [blame] | 116 | local -r output_mtime2=$(stat -c "%y" out/soong/bp2build_workspace_marker) |
Jingwen Chen | 53dfa40 | 2021-08-12 09:37:14 +0000 | [diff] [blame] | 117 | |
| 118 | if [[ "$output_mtime1" != "$output_mtime2" ]]; then |
| 119 | fail "Output bp2build marker file changed on null build" |
| 120 | fi |
| 121 | } |
| 122 | |
Jingwen Chen | 7e11eb8 | 2022-10-13 09:25:38 +0000 | [diff] [blame] | 123 | function test_different_relative_outdir { |
| 124 | setup |
Jingwen Chen | 7e11eb8 | 2022-10-13 09:25:38 +0000 | [diff] [blame] | 125 | |
| 126 | mkdir -p a |
| 127 | touch a/g.txt |
| 128 | cat > a/Android.bp <<'EOF' |
| 129 | filegroup { |
| 130 | name: "g", |
| 131 | srcs: ["g.txt"], |
| 132 | bazel_module: {bp2build_available: true}, |
| 133 | } |
| 134 | EOF |
| 135 | |
| 136 | # A directory under $MOCK_TOP |
| 137 | outdir=out2 |
| 138 | trap "rm -rf $outdir" EXIT |
| 139 | # Modify OUT_DIR in a subshell so it doesn't affect the top level one. |
Cole Faust | de12be3 | 2022-11-19 15:14:48 -0800 | [diff] [blame] | 140 | (export OUT_DIR=$outdir; run_soong bp2build && run_bazel build --config=bp2build --config=ci //a:g) |
Jingwen Chen | 7e11eb8 | 2022-10-13 09:25:38 +0000 | [diff] [blame] | 141 | } |
| 142 | |
Jingwen Chen | 7e11eb8 | 2022-10-13 09:25:38 +0000 | [diff] [blame] | 143 | function test_different_absolute_outdir { |
| 144 | setup |
Jingwen Chen | 7e11eb8 | 2022-10-13 09:25:38 +0000 | [diff] [blame] | 145 | |
| 146 | mkdir -p a |
| 147 | touch a/g.txt |
| 148 | cat > a/Android.bp <<'EOF' |
| 149 | filegroup { |
| 150 | name: "g", |
| 151 | srcs: ["g.txt"], |
| 152 | bazel_module: {bp2build_available: true}, |
| 153 | } |
| 154 | EOF |
| 155 | |
| 156 | # A directory under /tmp/... |
| 157 | outdir=$(mktemp -t -d st.XXXXX) |
| 158 | trap 'rm -rf $outdir' EXIT |
| 159 | # Modify OUT_DIR in a subshell so it doesn't affect the top level one. |
Cole Faust | de12be3 | 2022-11-19 15:14:48 -0800 | [diff] [blame] | 160 | (export OUT_DIR=$outdir; run_soong bp2build && run_bazel build --config=bp2build --config=ci //a:g) |
Jingwen Chen | 7e11eb8 | 2022-10-13 09:25:38 +0000 | [diff] [blame] | 161 | } |
| 162 | |
Usta Shrestha | 572ecec | 2022-12-08 01:29:21 -0500 | [diff] [blame] | 163 | function _bp2build_generates_all_buildfiles { |
Rupert Shuttleworth | 2a4fc3e | 2021-04-21 07:10:09 -0400 | [diff] [blame] | 164 | setup |
Rupert Shuttleworth | 2a4fc3e | 2021-04-21 07:10:09 -0400 | [diff] [blame] | 165 | |
| 166 | mkdir -p foo/convertible_soong_module |
| 167 | cat > foo/convertible_soong_module/Android.bp <<'EOF' |
| 168 | genrule { |
| 169 | name: "the_answer", |
| 170 | cmd: "echo '42' > $(out)", |
| 171 | out: [ |
| 172 | "the_answer.txt", |
| 173 | ], |
| 174 | bazel_module: { |
| 175 | bp2build_available: true, |
| 176 | }, |
| 177 | } |
| 178 | EOF |
| 179 | |
| 180 | mkdir -p foo/unconvertible_soong_module |
| 181 | cat > foo/unconvertible_soong_module/Android.bp <<'EOF' |
| 182 | genrule { |
| 183 | name: "not_the_answer", |
| 184 | cmd: "echo '43' > $(out)", |
| 185 | out: [ |
| 186 | "not_the_answer.txt", |
| 187 | ], |
| 188 | bazel_module: { |
| 189 | bp2build_available: false, |
| 190 | }, |
| 191 | } |
| 192 | EOF |
| 193 | |
Lukacs T. Berki | a1b9372 | 2021-09-02 17:23:06 +0200 | [diff] [blame] | 194 | run_soong bp2build |
Rupert Shuttleworth | 2a4fc3e | 2021-04-21 07:10:09 -0400 | [diff] [blame] | 195 | |
Rupert Shuttleworth | 413a7a9 | 2021-05-18 07:47:15 -0400 | [diff] [blame] | 196 | if [[ ! -f "./out/soong/workspace/foo/convertible_soong_module/${GENERATED_BUILD_FILE_NAME}" ]]; then |
| 197 | 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] | 198 | fi |
| 199 | |
Rupert Shuttleworth | 413a7a9 | 2021-05-18 07:47:15 -0400 | [diff] [blame] | 200 | if [[ ! -f "./out/soong/workspace/foo/unconvertible_soong_module/${GENERATED_BUILD_FILE_NAME}" ]]; then |
| 201 | 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] | 202 | fi |
| 203 | |
Rupert Shuttleworth | 413a7a9 | 2021-05-18 07:47:15 -0400 | [diff] [blame] | 204 | if ! grep "the_answer" "./out/soong/workspace/foo/convertible_soong_module/${GENERATED_BUILD_FILE_NAME}"; then |
| 205 | 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] | 206 | fi |
| 207 | |
Rupert Shuttleworth | 413a7a9 | 2021-05-18 07:47:15 -0400 | [diff] [blame] | 208 | if grep "not_the_answer" "./out/soong/workspace/foo/unconvertible_soong_module/${GENERATED_BUILD_FILE_NAME}"; then |
| 209 | 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] | 210 | fi |
| 211 | |
Rupert Shuttleworth | 413a7a9 | 2021-05-18 07:47:15 -0400 | [diff] [blame] | 212 | if ! grep "filegroup" "./out/soong/workspace/foo/unconvertible_soong_module/${GENERATED_BUILD_FILE_NAME}"; then |
| 213 | fail "missing filegroup in unconvertible_soong_module/${GENERATED_BUILD_FILE_NAME}" |
Rupert Shuttleworth | 2a4fc3e | 2021-04-21 07:10:09 -0400 | [diff] [blame] | 214 | fi |
| 215 | |
| 216 | # NOTE: We don't actually use the extra BUILD file for anything here |
Cole Faust | de12be3 | 2022-11-19 15:14:48 -0800 | [diff] [blame] | 217 | run_bazel build --config=android --config=bp2build --config=ci //foo/... |
Rupert Shuttleworth | 2a4fc3e | 2021-04-21 07:10:09 -0400 | [diff] [blame] | 218 | |
Usta (Tsering) Shrestha | c4c07b1 | 2022-11-08 18:31:14 -0500 | [diff] [blame] | 219 | local -r the_answer_file="$(find -L bazel-out -name the_answer.txt)" |
Rupert Shuttleworth | 2a4fc3e | 2021-04-21 07:10:09 -0400 | [diff] [blame] | 220 | if [[ ! -f "${the_answer_file}" ]]; then |
Cole Faust | b85d1a1 | 2022-11-08 18:14:01 -0800 | [diff] [blame] | 221 | fail "Expected the_answer.txt to be generated, but was missing" |
Rupert Shuttleworth | 2a4fc3e | 2021-04-21 07:10:09 -0400 | [diff] [blame] | 222 | fi |
| 223 | if ! grep 42 "${the_answer_file}"; then |
| 224 | fail "Expected to find 42 in '${the_answer_file}'" |
| 225 | fi |
| 226 | } |
| 227 | |
Usta Shrestha | 572ecec | 2022-12-08 01:29:21 -0500 | [diff] [blame] | 228 | function test_bp2build_generates_all_buildfiles { |
| 229 | _save_trap=$(trap -p EXIT) |
| 230 | trap '[[ $? -ne 0 ]] && echo Are you running this locally? Try changing --sandbox_tmpfs_path to something other than /tmp/ in build/bazel/linux.bazelrc.' EXIT |
| 231 | _bp2build_generates_all_buildfiles |
| 232 | eval "${_save_trap}" |
| 233 | } |
Lukacs T. Berki | e3487c8 | 2022-05-02 10:13:19 +0200 | [diff] [blame] | 234 | |
Chris Parsons | 8152a94 | 2023-06-06 16:17:50 +0000 | [diff] [blame] | 235 | function test_build_files_take_precedence { |
| 236 | _save_trap=$(trap -p EXIT) |
| 237 | trap '[[ $? -ne 0 ]] && echo Are you running this locally? Try changing --sandbox_tmpfs_path to something other than /tmp/ in build/bazel/linux.bazelrc.' EXIT |
| 238 | _build_files_take_precedence |
| 239 | eval "${_save_trap}" |
| 240 | } |
| 241 | |
| 242 | function _build_files_take_precedence { |
| 243 | setup |
| 244 | |
| 245 | # This specific directory is hardcoded in bp2build as being one |
| 246 | # where the BUILD file should be intentionally kept. |
| 247 | mkdir -p testpkg/keep_build_file |
| 248 | cat > testpkg/keep_build_file/Android.bp <<'EOF' |
| 249 | genrule { |
| 250 | name: "print_origin", |
| 251 | cmd: "echo 'from_soong' > $(out)", |
| 252 | out: [ |
| 253 | "origin.txt", |
| 254 | ], |
| 255 | bazel_module: { |
| 256 | bp2build_available: true, |
| 257 | }, |
| 258 | } |
| 259 | EOF |
| 260 | |
| 261 | run_soong bp2build |
| 262 | run_bazel build --config=android --config=bp2build --config=ci //testpkg/keep_build_file:print_origin |
| 263 | |
| 264 | local -r output_file="$(find -L bazel-out -name origin.txt)" |
| 265 | if [[ ! -f "${output_file}" ]]; then |
| 266 | fail "Expected origin.txt to be generated, but was missing" |
| 267 | fi |
| 268 | if ! grep from_soong "${output_file}"; then |
| 269 | fail "Expected to find 'from_soong' in '${output_file}'" |
| 270 | fi |
| 271 | |
| 272 | cat > testpkg/keep_build_file/BUILD.bazel <<'EOF' |
| 273 | genrule( |
| 274 | name = "print_origin", |
| 275 | outs = ["origin.txt"], |
| 276 | cmd = "echo 'from_bazel' > $@", |
| 277 | ) |
| 278 | EOF |
| 279 | |
| 280 | # Clean the workspace. There is a test infrastructure bug where run_bazel |
| 281 | # will symlink Android.bp files in the source directory again and thus |
| 282 | # pollute the workspace. |
| 283 | # TODO: b/286059878 - Remove this clean after the underlying bug is fixed. |
| 284 | run_soong clean |
| 285 | run_soong bp2build |
| 286 | run_bazel build --config=android --config=bp2build --config=ci //testpkg/keep_build_file:print_origin |
| 287 | if ! grep from_bazel "${output_file}"; then |
| 288 | fail "Expected to find 'from_bazel' in '${output_file}'" |
| 289 | fi |
| 290 | } |
| 291 | |
Usta (Tsering) Shrestha | c4c07b1 | 2022-11-08 18:31:14 -0500 | [diff] [blame] | 292 | function test_bp2build_symlinks_files { |
| 293 | setup |
| 294 | mkdir -p foo |
| 295 | touch foo/BLANK1 |
| 296 | touch foo/BLANK2 |
| 297 | touch foo/F2D |
| 298 | touch foo/BUILD |
| 299 | |
| 300 | run_soong bp2build |
| 301 | |
| 302 | if [[ -e "./out/soong/workspace/foo/BUILD" ]]; then |
| 303 | fail "./out/soong/workspace/foo/BUILD should be omitted" |
| 304 | fi |
| 305 | for file in BLANK1 BLANK2 F2D |
| 306 | do |
| 307 | if [[ ! -L "./out/soong/workspace/foo/$file" ]]; then |
| 308 | fail "./out/soong/workspace/foo/$file should exist" |
| 309 | fi |
| 310 | done |
| 311 | local -r BLANK1_BEFORE=$(stat -c %y "./out/soong/workspace/foo/BLANK1") |
| 312 | |
| 313 | rm foo/BLANK2 |
| 314 | rm foo/F2D |
| 315 | mkdir foo/F2D |
| 316 | touch foo/F2D/BUILD |
| 317 | |
| 318 | run_soong bp2build |
| 319 | |
| 320 | if [[ -e "./out/soong/workspace/foo/BUILD" ]]; then |
| 321 | fail "./out/soong/workspace/foo/BUILD should be omitted" |
| 322 | fi |
| 323 | local -r BLANK1_AFTER=$(stat -c %y "./out/soong/workspace/foo/BLANK1") |
| 324 | if [[ "$BLANK1_AFTER" != "$BLANK1_BEFORE" ]]; then |
| 325 | fail "./out/soong/workspace/foo/BLANK1 should be untouched" |
| 326 | fi |
| 327 | if [[ -e "./out/soong/workspace/foo/BLANK2" ]]; then |
| 328 | fail "./out/soong/workspace/foo/BLANK2 should be removed" |
| 329 | fi |
| 330 | if [[ -L "./out/soong/workspace/foo/F2D" ]] || [[ ! -d "./out/soong/workspace/foo/F2D" ]]; then |
| 331 | fail "./out/soong/workspace/foo/F2D should be a dir" |
| 332 | fi |
| 333 | } |
| 334 | |
Lukacs T. Berki | e3487c8 | 2022-05-02 10:13:19 +0200 | [diff] [blame] | 335 | function test_cc_correctness { |
| 336 | setup |
Lukacs T. Berki | e3487c8 | 2022-05-02 10:13:19 +0200 | [diff] [blame] | 337 | |
| 338 | mkdir -p a |
| 339 | cat > a/Android.bp <<EOF |
| 340 | cc_object { |
| 341 | name: "qq", |
| 342 | srcs: ["qq.cc"], |
| 343 | bazel_module: { |
| 344 | bp2build_available: true, |
| 345 | }, |
| 346 | stl: "none", |
| 347 | system_shared_libs: [], |
| 348 | } |
| 349 | EOF |
| 350 | |
| 351 | cat > a/qq.cc <<EOF |
| 352 | #include "qq.h" |
| 353 | int qq() { |
| 354 | return QQ; |
| 355 | } |
| 356 | EOF |
| 357 | |
| 358 | cat > a/qq.h <<EOF |
| 359 | #define QQ 1 |
| 360 | EOF |
| 361 | |
| 362 | run_soong bp2build |
| 363 | |
Cole Faust | de12be3 | 2022-11-19 15:14:48 -0800 | [diff] [blame] | 364 | run_bazel build --config=android --config=bp2build --config=ci //a:qq |
Usta Shrestha | 2c9a5e3 | 2022-06-09 12:22:36 -0400 | [diff] [blame] | 365 | local -r output_mtime1=$(stat -c "%y" bazel-bin/a/_objs/qq/qq.o) |
Lukacs T. Berki | e3487c8 | 2022-05-02 10:13:19 +0200 | [diff] [blame] | 366 | |
Cole Faust | de12be3 | 2022-11-19 15:14:48 -0800 | [diff] [blame] | 367 | run_bazel build --config=android --config=bp2build --config=ci //a:qq |
Usta Shrestha | 2c9a5e3 | 2022-06-09 12:22:36 -0400 | [diff] [blame] | 368 | local -r output_mtime2=$(stat -c "%y" bazel-bin/a/_objs/qq/qq.o) |
Lukacs T. Berki | e3487c8 | 2022-05-02 10:13:19 +0200 | [diff] [blame] | 369 | |
| 370 | if [[ "$output_mtime1" != "$output_mtime2" ]]; then |
| 371 | fail "output changed on null build" |
| 372 | fi |
| 373 | |
| 374 | cat > a/qq.h <<EOF |
| 375 | #define QQ 2 |
| 376 | EOF |
| 377 | |
Cole Faust | de12be3 | 2022-11-19 15:14:48 -0800 | [diff] [blame] | 378 | run_bazel build --config=android --config=bp2build --config=ci //a:qq |
Usta Shrestha | 2c9a5e3 | 2022-06-09 12:22:36 -0400 | [diff] [blame] | 379 | local -r output_mtime3=$(stat -c "%y" bazel-bin/a/_objs/qq/qq.o) |
Lukacs T. Berki | e3487c8 | 2022-05-02 10:13:19 +0200 | [diff] [blame] | 380 | |
| 381 | if [[ "$output_mtime1" == "$output_mtime3" ]]; then |
| 382 | fail "output not changed when included header changed" |
| 383 | fi |
| 384 | } |
| 385 | |
Jingwen Chen | d4b1dc8 | 2022-05-12 11:08:03 +0000 | [diff] [blame] | 386 | # Regression test for the following failure during symlink forest creation: |
| 387 | # |
| 388 | # Cannot stat '/tmp/st.rr054/foo/bar/unresolved_symlink': stat /tmp/st.rr054/foo/bar/unresolved_symlink: no such file or directory |
| 389 | # |
| 390 | function test_bp2build_null_build_with_unresolved_symlink_in_source() { |
| 391 | setup |
| 392 | |
| 393 | mkdir -p foo/bar |
| 394 | ln -s /tmp/non-existent foo/bar/unresolved_symlink |
| 395 | cat > foo/bar/Android.bp <<'EOF' |
| 396 | filegroup { |
| 397 | name: "fg", |
| 398 | srcs: ["unresolved_symlink/non-existent-file.txt"], |
| 399 | } |
| 400 | EOF |
| 401 | |
| 402 | run_soong bp2build |
| 403 | |
| 404 | dest=$(readlink -f out/soong/workspace/foo/bar/unresolved_symlink) |
| 405 | if [[ "$dest" != "/tmp/non-existent" ]]; then |
| 406 | fail "expected to plant an unresolved symlink out/soong/workspace/foo/bar/unresolved_symlink that resolves to /tmp/non-existent" |
| 407 | fi |
| 408 | } |
| 409 | |
Cole Faust | 319abae | 2023-06-06 15:12:49 -0700 | [diff] [blame] | 410 | function test_bazel_standalone_output_paths_contain_product_name { |
| 411 | setup |
| 412 | mkdir -p a |
| 413 | cat > a/Android.bp <<EOF |
| 414 | cc_object { |
| 415 | name: "qq", |
| 416 | srcs: ["qq.cc"], |
| 417 | bazel_module: { |
| 418 | bp2build_available: true, |
| 419 | }, |
| 420 | stl: "none", |
| 421 | system_shared_libs: [], |
| 422 | } |
| 423 | EOF |
| 424 | |
| 425 | cat > a/qq.cc <<EOF |
| 426 | #include "qq.h" |
| 427 | int qq() { |
| 428 | return QQ; |
| 429 | } |
| 430 | EOF |
| 431 | |
| 432 | cat > a/qq.h <<EOF |
| 433 | #define QQ 1 |
| 434 | EOF |
| 435 | |
| 436 | export TARGET_PRODUCT=aosp_arm; run_soong bp2build |
| 437 | local -r output=$(run_bazel cquery //a:qq --output=files --config=android --config=bp2build --config=ci) |
| 438 | if [[ ! $(echo ${output} | grep "bazel-out/aosp_arm") ]]; then |
| 439 | fail "Did not find the product name '${TARGET_PRODUCT}' in the output path. This can cause " \ |
| 440 | "unnecessary rebuilds when toggling between products as bazel outputs for different products will " \ |
| 441 | "clobber each other. Output paths are: \n${output}" |
| 442 | fi |
| 443 | } |
| 444 | |
Usta Shrestha | 572ecec | 2022-12-08 01:29:21 -0500 | [diff] [blame] | 445 | scan_and_run_tests |