Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 1 | #!/bin/bash -eu |
| 2 | |
Rupert Shuttleworth | 2a4fc3e | 2021-04-21 07:10:09 -0400 | [diff] [blame^] | 3 | set -o pipefail |
| 4 | |
Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 5 | # This test exercises the bootstrapping process of the build system |
| 6 | # in a source tree that only contains enough files for Bazel and Soong to work. |
| 7 | |
Lukacs T. Berki | 3b730c4 | 2021-04-08 13:21:13 +0200 | [diff] [blame] | 8 | source "$(dirname "$0")/lib.sh" |
Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 9 | |
| 10 | function test_smoke { |
| 11 | setup |
| 12 | run_soong |
| 13 | } |
| 14 | |
Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 15 | function test_null_build() { |
| 16 | setup |
| 17 | run_soong |
| 18 | local bootstrap_mtime1=$(stat -c "%y" out/soong/.bootstrap/build.ninja) |
| 19 | local output_mtime1=$(stat -c "%y" out/soong/build.ninja) |
| 20 | run_soong |
| 21 | local bootstrap_mtime2=$(stat -c "%y" out/soong/.bootstrap/build.ninja) |
| 22 | local output_mtime2=$(stat -c "%y" out/soong/build.ninja) |
| 23 | |
| 24 | if [[ "$bootstrap_mtime1" == "$bootstrap_mtime2" ]]; then |
| 25 | # Bootstrapping is always done. It doesn't take a measurable amount of time. |
| 26 | fail "Bootstrap Ninja file did not change on null build" |
| 27 | fi |
| 28 | |
| 29 | if [[ "$output_mtime1" != "$output_mtime2" ]]; then |
| 30 | fail "Output Ninja file changed on null build" |
| 31 | fi |
| 32 | } |
| 33 | |
| 34 | function test_soong_build_rebuilt_if_blueprint_changes() { |
| 35 | setup |
| 36 | run_soong |
| 37 | local mtime1=$(stat -c "%y" out/soong/.bootstrap/build.ninja) |
| 38 | |
| 39 | sed -i 's/pluginGenSrcCmd/pluginGenSrcCmd2/g' build/blueprint/bootstrap/bootstrap.go |
| 40 | |
| 41 | run_soong |
| 42 | local mtime2=$(stat -c "%y" out/soong/.bootstrap/build.ninja) |
| 43 | |
| 44 | if [[ "$mtime1" == "$mtime2" ]]; then |
| 45 | fail "Bootstrap Ninja file did not change" |
| 46 | fi |
| 47 | } |
| 48 | |
| 49 | function test_change_android_bp() { |
| 50 | setup |
| 51 | mkdir -p a |
| 52 | cat > a/Android.bp <<'EOF' |
| 53 | python_binary_host { |
| 54 | name: "my_little_binary_host", |
| 55 | srcs: ["my_little_binary_host.py"] |
| 56 | } |
| 57 | EOF |
| 58 | touch a/my_little_binary_host.py |
| 59 | run_soong |
| 60 | |
| 61 | grep -q "^# Module:.*my_little_binary_host" out/soong/build.ninja || fail "module not found" |
| 62 | |
| 63 | cat > a/Android.bp <<'EOF' |
| 64 | python_binary_host { |
| 65 | name: "my_great_binary_host", |
| 66 | srcs: ["my_great_binary_host.py"] |
| 67 | } |
| 68 | EOF |
| 69 | touch a/my_great_binary_host.py |
| 70 | run_soong |
| 71 | |
| 72 | grep -q "^# Module:.*my_little_binary_host" out/soong/build.ninja && fail "old module found" |
| 73 | grep -q "^# Module:.*my_great_binary_host" out/soong/build.ninja || fail "new module not found" |
| 74 | } |
| 75 | |
| 76 | |
| 77 | function test_add_android_bp() { |
| 78 | setup |
| 79 | run_soong |
| 80 | local mtime1=$(stat -c "%y" out/soong/build.ninja) |
| 81 | |
| 82 | mkdir -p a |
| 83 | cat > a/Android.bp <<'EOF' |
| 84 | python_binary_host { |
| 85 | name: "my_little_binary_host", |
| 86 | srcs: ["my_little_binary_host.py"] |
| 87 | } |
| 88 | EOF |
| 89 | touch a/my_little_binary_host.py |
| 90 | run_soong |
| 91 | |
| 92 | local mtime2=$(stat -c "%y" out/soong/build.ninja) |
| 93 | if [[ "$mtime1" == "$mtime2" ]]; then |
| 94 | fail "Output Ninja file did not change" |
| 95 | fi |
| 96 | |
| 97 | grep -q "^# Module:.*my_little_binary_host$" out/soong/build.ninja || fail "New module not in output" |
| 98 | |
| 99 | run_soong |
| 100 | } |
| 101 | |
| 102 | function test_delete_android_bp() { |
| 103 | setup |
| 104 | mkdir -p a |
| 105 | cat > a/Android.bp <<'EOF' |
| 106 | python_binary_host { |
| 107 | name: "my_little_binary_host", |
| 108 | srcs: ["my_little_binary_host.py"] |
| 109 | } |
| 110 | EOF |
| 111 | touch a/my_little_binary_host.py |
| 112 | run_soong |
| 113 | |
| 114 | grep -q "^# Module:.*my_little_binary_host$" out/soong/build.ninja || fail "Module not in output" |
| 115 | |
| 116 | rm a/Android.bp |
| 117 | run_soong |
| 118 | |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 119 | if grep -q "^# Module:.*my_little_binary_host$" out/soong/build.ninja; then |
| 120 | fail "Old module in output" |
| 121 | fi |
Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 122 | } |
| 123 | |
Colin Cross | 1042595 | 2021-04-12 18:59:18 -0700 | [diff] [blame] | 124 | # Test that an incremental build with a glob doesn't rerun soong_build, and |
| 125 | # only regenerates the globs on the first but not the second incremental build. |
| 126 | function test_glob_noop_incremental() { |
| 127 | setup |
| 128 | |
Colin Cross | b72877f | 2021-04-16 10:09:54 -0700 | [diff] [blame] | 129 | # This test needs to start from a clean build, but setup creates an |
| 130 | # initialized tree that has already been built once. Clear the out |
Lukacs T. Berki | 731bb91 | 2021-04-16 09:16:19 +0200 | [diff] [blame] | 131 | # directory to start from scratch (see b/185591972) |
Colin Cross | b72877f | 2021-04-16 10:09:54 -0700 | [diff] [blame] | 132 | rm -rf out |
| 133 | |
Colin Cross | 1042595 | 2021-04-12 18:59:18 -0700 | [diff] [blame] | 134 | mkdir -p a |
| 135 | cat > a/Android.bp <<'EOF' |
| 136 | python_binary_host { |
| 137 | name: "my_little_binary_host", |
| 138 | srcs: ["*.py"], |
| 139 | } |
| 140 | EOF |
| 141 | touch a/my_little_binary_host.py |
| 142 | run_soong |
| 143 | local ninja_mtime1=$(stat -c "%y" out/soong/build.ninja) |
| 144 | |
Colin Cross | cb33a00 | 2021-04-12 22:25:17 -0700 | [diff] [blame] | 145 | local glob_deps_file=out/soong/.primary/globs/0.d |
Colin Cross | 1042595 | 2021-04-12 18:59:18 -0700 | [diff] [blame] | 146 | |
| 147 | if [ -e "$glob_deps_file" ]; then |
| 148 | fail "Glob deps file unexpectedly written on first build" |
| 149 | fi |
| 150 | |
| 151 | run_soong |
| 152 | local ninja_mtime2=$(stat -c "%y" out/soong/build.ninja) |
| 153 | |
| 154 | # There is an ineffiencency in glob that requires bpglob to rerun once for each glob to update |
| 155 | # the entry in the .ninja_log. It doesn't update the output file, but we can detect the rerun |
| 156 | # by checking if the deps file was created. |
| 157 | if [ ! -e "$glob_deps_file" ]; then |
| 158 | fail "Glob deps file missing after second build" |
| 159 | fi |
| 160 | |
| 161 | local glob_deps_mtime2=$(stat -c "%y" "$glob_deps_file") |
| 162 | |
| 163 | if [[ "$ninja_mtime1" != "$ninja_mtime2" ]]; then |
| 164 | fail "Ninja file rewritten on null incremental build" |
| 165 | fi |
| 166 | |
| 167 | run_soong |
| 168 | local ninja_mtime3=$(stat -c "%y" out/soong/build.ninja) |
| 169 | local glob_deps_mtime3=$(stat -c "%y" "$glob_deps_file") |
| 170 | |
| 171 | if [[ "$ninja_mtime2" != "$ninja_mtime3" ]]; then |
| 172 | fail "Ninja file rewritten on null incremental build" |
| 173 | fi |
| 174 | |
| 175 | # The bpglob commands should not rerun after the first incremental build. |
| 176 | if [[ "$glob_deps_mtime2" != "$glob_deps_mtime3" ]]; then |
| 177 | fail "Glob deps file rewritten on second null incremental build" |
| 178 | fi |
| 179 | } |
| 180 | |
Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 181 | function test_add_file_to_glob() { |
| 182 | setup |
| 183 | |
| 184 | mkdir -p a |
| 185 | cat > a/Android.bp <<'EOF' |
| 186 | python_binary_host { |
| 187 | name: "my_little_binary_host", |
| 188 | srcs: ["*.py"], |
| 189 | } |
| 190 | EOF |
| 191 | touch a/my_little_binary_host.py |
| 192 | run_soong |
| 193 | local mtime1=$(stat -c "%y" out/soong/build.ninja) |
| 194 | |
| 195 | touch a/my_little_library.py |
| 196 | run_soong |
| 197 | |
| 198 | local mtime2=$(stat -c "%y" out/soong/build.ninja) |
| 199 | if [[ "$mtime1" == "$mtime2" ]]; then |
| 200 | fail "Output Ninja file did not change" |
| 201 | fi |
| 202 | |
| 203 | grep -q my_little_library.py out/soong/build.ninja || fail "new file is not in output" |
| 204 | } |
| 205 | |
Lukacs T. Berki | f0b3b94 | 2021-03-23 11:46:47 +0100 | [diff] [blame] | 206 | function test_soong_build_rerun_iff_environment_changes() { |
| 207 | setup |
| 208 | |
| 209 | mkdir -p cherry |
| 210 | cat > cherry/Android.bp <<'EOF' |
| 211 | bootstrap_go_package { |
| 212 | name: "cherry", |
| 213 | pkgPath: "android/soong/cherry", |
| 214 | deps: [ |
| 215 | "blueprint", |
| 216 | "soong", |
| 217 | "soong-android", |
| 218 | ], |
| 219 | srcs: [ |
| 220 | "cherry.go", |
| 221 | ], |
| 222 | pluginFor: ["soong_build"], |
| 223 | } |
| 224 | EOF |
| 225 | |
| 226 | cat > cherry/cherry.go <<'EOF' |
| 227 | package cherry |
| 228 | |
| 229 | import ( |
| 230 | "android/soong/android" |
| 231 | "github.com/google/blueprint" |
| 232 | ) |
| 233 | |
| 234 | var ( |
| 235 | pctx = android.NewPackageContext("cherry") |
| 236 | ) |
| 237 | |
| 238 | func init() { |
| 239 | android.RegisterSingletonType("cherry", CherrySingleton) |
| 240 | } |
| 241 | |
| 242 | func CherrySingleton() android.Singleton { |
| 243 | return &cherrySingleton{} |
| 244 | } |
| 245 | |
| 246 | type cherrySingleton struct{} |
| 247 | |
| 248 | func (p *cherrySingleton) GenerateBuildActions(ctx android.SingletonContext) { |
| 249 | cherryRule := ctx.Rule(pctx, "cherry", |
| 250 | blueprint.RuleParams{ |
| 251 | Command: "echo CHERRY IS " + ctx.Config().Getenv("CHERRY") + " > ${out}", |
| 252 | CommandDeps: []string{}, |
| 253 | Description: "Cherry", |
| 254 | }) |
| 255 | |
| 256 | outputFile := android.PathForOutput(ctx, "cherry", "cherry.txt") |
| 257 | var deps android.Paths |
| 258 | |
| 259 | ctx.Build(pctx, android.BuildParams{ |
| 260 | Rule: cherryRule, |
| 261 | Output: outputFile, |
| 262 | Inputs: deps, |
| 263 | }) |
| 264 | } |
| 265 | EOF |
| 266 | |
| 267 | export CHERRY=TASTY |
| 268 | run_soong |
| 269 | grep -q "CHERRY IS TASTY" out/soong/build.ninja \ |
| 270 | || fail "first value of environment variable is not used" |
| 271 | |
| 272 | export CHERRY=RED |
| 273 | run_soong |
| 274 | grep -q "CHERRY IS RED" out/soong/build.ninja \ |
| 275 | || fail "second value of environment variable not used" |
| 276 | local mtime1=$(stat -c "%y" out/soong/build.ninja) |
| 277 | |
| 278 | run_soong |
| 279 | local mtime2=$(stat -c "%y" out/soong/build.ninja) |
| 280 | if [[ "$mtime1" != "$mtime2" ]]; then |
| 281 | fail "Output Ninja file changed when environment variable did not" |
| 282 | fi |
| 283 | |
| 284 | } |
| 285 | |
Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 286 | function test_add_file_to_soong_build() { |
| 287 | setup |
| 288 | run_soong |
| 289 | local mtime1=$(stat -c "%y" out/soong/build.ninja) |
| 290 | |
| 291 | mkdir -p a |
| 292 | cat > a/Android.bp <<'EOF' |
| 293 | bootstrap_go_package { |
| 294 | name: "picard-soong-rules", |
| 295 | pkgPath: "android/soong/picard", |
| 296 | deps: [ |
| 297 | "blueprint", |
| 298 | "soong", |
| 299 | "soong-android", |
| 300 | ], |
| 301 | srcs: [ |
| 302 | "picard.go", |
| 303 | ], |
| 304 | pluginFor: ["soong_build"], |
| 305 | } |
| 306 | EOF |
| 307 | |
| 308 | cat > a/picard.go <<'EOF' |
| 309 | package picard |
| 310 | |
| 311 | import ( |
| 312 | "android/soong/android" |
| 313 | "github.com/google/blueprint" |
| 314 | ) |
| 315 | |
| 316 | var ( |
| 317 | pctx = android.NewPackageContext("picard") |
| 318 | ) |
| 319 | |
| 320 | func init() { |
| 321 | android.RegisterSingletonType("picard", PicardSingleton) |
| 322 | } |
| 323 | |
| 324 | func PicardSingleton() android.Singleton { |
| 325 | return &picardSingleton{} |
| 326 | } |
| 327 | |
| 328 | type picardSingleton struct{} |
| 329 | |
| 330 | func (p *picardSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
| 331 | picardRule := ctx.Rule(pctx, "picard", |
| 332 | blueprint.RuleParams{ |
| 333 | Command: "echo Make it so. > ${out}", |
| 334 | CommandDeps: []string{}, |
| 335 | Description: "Something quotable", |
| 336 | }) |
| 337 | |
| 338 | outputFile := android.PathForOutput(ctx, "picard", "picard.txt") |
| 339 | var deps android.Paths |
| 340 | |
| 341 | ctx.Build(pctx, android.BuildParams{ |
| 342 | Rule: picardRule, |
| 343 | Output: outputFile, |
| 344 | Inputs: deps, |
| 345 | }) |
| 346 | } |
| 347 | |
| 348 | EOF |
| 349 | |
| 350 | run_soong |
| 351 | local mtime2=$(stat -c "%y" out/soong/build.ninja) |
| 352 | if [[ "$mtime1" == "$mtime2" ]]; then |
| 353 | fail "Output Ninja file did not change" |
| 354 | fi |
| 355 | |
| 356 | grep -q "Make it so" out/soong/build.ninja || fail "New action not present" |
| 357 | } |
| 358 | |
Colin Cross | c02504e | 2021-04-08 10:34:16 -0700 | [diff] [blame] | 359 | # Tests a glob in a build= statement in an Android.bp file, which is interpreted |
| 360 | # during bootstrapping. |
| 361 | function test_glob_during_bootstrapping() { |
| 362 | setup |
| 363 | |
| 364 | mkdir -p a |
| 365 | cat > a/Android.bp <<'EOF' |
| 366 | build=["foo*.bp"] |
| 367 | EOF |
| 368 | cat > a/fooa.bp <<'EOF' |
| 369 | bootstrap_go_package { |
| 370 | name: "picard-soong-rules", |
| 371 | pkgPath: "android/soong/picard", |
| 372 | deps: [ |
| 373 | "blueprint", |
| 374 | "soong", |
| 375 | "soong-android", |
| 376 | ], |
| 377 | srcs: [ |
| 378 | "picard.go", |
| 379 | ], |
| 380 | pluginFor: ["soong_build"], |
| 381 | } |
| 382 | EOF |
| 383 | |
| 384 | cat > a/picard.go <<'EOF' |
| 385 | package picard |
| 386 | |
| 387 | import ( |
| 388 | "android/soong/android" |
| 389 | "github.com/google/blueprint" |
| 390 | ) |
| 391 | |
| 392 | var ( |
| 393 | pctx = android.NewPackageContext("picard") |
| 394 | ) |
| 395 | |
| 396 | func init() { |
| 397 | android.RegisterSingletonType("picard", PicardSingleton) |
| 398 | } |
| 399 | |
| 400 | func PicardSingleton() android.Singleton { |
| 401 | return &picardSingleton{} |
| 402 | } |
| 403 | |
| 404 | type picardSingleton struct{} |
| 405 | |
| 406 | var Message = "Make it so." |
| 407 | |
| 408 | func (p *picardSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
| 409 | picardRule := ctx.Rule(pctx, "picard", |
| 410 | blueprint.RuleParams{ |
| 411 | Command: "echo " + Message + " > ${out}", |
| 412 | CommandDeps: []string{}, |
| 413 | Description: "Something quotable", |
| 414 | }) |
| 415 | |
| 416 | outputFile := android.PathForOutput(ctx, "picard", "picard.txt") |
| 417 | var deps android.Paths |
| 418 | |
| 419 | ctx.Build(pctx, android.BuildParams{ |
| 420 | Rule: picardRule, |
| 421 | Output: outputFile, |
| 422 | Inputs: deps, |
| 423 | }) |
| 424 | } |
| 425 | |
| 426 | EOF |
| 427 | |
| 428 | run_soong |
| 429 | local mtime1=$(stat -c "%y" out/soong/build.ninja) |
| 430 | |
| 431 | grep -q "Make it so" out/soong/build.ninja || fail "Original action not present" |
| 432 | |
| 433 | cat > a/foob.bp <<'EOF' |
| 434 | bootstrap_go_package { |
| 435 | name: "worf-soong-rules", |
| 436 | pkgPath: "android/soong/worf", |
| 437 | deps: [ |
| 438 | "blueprint", |
| 439 | "soong", |
| 440 | "soong-android", |
| 441 | "picard-soong-rules", |
| 442 | ], |
| 443 | srcs: [ |
| 444 | "worf.go", |
| 445 | ], |
| 446 | pluginFor: ["soong_build"], |
| 447 | } |
| 448 | EOF |
| 449 | |
| 450 | cat > a/worf.go <<'EOF' |
| 451 | package worf |
| 452 | |
| 453 | import "android/soong/picard" |
| 454 | |
| 455 | func init() { |
| 456 | picard.Message = "Engage." |
| 457 | } |
| 458 | EOF |
| 459 | |
| 460 | run_soong |
| 461 | local mtime2=$(stat -c "%y" out/soong/build.ninja) |
| 462 | if [[ "$mtime1" == "$mtime2" ]]; then |
| 463 | fail "Output Ninja file did not change" |
| 464 | fi |
| 465 | |
| 466 | grep -q "Engage" out/soong/build.ninja || fail "New action not present" |
| 467 | |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 468 | if grep -q "Make it so" out/soong/build.ninja; then |
| 469 | fail "Original action still present" |
| 470 | fi |
Colin Cross | c02504e | 2021-04-08 10:34:16 -0700 | [diff] [blame] | 471 | } |
| 472 | |
Lukacs T. Berki | f0b3b94 | 2021-03-23 11:46:47 +0100 | [diff] [blame] | 473 | function test_null_build_after_docs { |
| 474 | setup |
| 475 | run_soong |
| 476 | local mtime1=$(stat -c "%y" out/soong/build.ninja) |
| 477 | |
| 478 | prebuilts/build-tools/linux-x86/bin/ninja -f out/soong/build.ninja soong_docs |
| 479 | run_soong |
| 480 | local mtime2=$(stat -c "%y" out/soong/build.ninja) |
| 481 | |
| 482 | if [[ "$mtime1" != "$mtime2" ]]; then |
| 483 | fail "Output Ninja file changed on null build" |
| 484 | fi |
| 485 | } |
| 486 | |
Chris Parsons | ec1a3dc | 2021-04-20 15:32:07 -0400 | [diff] [blame] | 487 | function test_bp2build_smoke { |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 488 | setup |
Chris Parsons | ec1a3dc | 2021-04-20 15:32:07 -0400 | [diff] [blame] | 489 | GENERATE_BAZEL_FILES=1 run_soong |
Lukacs T. Berki | b353cca | 2021-04-16 13:47:36 +0200 | [diff] [blame] | 490 | [[ -e out/soong/.bootstrap/bp2build_workspace_marker ]] || fail "bp2build marker file not created" |
| 491 | [[ -e out/soong/workspace ]] || fail "Bazel workspace not created" |
Lukacs T. Berki | d518e1a | 2021-04-14 13:49:50 +0200 | [diff] [blame] | 492 | } |
| 493 | |
Chris Parsons | ec1a3dc | 2021-04-20 15:32:07 -0400 | [diff] [blame] | 494 | function test_bp2build_add_android_bp { |
Lukacs T. Berki | d518e1a | 2021-04-14 13:49:50 +0200 | [diff] [blame] | 495 | setup |
| 496 | |
| 497 | mkdir -p a |
| 498 | touch a/a.txt |
| 499 | cat > a/Android.bp <<'EOF' |
| 500 | filegroup { |
| 501 | name: "a", |
| 502 | srcs: ["a.txt"], |
| 503 | bazel_module: { bp2build_available: true }, |
| 504 | } |
| 505 | EOF |
| 506 | |
Chris Parsons | ec1a3dc | 2021-04-20 15:32:07 -0400 | [diff] [blame] | 507 | GENERATE_BAZEL_FILES=1 run_soong |
Lukacs T. Berki | b353cca | 2021-04-16 13:47:36 +0200 | [diff] [blame] | 508 | [[ -e out/soong/bp2build/a/BUILD ]] || fail "a/BUILD not created" |
| 509 | [[ -L out/soong/workspace/a/BUILD ]] || fail "a/BUILD not symlinked" |
Lukacs T. Berki | d518e1a | 2021-04-14 13:49:50 +0200 | [diff] [blame] | 510 | |
| 511 | mkdir -p b |
| 512 | touch b/b.txt |
| 513 | cat > b/Android.bp <<'EOF' |
| 514 | filegroup { |
| 515 | name: "b", |
| 516 | srcs: ["b.txt"], |
| 517 | bazel_module: { bp2build_available: true }, |
| 518 | } |
| 519 | EOF |
| 520 | |
Chris Parsons | ec1a3dc | 2021-04-20 15:32:07 -0400 | [diff] [blame] | 521 | GENERATE_BAZEL_FILES=1 run_soong |
Lukacs T. Berki | b353cca | 2021-04-16 13:47:36 +0200 | [diff] [blame] | 522 | [[ -e out/soong/bp2build/b/BUILD ]] || fail "a/BUILD not created" |
| 523 | [[ -L out/soong/workspace/b/BUILD ]] || fail "a/BUILD not symlinked" |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 524 | } |
| 525 | |
Chris Parsons | ec1a3dc | 2021-04-20 15:32:07 -0400 | [diff] [blame] | 526 | function test_bp2build_null_build { |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 527 | setup |
Lukacs T. Berki | d518e1a | 2021-04-14 13:49:50 +0200 | [diff] [blame] | 528 | |
Chris Parsons | ec1a3dc | 2021-04-20 15:32:07 -0400 | [diff] [blame] | 529 | GENERATE_BAZEL_FILES=1 run_soong |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 530 | local mtime1=$(stat -c "%y" out/soong/build.ninja) |
| 531 | |
Chris Parsons | ec1a3dc | 2021-04-20 15:32:07 -0400 | [diff] [blame] | 532 | GENERATE_BAZEL_FILES=1 run_soong |
Lukacs T. Berki | f8e2428 | 2021-04-14 10:31:00 +0200 | [diff] [blame] | 533 | local mtime2=$(stat -c "%y" out/soong/build.ninja) |
| 534 | |
| 535 | if [[ "$mtime1" != "$mtime2" ]]; then |
| 536 | fail "Output Ninja file changed on null build" |
| 537 | fi |
| 538 | } |
| 539 | |
Chris Parsons | ec1a3dc | 2021-04-20 15:32:07 -0400 | [diff] [blame] | 540 | function test_bp2build_add_to_glob { |
Lukacs T. Berki | d518e1a | 2021-04-14 13:49:50 +0200 | [diff] [blame] | 541 | setup |
| 542 | |
| 543 | mkdir -p a |
| 544 | touch a/a1.txt |
| 545 | cat > a/Android.bp <<'EOF' |
| 546 | filegroup { |
| 547 | name: "a", |
| 548 | srcs: ["*.txt"], |
| 549 | bazel_module: { bp2build_available: true }, |
| 550 | } |
| 551 | EOF |
| 552 | |
Chris Parsons | ec1a3dc | 2021-04-20 15:32:07 -0400 | [diff] [blame] | 553 | GENERATE_BAZEL_FILES=1 run_soong |
Lukacs T. Berki | d518e1a | 2021-04-14 13:49:50 +0200 | [diff] [blame] | 554 | grep -q a1.txt out/soong/bp2build/a/BUILD || fail "a1.txt not in BUILD file" |
| 555 | |
| 556 | touch a/a2.txt |
Chris Parsons | ec1a3dc | 2021-04-20 15:32:07 -0400 | [diff] [blame] | 557 | GENERATE_BAZEL_FILES=1 run_soong |
Lukacs T. Berki | d518e1a | 2021-04-14 13:49:50 +0200 | [diff] [blame] | 558 | grep -q a2.txt out/soong/bp2build/a/BUILD || fail "a2.txt not in BUILD file" |
| 559 | } |
| 560 | |
Lukacs T. Berki | 97bb9f1 | 2021-04-01 18:28:45 +0200 | [diff] [blame] | 561 | function test_dump_json_module_graph() { |
| 562 | setup |
| 563 | SOONG_DUMP_JSON_MODULE_GRAPH="$MOCK_TOP/modules.json" run_soong |
| 564 | if [[ ! -r "$MOCK_TOP/modules.json" ]]; then |
| 565 | fail "JSON file was not created" |
| 566 | fi |
| 567 | } |
| 568 | |
Chris Parsons | ec1a3dc | 2021-04-20 15:32:07 -0400 | [diff] [blame] | 569 | function test_bp2build_bazel_workspace_structure { |
Lukacs T. Berki | b353cca | 2021-04-16 13:47:36 +0200 | [diff] [blame] | 570 | setup |
| 571 | |
| 572 | mkdir -p a/b |
| 573 | touch a/a.txt |
| 574 | touch a/b/b.txt |
| 575 | cat > a/b/Android.bp <<'EOF' |
| 576 | filegroup { |
| 577 | name: "b", |
| 578 | srcs: ["b.txt"], |
| 579 | bazel_module: { bp2build_available: true }, |
| 580 | } |
| 581 | EOF |
| 582 | |
Chris Parsons | ec1a3dc | 2021-04-20 15:32:07 -0400 | [diff] [blame] | 583 | GENERATE_BAZEL_FILES=1 run_soong |
Lukacs T. Berki | b353cca | 2021-04-16 13:47:36 +0200 | [diff] [blame] | 584 | [[ -e out/soong/workspace ]] || fail "Bazel workspace not created" |
| 585 | [[ -d out/soong/workspace/a/b ]] || fail "module directory not a directory" |
| 586 | [[ -L out/soong/workspace/a/b/BUILD ]] || fail "BUILD file not symlinked" |
| 587 | [[ "$(readlink -f out/soong/workspace/a/b/BUILD)" =~ bp2build/a/b/BUILD$ ]] \ |
| 588 | || fail "BUILD files symlinked at the wrong place" |
| 589 | [[ -L out/soong/workspace/a/b/b.txt ]] || fail "a/b/b.txt not symlinked" |
| 590 | [[ -L out/soong/workspace/a/a.txt ]] || fail "a/b/a.txt not symlinked" |
| 591 | [[ ! -e out/soong/workspace/out ]] || fail "out directory symlinked" |
| 592 | } |
| 593 | |
Chris Parsons | ec1a3dc | 2021-04-20 15:32:07 -0400 | [diff] [blame] | 594 | function test_bp2build_bazel_workspace_add_file { |
Lukacs T. Berki | b353cca | 2021-04-16 13:47:36 +0200 | [diff] [blame] | 595 | setup |
| 596 | |
| 597 | mkdir -p a |
| 598 | touch a/a.txt |
| 599 | cat > a/Android.bp <<EOF |
| 600 | filegroup { |
| 601 | name: "a", |
| 602 | srcs: ["a.txt"], |
| 603 | bazel_module: { bp2build_available: true }, |
| 604 | } |
| 605 | EOF |
| 606 | |
Chris Parsons | ec1a3dc | 2021-04-20 15:32:07 -0400 | [diff] [blame] | 607 | GENERATE_BAZEL_FILES=1 run_soong |
Lukacs T. Berki | b353cca | 2021-04-16 13:47:36 +0200 | [diff] [blame] | 608 | |
| 609 | touch a/a2.txt # No reference in the .bp file needed |
Chris Parsons | ec1a3dc | 2021-04-20 15:32:07 -0400 | [diff] [blame] | 610 | GENERATE_BAZEL_FILES=1 run_soong |
Lukacs T. Berki | b353cca | 2021-04-16 13:47:36 +0200 | [diff] [blame] | 611 | [[ -L out/soong/workspace/a/a2.txt ]] || fail "a/a2.txt not symlinked" |
| 612 | } |
| 613 | |
Lukacs T. Berki | b21166e | 2021-04-21 11:58:36 +0200 | [diff] [blame] | 614 | function test_bp2build_build_file_precedence { |
| 615 | setup |
| 616 | |
| 617 | mkdir -p a |
| 618 | touch a/a.txt |
| 619 | touch a/BUILD |
| 620 | cat > a/Android.bp <<EOF |
| 621 | filegroup { |
| 622 | name: "a", |
| 623 | srcs: ["a.txt"], |
| 624 | bazel_module: { bp2build_available: true }, |
| 625 | } |
| 626 | EOF |
| 627 | |
| 628 | GENERATE_BAZEL_FILES=1 run_soong |
| 629 | [[ -L out/soong/workspace/a/BUILD ]] || fail "BUILD file not symlinked" |
| 630 | [[ "$(readlink -f out/soong/workspace/a/BUILD)" =~ bp2build/a/BUILD$ ]] \ |
| 631 | || fail "BUILD files symlinked to the wrong place" |
| 632 | } |
| 633 | |
| 634 | function test_bp2build_reports_multiple_errors { |
| 635 | setup |
| 636 | |
| 637 | mkdir -p a/BUILD |
| 638 | touch a/a.txt |
| 639 | cat > a/Android.bp <<EOF |
| 640 | filegroup { |
| 641 | name: "a", |
| 642 | srcs: ["a.txt"], |
| 643 | bazel_module: { bp2build_available: true }, |
| 644 | } |
| 645 | EOF |
| 646 | |
| 647 | mkdir -p b/BUILD |
| 648 | touch b/b.txt |
| 649 | cat > b/Android.bp <<EOF |
| 650 | filegroup { |
| 651 | name: "b", |
| 652 | srcs: ["b.txt"], |
| 653 | bazel_module: { bp2build_available: true }, |
| 654 | } |
| 655 | EOF |
| 656 | |
| 657 | if GENERATE_BAZEL_FILES=1 run_soong >& "$MOCK_TOP/errors"; then |
| 658 | fail "Build should have failed" |
| 659 | fi |
| 660 | |
| 661 | grep -q "a/BUILD' exist" "$MOCK_TOP/errors" || fail "Error for a/BUILD not found" |
| 662 | grep -q "b/BUILD' exist" "$MOCK_TOP/errors" || fail "Error for b/BUILD not found" |
| 663 | } |
| 664 | |
Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 665 | test_smoke |
| 666 | test_null_build |
Lukacs T. Berki | f0b3b94 | 2021-03-23 11:46:47 +0100 | [diff] [blame] | 667 | test_null_build_after_docs |
Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 668 | test_soong_build_rebuilt_if_blueprint_changes |
Lukacs T. Berki | b353cca | 2021-04-16 13:47:36 +0200 | [diff] [blame] | 669 | # test_glob_noop_incremental # Currently failing |
Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 670 | test_add_file_to_glob |
| 671 | test_add_android_bp |
| 672 | test_change_android_bp |
| 673 | test_delete_android_bp |
| 674 | test_add_file_to_soong_build |
Colin Cross | c02504e | 2021-04-08 10:34:16 -0700 | [diff] [blame] | 675 | test_glob_during_bootstrapping |
Lukacs T. Berki | f0b3b94 | 2021-03-23 11:46:47 +0100 | [diff] [blame] | 676 | test_soong_build_rerun_iff_environment_changes |
Lukacs T. Berki | 97bb9f1 | 2021-04-01 18:28:45 +0200 | [diff] [blame] | 677 | test_dump_json_module_graph |
Chris Parsons | ec1a3dc | 2021-04-20 15:32:07 -0400 | [diff] [blame] | 678 | test_bp2build_smoke |
| 679 | test_bp2build_null_build |
| 680 | test_bp2build_add_android_bp |
| 681 | test_bp2build_add_to_glob |
| 682 | test_bp2build_bazel_workspace_structure |
| 683 | test_bp2build_bazel_workspace_add_file |
Lukacs T. Berki | b21166e | 2021-04-21 11:58:36 +0200 | [diff] [blame] | 684 | test_bp2build_build_file_precedence |
| 685 | test_bp2build_reports_multiple_errors |