blob: d89e6b7025cfdb22bbd9f4f64e75a9555a860035 [file] [log] [blame]
Lukacs T. Berkid1e3f1f2021-03-16 08:55:23 +01001#!/bin/bash -eu
2
Rupert Shuttleworth2a4fc3e2021-04-21 07:10:09 -04003set -o pipefail
4
Lukacs T. Berkid1e3f1f2021-03-16 08:55:23 +01005# 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. Berki3b730c42021-04-08 13:21:13 +02008source "$(dirname "$0")/lib.sh"
Lukacs T. Berkid1e3f1f2021-03-16 08:55:23 +01009
Rupert Shuttleworth413a7a92021-05-18 07:47:15 -040010readonly GENERATED_BUILD_FILE_NAME="BUILD.bazel"
11
Lukacs T. Berkid1e3f1f2021-03-16 08:55:23 +010012function test_smoke {
13 setup
14 run_soong
15}
16
Lukacs T. Berkid1e3f1f2021-03-16 08:55:23 +010017function test_null_build() {
18 setup
19 run_soong
Lukacs T. Berki90b43342021-11-02 14:42:04 +010020 local bootstrap_mtime1=$(stat -c "%y" out/soong/bootstrap.ninja)
Lukacs T. Berkid1e3f1f2021-03-16 08:55:23 +010021 local output_mtime1=$(stat -c "%y" out/soong/build.ninja)
22 run_soong
Lukacs T. Berki90b43342021-11-02 14:42:04 +010023 local bootstrap_mtime2=$(stat -c "%y" out/soong/bootstrap.ninja)
Lukacs T. Berkid1e3f1f2021-03-16 08:55:23 +010024 local output_mtime2=$(stat -c "%y" out/soong/build.ninja)
25
26 if [[ "$bootstrap_mtime1" == "$bootstrap_mtime2" ]]; then
27 # Bootstrapping is always done. It doesn't take a measurable amount of time.
28 fail "Bootstrap Ninja file did not change on null build"
29 fi
30
31 if [[ "$output_mtime1" != "$output_mtime2" ]]; then
32 fail "Output Ninja file changed on null build"
33 fi
34}
35
36function test_soong_build_rebuilt_if_blueprint_changes() {
37 setup
38 run_soong
Lukacs T. Berki90b43342021-11-02 14:42:04 +010039 local mtime1=$(stat -c "%y" out/soong/bootstrap.ninja)
Lukacs T. Berkid1e3f1f2021-03-16 08:55:23 +010040
41 sed -i 's/pluginGenSrcCmd/pluginGenSrcCmd2/g' build/blueprint/bootstrap/bootstrap.go
42
43 run_soong
Lukacs T. Berki90b43342021-11-02 14:42:04 +010044 local mtime2=$(stat -c "%y" out/soong/bootstrap.ninja)
Lukacs T. Berkid1e3f1f2021-03-16 08:55:23 +010045
46 if [[ "$mtime1" == "$mtime2" ]]; then
47 fail "Bootstrap Ninja file did not change"
48 fi
49}
50
51function test_change_android_bp() {
52 setup
53 mkdir -p a
54 cat > a/Android.bp <<'EOF'
55python_binary_host {
56 name: "my_little_binary_host",
57 srcs: ["my_little_binary_host.py"]
58}
59EOF
60 touch a/my_little_binary_host.py
61 run_soong
62
63 grep -q "^# Module:.*my_little_binary_host" out/soong/build.ninja || fail "module not found"
64
65 cat > a/Android.bp <<'EOF'
66python_binary_host {
67 name: "my_great_binary_host",
68 srcs: ["my_great_binary_host.py"]
69}
70EOF
71 touch a/my_great_binary_host.py
72 run_soong
73
74 grep -q "^# Module:.*my_little_binary_host" out/soong/build.ninja && fail "old module found"
75 grep -q "^# Module:.*my_great_binary_host" out/soong/build.ninja || fail "new module not found"
76}
77
78
79function test_add_android_bp() {
80 setup
81 run_soong
82 local mtime1=$(stat -c "%y" out/soong/build.ninja)
83
84 mkdir -p a
85 cat > a/Android.bp <<'EOF'
86python_binary_host {
87 name: "my_little_binary_host",
88 srcs: ["my_little_binary_host.py"]
89}
90EOF
91 touch a/my_little_binary_host.py
92 run_soong
93
94 local mtime2=$(stat -c "%y" out/soong/build.ninja)
95 if [[ "$mtime1" == "$mtime2" ]]; then
96 fail "Output Ninja file did not change"
97 fi
98
99 grep -q "^# Module:.*my_little_binary_host$" out/soong/build.ninja || fail "New module not in output"
100
101 run_soong
102}
103
104function test_delete_android_bp() {
105 setup
106 mkdir -p a
107 cat > a/Android.bp <<'EOF'
108python_binary_host {
109 name: "my_little_binary_host",
110 srcs: ["my_little_binary_host.py"]
111}
112EOF
113 touch a/my_little_binary_host.py
114 run_soong
115
116 grep -q "^# Module:.*my_little_binary_host$" out/soong/build.ninja || fail "Module not in output"
117
118 rm a/Android.bp
119 run_soong
120
Lukacs T. Berkif8e24282021-04-14 10:31:00 +0200121 if grep -q "^# Module:.*my_little_binary_host$" out/soong/build.ninja; then
122 fail "Old module in output"
123 fi
Lukacs T. Berkid1e3f1f2021-03-16 08:55:23 +0100124}
125
Colin Cross10425952021-04-12 18:59:18 -0700126# Test that an incremental build with a glob doesn't rerun soong_build, and
127# only regenerates the globs on the first but not the second incremental build.
128function test_glob_noop_incremental() {
129 setup
130
Colin Crossb72877f2021-04-16 10:09:54 -0700131 # This test needs to start from a clean build, but setup creates an
132 # initialized tree that has already been built once. Clear the out
Lukacs T. Berki731bb912021-04-16 09:16:19 +0200133 # directory to start from scratch (see b/185591972)
Colin Crossb72877f2021-04-16 10:09:54 -0700134 rm -rf out
135
Colin Cross10425952021-04-12 18:59:18 -0700136 mkdir -p a
137 cat > a/Android.bp <<'EOF'
138python_binary_host {
139 name: "my_little_binary_host",
140 srcs: ["*.py"],
141}
142EOF
143 touch a/my_little_binary_host.py
144 run_soong
145 local ninja_mtime1=$(stat -c "%y" out/soong/build.ninja)
146
Lukacs T. Berkia806e412021-09-01 08:57:48 +0200147 local glob_deps_file=out/soong/globs/build/0.d
Colin Cross10425952021-04-12 18:59:18 -0700148
149 if [ -e "$glob_deps_file" ]; then
150 fail "Glob deps file unexpectedly written on first build"
151 fi
152
153 run_soong
154 local ninja_mtime2=$(stat -c "%y" out/soong/build.ninja)
155
156 # There is an ineffiencency in glob that requires bpglob to rerun once for each glob to update
157 # the entry in the .ninja_log. It doesn't update the output file, but we can detect the rerun
158 # by checking if the deps file was created.
159 if [ ! -e "$glob_deps_file" ]; then
160 fail "Glob deps file missing after second build"
161 fi
162
163 local glob_deps_mtime2=$(stat -c "%y" "$glob_deps_file")
164
165 if [[ "$ninja_mtime1" != "$ninja_mtime2" ]]; then
166 fail "Ninja file rewritten on null incremental build"
167 fi
168
169 run_soong
170 local ninja_mtime3=$(stat -c "%y" out/soong/build.ninja)
171 local glob_deps_mtime3=$(stat -c "%y" "$glob_deps_file")
172
173 if [[ "$ninja_mtime2" != "$ninja_mtime3" ]]; then
174 fail "Ninja file rewritten on null incremental build"
175 fi
176
177 # The bpglob commands should not rerun after the first incremental build.
178 if [[ "$glob_deps_mtime2" != "$glob_deps_mtime3" ]]; then
179 fail "Glob deps file rewritten on second null incremental build"
180 fi
181}
182
Lukacs T. Berkid1e3f1f2021-03-16 08:55:23 +0100183function test_add_file_to_glob() {
184 setup
185
186 mkdir -p a
187 cat > a/Android.bp <<'EOF'
188python_binary_host {
189 name: "my_little_binary_host",
190 srcs: ["*.py"],
191}
192EOF
193 touch a/my_little_binary_host.py
194 run_soong
195 local mtime1=$(stat -c "%y" out/soong/build.ninja)
196
197 touch a/my_little_library.py
198 run_soong
199
200 local mtime2=$(stat -c "%y" out/soong/build.ninja)
201 if [[ "$mtime1" == "$mtime2" ]]; then
202 fail "Output Ninja file did not change"
203 fi
204
205 grep -q my_little_library.py out/soong/build.ninja || fail "new file is not in output"
206}
207
Lukacs T. Berkif0b3b942021-03-23 11:46:47 +0100208function test_soong_build_rerun_iff_environment_changes() {
209 setup
210
211 mkdir -p cherry
212 cat > cherry/Android.bp <<'EOF'
213bootstrap_go_package {
214 name: "cherry",
215 pkgPath: "android/soong/cherry",
216 deps: [
217 "blueprint",
218 "soong",
219 "soong-android",
220 ],
221 srcs: [
222 "cherry.go",
223 ],
224 pluginFor: ["soong_build"],
225}
226EOF
227
228 cat > cherry/cherry.go <<'EOF'
229package cherry
230
231import (
232 "android/soong/android"
233 "github.com/google/blueprint"
234)
235
236var (
237 pctx = android.NewPackageContext("cherry")
238)
239
240func init() {
241 android.RegisterSingletonType("cherry", CherrySingleton)
242}
243
244func CherrySingleton() android.Singleton {
245 return &cherrySingleton{}
246}
247
248type cherrySingleton struct{}
249
250func (p *cherrySingleton) GenerateBuildActions(ctx android.SingletonContext) {
251 cherryRule := ctx.Rule(pctx, "cherry",
252 blueprint.RuleParams{
253 Command: "echo CHERRY IS " + ctx.Config().Getenv("CHERRY") + " > ${out}",
254 CommandDeps: []string{},
255 Description: "Cherry",
256 })
257
258 outputFile := android.PathForOutput(ctx, "cherry", "cherry.txt")
259 var deps android.Paths
260
261 ctx.Build(pctx, android.BuildParams{
262 Rule: cherryRule,
263 Output: outputFile,
264 Inputs: deps,
265 })
266}
267EOF
268
269 export CHERRY=TASTY
270 run_soong
271 grep -q "CHERRY IS TASTY" out/soong/build.ninja \
272 || fail "first value of environment variable is not used"
273
274 export CHERRY=RED
275 run_soong
276 grep -q "CHERRY IS RED" out/soong/build.ninja \
277 || fail "second value of environment variable not used"
278 local mtime1=$(stat -c "%y" out/soong/build.ninja)
279
280 run_soong
281 local mtime2=$(stat -c "%y" out/soong/build.ninja)
282 if [[ "$mtime1" != "$mtime2" ]]; then
283 fail "Output Ninja file changed when environment variable did not"
284 fi
285
286}
287
Colin Cross662d6142022-11-03 20:38:01 -0700288function test_create_global_include_directory() {
289 setup
290 run_soong
291 local mtime1=$(stat -c "%y" out/soong/build.ninja)
292
293 # Soong needs to know if top level directories like hardware/ exist for use
294 # as global include directories. Make sure that doesn't cause regens for
295 # unrelated changes to the top level directory.
296 mkdir -p system/core
297
298 run_soong
299 local mtime2=$(stat -c "%y" out/soong/build.ninja)
300 if [[ "$mtime1" != "$mtime2" ]]; then
301 fail "Output Ninja file changed when top level directory changed"
302 fi
303
304 # Make sure it does regen if a missing directory in the path of a global
305 # include directory is added.
306 mkdir -p system/core/include
307
308 run_soong
309 local mtime3=$(stat -c "%y" out/soong/build.ninja)
310 if [[ "$mtime2" = "$mtime3" ]]; then
311 fail "Output Ninja file did not change when global include directory created"
312 fi
313
314}
315
316
Lukacs T. Berkid1e3f1f2021-03-16 08:55:23 +0100317function test_add_file_to_soong_build() {
318 setup
319 run_soong
320 local mtime1=$(stat -c "%y" out/soong/build.ninja)
321
322 mkdir -p a
323 cat > a/Android.bp <<'EOF'
324bootstrap_go_package {
325 name: "picard-soong-rules",
326 pkgPath: "android/soong/picard",
327 deps: [
328 "blueprint",
329 "soong",
330 "soong-android",
331 ],
332 srcs: [
333 "picard.go",
334 ],
335 pluginFor: ["soong_build"],
336}
337EOF
338
339 cat > a/picard.go <<'EOF'
340package picard
341
342import (
343 "android/soong/android"
344 "github.com/google/blueprint"
345)
346
347var (
348 pctx = android.NewPackageContext("picard")
349)
350
351func init() {
352 android.RegisterSingletonType("picard", PicardSingleton)
353}
354
355func PicardSingleton() android.Singleton {
356 return &picardSingleton{}
357}
358
359type picardSingleton struct{}
360
361func (p *picardSingleton) GenerateBuildActions(ctx android.SingletonContext) {
362 picardRule := ctx.Rule(pctx, "picard",
363 blueprint.RuleParams{
364 Command: "echo Make it so. > ${out}",
365 CommandDeps: []string{},
366 Description: "Something quotable",
367 })
368
369 outputFile := android.PathForOutput(ctx, "picard", "picard.txt")
370 var deps android.Paths
371
372 ctx.Build(pctx, android.BuildParams{
373 Rule: picardRule,
374 Output: outputFile,
375 Inputs: deps,
376 })
377}
378
379EOF
380
381 run_soong
382 local mtime2=$(stat -c "%y" out/soong/build.ninja)
383 if [[ "$mtime1" == "$mtime2" ]]; then
384 fail "Output Ninja file did not change"
385 fi
386
387 grep -q "Make it so" out/soong/build.ninja || fail "New action not present"
388}
389
Colin Crossc02504e2021-04-08 10:34:16 -0700390# Tests a glob in a build= statement in an Android.bp file, which is interpreted
391# during bootstrapping.
392function test_glob_during_bootstrapping() {
393 setup
394
395 mkdir -p a
396 cat > a/Android.bp <<'EOF'
397build=["foo*.bp"]
398EOF
399 cat > a/fooa.bp <<'EOF'
400bootstrap_go_package {
401 name: "picard-soong-rules",
402 pkgPath: "android/soong/picard",
403 deps: [
404 "blueprint",
405 "soong",
406 "soong-android",
407 ],
408 srcs: [
409 "picard.go",
410 ],
411 pluginFor: ["soong_build"],
412}
413EOF
414
415 cat > a/picard.go <<'EOF'
416package picard
417
418import (
419 "android/soong/android"
420 "github.com/google/blueprint"
421)
422
423var (
424 pctx = android.NewPackageContext("picard")
425)
426
427func init() {
428 android.RegisterSingletonType("picard", PicardSingleton)
429}
430
431func PicardSingleton() android.Singleton {
432 return &picardSingleton{}
433}
434
435type picardSingleton struct{}
436
437var Message = "Make it so."
438
439func (p *picardSingleton) GenerateBuildActions(ctx android.SingletonContext) {
440 picardRule := ctx.Rule(pctx, "picard",
441 blueprint.RuleParams{
442 Command: "echo " + Message + " > ${out}",
443 CommandDeps: []string{},
444 Description: "Something quotable",
445 })
446
447 outputFile := android.PathForOutput(ctx, "picard", "picard.txt")
448 var deps android.Paths
449
450 ctx.Build(pctx, android.BuildParams{
451 Rule: picardRule,
452 Output: outputFile,
453 Inputs: deps,
454 })
455}
456
457EOF
458
459 run_soong
460 local mtime1=$(stat -c "%y" out/soong/build.ninja)
461
462 grep -q "Make it so" out/soong/build.ninja || fail "Original action not present"
463
464 cat > a/foob.bp <<'EOF'
465bootstrap_go_package {
466 name: "worf-soong-rules",
467 pkgPath: "android/soong/worf",
468 deps: [
469 "blueprint",
470 "soong",
471 "soong-android",
472 "picard-soong-rules",
473 ],
474 srcs: [
475 "worf.go",
476 ],
477 pluginFor: ["soong_build"],
478}
479EOF
480
481 cat > a/worf.go <<'EOF'
482package worf
483
484import "android/soong/picard"
485
486func init() {
487 picard.Message = "Engage."
488}
489EOF
490
491 run_soong
492 local mtime2=$(stat -c "%y" out/soong/build.ninja)
493 if [[ "$mtime1" == "$mtime2" ]]; then
494 fail "Output Ninja file did not change"
495 fi
496
497 grep -q "Engage" out/soong/build.ninja || fail "New action not present"
498
Lukacs T. Berkif8e24282021-04-14 10:31:00 +0200499 if grep -q "Make it so" out/soong/build.ninja; then
500 fail "Original action still present"
501 fi
Colin Crossc02504e2021-04-08 10:34:16 -0700502}
503
Lukacs T. Berkic6012f32021-09-06 18:31:46 +0200504function test_soong_docs_smoke() {
Lukacs T. Berkif0b3b942021-03-23 11:46:47 +0100505 setup
Lukacs T. Berkif0b3b942021-03-23 11:46:47 +0100506
Lukacs T. Berkic6012f32021-09-06 18:31:46 +0200507 run_soong soong_docs
508
509 [[ -e "out/soong/docs/soong_build.html" ]] || fail "Documentation for main page not created"
510 [[ -e "out/soong/docs/cc.html" ]] || fail "Documentation for C++ modules not created"
511}
512
513function test_null_build_after_soong_docs() {
514 setup
Lukacs T. Berki1a86bd22021-08-19 16:24:30 +0200515
Lukacs T. Berkif0b3b942021-03-23 11:46:47 +0100516 run_soong
Lukacs T. Berkic6012f32021-09-06 18:31:46 +0200517 local ninja_mtime1=$(stat -c "%y" out/soong/build.ninja)
Lukacs T. Berkif0b3b942021-03-23 11:46:47 +0100518
Lukacs T. Berkic6012f32021-09-06 18:31:46 +0200519 run_soong soong_docs
520 local docs_mtime1=$(stat -c "%y" out/soong/docs/soong_build.html)
521
522 run_soong soong_docs
523 local docs_mtime2=$(stat -c "%y" out/soong/docs/soong_build.html)
524
525 if [[ "$docs_mtime1" != "$docs_mtime2" ]]; then
526 fail "Output Ninja file changed on null build"
527 fi
528
529 run_soong
530 local ninja_mtime2=$(stat -c "%y" out/soong/build.ninja)
531
532 if [[ "$ninja_mtime1" != "$ninja_mtime2" ]]; then
Lukacs T. Berkif0b3b942021-03-23 11:46:47 +0100533 fail "Output Ninja file changed on null build"
534 fi
535}
536
Spandan Das05063612021-06-25 01:39:04 +0000537function test_write_to_source_tree {
538 setup
539 mkdir -p a
540 cat > a/Android.bp <<EOF
541genrule {
542 name: "write_to_source_tree",
543 out: ["write_to_source_tree"],
544 cmd: "touch file_in_source_tree && touch \$(out)",
545}
546EOF
547 readonly EXPECTED_OUT=out/soong/.intermediates/a/write_to_source_tree/gen/write_to_source_tree
548 readonly ERROR_LOG=${MOCK_TOP}/out/error.log
549 readonly ERROR_MSG="Read-only file system"
550 readonly ERROR_HINT_PATTERN="BUILD_BROKEN_SRC_DIR"
551 # Test in ReadOnly source tree
552 run_ninja BUILD_BROKEN_SRC_DIR_IS_WRITABLE=false ${EXPECTED_OUT} &> /dev/null && \
553 fail "Write to source tree should not work in a ReadOnly source tree"
554
555 if grep -q "${ERROR_MSG}" ${ERROR_LOG} && grep -q "${ERROR_HINT_PATTERN}" ${ERROR_LOG} ; then
556 echo Error message and error hint found in logs >/dev/null
557 else
558 fail "Did not find Read-only error AND error hint in error.log"
559 fi
560
561 # Test in ReadWrite source tree
562 run_ninja BUILD_BROKEN_SRC_DIR_IS_WRITABLE=true ${EXPECTED_OUT} &> /dev/null || \
563 fail "Write to source tree did not succeed in a ReadWrite source tree"
564
565 if grep -q "${ERROR_MSG}\|${ERROR_HINT_PATTERN}" ${ERROR_LOG} ; then
566 fail "Found read-only error OR error hint in error.log"
567 fi
568}
569
Chris Parsonsec1a3dc2021-04-20 15:32:07 -0400570function test_bp2build_smoke {
Lukacs T. Berkif8e24282021-04-14 10:31:00 +0200571 setup
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200572 run_soong bp2build
Lukacs T. Berki90b43342021-11-02 14:42:04 +0100573 [[ -e out/soong/bp2build_workspace_marker ]] || fail "bp2build marker file not created"
Lukacs T. Berkib353cca2021-04-16 13:47:36 +0200574 [[ -e out/soong/workspace ]] || fail "Bazel workspace not created"
Lukacs T. Berkid518e1a2021-04-14 13:49:50 +0200575}
576
Lukacs T. Berki56ebaf32021-08-12 14:03:55 +0200577function test_bp2build_generates_marker_file {
Jingwen Chen4fabaf52021-05-25 02:40:29 +0000578 setup
Jingwen Chen4fabaf52021-05-25 02:40:29 +0000579
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200580 run_soong bp2build
Jingwen Chen4fabaf52021-05-25 02:40:29 +0000581
Lukacs T. Berkic541cd22022-10-26 07:26:50 +0000582 if [[ ! -f "./out/soong/bp2build_files_marker" ]]; then
583 fail "bp2build marker file was not generated"
584 fi
585
Lukacs T. Berki90b43342021-11-02 14:42:04 +0100586 if [[ ! -f "./out/soong/bp2build_workspace_marker" ]]; then
Lukacs T. Berkic541cd22022-10-26 07:26:50 +0000587 fail "symlink forest marker file was not generated"
588 fi
589}
590
591function test_bp2build_add_irrelevant_file {
592 setup
593
594 mkdir -p a/b
595 touch a/b/c.txt
596 cat > a/b/Android.bp <<'EOF'
597filegroup {
598 name: "c",
599 srcs: ["c.txt"],
600 bazel_module: { bp2build_available: true },
601}
602EOF
603
604 run_soong bp2build
605 if [[ ! -e out/soong/bp2build/a/b/BUILD.bazel ]]; then
606 fail "BUILD file in symlink forest was not created";
607 fi
608
609 local mtime1=$(stat -c "%y" out/soong/bp2build/a/b/BUILD.bazel)
610
611 touch a/irrelevant.txt
612 run_soong bp2build
613 local mtime2=$(stat -c "%y" out/soong/bp2build/a/b/BUILD.bazel)
614
615 if [[ "$mtime1" != "$mtime2" ]]; then
616 fail "BUILD.bazel file was regenerated"
617 fi
618
619 if [[ ! -e "out/soong/workspace/a/irrelevant.txt" ]]; then
620 fail "New file was not symlinked into symlink forest"
Jingwen Chen4fabaf52021-05-25 02:40:29 +0000621 fi
622}
623
Chris Parsonsec1a3dc2021-04-20 15:32:07 -0400624function test_bp2build_add_android_bp {
Lukacs T. Berkid518e1a2021-04-14 13:49:50 +0200625 setup
626
627 mkdir -p a
628 touch a/a.txt
629 cat > a/Android.bp <<'EOF'
630filegroup {
631 name: "a",
632 srcs: ["a.txt"],
633 bazel_module: { bp2build_available: true },
634}
635EOF
636
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200637 run_soong bp2build
Rupert Shuttleworth413a7a92021-05-18 07:47:15 -0400638 [[ -e out/soong/bp2build/a/${GENERATED_BUILD_FILE_NAME} ]] || fail "a/${GENERATED_BUILD_FILE_NAME} not created"
639 [[ -L out/soong/workspace/a/${GENERATED_BUILD_FILE_NAME} ]] || fail "a/${GENERATED_BUILD_FILE_NAME} not symlinked"
Lukacs T. Berkid518e1a2021-04-14 13:49:50 +0200640
641 mkdir -p b
642 touch b/b.txt
643 cat > b/Android.bp <<'EOF'
644filegroup {
645 name: "b",
646 srcs: ["b.txt"],
647 bazel_module: { bp2build_available: true },
648}
649EOF
650
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200651 run_soong bp2build
Rupert Shuttleworth413a7a92021-05-18 07:47:15 -0400652 [[ -e out/soong/bp2build/b/${GENERATED_BUILD_FILE_NAME} ]] || fail "a/${GENERATED_BUILD_FILE_NAME} not created"
653 [[ -L out/soong/workspace/b/${GENERATED_BUILD_FILE_NAME} ]] || fail "a/${GENERATED_BUILD_FILE_NAME} not symlinked"
Lukacs T. Berkif8e24282021-04-14 10:31:00 +0200654}
655
Chris Parsonsec1a3dc2021-04-20 15:32:07 -0400656function test_bp2build_null_build {
Lukacs T. Berkif8e24282021-04-14 10:31:00 +0200657 setup
Lukacs T. Berkid518e1a2021-04-14 13:49:50 +0200658
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200659 run_soong bp2build
Lukacs T. Berki90b43342021-11-02 14:42:04 +0100660 local mtime1=$(stat -c "%y" out/soong/bp2build_workspace_marker)
Lukacs T. Berkif8e24282021-04-14 10:31:00 +0200661
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200662 run_soong bp2build
Lukacs T. Berki90b43342021-11-02 14:42:04 +0100663 local mtime2=$(stat -c "%y" out/soong/bp2build_workspace_marker)
Lukacs T. Berkif8e24282021-04-14 10:31:00 +0200664
665 if [[ "$mtime1" != "$mtime2" ]]; then
666 fail "Output Ninja file changed on null build"
667 fi
668}
669
Chris Parsonsec1a3dc2021-04-20 15:32:07 -0400670function test_bp2build_add_to_glob {
Lukacs T. Berkid518e1a2021-04-14 13:49:50 +0200671 setup
672
673 mkdir -p a
674 touch a/a1.txt
675 cat > a/Android.bp <<'EOF'
676filegroup {
677 name: "a",
678 srcs: ["*.txt"],
679 bazel_module: { bp2build_available: true },
680}
681EOF
682
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200683 run_soong bp2build
Rupert Shuttleworth413a7a92021-05-18 07:47:15 -0400684 grep -q a1.txt "out/soong/bp2build/a/${GENERATED_BUILD_FILE_NAME}" || fail "a1.txt not in ${GENERATED_BUILD_FILE_NAME} file"
Lukacs T. Berkid518e1a2021-04-14 13:49:50 +0200685
686 touch a/a2.txt
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200687 run_soong bp2build
Rupert Shuttleworth413a7a92021-05-18 07:47:15 -0400688 grep -q a2.txt "out/soong/bp2build/a/${GENERATED_BUILD_FILE_NAME}" || fail "a2.txt not in ${GENERATED_BUILD_FILE_NAME} file"
Lukacs T. Berkid518e1a2021-04-14 13:49:50 +0200689}
690
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200691function test_multiple_soong_build_modes() {
692 setup
693 run_soong json-module-graph bp2build nothing
Lukacs T. Berki90b43342021-11-02 14:42:04 +0100694 if [[ ! -f "out/soong/bp2build_workspace_marker" ]]; then
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200695 fail "bp2build marker file was not generated"
696 fi
697
698
699 if [[ ! -f "out/soong/module-graph.json" ]]; then
700 fail "JSON file was not created"
701 fi
702
703 if [[ ! -f "out/soong/build.ninja" ]]; then
704 fail "Main build.ninja file was not created"
705 fi
706}
707
Lukacs T. Berki97bb9f12021-04-01 18:28:45 +0200708function test_dump_json_module_graph() {
709 setup
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200710 run_soong json-module-graph
711 if [[ ! -r "out/soong/module-graph.json" ]]; then
Lukacs T. Berki97bb9f12021-04-01 18:28:45 +0200712 fail "JSON file was not created"
713 fi
714}
715
Lukacs T. Berkie571dc32021-08-25 14:14:13 +0200716function test_json_module_graph_back_and_forth_null_build() {
717 setup
718
719 run_soong
720 local ninja_mtime1=$(stat -c "%y" out/soong/build.ninja)
721
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200722 run_soong json-module-graph
Lukacs T. Berkie571dc32021-08-25 14:14:13 +0200723 local json_mtime1=$(stat -c "%y" out/soong/module-graph.json)
724
725 run_soong
726 local ninja_mtime2=$(stat -c "%y" out/soong/build.ninja)
727 if [[ "$ninja_mtime1" != "$ninja_mtime2" ]]; then
728 fail "Output Ninja file changed after writing JSON module graph"
729 fi
730
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200731 run_soong json-module-graph
Lukacs T. Berkie571dc32021-08-25 14:14:13 +0200732 local json_mtime2=$(stat -c "%y" out/soong/module-graph.json)
733 if [[ "$json_mtime1" != "$json_mtime2" ]]; then
734 fail "JSON module graph file changed after writing Ninja file"
735 fi
736
737}
738
739
Chris Parsonsec1a3dc2021-04-20 15:32:07 -0400740function test_bp2build_bazel_workspace_structure {
Lukacs T. Berkib353cca2021-04-16 13:47:36 +0200741 setup
742
743 mkdir -p a/b
744 touch a/a.txt
745 touch a/b/b.txt
746 cat > a/b/Android.bp <<'EOF'
747filegroup {
748 name: "b",
749 srcs: ["b.txt"],
750 bazel_module: { bp2build_available: true },
751}
752EOF
753
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200754 run_soong bp2build
Lukacs T. Berkib353cca2021-04-16 13:47:36 +0200755 [[ -e out/soong/workspace ]] || fail "Bazel workspace not created"
756 [[ -d out/soong/workspace/a/b ]] || fail "module directory not a directory"
Rupert Shuttleworth413a7a92021-05-18 07:47:15 -0400757 [[ -L "out/soong/workspace/a/b/${GENERATED_BUILD_FILE_NAME}" ]] || fail "${GENERATED_BUILD_FILE_NAME} file not symlinked"
758 [[ "$(readlink -f out/soong/workspace/a/b/${GENERATED_BUILD_FILE_NAME})" =~ "bp2build/a/b/${GENERATED_BUILD_FILE_NAME}"$ ]] \
Lukacs T. Berkib353cca2021-04-16 13:47:36 +0200759 || fail "BUILD files symlinked at the wrong place"
760 [[ -L out/soong/workspace/a/b/b.txt ]] || fail "a/b/b.txt not symlinked"
761 [[ -L out/soong/workspace/a/a.txt ]] || fail "a/b/a.txt not symlinked"
762 [[ ! -e out/soong/workspace/out ]] || fail "out directory symlinked"
763}
764
Chris Parsonsec1a3dc2021-04-20 15:32:07 -0400765function test_bp2build_bazel_workspace_add_file {
Lukacs T. Berkib353cca2021-04-16 13:47:36 +0200766 setup
767
768 mkdir -p a
769 touch a/a.txt
770 cat > a/Android.bp <<EOF
771filegroup {
772 name: "a",
773 srcs: ["a.txt"],
774 bazel_module: { bp2build_available: true },
775}
776EOF
777
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200778 run_soong bp2build
Lukacs T. Berkib353cca2021-04-16 13:47:36 +0200779
780 touch a/a2.txt # No reference in the .bp file needed
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200781 run_soong bp2build
Lukacs T. Berkib353cca2021-04-16 13:47:36 +0200782 [[ -L out/soong/workspace/a/a2.txt ]] || fail "a/a2.txt not symlinked"
783}
784
Lukacs T. Berkib21166e2021-04-21 11:58:36 +0200785function test_bp2build_build_file_precedence {
786 setup
787
788 mkdir -p a
789 touch a/a.txt
Rupert Shuttleworth413a7a92021-05-18 07:47:15 -0400790 touch a/${GENERATED_BUILD_FILE_NAME}
Lukacs T. Berkib21166e2021-04-21 11:58:36 +0200791 cat > a/Android.bp <<EOF
792filegroup {
793 name: "a",
794 srcs: ["a.txt"],
795 bazel_module: { bp2build_available: true },
796}
797EOF
798
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200799 run_soong bp2build
Rupert Shuttleworth413a7a92021-05-18 07:47:15 -0400800 [[ -L "out/soong/workspace/a/${GENERATED_BUILD_FILE_NAME}" ]] || fail "${GENERATED_BUILD_FILE_NAME} file not symlinked"
801 [[ "$(readlink -f out/soong/workspace/a/${GENERATED_BUILD_FILE_NAME})" =~ "bp2build/a/${GENERATED_BUILD_FILE_NAME}"$ ]] \
802 || fail "${GENERATED_BUILD_FILE_NAME} files symlinked to the wrong place"
Lukacs T. Berkib21166e2021-04-21 11:58:36 +0200803}
804
805function test_bp2build_reports_multiple_errors {
806 setup
807
Rupert Shuttleworth413a7a92021-05-18 07:47:15 -0400808 mkdir -p "a/${GENERATED_BUILD_FILE_NAME}"
Lukacs T. Berkib21166e2021-04-21 11:58:36 +0200809 touch a/a.txt
810 cat > a/Android.bp <<EOF
811filegroup {
812 name: "a",
813 srcs: ["a.txt"],
814 bazel_module: { bp2build_available: true },
815}
816EOF
817
Rupert Shuttleworth413a7a92021-05-18 07:47:15 -0400818 mkdir -p "b/${GENERATED_BUILD_FILE_NAME}"
Lukacs T. Berkib21166e2021-04-21 11:58:36 +0200819 touch b/b.txt
820 cat > b/Android.bp <<EOF
821filegroup {
822 name: "b",
823 srcs: ["b.txt"],
824 bazel_module: { bp2build_available: true },
825}
826EOF
827
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200828 if run_soong bp2build >& "$MOCK_TOP/errors"; then
Lukacs T. Berkib21166e2021-04-21 11:58:36 +0200829 fail "Build should have failed"
830 fi
831
Rupert Shuttleworth413a7a92021-05-18 07:47:15 -0400832 grep -q "a/${GENERATED_BUILD_FILE_NAME}' exist" "$MOCK_TOP/errors" || fail "Error for a/${GENERATED_BUILD_FILE_NAME} not found"
833 grep -q "b/${GENERATED_BUILD_FILE_NAME}' exist" "$MOCK_TOP/errors" || fail "Error for b/${GENERATED_BUILD_FILE_NAME} not found"
Lukacs T. Berkib21166e2021-04-21 11:58:36 +0200834}
835
Lukacs T. Berki56ebaf32021-08-12 14:03:55 +0200836function test_bp2build_back_and_forth_null_build {
837 setup
838
839 run_soong
840 local output_mtime1=$(stat -c "%y" out/soong/build.ninja)
841
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200842 run_soong bp2build
Lukacs T. Berki56ebaf32021-08-12 14:03:55 +0200843 local output_mtime2=$(stat -c "%y" out/soong/build.ninja)
844 if [[ "$output_mtime1" != "$output_mtime2" ]]; then
845 fail "Output Ninja file changed when switching to bp2build"
846 fi
847
Lukacs T. Berki90b43342021-11-02 14:42:04 +0100848 local marker_mtime1=$(stat -c "%y" out/soong/bp2build_workspace_marker)
Lukacs T. Berki56ebaf32021-08-12 14:03:55 +0200849
850 run_soong
851 local output_mtime3=$(stat -c "%y" out/soong/build.ninja)
Lukacs T. Berki90b43342021-11-02 14:42:04 +0100852 local marker_mtime2=$(stat -c "%y" out/soong/bp2build_workspace_marker)
Lukacs T. Berki56ebaf32021-08-12 14:03:55 +0200853 if [[ "$output_mtime1" != "$output_mtime3" ]]; then
854 fail "Output Ninja file changed when switching to regular build from bp2build"
855 fi
856 if [[ "$marker_mtime1" != "$marker_mtime2" ]]; then
857 fail "bp2build marker file changed when switching to regular build from bp2build"
858 fi
859
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200860 run_soong bp2build
Lukacs T. Berki56ebaf32021-08-12 14:03:55 +0200861 local output_mtime4=$(stat -c "%y" out/soong/build.ninja)
Lukacs T. Berki90b43342021-11-02 14:42:04 +0100862 local marker_mtime3=$(stat -c "%y" out/soong/bp2build_workspace_marker)
Lukacs T. Berki56ebaf32021-08-12 14:03:55 +0200863 if [[ "$output_mtime1" != "$output_mtime4" ]]; then
864 fail "Output Ninja file changed when switching back to bp2build"
865 fi
866 if [[ "$marker_mtime1" != "$marker_mtime3" ]]; then
867 fail "bp2build marker file changed when switching back to bp2build"
868 fi
869}
870
Lukacs T. Berki3a821692021-09-06 17:08:02 +0200871function test_queryview_smoke() {
872 setup
873
874 run_soong queryview
875 [[ -e out/soong/queryview/WORKSPACE ]] || fail "queryview WORKSPACE file not created"
876
877}
878
879function test_queryview_null_build() {
880 setup
881
882 run_soong queryview
883 local output_mtime1=$(stat -c "%y" out/soong/queryview.marker)
884
885 run_soong queryview
886 local output_mtime2=$(stat -c "%y" out/soong/queryview.marker)
887
888 if [[ "$output_mtime1" != "$output_mtime2" ]]; then
889 fail "Queryview marker file changed on null build"
890 fi
891}
892
Lukacs T. Berkid1e3f1f2021-03-16 08:55:23 +0100893test_smoke
894test_null_build
Lukacs T. Berkic6012f32021-09-06 18:31:46 +0200895test_soong_docs_smoke
896test_null_build_after_soong_docs
Lukacs T. Berkid1e3f1f2021-03-16 08:55:23 +0100897test_soong_build_rebuilt_if_blueprint_changes
Lukacs T. Berki69ed2a22021-04-21 12:05:08 +0200898test_glob_noop_incremental
Lukacs T. Berkid1e3f1f2021-03-16 08:55:23 +0100899test_add_file_to_glob
900test_add_android_bp
901test_change_android_bp
902test_delete_android_bp
903test_add_file_to_soong_build
Colin Crossc02504e2021-04-08 10:34:16 -0700904test_glob_during_bootstrapping
Lukacs T. Berkif0b3b942021-03-23 11:46:47 +0100905test_soong_build_rerun_iff_environment_changes
Colin Cross662d6142022-11-03 20:38:01 -0700906test_create_global_include_directory
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200907test_multiple_soong_build_modes
Lukacs T. Berki97bb9f12021-04-01 18:28:45 +0200908test_dump_json_module_graph
Lukacs T. Berkie571dc32021-08-25 14:14:13 +0200909test_json_module_graph_back_and_forth_null_build
Spandan Das05063612021-06-25 01:39:04 +0000910test_write_to_source_tree
Lukacs T. Berki3a821692021-09-06 17:08:02 +0200911test_queryview_smoke
912test_queryview_null_build
Chris Parsonsec1a3dc2021-04-20 15:32:07 -0400913test_bp2build_smoke
Lukacs T. Berki56ebaf32021-08-12 14:03:55 +0200914test_bp2build_generates_marker_file
Chris Parsonsec1a3dc2021-04-20 15:32:07 -0400915test_bp2build_null_build
Lukacs T. Berki56ebaf32021-08-12 14:03:55 +0200916test_bp2build_back_and_forth_null_build
Chris Parsonsec1a3dc2021-04-20 15:32:07 -0400917test_bp2build_add_android_bp
Lukacs T. Berkic541cd22022-10-26 07:26:50 +0000918test_bp2build_add_irrelevant_file
Chris Parsonsec1a3dc2021-04-20 15:32:07 -0400919test_bp2build_add_to_glob
920test_bp2build_bazel_workspace_structure
921test_bp2build_bazel_workspace_add_file
Lukacs T. Berkib21166e2021-04-21 11:58:36 +0200922test_bp2build_build_file_precedence
923test_bp2build_reports_multiple_errors