Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 1 | #!/bin/bash -eu |
| 2 | |
| 3 | # This test exercises the bootstrapping process of the build system |
| 4 | # in a source tree that only contains enough files for Bazel and Soong to work. |
| 5 | |
Lukacs T. Berki | 3b730c4 | 2021-04-08 13:21:13 +0200 | [diff] [blame^] | 6 | source "$(dirname "$0")/lib.sh" |
Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 7 | |
| 8 | function test_smoke { |
| 9 | setup |
| 10 | run_soong |
| 11 | } |
| 12 | |
Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 13 | function test_null_build() { |
| 14 | setup |
| 15 | run_soong |
| 16 | local bootstrap_mtime1=$(stat -c "%y" out/soong/.bootstrap/build.ninja) |
| 17 | local output_mtime1=$(stat -c "%y" out/soong/build.ninja) |
| 18 | run_soong |
| 19 | local bootstrap_mtime2=$(stat -c "%y" out/soong/.bootstrap/build.ninja) |
| 20 | local output_mtime2=$(stat -c "%y" out/soong/build.ninja) |
| 21 | |
| 22 | if [[ "$bootstrap_mtime1" == "$bootstrap_mtime2" ]]; then |
| 23 | # Bootstrapping is always done. It doesn't take a measurable amount of time. |
| 24 | fail "Bootstrap Ninja file did not change on null build" |
| 25 | fi |
| 26 | |
| 27 | if [[ "$output_mtime1" != "$output_mtime2" ]]; then |
| 28 | fail "Output Ninja file changed on null build" |
| 29 | fi |
| 30 | } |
| 31 | |
| 32 | function test_soong_build_rebuilt_if_blueprint_changes() { |
| 33 | setup |
| 34 | run_soong |
| 35 | local mtime1=$(stat -c "%y" out/soong/.bootstrap/build.ninja) |
| 36 | |
| 37 | sed -i 's/pluginGenSrcCmd/pluginGenSrcCmd2/g' build/blueprint/bootstrap/bootstrap.go |
| 38 | |
| 39 | run_soong |
| 40 | local mtime2=$(stat -c "%y" out/soong/.bootstrap/build.ninja) |
| 41 | |
| 42 | if [[ "$mtime1" == "$mtime2" ]]; then |
| 43 | fail "Bootstrap Ninja file did not change" |
| 44 | fi |
| 45 | } |
| 46 | |
| 47 | function test_change_android_bp() { |
| 48 | setup |
| 49 | mkdir -p a |
| 50 | cat > a/Android.bp <<'EOF' |
| 51 | python_binary_host { |
| 52 | name: "my_little_binary_host", |
| 53 | srcs: ["my_little_binary_host.py"] |
| 54 | } |
| 55 | EOF |
| 56 | touch a/my_little_binary_host.py |
| 57 | run_soong |
| 58 | |
| 59 | grep -q "^# Module:.*my_little_binary_host" out/soong/build.ninja || fail "module not found" |
| 60 | |
| 61 | cat > a/Android.bp <<'EOF' |
| 62 | python_binary_host { |
| 63 | name: "my_great_binary_host", |
| 64 | srcs: ["my_great_binary_host.py"] |
| 65 | } |
| 66 | EOF |
| 67 | touch a/my_great_binary_host.py |
| 68 | run_soong |
| 69 | |
| 70 | grep -q "^# Module:.*my_little_binary_host" out/soong/build.ninja && fail "old module found" |
| 71 | grep -q "^# Module:.*my_great_binary_host" out/soong/build.ninja || fail "new module not found" |
| 72 | } |
| 73 | |
| 74 | |
| 75 | function test_add_android_bp() { |
| 76 | setup |
| 77 | run_soong |
| 78 | local mtime1=$(stat -c "%y" out/soong/build.ninja) |
| 79 | |
| 80 | mkdir -p a |
| 81 | cat > a/Android.bp <<'EOF' |
| 82 | python_binary_host { |
| 83 | name: "my_little_binary_host", |
| 84 | srcs: ["my_little_binary_host.py"] |
| 85 | } |
| 86 | EOF |
| 87 | touch a/my_little_binary_host.py |
| 88 | run_soong |
| 89 | |
| 90 | local mtime2=$(stat -c "%y" out/soong/build.ninja) |
| 91 | if [[ "$mtime1" == "$mtime2" ]]; then |
| 92 | fail "Output Ninja file did not change" |
| 93 | fi |
| 94 | |
| 95 | grep -q "^# Module:.*my_little_binary_host$" out/soong/build.ninja || fail "New module not in output" |
| 96 | |
| 97 | run_soong |
| 98 | } |
| 99 | |
| 100 | function test_delete_android_bp() { |
| 101 | setup |
| 102 | mkdir -p a |
| 103 | cat > a/Android.bp <<'EOF' |
| 104 | python_binary_host { |
| 105 | name: "my_little_binary_host", |
| 106 | srcs: ["my_little_binary_host.py"] |
| 107 | } |
| 108 | EOF |
| 109 | touch a/my_little_binary_host.py |
| 110 | run_soong |
| 111 | |
| 112 | grep -q "^# Module:.*my_little_binary_host$" out/soong/build.ninja || fail "Module not in output" |
| 113 | |
| 114 | rm a/Android.bp |
| 115 | run_soong |
| 116 | |
| 117 | grep -q "^# Module:.*my_little_binary_host$" out/soong/build.ninja && fail "Old module in output" |
| 118 | } |
| 119 | |
| 120 | function test_add_file_to_glob() { |
| 121 | setup |
| 122 | |
| 123 | mkdir -p a |
| 124 | cat > a/Android.bp <<'EOF' |
| 125 | python_binary_host { |
| 126 | name: "my_little_binary_host", |
| 127 | srcs: ["*.py"], |
| 128 | } |
| 129 | EOF |
| 130 | touch a/my_little_binary_host.py |
| 131 | run_soong |
| 132 | local mtime1=$(stat -c "%y" out/soong/build.ninja) |
| 133 | |
| 134 | touch a/my_little_library.py |
| 135 | run_soong |
| 136 | |
| 137 | local mtime2=$(stat -c "%y" out/soong/build.ninja) |
| 138 | if [[ "$mtime1" == "$mtime2" ]]; then |
| 139 | fail "Output Ninja file did not change" |
| 140 | fi |
| 141 | |
| 142 | grep -q my_little_library.py out/soong/build.ninja || fail "new file is not in output" |
| 143 | } |
| 144 | |
Lukacs T. Berki | f0b3b94 | 2021-03-23 11:46:47 +0100 | [diff] [blame] | 145 | function test_soong_build_rerun_iff_environment_changes() { |
| 146 | setup |
| 147 | |
| 148 | mkdir -p cherry |
| 149 | cat > cherry/Android.bp <<'EOF' |
| 150 | bootstrap_go_package { |
| 151 | name: "cherry", |
| 152 | pkgPath: "android/soong/cherry", |
| 153 | deps: [ |
| 154 | "blueprint", |
| 155 | "soong", |
| 156 | "soong-android", |
| 157 | ], |
| 158 | srcs: [ |
| 159 | "cherry.go", |
| 160 | ], |
| 161 | pluginFor: ["soong_build"], |
| 162 | } |
| 163 | EOF |
| 164 | |
| 165 | cat > cherry/cherry.go <<'EOF' |
| 166 | package cherry |
| 167 | |
| 168 | import ( |
| 169 | "android/soong/android" |
| 170 | "github.com/google/blueprint" |
| 171 | ) |
| 172 | |
| 173 | var ( |
| 174 | pctx = android.NewPackageContext("cherry") |
| 175 | ) |
| 176 | |
| 177 | func init() { |
| 178 | android.RegisterSingletonType("cherry", CherrySingleton) |
| 179 | } |
| 180 | |
| 181 | func CherrySingleton() android.Singleton { |
| 182 | return &cherrySingleton{} |
| 183 | } |
| 184 | |
| 185 | type cherrySingleton struct{} |
| 186 | |
| 187 | func (p *cherrySingleton) GenerateBuildActions(ctx android.SingletonContext) { |
| 188 | cherryRule := ctx.Rule(pctx, "cherry", |
| 189 | blueprint.RuleParams{ |
| 190 | Command: "echo CHERRY IS " + ctx.Config().Getenv("CHERRY") + " > ${out}", |
| 191 | CommandDeps: []string{}, |
| 192 | Description: "Cherry", |
| 193 | }) |
| 194 | |
| 195 | outputFile := android.PathForOutput(ctx, "cherry", "cherry.txt") |
| 196 | var deps android.Paths |
| 197 | |
| 198 | ctx.Build(pctx, android.BuildParams{ |
| 199 | Rule: cherryRule, |
| 200 | Output: outputFile, |
| 201 | Inputs: deps, |
| 202 | }) |
| 203 | } |
| 204 | EOF |
| 205 | |
| 206 | export CHERRY=TASTY |
| 207 | run_soong |
| 208 | grep -q "CHERRY IS TASTY" out/soong/build.ninja \ |
| 209 | || fail "first value of environment variable is not used" |
| 210 | |
| 211 | export CHERRY=RED |
| 212 | run_soong |
| 213 | grep -q "CHERRY IS RED" out/soong/build.ninja \ |
| 214 | || fail "second value of environment variable not used" |
| 215 | local mtime1=$(stat -c "%y" out/soong/build.ninja) |
| 216 | |
| 217 | run_soong |
| 218 | local mtime2=$(stat -c "%y" out/soong/build.ninja) |
| 219 | if [[ "$mtime1" != "$mtime2" ]]; then |
| 220 | fail "Output Ninja file changed when environment variable did not" |
| 221 | fi |
| 222 | |
| 223 | } |
| 224 | |
Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 225 | function test_add_file_to_soong_build() { |
| 226 | setup |
| 227 | run_soong |
| 228 | local mtime1=$(stat -c "%y" out/soong/build.ninja) |
| 229 | |
| 230 | mkdir -p a |
| 231 | cat > a/Android.bp <<'EOF' |
| 232 | bootstrap_go_package { |
| 233 | name: "picard-soong-rules", |
| 234 | pkgPath: "android/soong/picard", |
| 235 | deps: [ |
| 236 | "blueprint", |
| 237 | "soong", |
| 238 | "soong-android", |
| 239 | ], |
| 240 | srcs: [ |
| 241 | "picard.go", |
| 242 | ], |
| 243 | pluginFor: ["soong_build"], |
| 244 | } |
| 245 | EOF |
| 246 | |
| 247 | cat > a/picard.go <<'EOF' |
| 248 | package picard |
| 249 | |
| 250 | import ( |
| 251 | "android/soong/android" |
| 252 | "github.com/google/blueprint" |
| 253 | ) |
| 254 | |
| 255 | var ( |
| 256 | pctx = android.NewPackageContext("picard") |
| 257 | ) |
| 258 | |
| 259 | func init() { |
| 260 | android.RegisterSingletonType("picard", PicardSingleton) |
| 261 | } |
| 262 | |
| 263 | func PicardSingleton() android.Singleton { |
| 264 | return &picardSingleton{} |
| 265 | } |
| 266 | |
| 267 | type picardSingleton struct{} |
| 268 | |
| 269 | func (p *picardSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
| 270 | picardRule := ctx.Rule(pctx, "picard", |
| 271 | blueprint.RuleParams{ |
| 272 | Command: "echo Make it so. > ${out}", |
| 273 | CommandDeps: []string{}, |
| 274 | Description: "Something quotable", |
| 275 | }) |
| 276 | |
| 277 | outputFile := android.PathForOutput(ctx, "picard", "picard.txt") |
| 278 | var deps android.Paths |
| 279 | |
| 280 | ctx.Build(pctx, android.BuildParams{ |
| 281 | Rule: picardRule, |
| 282 | Output: outputFile, |
| 283 | Inputs: deps, |
| 284 | }) |
| 285 | } |
| 286 | |
| 287 | EOF |
| 288 | |
| 289 | run_soong |
| 290 | local mtime2=$(stat -c "%y" out/soong/build.ninja) |
| 291 | if [[ "$mtime1" == "$mtime2" ]]; then |
| 292 | fail "Output Ninja file did not change" |
| 293 | fi |
| 294 | |
| 295 | grep -q "Make it so" out/soong/build.ninja || fail "New action not present" |
| 296 | } |
| 297 | |
Lukacs T. Berki | f0b3b94 | 2021-03-23 11:46:47 +0100 | [diff] [blame] | 298 | function test_null_build_after_docs { |
| 299 | setup |
| 300 | run_soong |
| 301 | local mtime1=$(stat -c "%y" out/soong/build.ninja) |
| 302 | |
| 303 | prebuilts/build-tools/linux-x86/bin/ninja -f out/soong/build.ninja soong_docs |
| 304 | run_soong |
| 305 | local mtime2=$(stat -c "%y" out/soong/build.ninja) |
| 306 | |
| 307 | if [[ "$mtime1" != "$mtime2" ]]; then |
| 308 | fail "Output Ninja file changed on null build" |
| 309 | fi |
| 310 | } |
| 311 | |
Lukacs T. Berki | 97bb9f1 | 2021-04-01 18:28:45 +0200 | [diff] [blame] | 312 | function test_dump_json_module_graph() { |
| 313 | setup |
| 314 | SOONG_DUMP_JSON_MODULE_GRAPH="$MOCK_TOP/modules.json" run_soong |
| 315 | if [[ ! -r "$MOCK_TOP/modules.json" ]]; then |
| 316 | fail "JSON file was not created" |
| 317 | fi |
| 318 | } |
| 319 | |
Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 320 | test_smoke |
| 321 | test_null_build |
Lukacs T. Berki | f0b3b94 | 2021-03-23 11:46:47 +0100 | [diff] [blame] | 322 | test_null_build_after_docs |
Lukacs T. Berki | d1e3f1f | 2021-03-16 08:55:23 +0100 | [diff] [blame] | 323 | test_soong_build_rebuilt_if_blueprint_changes |
| 324 | test_add_file_to_glob |
| 325 | test_add_android_bp |
| 326 | test_change_android_bp |
| 327 | test_delete_android_bp |
| 328 | test_add_file_to_soong_build |
Lukacs T. Berki | f0b3b94 | 2021-03-23 11:46:47 +0100 | [diff] [blame] | 329 | test_soong_build_rerun_iff_environment_changes |
Lukacs T. Berki | 97bb9f1 | 2021-04-01 18:28:45 +0200 | [diff] [blame] | 330 | test_dump_json_module_graph |