blob: 5853a7b0018bfd2e8f8fa4b66390b29f3ef502a4 [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
20 local bootstrap_mtime1=$(stat -c "%y" out/soong/.bootstrap/build.ninja)
21 local output_mtime1=$(stat -c "%y" out/soong/build.ninja)
22 run_soong
23 local bootstrap_mtime2=$(stat -c "%y" out/soong/.bootstrap/build.ninja)
24 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
39 local mtime1=$(stat -c "%y" out/soong/.bootstrap/build.ninja)
40
41 sed -i 's/pluginGenSrcCmd/pluginGenSrcCmd2/g' build/blueprint/bootstrap/bootstrap.go
42
43 run_soong
44 local mtime2=$(stat -c "%y" out/soong/.bootstrap/build.ninja)
45
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
Lukacs T. Berkid1e3f1f2021-03-16 08:55:23 +0100288function test_add_file_to_soong_build() {
289 setup
290 run_soong
291 local mtime1=$(stat -c "%y" out/soong/build.ninja)
292
293 mkdir -p a
294 cat > a/Android.bp <<'EOF'
295bootstrap_go_package {
296 name: "picard-soong-rules",
297 pkgPath: "android/soong/picard",
298 deps: [
299 "blueprint",
300 "soong",
301 "soong-android",
302 ],
303 srcs: [
304 "picard.go",
305 ],
306 pluginFor: ["soong_build"],
307}
308EOF
309
310 cat > a/picard.go <<'EOF'
311package picard
312
313import (
314 "android/soong/android"
315 "github.com/google/blueprint"
316)
317
318var (
319 pctx = android.NewPackageContext("picard")
320)
321
322func init() {
323 android.RegisterSingletonType("picard", PicardSingleton)
324}
325
326func PicardSingleton() android.Singleton {
327 return &picardSingleton{}
328}
329
330type picardSingleton struct{}
331
332func (p *picardSingleton) GenerateBuildActions(ctx android.SingletonContext) {
333 picardRule := ctx.Rule(pctx, "picard",
334 blueprint.RuleParams{
335 Command: "echo Make it so. > ${out}",
336 CommandDeps: []string{},
337 Description: "Something quotable",
338 })
339
340 outputFile := android.PathForOutput(ctx, "picard", "picard.txt")
341 var deps android.Paths
342
343 ctx.Build(pctx, android.BuildParams{
344 Rule: picardRule,
345 Output: outputFile,
346 Inputs: deps,
347 })
348}
349
350EOF
351
352 run_soong
353 local mtime2=$(stat -c "%y" out/soong/build.ninja)
354 if [[ "$mtime1" == "$mtime2" ]]; then
355 fail "Output Ninja file did not change"
356 fi
357
358 grep -q "Make it so" out/soong/build.ninja || fail "New action not present"
359}
360
Colin Crossc02504e2021-04-08 10:34:16 -0700361# Tests a glob in a build= statement in an Android.bp file, which is interpreted
362# during bootstrapping.
363function test_glob_during_bootstrapping() {
364 setup
365
366 mkdir -p a
367 cat > a/Android.bp <<'EOF'
368build=["foo*.bp"]
369EOF
370 cat > a/fooa.bp <<'EOF'
371bootstrap_go_package {
372 name: "picard-soong-rules",
373 pkgPath: "android/soong/picard",
374 deps: [
375 "blueprint",
376 "soong",
377 "soong-android",
378 ],
379 srcs: [
380 "picard.go",
381 ],
382 pluginFor: ["soong_build"],
383}
384EOF
385
386 cat > a/picard.go <<'EOF'
387package picard
388
389import (
390 "android/soong/android"
391 "github.com/google/blueprint"
392)
393
394var (
395 pctx = android.NewPackageContext("picard")
396)
397
398func init() {
399 android.RegisterSingletonType("picard", PicardSingleton)
400}
401
402func PicardSingleton() android.Singleton {
403 return &picardSingleton{}
404}
405
406type picardSingleton struct{}
407
408var Message = "Make it so."
409
410func (p *picardSingleton) GenerateBuildActions(ctx android.SingletonContext) {
411 picardRule := ctx.Rule(pctx, "picard",
412 blueprint.RuleParams{
413 Command: "echo " + Message + " > ${out}",
414 CommandDeps: []string{},
415 Description: "Something quotable",
416 })
417
418 outputFile := android.PathForOutput(ctx, "picard", "picard.txt")
419 var deps android.Paths
420
421 ctx.Build(pctx, android.BuildParams{
422 Rule: picardRule,
423 Output: outputFile,
424 Inputs: deps,
425 })
426}
427
428EOF
429
430 run_soong
431 local mtime1=$(stat -c "%y" out/soong/build.ninja)
432
433 grep -q "Make it so" out/soong/build.ninja || fail "Original action not present"
434
435 cat > a/foob.bp <<'EOF'
436bootstrap_go_package {
437 name: "worf-soong-rules",
438 pkgPath: "android/soong/worf",
439 deps: [
440 "blueprint",
441 "soong",
442 "soong-android",
443 "picard-soong-rules",
444 ],
445 srcs: [
446 "worf.go",
447 ],
448 pluginFor: ["soong_build"],
449}
450EOF
451
452 cat > a/worf.go <<'EOF'
453package worf
454
455import "android/soong/picard"
456
457func init() {
458 picard.Message = "Engage."
459}
460EOF
461
462 run_soong
463 local mtime2=$(stat -c "%y" out/soong/build.ninja)
464 if [[ "$mtime1" == "$mtime2" ]]; then
465 fail "Output Ninja file did not change"
466 fi
467
468 grep -q "Engage" out/soong/build.ninja || fail "New action not present"
469
Lukacs T. Berkif8e24282021-04-14 10:31:00 +0200470 if grep -q "Make it so" out/soong/build.ninja; then
471 fail "Original action still present"
472 fi
Colin Crossc02504e2021-04-08 10:34:16 -0700473}
474
Lukacs T. Berkif0b3b942021-03-23 11:46:47 +0100475function test_null_build_after_docs {
476 setup
477 run_soong
478 local mtime1=$(stat -c "%y" out/soong/build.ninja)
479
Lukacs T. Berki1a86bd22021-08-19 16:24:30 +0200480 prebuilts/build-tools/linux-x86/bin/ninja -f out/combined.ninja soong_docs
481
Lukacs T. Berkif0b3b942021-03-23 11:46:47 +0100482 run_soong
483 local mtime2=$(stat -c "%y" out/soong/build.ninja)
484
485 if [[ "$mtime1" != "$mtime2" ]]; then
486 fail "Output Ninja file changed on null build"
487 fi
488}
489
Spandan Das05063612021-06-25 01:39:04 +0000490function test_write_to_source_tree {
491 setup
492 mkdir -p a
493 cat > a/Android.bp <<EOF
494genrule {
495 name: "write_to_source_tree",
496 out: ["write_to_source_tree"],
497 cmd: "touch file_in_source_tree && touch \$(out)",
498}
499EOF
500 readonly EXPECTED_OUT=out/soong/.intermediates/a/write_to_source_tree/gen/write_to_source_tree
501 readonly ERROR_LOG=${MOCK_TOP}/out/error.log
502 readonly ERROR_MSG="Read-only file system"
503 readonly ERROR_HINT_PATTERN="BUILD_BROKEN_SRC_DIR"
504 # Test in ReadOnly source tree
505 run_ninja BUILD_BROKEN_SRC_DIR_IS_WRITABLE=false ${EXPECTED_OUT} &> /dev/null && \
506 fail "Write to source tree should not work in a ReadOnly source tree"
507
508 if grep -q "${ERROR_MSG}" ${ERROR_LOG} && grep -q "${ERROR_HINT_PATTERN}" ${ERROR_LOG} ; then
509 echo Error message and error hint found in logs >/dev/null
510 else
511 fail "Did not find Read-only error AND error hint in error.log"
512 fi
513
514 # Test in ReadWrite source tree
515 run_ninja BUILD_BROKEN_SRC_DIR_IS_WRITABLE=true ${EXPECTED_OUT} &> /dev/null || \
516 fail "Write to source tree did not succeed in a ReadWrite source tree"
517
518 if grep -q "${ERROR_MSG}\|${ERROR_HINT_PATTERN}" ${ERROR_LOG} ; then
519 fail "Found read-only error OR error hint in error.log"
520 fi
521}
522
Chris Parsonsec1a3dc2021-04-20 15:32:07 -0400523function test_bp2build_smoke {
Lukacs T. Berkif8e24282021-04-14 10:31:00 +0200524 setup
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200525 run_soong bp2build
Lukacs T. Berkib353cca2021-04-16 13:47:36 +0200526 [[ -e out/soong/.bootstrap/bp2build_workspace_marker ]] || fail "bp2build marker file not created"
527 [[ -e out/soong/workspace ]] || fail "Bazel workspace not created"
Lukacs T. Berkid518e1a2021-04-14 13:49:50 +0200528}
529
Lukacs T. Berki56ebaf32021-08-12 14:03:55 +0200530function test_bp2build_generates_marker_file {
Jingwen Chen4fabaf52021-05-25 02:40:29 +0000531 setup
532 create_mock_bazel
533
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200534 run_soong bp2build
Jingwen Chen4fabaf52021-05-25 02:40:29 +0000535
Lukacs T. Berki56ebaf32021-08-12 14:03:55 +0200536 if [[ ! -f "./out/soong/.bootstrap/bp2build_workspace_marker" ]]; then
537 fail "Marker file was not generated"
Jingwen Chen4fabaf52021-05-25 02:40:29 +0000538 fi
539}
540
Chris Parsonsec1a3dc2021-04-20 15:32:07 -0400541function test_bp2build_add_android_bp {
Lukacs T. Berkid518e1a2021-04-14 13:49:50 +0200542 setup
543
544 mkdir -p a
545 touch a/a.txt
546 cat > a/Android.bp <<'EOF'
547filegroup {
548 name: "a",
549 srcs: ["a.txt"],
550 bazel_module: { bp2build_available: true },
551}
552EOF
553
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200554 run_soong bp2build
Rupert Shuttleworth413a7a92021-05-18 07:47:15 -0400555 [[ -e out/soong/bp2build/a/${GENERATED_BUILD_FILE_NAME} ]] || fail "a/${GENERATED_BUILD_FILE_NAME} not created"
556 [[ -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 +0200557
558 mkdir -p b
559 touch b/b.txt
560 cat > b/Android.bp <<'EOF'
561filegroup {
562 name: "b",
563 srcs: ["b.txt"],
564 bazel_module: { bp2build_available: true },
565}
566EOF
567
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200568 run_soong bp2build
Rupert Shuttleworth413a7a92021-05-18 07:47:15 -0400569 [[ -e out/soong/bp2build/b/${GENERATED_BUILD_FILE_NAME} ]] || fail "a/${GENERATED_BUILD_FILE_NAME} not created"
570 [[ -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 +0200571}
572
Chris Parsonsec1a3dc2021-04-20 15:32:07 -0400573function test_bp2build_null_build {
Lukacs T. Berkif8e24282021-04-14 10:31:00 +0200574 setup
Lukacs T. Berkid518e1a2021-04-14 13:49:50 +0200575
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200576 run_soong bp2build
Lukacs T. Berki56ebaf32021-08-12 14:03:55 +0200577 local mtime1=$(stat -c "%y" out/soong/.bootstrap/bp2build_workspace_marker)
Lukacs T. Berkif8e24282021-04-14 10:31:00 +0200578
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200579 run_soong bp2build
Lukacs T. Berki56ebaf32021-08-12 14:03:55 +0200580 local mtime2=$(stat -c "%y" out/soong/.bootstrap/bp2build_workspace_marker)
Lukacs T. Berkif8e24282021-04-14 10:31:00 +0200581
582 if [[ "$mtime1" != "$mtime2" ]]; then
583 fail "Output Ninja file changed on null build"
584 fi
585}
586
Chris Parsonsec1a3dc2021-04-20 15:32:07 -0400587function test_bp2build_add_to_glob {
Lukacs T. Berkid518e1a2021-04-14 13:49:50 +0200588 setup
589
590 mkdir -p a
591 touch a/a1.txt
592 cat > a/Android.bp <<'EOF'
593filegroup {
594 name: "a",
595 srcs: ["*.txt"],
596 bazel_module: { bp2build_available: true },
597}
598EOF
599
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200600 run_soong bp2build
Rupert Shuttleworth413a7a92021-05-18 07:47:15 -0400601 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 +0200602
603 touch a/a2.txt
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200604 run_soong bp2build
Rupert Shuttleworth413a7a92021-05-18 07:47:15 -0400605 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 +0200606}
607
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200608function test_multiple_soong_build_modes() {
609 setup
610 run_soong json-module-graph bp2build nothing
611 if [[ ! -f "out/soong/.bootstrap/bp2build_workspace_marker" ]]; then
612 fail "bp2build marker file was not generated"
613 fi
614
615
616 if [[ ! -f "out/soong/module-graph.json" ]]; then
617 fail "JSON file was not created"
618 fi
619
620 if [[ ! -f "out/soong/build.ninja" ]]; then
621 fail "Main build.ninja file was not created"
622 fi
623}
624
Lukacs T. Berki97bb9f12021-04-01 18:28:45 +0200625function test_dump_json_module_graph() {
626 setup
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200627 run_soong json-module-graph
628 if [[ ! -r "out/soong/module-graph.json" ]]; then
Lukacs T. Berki97bb9f12021-04-01 18:28:45 +0200629 fail "JSON file was not created"
630 fi
631}
632
Lukacs T. Berkie571dc32021-08-25 14:14:13 +0200633function test_json_module_graph_back_and_forth_null_build() {
634 setup
635
636 run_soong
637 local ninja_mtime1=$(stat -c "%y" out/soong/build.ninja)
638
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200639 run_soong json-module-graph
Lukacs T. Berkie571dc32021-08-25 14:14:13 +0200640 local json_mtime1=$(stat -c "%y" out/soong/module-graph.json)
641
642 run_soong
643 local ninja_mtime2=$(stat -c "%y" out/soong/build.ninja)
644 if [[ "$ninja_mtime1" != "$ninja_mtime2" ]]; then
645 fail "Output Ninja file changed after writing JSON module graph"
646 fi
647
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200648 run_soong json-module-graph
Lukacs T. Berkie571dc32021-08-25 14:14:13 +0200649 local json_mtime2=$(stat -c "%y" out/soong/module-graph.json)
650 if [[ "$json_mtime1" != "$json_mtime2" ]]; then
651 fail "JSON module graph file changed after writing Ninja file"
652 fi
653
654}
655
656
Chris Parsonsec1a3dc2021-04-20 15:32:07 -0400657function test_bp2build_bazel_workspace_structure {
Lukacs T. Berkib353cca2021-04-16 13:47:36 +0200658 setup
659
660 mkdir -p a/b
661 touch a/a.txt
662 touch a/b/b.txt
663 cat > a/b/Android.bp <<'EOF'
664filegroup {
665 name: "b",
666 srcs: ["b.txt"],
667 bazel_module: { bp2build_available: true },
668}
669EOF
670
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200671 run_soong bp2build
Lukacs T. Berkib353cca2021-04-16 13:47:36 +0200672 [[ -e out/soong/workspace ]] || fail "Bazel workspace not created"
673 [[ -d out/soong/workspace/a/b ]] || fail "module directory not a directory"
Rupert Shuttleworth413a7a92021-05-18 07:47:15 -0400674 [[ -L "out/soong/workspace/a/b/${GENERATED_BUILD_FILE_NAME}" ]] || fail "${GENERATED_BUILD_FILE_NAME} file not symlinked"
675 [[ "$(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 +0200676 || fail "BUILD files symlinked at the wrong place"
677 [[ -L out/soong/workspace/a/b/b.txt ]] || fail "a/b/b.txt not symlinked"
678 [[ -L out/soong/workspace/a/a.txt ]] || fail "a/b/a.txt not symlinked"
679 [[ ! -e out/soong/workspace/out ]] || fail "out directory symlinked"
680}
681
Chris Parsonsec1a3dc2021-04-20 15:32:07 -0400682function test_bp2build_bazel_workspace_add_file {
Lukacs T. Berkib353cca2021-04-16 13:47:36 +0200683 setup
684
685 mkdir -p a
686 touch a/a.txt
687 cat > a/Android.bp <<EOF
688filegroup {
689 name: "a",
690 srcs: ["a.txt"],
691 bazel_module: { bp2build_available: true },
692}
693EOF
694
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200695 run_soong bp2build
Lukacs T. Berkib353cca2021-04-16 13:47:36 +0200696
697 touch a/a2.txt # No reference in the .bp file needed
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200698 run_soong bp2build
Lukacs T. Berkib353cca2021-04-16 13:47:36 +0200699 [[ -L out/soong/workspace/a/a2.txt ]] || fail "a/a2.txt not symlinked"
700}
701
Lukacs T. Berkib21166e2021-04-21 11:58:36 +0200702function test_bp2build_build_file_precedence {
703 setup
704
705 mkdir -p a
706 touch a/a.txt
Rupert Shuttleworth413a7a92021-05-18 07:47:15 -0400707 touch a/${GENERATED_BUILD_FILE_NAME}
Lukacs T. Berkib21166e2021-04-21 11:58:36 +0200708 cat > a/Android.bp <<EOF
709filegroup {
710 name: "a",
711 srcs: ["a.txt"],
712 bazel_module: { bp2build_available: true },
713}
714EOF
715
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200716 run_soong bp2build
Rupert Shuttleworth413a7a92021-05-18 07:47:15 -0400717 [[ -L "out/soong/workspace/a/${GENERATED_BUILD_FILE_NAME}" ]] || fail "${GENERATED_BUILD_FILE_NAME} file not symlinked"
718 [[ "$(readlink -f out/soong/workspace/a/${GENERATED_BUILD_FILE_NAME})" =~ "bp2build/a/${GENERATED_BUILD_FILE_NAME}"$ ]] \
719 || fail "${GENERATED_BUILD_FILE_NAME} files symlinked to the wrong place"
Lukacs T. Berkib21166e2021-04-21 11:58:36 +0200720}
721
722function test_bp2build_reports_multiple_errors {
723 setup
724
Rupert Shuttleworth413a7a92021-05-18 07:47:15 -0400725 mkdir -p "a/${GENERATED_BUILD_FILE_NAME}"
Lukacs T. Berkib21166e2021-04-21 11:58:36 +0200726 touch a/a.txt
727 cat > a/Android.bp <<EOF
728filegroup {
729 name: "a",
730 srcs: ["a.txt"],
731 bazel_module: { bp2build_available: true },
732}
733EOF
734
Rupert Shuttleworth413a7a92021-05-18 07:47:15 -0400735 mkdir -p "b/${GENERATED_BUILD_FILE_NAME}"
Lukacs T. Berkib21166e2021-04-21 11:58:36 +0200736 touch b/b.txt
737 cat > b/Android.bp <<EOF
738filegroup {
739 name: "b",
740 srcs: ["b.txt"],
741 bazel_module: { bp2build_available: true },
742}
743EOF
744
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200745 if run_soong bp2build >& "$MOCK_TOP/errors"; then
Lukacs T. Berkib21166e2021-04-21 11:58:36 +0200746 fail "Build should have failed"
747 fi
748
Rupert Shuttleworth413a7a92021-05-18 07:47:15 -0400749 grep -q "a/${GENERATED_BUILD_FILE_NAME}' exist" "$MOCK_TOP/errors" || fail "Error for a/${GENERATED_BUILD_FILE_NAME} not found"
750 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 +0200751}
752
Lukacs T. Berki56ebaf32021-08-12 14:03:55 +0200753function test_bp2build_back_and_forth_null_build {
754 setup
755
756 run_soong
757 local output_mtime1=$(stat -c "%y" out/soong/build.ninja)
758
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200759 run_soong bp2build
Lukacs T. Berki56ebaf32021-08-12 14:03:55 +0200760 local output_mtime2=$(stat -c "%y" out/soong/build.ninja)
761 if [[ "$output_mtime1" != "$output_mtime2" ]]; then
762 fail "Output Ninja file changed when switching to bp2build"
763 fi
764
765 local marker_mtime1=$(stat -c "%y" out/soong/.bootstrap/bp2build_workspace_marker)
766
767 run_soong
768 local output_mtime3=$(stat -c "%y" out/soong/build.ninja)
769 local marker_mtime2=$(stat -c "%y" out/soong/.bootstrap/bp2build_workspace_marker)
770 if [[ "$output_mtime1" != "$output_mtime3" ]]; then
771 fail "Output Ninja file changed when switching to regular build from bp2build"
772 fi
773 if [[ "$marker_mtime1" != "$marker_mtime2" ]]; then
774 fail "bp2build marker file changed when switching to regular build from bp2build"
775 fi
776
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200777 run_soong bp2build
Lukacs T. Berki56ebaf32021-08-12 14:03:55 +0200778 local output_mtime4=$(stat -c "%y" out/soong/build.ninja)
779 local marker_mtime3=$(stat -c "%y" out/soong/.bootstrap/bp2build_workspace_marker)
780 if [[ "$output_mtime1" != "$output_mtime4" ]]; then
781 fail "Output Ninja file changed when switching back to bp2build"
782 fi
783 if [[ "$marker_mtime1" != "$marker_mtime3" ]]; then
784 fail "bp2build marker file changed when switching back to bp2build"
785 fi
786}
787
Lukacs T. Berkid1e3f1f2021-03-16 08:55:23 +0100788test_smoke
789test_null_build
Lukacs T. Berkif0b3b942021-03-23 11:46:47 +0100790test_null_build_after_docs
Lukacs T. Berkid1e3f1f2021-03-16 08:55:23 +0100791test_soong_build_rebuilt_if_blueprint_changes
Lukacs T. Berki69ed2a22021-04-21 12:05:08 +0200792test_glob_noop_incremental
Lukacs T. Berkid1e3f1f2021-03-16 08:55:23 +0100793test_add_file_to_glob
794test_add_android_bp
795test_change_android_bp
796test_delete_android_bp
797test_add_file_to_soong_build
Colin Crossc02504e2021-04-08 10:34:16 -0700798test_glob_during_bootstrapping
Lukacs T. Berkif0b3b942021-03-23 11:46:47 +0100799test_soong_build_rerun_iff_environment_changes
Lukacs T. Berkia1b93722021-09-02 17:23:06 +0200800test_multiple_soong_build_modes
Lukacs T. Berki97bb9f12021-04-01 18:28:45 +0200801test_dump_json_module_graph
Lukacs T. Berkie571dc32021-08-25 14:14:13 +0200802test_json_module_graph_back_and_forth_null_build
Spandan Das05063612021-06-25 01:39:04 +0000803test_write_to_source_tree
Chris Parsonsec1a3dc2021-04-20 15:32:07 -0400804test_bp2build_smoke
Lukacs T. Berki56ebaf32021-08-12 14:03:55 +0200805test_bp2build_generates_marker_file
Chris Parsonsec1a3dc2021-04-20 15:32:07 -0400806test_bp2build_null_build
Lukacs T. Berki56ebaf32021-08-12 14:03:55 +0200807test_bp2build_back_and_forth_null_build
Chris Parsonsec1a3dc2021-04-20 15:32:07 -0400808test_bp2build_add_android_bp
809test_bp2build_add_to_glob
810test_bp2build_bazel_workspace_structure
811test_bp2build_bazel_workspace_add_file
Lukacs T. Berkib21166e2021-04-21 11:58:36 +0200812test_bp2build_build_file_precedence
813test_bp2build_reports_multiple_errors