Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 1 | // Copyright 2017 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package java |
| 16 | |
| 17 | import ( |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 18 | "fmt" |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 19 | "path/filepath" |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 20 | "reflect" |
Colin Cross | b69301e | 2017-12-01 10:48:26 -0800 | [diff] [blame] | 21 | "sort" |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 22 | "strings" |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 23 | "testing" |
Jaewoong Jung | a5e5abc | 2019-04-26 14:31:50 -0700 | [diff] [blame] | 24 | |
| 25 | "github.com/google/blueprint/proptools" |
| 26 | |
| 27 | "android/soong/android" |
| 28 | "android/soong/cc" |
Ulya Trafimovich | 9023b02 | 2021-03-22 16:02:28 +0000 | [diff] [blame] | 29 | "android/soong/dexpreopt" |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 30 | ) |
| 31 | |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame] | 32 | // testApp runs tests using the prepareForJavaTest |
Paul Duffin | 0ed42d3 | 2021-03-13 02:19:32 +0000 | [diff] [blame] | 33 | // |
| 34 | // See testJava for an explanation as to how to stop using this deprecated method. |
| 35 | // |
| 36 | // deprecated |
| 37 | func testApp(t *testing.T, bp string) *android.TestContext { |
| 38 | t.Helper() |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame] | 39 | result := prepareForJavaTest.RunTestWithBp(t, bp) |
Paul Duffin | 0ed42d3 | 2021-03-13 02:19:32 +0000 | [diff] [blame] | 40 | return result.TestContext |
| 41 | } |
| 42 | |
| 43 | func TestApp(t *testing.T) { |
| 44 | resourceFiles := []string{ |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 45 | "res/layout/layout.xml", |
| 46 | "res/values/strings.xml", |
| 47 | "res/values-en-rUS/strings.xml", |
| 48 | } |
| 49 | |
Paul Duffin | 0ed42d3 | 2021-03-13 02:19:32 +0000 | [diff] [blame] | 50 | compiledResourceFiles := []string{ |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 51 | "aapt2/res/layout_layout.xml.flat", |
| 52 | "aapt2/res/values_strings.arsc.flat", |
| 53 | "aapt2/res/values-en-rUS_strings.arsc.flat", |
| 54 | } |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 55 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 56 | for _, moduleType := range []string{"android_app", "android_library"} { |
| 57 | t.Run(moduleType, func(t *testing.T) { |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame] | 58 | result := android.GroupFixturePreparers( |
| 59 | prepareForJavaTest, |
Paul Duffin | 0ed42d3 | 2021-03-13 02:19:32 +0000 | [diff] [blame] | 60 | android.FixtureModifyMockFS(func(fs android.MockFS) { |
| 61 | for _, file := range resourceFiles { |
| 62 | fs[file] = nil |
| 63 | } |
| 64 | }), |
| 65 | ).RunTestWithBp(t, moduleType+` { |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 66 | name: "foo", |
| 67 | srcs: ["a.java"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 68 | sdk_version: "current" |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 69 | } |
| 70 | `) |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 71 | |
Paul Duffin | 0ed42d3 | 2021-03-13 02:19:32 +0000 | [diff] [blame] | 72 | foo := result.ModuleForTests("foo", "android_common") |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 73 | |
Colin Cross | 3165695 | 2018-05-24 16:11:20 -0700 | [diff] [blame] | 74 | var expectedLinkImplicits []string |
| 75 | |
| 76 | manifestFixer := foo.Output("manifest_fixer/AndroidManifest.xml") |
| 77 | expectedLinkImplicits = append(expectedLinkImplicits, manifestFixer.Output.String()) |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 78 | |
Paul Duffin | 0ed42d3 | 2021-03-13 02:19:32 +0000 | [diff] [blame] | 79 | frameworkRes := result.ModuleForTests("framework-res", "android_common") |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 80 | expectedLinkImplicits = append(expectedLinkImplicits, |
| 81 | frameworkRes.Output("package-res.apk").Output.String()) |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 82 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 83 | // Test the mapping from input files to compiled output file names |
| 84 | compile := foo.Output(compiledResourceFiles[0]) |
Paul Duffin | 0ed42d3 | 2021-03-13 02:19:32 +0000 | [diff] [blame] | 85 | android.AssertDeepEquals(t, "aapt2 compile inputs", resourceFiles, compile.Inputs.Strings()) |
Colin Cross | b69301e | 2017-12-01 10:48:26 -0800 | [diff] [blame] | 86 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 87 | compiledResourceOutputs := compile.Outputs.Strings() |
| 88 | sort.Strings(compiledResourceOutputs) |
Colin Cross | b69301e | 2017-12-01 10:48:26 -0800 | [diff] [blame] | 89 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 90 | expectedLinkImplicits = append(expectedLinkImplicits, compiledResourceOutputs...) |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 91 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 92 | list := foo.Output("aapt2/res.list") |
| 93 | expectedLinkImplicits = append(expectedLinkImplicits, list.Output.String()) |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 94 | |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 95 | // Check that the link rule uses |
Paul Duffin | 0ed42d3 | 2021-03-13 02:19:32 +0000 | [diff] [blame] | 96 | res := result.ModuleForTests("foo", "android_common").Output("package-res.apk") |
| 97 | android.AssertDeepEquals(t, "aapt2 link implicits", expectedLinkImplicits, res.Implicits.Strings()) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 98 | }) |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 99 | } |
| 100 | } |
Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 101 | |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 102 | func TestAppSplits(t *testing.T) { |
| 103 | ctx := testApp(t, ` |
| 104 | android_app { |
| 105 | name: "foo", |
| 106 | srcs: ["a.java"], |
| 107 | package_splits: ["v4", "v7,hdpi"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 108 | sdk_version: "current" |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 109 | }`) |
| 110 | |
| 111 | foo := ctx.ModuleForTests("foo", "android_common") |
| 112 | |
| 113 | expectedOutputs := []string{ |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 114 | "out/soong/.intermediates/foo/android_common/foo.apk", |
| 115 | "out/soong/.intermediates/foo/android_common/foo_v4.apk", |
| 116 | "out/soong/.intermediates/foo/android_common/foo_v7_hdpi.apk", |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 117 | } |
| 118 | for _, expectedOutput := range expectedOutputs { |
| 119 | foo.Output(expectedOutput) |
| 120 | } |
| 121 | |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 122 | outputFiles, err := foo.Module().(*AndroidApp).OutputFiles("") |
| 123 | if err != nil { |
| 124 | t.Fatal(err) |
| 125 | } |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 126 | android.AssertPathsRelativeToTopEquals(t, `OutputFiles("")`, expectedOutputs, outputFiles) |
Colin Cross | e560c4a | 2019-03-19 16:03:11 -0700 | [diff] [blame] | 127 | } |
| 128 | |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 129 | func TestPlatformAPIs(t *testing.T) { |
| 130 | testJava(t, ` |
| 131 | android_app { |
| 132 | name: "foo", |
| 133 | srcs: ["a.java"], |
| 134 | platform_apis: true, |
| 135 | } |
| 136 | `) |
| 137 | |
| 138 | testJava(t, ` |
| 139 | android_app { |
| 140 | name: "foo", |
| 141 | srcs: ["a.java"], |
| 142 | sdk_version: "current", |
| 143 | } |
| 144 | `) |
| 145 | |
Spandan Das | 6099934 | 2021-11-16 04:15:33 +0000 | [diff] [blame] | 146 | testJavaError(t, "This module has conflicting settings. sdk_version is empty, which means that this module is build against platform APIs. However platform_apis is not set to true", ` |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 147 | android_app { |
| 148 | name: "bar", |
| 149 | srcs: ["b.java"], |
| 150 | } |
| 151 | `) |
| 152 | |
Spandan Das | 6099934 | 2021-11-16 04:15:33 +0000 | [diff] [blame] | 153 | testJavaError(t, "This module has conflicting settings. sdk_version is not empty, which means this module cannot use platform APIs. However platform_apis is set to true.", ` |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 154 | android_app { |
| 155 | name: "bar", |
| 156 | srcs: ["b.java"], |
| 157 | sdk_version: "system_current", |
| 158 | platform_apis: true, |
| 159 | } |
| 160 | `) |
| 161 | } |
| 162 | |
Jeongik Cha | e403e9e | 2019-12-07 00:16:24 +0900 | [diff] [blame] | 163 | func TestAndroidAppLinkType(t *testing.T) { |
| 164 | testJava(t, ` |
| 165 | android_app { |
| 166 | name: "foo", |
| 167 | srcs: ["a.java"], |
| 168 | libs: ["bar"], |
| 169 | static_libs: ["baz"], |
| 170 | platform_apis: true, |
| 171 | } |
| 172 | |
| 173 | java_library { |
| 174 | name: "bar", |
| 175 | sdk_version: "current", |
| 176 | srcs: ["b.java"], |
| 177 | } |
| 178 | |
| 179 | android_library { |
| 180 | name: "baz", |
| 181 | sdk_version: "system_current", |
| 182 | srcs: ["c.java"], |
| 183 | } |
| 184 | `) |
| 185 | |
Steven Moreland | 0029898 | 2020-11-17 21:44:36 +0000 | [diff] [blame] | 186 | testJavaError(t, "consider adjusting sdk_version: OR platform_apis:", ` |
Jeongik Cha | e403e9e | 2019-12-07 00:16:24 +0900 | [diff] [blame] | 187 | android_app { |
| 188 | name: "foo", |
| 189 | srcs: ["a.java"], |
| 190 | libs: ["bar"], |
| 191 | sdk_version: "current", |
| 192 | static_libs: ["baz"], |
| 193 | } |
| 194 | |
| 195 | java_library { |
| 196 | name: "bar", |
| 197 | sdk_version: "current", |
| 198 | srcs: ["b.java"], |
| 199 | } |
| 200 | |
| 201 | android_library { |
| 202 | name: "baz", |
| 203 | sdk_version: "system_current", |
| 204 | srcs: ["c.java"], |
| 205 | } |
| 206 | `) |
| 207 | |
| 208 | testJava(t, ` |
| 209 | android_app { |
| 210 | name: "foo", |
| 211 | srcs: ["a.java"], |
| 212 | libs: ["bar"], |
| 213 | sdk_version: "system_current", |
| 214 | static_libs: ["baz"], |
| 215 | } |
| 216 | |
| 217 | java_library { |
| 218 | name: "bar", |
| 219 | sdk_version: "current", |
| 220 | srcs: ["b.java"], |
| 221 | } |
| 222 | |
| 223 | android_library { |
| 224 | name: "baz", |
| 225 | sdk_version: "system_current", |
| 226 | srcs: ["c.java"], |
| 227 | } |
| 228 | `) |
| 229 | |
Steven Moreland | 0029898 | 2020-11-17 21:44:36 +0000 | [diff] [blame] | 230 | testJavaError(t, "consider adjusting sdk_version: OR platform_apis:", ` |
Jeongik Cha | e403e9e | 2019-12-07 00:16:24 +0900 | [diff] [blame] | 231 | android_app { |
| 232 | name: "foo", |
| 233 | srcs: ["a.java"], |
| 234 | libs: ["bar"], |
| 235 | sdk_version: "system_current", |
| 236 | static_libs: ["baz"], |
| 237 | } |
| 238 | |
| 239 | java_library { |
| 240 | name: "bar", |
| 241 | sdk_version: "current", |
| 242 | srcs: ["b.java"], |
| 243 | } |
| 244 | |
| 245 | android_library { |
| 246 | name: "baz", |
| 247 | srcs: ["c.java"], |
| 248 | } |
| 249 | `) |
| 250 | } |
| 251 | |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 252 | func TestUpdatableApps(t *testing.T) { |
| 253 | testCases := []struct { |
| 254 | name string |
| 255 | bp string |
| 256 | expectedError string |
| 257 | }{ |
| 258 | { |
| 259 | name: "Stable public SDK", |
| 260 | bp: `android_app { |
| 261 | name: "foo", |
| 262 | srcs: ["a.java"], |
| 263 | sdk_version: "29", |
Artur Satayev | f40fc85 | 2020-04-16 13:43:02 +0100 | [diff] [blame] | 264 | min_sdk_version: "29", |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 265 | updatable: true, |
| 266 | }`, |
| 267 | }, |
| 268 | { |
| 269 | name: "Stable system SDK", |
| 270 | bp: `android_app { |
| 271 | name: "foo", |
| 272 | srcs: ["a.java"], |
| 273 | sdk_version: "system_29", |
Artur Satayev | f40fc85 | 2020-04-16 13:43:02 +0100 | [diff] [blame] | 274 | min_sdk_version: "29", |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 275 | updatable: true, |
| 276 | }`, |
| 277 | }, |
| 278 | { |
| 279 | name: "Current public SDK", |
| 280 | bp: `android_app { |
| 281 | name: "foo", |
| 282 | srcs: ["a.java"], |
| 283 | sdk_version: "current", |
Artur Satayev | f40fc85 | 2020-04-16 13:43:02 +0100 | [diff] [blame] | 284 | min_sdk_version: "29", |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 285 | updatable: true, |
| 286 | }`, |
| 287 | }, |
| 288 | { |
| 289 | name: "Current system SDK", |
| 290 | bp: `android_app { |
| 291 | name: "foo", |
| 292 | srcs: ["a.java"], |
| 293 | sdk_version: "system_current", |
Artur Satayev | f40fc85 | 2020-04-16 13:43:02 +0100 | [diff] [blame] | 294 | min_sdk_version: "29", |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 295 | updatable: true, |
| 296 | }`, |
| 297 | }, |
| 298 | { |
| 299 | name: "Current module SDK", |
| 300 | bp: `android_app { |
| 301 | name: "foo", |
| 302 | srcs: ["a.java"], |
| 303 | sdk_version: "module_current", |
Artur Satayev | f40fc85 | 2020-04-16 13:43:02 +0100 | [diff] [blame] | 304 | min_sdk_version: "29", |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 305 | updatable: true, |
| 306 | }`, |
| 307 | }, |
| 308 | { |
| 309 | name: "Current core SDK", |
| 310 | bp: `android_app { |
| 311 | name: "foo", |
| 312 | srcs: ["a.java"], |
| 313 | sdk_version: "core_current", |
Artur Satayev | f40fc85 | 2020-04-16 13:43:02 +0100 | [diff] [blame] | 314 | min_sdk_version: "29", |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 315 | updatable: true, |
| 316 | }`, |
| 317 | }, |
| 318 | { |
| 319 | name: "No Platform APIs", |
| 320 | bp: `android_app { |
| 321 | name: "foo", |
| 322 | srcs: ["a.java"], |
| 323 | platform_apis: true, |
Artur Satayev | f40fc85 | 2020-04-16 13:43:02 +0100 | [diff] [blame] | 324 | min_sdk_version: "29", |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 325 | updatable: true, |
| 326 | }`, |
| 327 | expectedError: "Updatable apps must use stable SDKs", |
| 328 | }, |
| 329 | { |
| 330 | name: "No Core Platform APIs", |
| 331 | bp: `android_app { |
| 332 | name: "foo", |
| 333 | srcs: ["a.java"], |
| 334 | sdk_version: "core_platform", |
Artur Satayev | f40fc85 | 2020-04-16 13:43:02 +0100 | [diff] [blame] | 335 | min_sdk_version: "29", |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 336 | updatable: true, |
| 337 | }`, |
| 338 | expectedError: "Updatable apps must use stable SDKs", |
| 339 | }, |
| 340 | { |
| 341 | name: "No unspecified APIs", |
| 342 | bp: `android_app { |
| 343 | name: "foo", |
| 344 | srcs: ["a.java"], |
| 345 | updatable: true, |
Artur Satayev | f40fc85 | 2020-04-16 13:43:02 +0100 | [diff] [blame] | 346 | min_sdk_version: "29", |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 347 | }`, |
| 348 | expectedError: "Updatable apps must use stable SDK", |
| 349 | }, |
Artur Satayev | f40fc85 | 2020-04-16 13:43:02 +0100 | [diff] [blame] | 350 | { |
| 351 | name: "Must specify min_sdk_version", |
| 352 | bp: `android_app { |
| 353 | name: "app_without_min_sdk_version", |
| 354 | srcs: ["a.java"], |
| 355 | sdk_version: "29", |
| 356 | updatable: true, |
| 357 | }`, |
| 358 | expectedError: "updatable apps must set min_sdk_version.", |
| 359 | }, |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | for _, test := range testCases { |
| 363 | t.Run(test.name, func(t *testing.T) { |
Paul Duffin | cdb88a9 | 2021-03-14 00:36:50 +0000 | [diff] [blame] | 364 | errorHandler := android.FixtureExpectsNoErrors |
| 365 | if test.expectedError != "" { |
| 366 | errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern(test.expectedError) |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 367 | } |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame] | 368 | android.GroupFixturePreparers( |
| 369 | prepareForJavaTest, FixtureWithPrebuiltApis(map[string][]string{ |
Paul Duffin | 2645a29 | 2021-03-13 02:36:00 +0000 | [diff] [blame] | 370 | "29": {"foo"}, |
| 371 | })). |
Paul Duffin | cdb88a9 | 2021-03-14 00:36:50 +0000 | [diff] [blame] | 372 | ExtendWithErrorHandler(errorHandler).RunTestWithBp(t, test.bp) |
Artur Satayev | 2db1c3f | 2020-04-08 19:09:30 +0100 | [diff] [blame] | 373 | }) |
| 374 | } |
| 375 | } |
| 376 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 377 | func TestUpdatableApps_TransitiveDepsShouldSetMinSdkVersion(t *testing.T) { |
| 378 | testJavaError(t, `module "bar".*: should support min_sdk_version\(29\)`, cc.GatherRequiredDepsForTest(android.Android)+` |
| 379 | android_app { |
| 380 | name: "foo", |
| 381 | srcs: ["a.java"], |
| 382 | updatable: true, |
| 383 | sdk_version: "current", |
| 384 | min_sdk_version: "29", |
| 385 | static_libs: ["bar"], |
| 386 | } |
| 387 | |
| 388 | java_library { |
| 389 | name: "bar", |
| 390 | sdk_version: "current", |
| 391 | } |
| 392 | `) |
| 393 | } |
| 394 | |
Jooyung Han | bbc3fb7 | 2020-04-29 14:01:06 +0900 | [diff] [blame] | 395 | func TestUpdatableApps_JniLibsShouldShouldSupportMinSdkVersion(t *testing.T) { |
| 396 | testJava(t, cc.GatherRequiredDepsForTest(android.Android)+` |
| 397 | android_app { |
| 398 | name: "foo", |
| 399 | srcs: ["a.java"], |
| 400 | updatable: true, |
| 401 | sdk_version: "current", |
| 402 | min_sdk_version: "current", |
| 403 | jni_libs: ["libjni"], |
| 404 | } |
| 405 | |
| 406 | cc_library { |
| 407 | name: "libjni", |
| 408 | stl: "none", |
| 409 | system_shared_libs: [], |
| 410 | sdk_version: "current", |
| 411 | } |
| 412 | `) |
| 413 | } |
| 414 | |
| 415 | func TestUpdatableApps_JniLibShouldBeBuiltAgainstMinSdkVersion(t *testing.T) { |
| 416 | bp := cc.GatherRequiredDepsForTest(android.Android) + ` |
| 417 | android_app { |
| 418 | name: "foo", |
| 419 | srcs: ["a.java"], |
| 420 | updatable: true, |
| 421 | sdk_version: "current", |
| 422 | min_sdk_version: "29", |
| 423 | jni_libs: ["libjni"], |
| 424 | } |
| 425 | |
| 426 | cc_library { |
| 427 | name: "libjni", |
| 428 | stl: "none", |
| 429 | system_shared_libs: [], |
Spandan Das | 2e8c044 | 2022-05-08 00:39:35 +0000 | [diff] [blame] | 430 | sdk_version: "current", |
| 431 | min_sdk_version: "29", |
Jooyung Han | bbc3fb7 | 2020-04-29 14:01:06 +0900 | [diff] [blame] | 432 | } |
Jooyung Han | bbc3fb7 | 2020-04-29 14:01:06 +0900 | [diff] [blame] | 433 | ` |
| 434 | fs := map[string][]byte{ |
| 435 | "prebuilts/ndk/current/platforms/android-29/arch-arm64/usr/lib/crtbegin_so.o": nil, |
| 436 | "prebuilts/ndk/current/platforms/android-29/arch-arm64/usr/lib/crtend_so.o": nil, |
| 437 | "prebuilts/ndk/current/platforms/android-29/arch-arm/usr/lib/crtbegin_so.o": nil, |
| 438 | "prebuilts/ndk/current/platforms/android-29/arch-arm/usr/lib/crtend_so.o": nil, |
| 439 | } |
| 440 | |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 441 | ctx, _ := testJavaWithFS(t, bp, fs) |
Jooyung Han | bbc3fb7 | 2020-04-29 14:01:06 +0900 | [diff] [blame] | 442 | |
| 443 | inputs := ctx.ModuleForTests("libjni", "android_arm64_armv8-a_sdk_shared").Description("link").Implicits |
| 444 | var crtbeginFound, crtendFound bool |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 445 | expectedCrtBegin := ctx.ModuleForTests("crtbegin_so", |
Colin Cross | dea1d03 | 2022-12-06 14:50:08 -0800 | [diff] [blame] | 446 | "android_arm64_armv8-a_sdk_29").Rule("noAddrSig").Output |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 447 | expectedCrtEnd := ctx.ModuleForTests("crtend_so", |
Colin Cross | dea1d03 | 2022-12-06 14:50:08 -0800 | [diff] [blame] | 448 | "android_arm64_armv8-a_sdk_29").Rule("noAddrSig").Output |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 449 | implicits := []string{} |
Jooyung Han | bbc3fb7 | 2020-04-29 14:01:06 +0900 | [diff] [blame] | 450 | for _, input := range inputs { |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 451 | implicits = append(implicits, input.String()) |
| 452 | if strings.HasSuffix(input.String(), expectedCrtBegin.String()) { |
Jooyung Han | bbc3fb7 | 2020-04-29 14:01:06 +0900 | [diff] [blame] | 453 | crtbeginFound = true |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 454 | } else if strings.HasSuffix(input.String(), expectedCrtEnd.String()) { |
Jooyung Han | bbc3fb7 | 2020-04-29 14:01:06 +0900 | [diff] [blame] | 455 | crtendFound = true |
| 456 | } |
| 457 | } |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 458 | if !crtbeginFound { |
| 459 | t.Error(fmt.Sprintf( |
| 460 | "expected implicit with suffix %q, have the following implicits:\n%s", |
| 461 | expectedCrtBegin, strings.Join(implicits, "\n"))) |
| 462 | } |
| 463 | if !crtendFound { |
| 464 | t.Error(fmt.Sprintf( |
| 465 | "expected implicit with suffix %q, have the following implicits:\n%s", |
| 466 | expectedCrtEnd, strings.Join(implicits, "\n"))) |
Jooyung Han | bbc3fb7 | 2020-04-29 14:01:06 +0900 | [diff] [blame] | 467 | } |
| 468 | } |
| 469 | |
| 470 | func TestUpdatableApps_ErrorIfJniLibDoesntSupportMinSdkVersion(t *testing.T) { |
| 471 | bp := cc.GatherRequiredDepsForTest(android.Android) + ` |
| 472 | android_app { |
| 473 | name: "foo", |
| 474 | srcs: ["a.java"], |
| 475 | updatable: true, |
| 476 | sdk_version: "current", |
| 477 | min_sdk_version: "29", // this APK should support 29 |
| 478 | jni_libs: ["libjni"], |
| 479 | } |
| 480 | |
| 481 | cc_library { |
| 482 | name: "libjni", |
| 483 | stl: "none", |
| 484 | sdk_version: "current", |
Spandan Das | 2e8c044 | 2022-05-08 00:39:35 +0000 | [diff] [blame] | 485 | min_sdk_version: "current", |
Jooyung Han | bbc3fb7 | 2020-04-29 14:01:06 +0900 | [diff] [blame] | 486 | } |
| 487 | ` |
Spandan Das | 2e8c044 | 2022-05-08 00:39:35 +0000 | [diff] [blame] | 488 | testJavaError(t, `"libjni" .*: min_sdk_version\(current\) is higher than min_sdk_version\(29\)`, bp) |
Jooyung Han | bbc3fb7 | 2020-04-29 14:01:06 +0900 | [diff] [blame] | 489 | } |
| 490 | |
Spandan Das | 2e8c044 | 2022-05-08 00:39:35 +0000 | [diff] [blame] | 491 | func TestUpdatableApps_ErrorIfDepMinSdkVersionIsHigher(t *testing.T) { |
Jooyung Han | bbc3fb7 | 2020-04-29 14:01:06 +0900 | [diff] [blame] | 492 | bp := cc.GatherRequiredDepsForTest(android.Android) + ` |
| 493 | android_app { |
| 494 | name: "foo", |
| 495 | srcs: ["a.java"], |
| 496 | updatable: true, |
| 497 | sdk_version: "current", |
| 498 | min_sdk_version: "29", // this APK should support 29 |
| 499 | jni_libs: ["libjni"], |
| 500 | } |
| 501 | |
| 502 | cc_library { |
| 503 | name: "libjni", |
| 504 | stl: "none", |
| 505 | shared_libs: ["libbar"], |
| 506 | system_shared_libs: [], |
| 507 | sdk_version: "27", |
Spandan Das | 2e8c044 | 2022-05-08 00:39:35 +0000 | [diff] [blame] | 508 | min_sdk_version: "27", |
Jooyung Han | bbc3fb7 | 2020-04-29 14:01:06 +0900 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | cc_library { |
| 512 | name: "libbar", |
| 513 | stl: "none", |
| 514 | system_shared_libs: [], |
| 515 | sdk_version: "current", |
Spandan Das | 2e8c044 | 2022-05-08 00:39:35 +0000 | [diff] [blame] | 516 | min_sdk_version: "current", |
Jooyung Han | bbc3fb7 | 2020-04-29 14:01:06 +0900 | [diff] [blame] | 517 | } |
| 518 | ` |
| 519 | testJavaError(t, `"libjni" .*: links "libbar" built against newer API version "current"`, bp) |
| 520 | } |
| 521 | |
Colin Cross | 0ddae7f | 2019-02-07 15:30:01 -0800 | [diff] [blame] | 522 | func TestResourceDirs(t *testing.T) { |
| 523 | testCases := []struct { |
| 524 | name string |
| 525 | prop string |
| 526 | resources []string |
| 527 | }{ |
| 528 | { |
| 529 | name: "no resource_dirs", |
| 530 | prop: "", |
| 531 | resources: []string{"res/res/values/strings.xml"}, |
| 532 | }, |
| 533 | { |
| 534 | name: "resource_dirs", |
| 535 | prop: `resource_dirs: ["res"]`, |
| 536 | resources: []string{"res/res/values/strings.xml"}, |
| 537 | }, |
| 538 | { |
| 539 | name: "empty resource_dirs", |
| 540 | prop: `resource_dirs: []`, |
| 541 | resources: nil, |
| 542 | }, |
| 543 | } |
| 544 | |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 545 | fs := android.MockFS{ |
Colin Cross | 0ddae7f | 2019-02-07 15:30:01 -0800 | [diff] [blame] | 546 | "res/res/values/strings.xml": nil, |
| 547 | } |
| 548 | |
| 549 | bp := ` |
| 550 | android_app { |
| 551 | name: "foo", |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 552 | sdk_version: "current", |
Colin Cross | 0ddae7f | 2019-02-07 15:30:01 -0800 | [diff] [blame] | 553 | %s |
| 554 | } |
| 555 | ` |
| 556 | |
| 557 | for _, testCase := range testCases { |
| 558 | t.Run(testCase.name, func(t *testing.T) { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 559 | result := android.GroupFixturePreparers( |
| 560 | PrepareForTestWithJavaDefaultModules, |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 561 | fs.AddToFixture(), |
| 562 | ).RunTestWithBp(t, fmt.Sprintf(bp, testCase.prop)) |
Colin Cross | 0ddae7f | 2019-02-07 15:30:01 -0800 | [diff] [blame] | 563 | |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 564 | module := result.ModuleForTests("foo", "android_common") |
Colin Cross | 0ddae7f | 2019-02-07 15:30:01 -0800 | [diff] [blame] | 565 | resourceList := module.MaybeOutput("aapt2/res.list") |
| 566 | |
| 567 | var resources []string |
| 568 | if resourceList.Rule != nil { |
| 569 | for _, compiledResource := range resourceList.Inputs.Strings() { |
| 570 | resources = append(resources, module.Output(compiledResource).Inputs.Strings()...) |
| 571 | } |
| 572 | } |
| 573 | |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 574 | android.AssertDeepEquals(t, "resource files", testCase.resources, resources) |
Colin Cross | 0ddae7f | 2019-02-07 15:30:01 -0800 | [diff] [blame] | 575 | }) |
| 576 | } |
| 577 | } |
| 578 | |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 579 | func TestLibraryAssets(t *testing.T) { |
| 580 | bp := ` |
| 581 | android_app { |
| 582 | name: "foo", |
| 583 | sdk_version: "current", |
| 584 | static_libs: ["lib1", "lib2", "lib3"], |
| 585 | } |
| 586 | |
| 587 | android_library { |
| 588 | name: "lib1", |
| 589 | sdk_version: "current", |
| 590 | asset_dirs: ["assets_a"], |
| 591 | } |
| 592 | |
| 593 | android_library { |
| 594 | name: "lib2", |
| 595 | sdk_version: "current", |
| 596 | } |
| 597 | |
| 598 | android_library { |
| 599 | name: "lib3", |
| 600 | sdk_version: "current", |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 601 | static_libs: ["lib4", "import"], |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | android_library { |
| 605 | name: "lib4", |
| 606 | sdk_version: "current", |
| 607 | asset_dirs: ["assets_b"], |
| 608 | } |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 609 | |
Jiakai Zhang | ba82e28 | 2023-10-13 18:08:59 +0100 | [diff] [blame] | 610 | android_library { |
| 611 | name: "lib5", |
| 612 | sdk_version: "current", |
| 613 | assets: [ |
| 614 | "path/to/asset_file_1", |
| 615 | "path/to/asset_file_2", |
| 616 | ], |
| 617 | } |
| 618 | |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 619 | android_library_import { |
| 620 | name: "import", |
| 621 | sdk_version: "current", |
| 622 | aars: ["import.aar"], |
| 623 | } |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 624 | ` |
| 625 | |
| 626 | testCases := []struct { |
Jiakai Zhang | ba82e28 | 2023-10-13 18:08:59 +0100 | [diff] [blame] | 627 | name string |
| 628 | assetFlag string |
| 629 | assetPackages []string |
| 630 | tmpAssetDirInputs []string |
| 631 | tmpAssetDirOutputs []string |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 632 | }{ |
| 633 | { |
| 634 | name: "foo", |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 635 | // lib1 has its own assets. lib3 doesn't have any, but lib4 and import have assets. |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 636 | assetPackages: []string{ |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 637 | "out/soong/.intermediates/foo/android_common/aapt2/package-res.apk", |
| 638 | "out/soong/.intermediates/lib1/android_common/assets.zip", |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 639 | "out/soong/.intermediates/lib4/android_common/assets.zip", |
| 640 | "out/soong/.intermediates/import/android_common/assets.zip", |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 641 | }, |
| 642 | }, |
| 643 | { |
| 644 | name: "lib1", |
| 645 | assetFlag: "-A assets_a", |
| 646 | }, |
| 647 | { |
| 648 | name: "lib2", |
| 649 | }, |
| 650 | { |
| 651 | name: "lib3", |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 652 | }, |
| 653 | { |
| 654 | name: "lib4", |
| 655 | assetFlag: "-A assets_b", |
| 656 | }, |
Jiakai Zhang | ba82e28 | 2023-10-13 18:08:59 +0100 | [diff] [blame] | 657 | { |
| 658 | name: "lib5", |
| 659 | assetFlag: "-A out/soong/.intermediates/lib5/android_common/tmp_asset_dir", |
| 660 | tmpAssetDirInputs: []string{ |
| 661 | "path/to/asset_file_1", |
| 662 | "path/to/asset_file_2", |
| 663 | }, |
| 664 | tmpAssetDirOutputs: []string{ |
| 665 | "out/soong/.intermediates/lib5/android_common/tmp_asset_dir/path/to/asset_file_1", |
| 666 | "out/soong/.intermediates/lib5/android_common/tmp_asset_dir/path/to/asset_file_2", |
| 667 | }, |
| 668 | }, |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 669 | } |
| 670 | ctx := testApp(t, bp) |
| 671 | |
| 672 | for _, test := range testCases { |
| 673 | t.Run(test.name, func(t *testing.T) { |
| 674 | m := ctx.ModuleForTests(test.name, "android_common") |
| 675 | |
| 676 | // Check asset flag in aapt2 link flags |
| 677 | var aapt2link android.TestingBuildParams |
| 678 | if len(test.assetPackages) > 0 { |
| 679 | aapt2link = m.Output("aapt2/package-res.apk") |
| 680 | } else { |
| 681 | aapt2link = m.Output("package-res.apk") |
| 682 | } |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 683 | aapt2link = aapt2link |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 684 | aapt2Flags := aapt2link.Args["flags"] |
| 685 | if test.assetFlag != "" { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 686 | android.AssertStringDoesContain(t, "asset flag", aapt2Flags, test.assetFlag) |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 687 | } else { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 688 | android.AssertStringDoesNotContain(t, "aapt2 link flags", aapt2Flags, " -A ") |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | // Check asset merge rule. |
| 692 | if len(test.assetPackages) > 0 { |
| 693 | mergeAssets := m.Output("package-res.apk") |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 694 | android.AssertPathsRelativeToTopEquals(t, "mergeAssets inputs", test.assetPackages, mergeAssets.Inputs) |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 695 | } |
Jiakai Zhang | ba82e28 | 2023-10-13 18:08:59 +0100 | [diff] [blame] | 696 | |
| 697 | if len(test.tmpAssetDirInputs) > 0 { |
| 698 | rule := m.Rule("tmp_asset_dir") |
| 699 | inputs := rule.Implicits |
| 700 | outputs := append(android.WritablePaths{rule.Output}, rule.ImplicitOutputs...).Paths() |
| 701 | android.AssertPathsRelativeToTopEquals(t, "tmp_asset_dir inputs", test.tmpAssetDirInputs, inputs) |
| 702 | android.AssertPathsRelativeToTopEquals(t, "tmp_asset_dir outputs", test.tmpAssetDirOutputs, outputs) |
| 703 | } |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 704 | }) |
| 705 | } |
| 706 | } |
| 707 | |
Colin Cross | b014f07 | 2021-02-26 14:54:36 -0800 | [diff] [blame] | 708 | func TestAppJavaResources(t *testing.T) { |
| 709 | bp := ` |
| 710 | android_app { |
| 711 | name: "foo", |
| 712 | sdk_version: "current", |
| 713 | java_resources: ["resources/a"], |
| 714 | srcs: ["a.java"], |
| 715 | } |
| 716 | |
| 717 | android_app { |
| 718 | name: "bar", |
| 719 | sdk_version: "current", |
| 720 | java_resources: ["resources/a"], |
| 721 | } |
| 722 | ` |
| 723 | |
| 724 | ctx := testApp(t, bp) |
| 725 | |
| 726 | foo := ctx.ModuleForTests("foo", "android_common") |
| 727 | fooResources := foo.Output("res/foo.jar") |
| 728 | fooDexJar := foo.Output("dex-withres/foo.jar") |
| 729 | fooDexJarAligned := foo.Output("dex-withres-aligned/foo.jar") |
| 730 | fooApk := foo.Rule("combineApk") |
| 731 | |
| 732 | if g, w := fooDexJar.Inputs.Strings(), fooResources.Output.String(); !android.InList(w, g) { |
| 733 | t.Errorf("expected resource jar %q in foo dex jar inputs %q", w, g) |
| 734 | } |
| 735 | |
| 736 | if g, w := fooDexJarAligned.Input.String(), fooDexJar.Output.String(); g != w { |
| 737 | t.Errorf("expected dex jar %q in foo aligned dex jar inputs %q", w, g) |
| 738 | } |
| 739 | |
| 740 | if g, w := fooApk.Inputs.Strings(), fooDexJarAligned.Output.String(); !android.InList(w, g) { |
| 741 | t.Errorf("expected aligned dex jar %q in foo apk inputs %q", w, g) |
| 742 | } |
| 743 | |
| 744 | bar := ctx.ModuleForTests("bar", "android_common") |
| 745 | barResources := bar.Output("res/bar.jar") |
| 746 | barApk := bar.Rule("combineApk") |
| 747 | |
| 748 | if g, w := barApk.Inputs.Strings(), barResources.Output.String(); !android.InList(w, g) { |
| 749 | t.Errorf("expected resources jar %q in bar apk inputs %q", w, g) |
| 750 | } |
| 751 | } |
| 752 | |
Colin Cross | ff3ff7f | 2023-07-05 14:04:12 -0700 | [diff] [blame] | 753 | func TestAndroidResourceProcessor(t *testing.T) { |
| 754 | testCases := []struct { |
Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 755 | name string |
| 756 | appUsesRP bool |
| 757 | directLibUsesRP bool |
| 758 | transitiveLibUsesRP bool |
| 759 | sharedLibUsesRP bool |
| 760 | sharedTransitiveStaticLibUsesRP bool |
| 761 | sharedTransitiveSharedLibUsesRP bool |
Colin Cross | ff3ff7f | 2023-07-05 14:04:12 -0700 | [diff] [blame] | 762 | |
| 763 | dontVerifyApp bool |
| 764 | appResources []string |
| 765 | appOverlays []string |
| 766 | appImports []string |
| 767 | appSrcJars []string |
| 768 | appClasspath []string |
| 769 | appCombined []string |
| 770 | |
| 771 | dontVerifyDirect bool |
| 772 | directResources []string |
| 773 | directOverlays []string |
| 774 | directImports []string |
| 775 | directSrcJars []string |
| 776 | directClasspath []string |
| 777 | directCombined []string |
| 778 | |
| 779 | dontVerifyTransitive bool |
| 780 | transitiveResources []string |
| 781 | transitiveOverlays []string |
| 782 | transitiveImports []string |
| 783 | transitiveSrcJars []string |
| 784 | transitiveClasspath []string |
| 785 | transitiveCombined []string |
| 786 | |
| 787 | dontVerifyDirectImport bool |
| 788 | directImportResources []string |
| 789 | directImportOverlays []string |
| 790 | directImportImports []string |
| 791 | |
| 792 | dontVerifyTransitiveImport bool |
| 793 | transitiveImportResources []string |
| 794 | transitiveImportOverlays []string |
| 795 | transitiveImportImports []string |
Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 796 | |
| 797 | dontVerifyShared bool |
| 798 | sharedResources []string |
| 799 | sharedOverlays []string |
| 800 | sharedImports []string |
| 801 | sharedSrcJars []string |
| 802 | sharedClasspath []string |
| 803 | sharedCombined []string |
Colin Cross | ff3ff7f | 2023-07-05 14:04:12 -0700 | [diff] [blame] | 804 | }{ |
| 805 | { |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 806 | // Test with all modules set to use_resource_processor: false (except android_library_import modules, |
| 807 | // which always use resource processor). |
| 808 | name: "legacy", |
| 809 | appUsesRP: false, |
| 810 | directLibUsesRP: false, |
| 811 | transitiveLibUsesRP: false, |
Colin Cross | ff3ff7f | 2023-07-05 14:04:12 -0700 | [diff] [blame] | 812 | |
| 813 | appResources: nil, |
| 814 | appOverlays: []string{ |
| 815 | "out/soong/.intermediates/transitive/android_common/package-res.apk", |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 816 | "out/soong/.intermediates/transitive_import_dep/android_common/package-res.apk", |
Colin Cross | ff3ff7f | 2023-07-05 14:04:12 -0700 | [diff] [blame] | 817 | "out/soong/.intermediates/transitive_import/android_common/package-res.apk", |
| 818 | "out/soong/.intermediates/direct/android_common/package-res.apk", |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 819 | "out/soong/.intermediates/direct_import_dep/android_common/package-res.apk", |
Colin Cross | ff3ff7f | 2023-07-05 14:04:12 -0700 | [diff] [blame] | 820 | "out/soong/.intermediates/direct_import/android_common/package-res.apk", |
| 821 | "out/soong/.intermediates/app/android_common/aapt2/app/res/values_strings.arsc.flat", |
| 822 | }, |
Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 823 | appImports: []string{ |
| 824 | "out/soong/.intermediates/shared/android_common/package-res.apk", |
| 825 | "out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk", |
| 826 | }, |
Colin Cross | ff3ff7f | 2023-07-05 14:04:12 -0700 | [diff] [blame] | 827 | appSrcJars: []string{"out/soong/.intermediates/app/android_common/gen/android/R.srcjar"}, |
| 828 | appClasspath: []string{ |
| 829 | "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar", |
Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 830 | "out/soong/.intermediates/shared/android_common/turbine-combined/shared.jar", |
Colin Cross | ff3ff7f | 2023-07-05 14:04:12 -0700 | [diff] [blame] | 831 | "out/soong/.intermediates/direct/android_common/turbine-combined/direct.jar", |
Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame^] | 832 | "out/soong/.intermediates/direct_import/android_common/turbine-combined/direct_import.jar", |
Colin Cross | ff3ff7f | 2023-07-05 14:04:12 -0700 | [diff] [blame] | 833 | }, |
| 834 | appCombined: []string{ |
| 835 | "out/soong/.intermediates/app/android_common/javac/app.jar", |
| 836 | "out/soong/.intermediates/direct/android_common/combined/direct.jar", |
Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame^] | 837 | "out/soong/.intermediates/direct_import/android_common/combined/direct_import.jar", |
Colin Cross | ff3ff7f | 2023-07-05 14:04:12 -0700 | [diff] [blame] | 838 | }, |
| 839 | |
| 840 | directResources: nil, |
| 841 | directOverlays: []string{ |
| 842 | "out/soong/.intermediates/transitive/android_common/package-res.apk", |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 843 | "out/soong/.intermediates/transitive_import_dep/android_common/package-res.apk", |
Colin Cross | ff3ff7f | 2023-07-05 14:04:12 -0700 | [diff] [blame] | 844 | "out/soong/.intermediates/transitive_import/android_common/package-res.apk", |
| 845 | "out/soong/.intermediates/direct/android_common/aapt2/direct/res/values_strings.arsc.flat", |
| 846 | }, |
| 847 | directImports: []string{"out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk"}, |
| 848 | directSrcJars: []string{"out/soong/.intermediates/direct/android_common/gen/android/R.srcjar"}, |
| 849 | directClasspath: []string{ |
| 850 | "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar", |
| 851 | "out/soong/.intermediates/transitive/android_common/turbine-combined/transitive.jar", |
Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame^] | 852 | "out/soong/.intermediates/transitive_import/android_common/turbine-combined/transitive_import.jar", |
Colin Cross | ff3ff7f | 2023-07-05 14:04:12 -0700 | [diff] [blame] | 853 | }, |
| 854 | directCombined: []string{ |
| 855 | "out/soong/.intermediates/direct/android_common/javac/direct.jar", |
| 856 | "out/soong/.intermediates/transitive/android_common/javac/transitive.jar", |
Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame^] | 857 | "out/soong/.intermediates/transitive_import/android_common/combined/transitive_import.jar", |
Colin Cross | ff3ff7f | 2023-07-05 14:04:12 -0700 | [diff] [blame] | 858 | }, |
| 859 | |
| 860 | transitiveResources: []string{"out/soong/.intermediates/transitive/android_common/aapt2/transitive/res/values_strings.arsc.flat"}, |
| 861 | transitiveOverlays: nil, |
| 862 | transitiveImports: []string{"out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk"}, |
| 863 | transitiveSrcJars: []string{"out/soong/.intermediates/transitive/android_common/gen/android/R.srcjar"}, |
| 864 | transitiveClasspath: []string{"out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar"}, |
| 865 | transitiveCombined: nil, |
| 866 | |
Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 867 | sharedResources: nil, |
| 868 | sharedOverlays: []string{ |
| 869 | "out/soong/.intermediates/shared_transitive_static/android_common/package-res.apk", |
| 870 | "out/soong/.intermediates/shared/android_common/aapt2/shared/res/values_strings.arsc.flat", |
| 871 | }, |
| 872 | sharedImports: []string{ |
| 873 | "out/soong/.intermediates/shared_transitive_shared/android_common/package-res.apk", |
| 874 | "out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk", |
| 875 | }, |
| 876 | sharedSrcJars: []string{"out/soong/.intermediates/shared/android_common/gen/android/R.srcjar"}, |
| 877 | sharedClasspath: []string{ |
| 878 | "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar", |
| 879 | "out/soong/.intermediates/shared_transitive_shared/android_common/turbine-combined/shared_transitive_shared.jar", |
| 880 | "out/soong/.intermediates/shared_transitive_static/android_common/turbine-combined/shared_transitive_static.jar", |
| 881 | }, |
| 882 | sharedCombined: []string{ |
| 883 | "out/soong/.intermediates/shared/android_common/javac/shared.jar", |
| 884 | "out/soong/.intermediates/shared_transitive_static/android_common/javac/shared_transitive_static.jar", |
| 885 | }, |
| 886 | |
Colin Cross | ff3ff7f | 2023-07-05 14:04:12 -0700 | [diff] [blame] | 887 | directImportResources: nil, |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 888 | directImportOverlays: []string{"out/soong/.intermediates/direct_import/android_common/flat-res/gen_res.flata"}, |
| 889 | directImportImports: []string{ |
| 890 | "out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk", |
Colin Cross | ff3ff7f | 2023-07-05 14:04:12 -0700 | [diff] [blame] | 891 | "out/soong/.intermediates/direct_import_dep/android_common/package-res.apk", |
| 892 | }, |
Colin Cross | ff3ff7f | 2023-07-05 14:04:12 -0700 | [diff] [blame] | 893 | |
| 894 | transitiveImportResources: nil, |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 895 | transitiveImportOverlays: []string{"out/soong/.intermediates/transitive_import/android_common/flat-res/gen_res.flata"}, |
| 896 | transitiveImportImports: []string{ |
| 897 | "out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk", |
Colin Cross | ff3ff7f | 2023-07-05 14:04:12 -0700 | [diff] [blame] | 898 | "out/soong/.intermediates/transitive_import_dep/android_common/package-res.apk", |
| 899 | }, |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 900 | }, |
| 901 | { |
| 902 | // Test with all modules set to use_resource_processor: true. |
Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 903 | name: "resource_processor", |
| 904 | appUsesRP: true, |
| 905 | directLibUsesRP: true, |
| 906 | transitiveLibUsesRP: true, |
| 907 | sharedLibUsesRP: true, |
| 908 | sharedTransitiveSharedLibUsesRP: true, |
| 909 | sharedTransitiveStaticLibUsesRP: true, |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 910 | |
| 911 | appResources: nil, |
| 912 | appOverlays: []string{ |
| 913 | "out/soong/.intermediates/transitive/android_common/package-res.apk", |
| 914 | "out/soong/.intermediates/transitive_import_dep/android_common/package-res.apk", |
| 915 | "out/soong/.intermediates/transitive_import/android_common/package-res.apk", |
| 916 | "out/soong/.intermediates/direct/android_common/package-res.apk", |
| 917 | "out/soong/.intermediates/direct_import_dep/android_common/package-res.apk", |
| 918 | "out/soong/.intermediates/direct_import/android_common/package-res.apk", |
| 919 | "out/soong/.intermediates/app/android_common/aapt2/app/res/values_strings.arsc.flat", |
| 920 | }, |
Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 921 | appImports: []string{ |
| 922 | "out/soong/.intermediates/shared/android_common/package-res.apk", |
| 923 | "out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk", |
| 924 | }, |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 925 | appSrcJars: nil, |
| 926 | appClasspath: []string{ |
| 927 | "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar", |
| 928 | "out/soong/.intermediates/app/android_common/busybox/R.jar", |
Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 929 | "out/soong/.intermediates/shared/android_common/turbine-combined/shared.jar", |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 930 | "out/soong/.intermediates/direct/android_common/turbine-combined/direct.jar", |
Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame^] | 931 | "out/soong/.intermediates/direct_import/android_common/turbine-combined/direct_import.jar", |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 932 | }, |
| 933 | appCombined: []string{ |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 934 | "out/soong/.intermediates/app/android_common/javac/app.jar", |
Colin Cross | fd620b2 | 2024-02-23 10:05:21 -0800 | [diff] [blame] | 935 | "out/soong/.intermediates/app/android_common/busybox/R.jar", |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 936 | "out/soong/.intermediates/direct/android_common/combined/direct.jar", |
Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame^] | 937 | "out/soong/.intermediates/direct_import/android_common/combined/direct_import.jar", |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 938 | }, |
| 939 | |
| 940 | directResources: nil, |
| 941 | directOverlays: []string{"out/soong/.intermediates/direct/android_common/aapt2/direct/res/values_strings.arsc.flat"}, |
| 942 | directImports: []string{ |
| 943 | "out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk", |
| 944 | "out/soong/.intermediates/transitive_import/android_common/package-res.apk", |
| 945 | "out/soong/.intermediates/transitive_import_dep/android_common/package-res.apk", |
| 946 | "out/soong/.intermediates/transitive/android_common/package-res.apk", |
| 947 | }, |
| 948 | directSrcJars: nil, |
| 949 | directClasspath: []string{ |
| 950 | "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar", |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 951 | "out/soong/.intermediates/direct/android_common/busybox/R.jar", |
Colin Cross | 1d3f590 | 2024-03-05 11:51:54 -0800 | [diff] [blame] | 952 | "out/soong/.intermediates/transitive/android_common/busybox/R.jar", |
| 953 | "out/soong/.intermediates/transitive_import_dep/android_common/busybox/R.jar", |
| 954 | "out/soong/.intermediates/transitive_import/android_common/busybox/R.jar", |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 955 | "out/soong/.intermediates/transitive/android_common/turbine-combined/transitive.jar", |
Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame^] | 956 | "out/soong/.intermediates/transitive_import/android_common/turbine-combined/transitive_import.jar", |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 957 | }, |
| 958 | directCombined: []string{ |
| 959 | "out/soong/.intermediates/direct/android_common/javac/direct.jar", |
| 960 | "out/soong/.intermediates/transitive/android_common/javac/transitive.jar", |
Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame^] | 961 | "out/soong/.intermediates/transitive_import/android_common/combined/transitive_import.jar", |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 962 | }, |
| 963 | |
| 964 | transitiveResources: []string{"out/soong/.intermediates/transitive/android_common/aapt2/transitive/res/values_strings.arsc.flat"}, |
| 965 | transitiveOverlays: nil, |
| 966 | transitiveImports: []string{"out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk"}, |
| 967 | transitiveSrcJars: nil, |
| 968 | transitiveClasspath: []string{ |
| 969 | "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar", |
| 970 | "out/soong/.intermediates/transitive/android_common/busybox/R.jar", |
| 971 | }, |
| 972 | transitiveCombined: nil, |
| 973 | |
Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 974 | sharedResources: nil, |
| 975 | sharedOverlays: []string{"out/soong/.intermediates/shared/android_common/aapt2/shared/res/values_strings.arsc.flat"}, |
| 976 | sharedImports: []string{ |
| 977 | "out/soong/.intermediates/shared_transitive_shared/android_common/package-res.apk", |
| 978 | "out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk", |
| 979 | "out/soong/.intermediates/shared_transitive_static/android_common/package-res.apk", |
| 980 | }, |
| 981 | sharedSrcJars: nil, |
| 982 | sharedClasspath: []string{ |
| 983 | "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar", |
Colin Cross | 1d3f590 | 2024-03-05 11:51:54 -0800 | [diff] [blame] | 984 | "out/soong/.intermediates/shared/android_common/busybox/R.jar", |
Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 985 | "out/soong/.intermediates/shared_transitive_static/android_common/busybox/R.jar", |
| 986 | "out/soong/.intermediates/shared_transitive_shared/android_common/busybox/R.jar", |
Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 987 | "out/soong/.intermediates/shared_transitive_shared/android_common/turbine-combined/shared_transitive_shared.jar", |
| 988 | "out/soong/.intermediates/shared_transitive_static/android_common/turbine-combined/shared_transitive_static.jar", |
| 989 | }, |
| 990 | sharedCombined: []string{ |
| 991 | "out/soong/.intermediates/shared/android_common/javac/shared.jar", |
| 992 | "out/soong/.intermediates/shared_transitive_static/android_common/javac/shared_transitive_static.jar", |
| 993 | }, |
| 994 | |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 995 | directImportResources: nil, |
| 996 | directImportOverlays: []string{"out/soong/.intermediates/direct_import/android_common/flat-res/gen_res.flata"}, |
| 997 | directImportImports: []string{ |
| 998 | "out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk", |
| 999 | "out/soong/.intermediates/direct_import_dep/android_common/package-res.apk", |
| 1000 | }, |
| 1001 | |
| 1002 | transitiveImportResources: nil, |
| 1003 | transitiveImportOverlays: []string{"out/soong/.intermediates/transitive_import/android_common/flat-res/gen_res.flata"}, |
| 1004 | transitiveImportImports: []string{ |
| 1005 | "out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk", |
| 1006 | "out/soong/.intermediates/transitive_import_dep/android_common/package-res.apk", |
| 1007 | }, |
| 1008 | }, { |
| 1009 | // Test an app building with resource processor enabled but with dependencies built without |
| 1010 | // resource processor. |
| 1011 | name: "app_resource_processor", |
| 1012 | appUsesRP: true, |
| 1013 | directLibUsesRP: false, |
| 1014 | transitiveLibUsesRP: false, |
| 1015 | |
| 1016 | appResources: nil, |
| 1017 | appOverlays: []string{ |
| 1018 | "out/soong/.intermediates/transitive/android_common/package-res.apk", |
| 1019 | "out/soong/.intermediates/transitive_import_dep/android_common/package-res.apk", |
| 1020 | "out/soong/.intermediates/transitive_import/android_common/package-res.apk", |
| 1021 | "out/soong/.intermediates/direct/android_common/package-res.apk", |
| 1022 | "out/soong/.intermediates/direct_import_dep/android_common/package-res.apk", |
| 1023 | "out/soong/.intermediates/direct_import/android_common/package-res.apk", |
| 1024 | "out/soong/.intermediates/app/android_common/aapt2/app/res/values_strings.arsc.flat", |
| 1025 | }, |
Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 1026 | appImports: []string{ |
| 1027 | "out/soong/.intermediates/shared/android_common/package-res.apk", |
| 1028 | "out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk", |
| 1029 | }, |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1030 | appSrcJars: nil, |
| 1031 | appClasspath: []string{ |
| 1032 | "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar", |
| 1033 | // R.jar has to come before direct.jar |
| 1034 | "out/soong/.intermediates/app/android_common/busybox/R.jar", |
Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 1035 | "out/soong/.intermediates/shared/android_common/turbine-combined/shared.jar", |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1036 | "out/soong/.intermediates/direct/android_common/turbine-combined/direct.jar", |
Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame^] | 1037 | "out/soong/.intermediates/direct_import/android_common/turbine-combined/direct_import.jar", |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1038 | }, |
| 1039 | appCombined: []string{ |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1040 | "out/soong/.intermediates/app/android_common/javac/app.jar", |
Colin Cross | fd620b2 | 2024-02-23 10:05:21 -0800 | [diff] [blame] | 1041 | "out/soong/.intermediates/app/android_common/busybox/R.jar", |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1042 | "out/soong/.intermediates/direct/android_common/combined/direct.jar", |
Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame^] | 1043 | "out/soong/.intermediates/direct_import/android_common/combined/direct_import.jar", |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1044 | }, |
| 1045 | |
| 1046 | dontVerifyDirect: true, |
| 1047 | dontVerifyTransitive: true, |
Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 1048 | dontVerifyShared: true, |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1049 | dontVerifyDirectImport: true, |
| 1050 | dontVerifyTransitiveImport: true, |
| 1051 | }, |
| 1052 | { |
| 1053 | // Test an app building without resource processor enabled but with a dependency built with |
| 1054 | // resource processor. |
| 1055 | name: "app_dependency_lib_resource_processor", |
| 1056 | appUsesRP: false, |
| 1057 | directLibUsesRP: true, |
| 1058 | transitiveLibUsesRP: false, |
| 1059 | |
| 1060 | appOverlays: []string{ |
| 1061 | "out/soong/.intermediates/transitive/android_common/package-res.apk", |
| 1062 | "out/soong/.intermediates/transitive_import_dep/android_common/package-res.apk", |
| 1063 | "out/soong/.intermediates/transitive_import/android_common/package-res.apk", |
| 1064 | "out/soong/.intermediates/direct/android_common/package-res.apk", |
| 1065 | "out/soong/.intermediates/direct_import_dep/android_common/package-res.apk", |
| 1066 | "out/soong/.intermediates/direct_import/android_common/package-res.apk", |
| 1067 | "out/soong/.intermediates/app/android_common/aapt2/app/res/values_strings.arsc.flat", |
| 1068 | }, |
Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 1069 | appImports: []string{ |
| 1070 | "out/soong/.intermediates/shared/android_common/package-res.apk", |
| 1071 | "out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk", |
| 1072 | }, |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1073 | appSrcJars: []string{"out/soong/.intermediates/app/android_common/gen/android/R.srcjar"}, |
| 1074 | appClasspath: []string{ |
| 1075 | "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar", |
Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 1076 | "out/soong/.intermediates/shared/android_common/turbine-combined/shared.jar", |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1077 | "out/soong/.intermediates/direct/android_common/turbine-combined/direct.jar", |
Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame^] | 1078 | "out/soong/.intermediates/direct_import/android_common/turbine-combined/direct_import.jar", |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1079 | }, |
| 1080 | appCombined: []string{ |
| 1081 | "out/soong/.intermediates/app/android_common/javac/app.jar", |
| 1082 | "out/soong/.intermediates/direct/android_common/combined/direct.jar", |
Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame^] | 1083 | "out/soong/.intermediates/direct_import/android_common/combined/direct_import.jar", |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1084 | }, |
| 1085 | |
| 1086 | directResources: nil, |
| 1087 | directOverlays: []string{"out/soong/.intermediates/direct/android_common/aapt2/direct/res/values_strings.arsc.flat"}, |
| 1088 | directImports: []string{ |
| 1089 | "out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk", |
| 1090 | "out/soong/.intermediates/transitive_import/android_common/package-res.apk", |
| 1091 | "out/soong/.intermediates/transitive_import_dep/android_common/package-res.apk", |
| 1092 | "out/soong/.intermediates/transitive/android_common/package-res.apk", |
| 1093 | }, |
| 1094 | directSrcJars: nil, |
| 1095 | directClasspath: []string{ |
| 1096 | "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar", |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1097 | "out/soong/.intermediates/direct/android_common/busybox/R.jar", |
Colin Cross | 1d3f590 | 2024-03-05 11:51:54 -0800 | [diff] [blame] | 1098 | "out/soong/.intermediates/transitive_import_dep/android_common/busybox/R.jar", |
| 1099 | "out/soong/.intermediates/transitive_import/android_common/busybox/R.jar", |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1100 | "out/soong/.intermediates/transitive/android_common/turbine-combined/transitive.jar", |
Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame^] | 1101 | "out/soong/.intermediates/transitive_import/android_common/turbine-combined/transitive_import.jar", |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1102 | }, |
| 1103 | directCombined: []string{ |
| 1104 | "out/soong/.intermediates/direct/android_common/javac/direct.jar", |
| 1105 | "out/soong/.intermediates/transitive/android_common/javac/transitive.jar", |
Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame^] | 1106 | "out/soong/.intermediates/transitive_import/android_common/combined/transitive_import.jar", |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1107 | }, |
| 1108 | |
| 1109 | dontVerifyTransitive: true, |
Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 1110 | dontVerifyShared: true, |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1111 | dontVerifyDirectImport: true, |
| 1112 | dontVerifyTransitiveImport: true, |
| 1113 | }, |
| 1114 | { |
| 1115 | // Test a library building without resource processor enabled but with a dependency built with |
| 1116 | // resource processor. |
| 1117 | name: "lib_dependency_lib_resource_processor", |
| 1118 | appUsesRP: false, |
| 1119 | directLibUsesRP: false, |
| 1120 | transitiveLibUsesRP: true, |
| 1121 | |
| 1122 | appOverlays: []string{ |
| 1123 | "out/soong/.intermediates/transitive/android_common/package-res.apk", |
| 1124 | "out/soong/.intermediates/transitive_import_dep/android_common/package-res.apk", |
| 1125 | "out/soong/.intermediates/transitive_import/android_common/package-res.apk", |
| 1126 | "out/soong/.intermediates/direct/android_common/package-res.apk", |
| 1127 | "out/soong/.intermediates/direct_import_dep/android_common/package-res.apk", |
| 1128 | "out/soong/.intermediates/direct_import/android_common/package-res.apk", |
| 1129 | "out/soong/.intermediates/app/android_common/aapt2/app/res/values_strings.arsc.flat", |
| 1130 | }, |
Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 1131 | appImports: []string{ |
| 1132 | "out/soong/.intermediates/shared/android_common/package-res.apk", |
| 1133 | "out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk", |
| 1134 | }, |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1135 | appSrcJars: []string{"out/soong/.intermediates/app/android_common/gen/android/R.srcjar"}, |
| 1136 | appClasspath: []string{ |
| 1137 | "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar", |
Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 1138 | "out/soong/.intermediates/shared/android_common/turbine-combined/shared.jar", |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1139 | "out/soong/.intermediates/direct/android_common/turbine-combined/direct.jar", |
Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame^] | 1140 | "out/soong/.intermediates/direct_import/android_common/turbine-combined/direct_import.jar", |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1141 | }, |
| 1142 | appCombined: []string{ |
| 1143 | "out/soong/.intermediates/app/android_common/javac/app.jar", |
| 1144 | "out/soong/.intermediates/direct/android_common/combined/direct.jar", |
Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame^] | 1145 | "out/soong/.intermediates/direct_import/android_common/combined/direct_import.jar", |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1146 | }, |
| 1147 | |
| 1148 | directResources: nil, |
| 1149 | directOverlays: []string{ |
| 1150 | "out/soong/.intermediates/transitive/android_common/package-res.apk", |
| 1151 | "out/soong/.intermediates/transitive_import_dep/android_common/package-res.apk", |
| 1152 | "out/soong/.intermediates/transitive_import/android_common/package-res.apk", |
| 1153 | "out/soong/.intermediates/direct/android_common/aapt2/direct/res/values_strings.arsc.flat", |
| 1154 | }, |
| 1155 | directImports: []string{"out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk"}, |
| 1156 | directSrcJars: []string{"out/soong/.intermediates/direct/android_common/gen/android/R.srcjar"}, |
| 1157 | directClasspath: []string{ |
| 1158 | "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar", |
| 1159 | "out/soong/.intermediates/transitive/android_common/turbine-combined/transitive.jar", |
Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame^] | 1160 | "out/soong/.intermediates/transitive_import/android_common/turbine-combined/transitive_import.jar", |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1161 | }, |
| 1162 | directCombined: []string{ |
| 1163 | "out/soong/.intermediates/direct/android_common/javac/direct.jar", |
| 1164 | "out/soong/.intermediates/transitive/android_common/javac/transitive.jar", |
Colin Cross | 9055e21 | 2024-03-23 04:43:41 +0000 | [diff] [blame^] | 1165 | "out/soong/.intermediates/transitive_import/android_common/combined/transitive_import.jar", |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1166 | }, |
| 1167 | |
| 1168 | transitiveResources: []string{"out/soong/.intermediates/transitive/android_common/aapt2/transitive/res/values_strings.arsc.flat"}, |
| 1169 | transitiveOverlays: nil, |
| 1170 | transitiveImports: []string{"out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk"}, |
| 1171 | transitiveSrcJars: nil, |
| 1172 | transitiveClasspath: []string{ |
| 1173 | "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar", |
| 1174 | "out/soong/.intermediates/transitive/android_common/busybox/R.jar", |
| 1175 | }, |
| 1176 | transitiveCombined: nil, |
| 1177 | |
Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 1178 | dontVerifyShared: true, |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1179 | dontVerifyDirectImport: true, |
| 1180 | dontVerifyTransitiveImport: true, |
Colin Cross | ff3ff7f | 2023-07-05 14:04:12 -0700 | [diff] [blame] | 1181 | }, |
| 1182 | } |
| 1183 | |
| 1184 | for _, testCase := range testCases { |
| 1185 | t.Run(testCase.name, func(t *testing.T) { |
| 1186 | bp := fmt.Sprintf(` |
| 1187 | android_app { |
| 1188 | name: "app", |
| 1189 | sdk_version: "current", |
| 1190 | srcs: ["app/app.java"], |
| 1191 | resource_dirs: ["app/res"], |
| 1192 | manifest: "app/AndroidManifest.xml", |
Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 1193 | libs: ["shared"], |
Colin Cross | ff3ff7f | 2023-07-05 14:04:12 -0700 | [diff] [blame] | 1194 | static_libs: ["direct", "direct_import"], |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1195 | use_resource_processor: %v, |
Colin Cross | ff3ff7f | 2023-07-05 14:04:12 -0700 | [diff] [blame] | 1196 | } |
| 1197 | |
| 1198 | android_library { |
| 1199 | name: "direct", |
| 1200 | sdk_version: "current", |
| 1201 | srcs: ["direct/direct.java"], |
| 1202 | resource_dirs: ["direct/res"], |
| 1203 | manifest: "direct/AndroidManifest.xml", |
| 1204 | static_libs: ["transitive", "transitive_import"], |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1205 | use_resource_processor: %v, |
Colin Cross | ff3ff7f | 2023-07-05 14:04:12 -0700 | [diff] [blame] | 1206 | } |
| 1207 | |
| 1208 | android_library { |
| 1209 | name: "transitive", |
| 1210 | sdk_version: "current", |
| 1211 | srcs: ["transitive/transitive.java"], |
| 1212 | resource_dirs: ["transitive/res"], |
| 1213 | manifest: "transitive/AndroidManifest.xml", |
Colin Cross | 4eae06d | 2023-06-20 22:40:02 -0700 | [diff] [blame] | 1214 | use_resource_processor: %v, |
Colin Cross | ff3ff7f | 2023-07-05 14:04:12 -0700 | [diff] [blame] | 1215 | } |
| 1216 | |
Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 1217 | android_library { |
| 1218 | name: "shared", |
| 1219 | sdk_version: "current", |
| 1220 | srcs: ["shared/shared.java"], |
| 1221 | resource_dirs: ["shared/res"], |
| 1222 | manifest: "shared/AndroidManifest.xml", |
| 1223 | use_resource_processor: %v, |
| 1224 | libs: ["shared_transitive_shared"], |
| 1225 | static_libs: ["shared_transitive_static"], |
| 1226 | } |
| 1227 | |
| 1228 | android_library { |
| 1229 | name: "shared_transitive_shared", |
| 1230 | sdk_version: "current", |
| 1231 | srcs: ["shared_transitive_shared/shared_transitive_shared.java"], |
| 1232 | resource_dirs: ["shared_transitive_shared/res"], |
| 1233 | manifest: "shared_transitive_shared/AndroidManifest.xml", |
| 1234 | use_resource_processor: %v, |
| 1235 | } |
| 1236 | |
| 1237 | android_library { |
| 1238 | name: "shared_transitive_static", |
| 1239 | sdk_version: "current", |
| 1240 | srcs: ["shared_transitive_static/shared.java"], |
| 1241 | resource_dirs: ["shared_transitive_static/res"], |
| 1242 | manifest: "shared_transitive_static/AndroidManifest.xml", |
| 1243 | use_resource_processor: %v, |
| 1244 | } |
| 1245 | |
Colin Cross | ff3ff7f | 2023-07-05 14:04:12 -0700 | [diff] [blame] | 1246 | android_library_import { |
| 1247 | name: "direct_import", |
| 1248 | sdk_version: "current", |
| 1249 | aars: ["direct_import.aar"], |
| 1250 | static_libs: ["direct_import_dep"], |
| 1251 | } |
| 1252 | |
| 1253 | android_library_import { |
| 1254 | name: "direct_import_dep", |
| 1255 | sdk_version: "current", |
| 1256 | aars: ["direct_import_dep.aar"], |
| 1257 | } |
| 1258 | |
| 1259 | android_library_import { |
| 1260 | name: "transitive_import", |
| 1261 | sdk_version: "current", |
| 1262 | aars: ["transitive_import.aar"], |
| 1263 | static_libs: ["transitive_import_dep"], |
| 1264 | } |
| 1265 | |
| 1266 | android_library_import { |
| 1267 | name: "transitive_import_dep", |
| 1268 | sdk_version: "current", |
| 1269 | aars: ["transitive_import_dep.aar"], |
| 1270 | } |
Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 1271 | `, testCase.appUsesRP, testCase.directLibUsesRP, testCase.transitiveLibUsesRP, |
| 1272 | testCase.sharedLibUsesRP, testCase.sharedTransitiveSharedLibUsesRP, testCase.sharedTransitiveStaticLibUsesRP) |
Colin Cross | ff3ff7f | 2023-07-05 14:04:12 -0700 | [diff] [blame] | 1273 | |
| 1274 | fs := android.MockFS{ |
Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 1275 | "app/res/values/strings.xml": nil, |
| 1276 | "direct/res/values/strings.xml": nil, |
| 1277 | "transitive/res/values/strings.xml": nil, |
| 1278 | "shared/res/values/strings.xml": nil, |
| 1279 | "shared_transitive_static/res/values/strings.xml": nil, |
| 1280 | "shared_transitive_shared/res/values/strings.xml": nil, |
Colin Cross | ff3ff7f | 2023-07-05 14:04:12 -0700 | [diff] [blame] | 1281 | } |
| 1282 | |
| 1283 | result := android.GroupFixturePreparers( |
| 1284 | PrepareForTestWithJavaDefaultModules, |
Colin Cross | ff3ff7f | 2023-07-05 14:04:12 -0700 | [diff] [blame] | 1285 | fs.AddToFixture(), |
| 1286 | ).RunTestWithBp(t, bp) |
| 1287 | |
| 1288 | type aaptInfo struct { |
| 1289 | resources, overlays, imports, srcJars, classpath, combined android.Paths |
| 1290 | } |
| 1291 | |
| 1292 | getAaptInfo := func(moduleName string) (aaptInfo aaptInfo) { |
| 1293 | mod := result.ModuleForTests(moduleName, "android_common") |
| 1294 | resourceListRule := mod.MaybeOutput("aapt2/res.list") |
| 1295 | overlayListRule := mod.MaybeOutput("aapt2/overlay.list") |
| 1296 | aaptRule := mod.Rule("aapt2Link") |
| 1297 | javacRule := mod.MaybeRule("javac") |
| 1298 | combinedRule := mod.MaybeOutput("combined/" + moduleName + ".jar") |
| 1299 | |
| 1300 | aaptInfo.resources = resourceListRule.Inputs |
| 1301 | aaptInfo.overlays = overlayListRule.Inputs |
| 1302 | |
| 1303 | aaptFlags := strings.Split(aaptRule.Args["flags"], " ") |
| 1304 | for i, flag := range aaptFlags { |
| 1305 | if flag == "-I" && i+1 < len(aaptFlags) { |
| 1306 | aaptInfo.imports = append(aaptInfo.imports, android.PathForTesting(aaptFlags[i+1])) |
| 1307 | } |
| 1308 | } |
| 1309 | |
| 1310 | if len(javacRule.Args["srcJars"]) > 0 { |
| 1311 | aaptInfo.srcJars = android.PathsForTesting(strings.Split(javacRule.Args["srcJars"], " ")...) |
| 1312 | } |
| 1313 | |
| 1314 | if len(javacRule.Args["classpath"]) > 0 { |
| 1315 | classpathArg := strings.TrimPrefix(javacRule.Args["classpath"], "-classpath ") |
| 1316 | aaptInfo.classpath = android.PathsForTesting(strings.Split(classpathArg, ":")...) |
| 1317 | } |
| 1318 | |
| 1319 | aaptInfo.combined = combinedRule.Inputs |
| 1320 | return |
| 1321 | } |
| 1322 | |
| 1323 | app := getAaptInfo("app") |
| 1324 | direct := getAaptInfo("direct") |
| 1325 | transitive := getAaptInfo("transitive") |
Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 1326 | shared := getAaptInfo("shared") |
Colin Cross | ff3ff7f | 2023-07-05 14:04:12 -0700 | [diff] [blame] | 1327 | directImport := getAaptInfo("direct_import") |
| 1328 | transitiveImport := getAaptInfo("transitive_import") |
| 1329 | |
| 1330 | if !testCase.dontVerifyApp { |
| 1331 | android.AssertPathsRelativeToTopEquals(t, "app resources", testCase.appResources, app.resources) |
| 1332 | android.AssertPathsRelativeToTopEquals(t, "app overlays", testCase.appOverlays, app.overlays) |
| 1333 | android.AssertPathsRelativeToTopEquals(t, "app imports", testCase.appImports, app.imports) |
| 1334 | android.AssertPathsRelativeToTopEquals(t, "app srcjars", testCase.appSrcJars, app.srcJars) |
| 1335 | android.AssertPathsRelativeToTopEquals(t, "app classpath", testCase.appClasspath, app.classpath) |
| 1336 | android.AssertPathsRelativeToTopEquals(t, "app combined", testCase.appCombined, app.combined) |
| 1337 | } |
| 1338 | |
| 1339 | if !testCase.dontVerifyDirect { |
| 1340 | android.AssertPathsRelativeToTopEquals(t, "direct resources", testCase.directResources, direct.resources) |
| 1341 | android.AssertPathsRelativeToTopEquals(t, "direct overlays", testCase.directOverlays, direct.overlays) |
| 1342 | android.AssertPathsRelativeToTopEquals(t, "direct imports", testCase.directImports, direct.imports) |
| 1343 | android.AssertPathsRelativeToTopEquals(t, "direct srcjars", testCase.directSrcJars, direct.srcJars) |
| 1344 | android.AssertPathsRelativeToTopEquals(t, "direct classpath", testCase.directClasspath, direct.classpath) |
| 1345 | android.AssertPathsRelativeToTopEquals(t, "direct combined", testCase.directCombined, direct.combined) |
| 1346 | } |
| 1347 | |
| 1348 | if !testCase.dontVerifyTransitive { |
| 1349 | android.AssertPathsRelativeToTopEquals(t, "transitive resources", testCase.transitiveResources, transitive.resources) |
| 1350 | android.AssertPathsRelativeToTopEquals(t, "transitive overlays", testCase.transitiveOverlays, transitive.overlays) |
| 1351 | android.AssertPathsRelativeToTopEquals(t, "transitive imports", testCase.transitiveImports, transitive.imports) |
| 1352 | android.AssertPathsRelativeToTopEquals(t, "transitive srcjars", testCase.transitiveSrcJars, transitive.srcJars) |
| 1353 | android.AssertPathsRelativeToTopEquals(t, "transitive classpath", testCase.transitiveClasspath, transitive.classpath) |
| 1354 | android.AssertPathsRelativeToTopEquals(t, "transitive combined", testCase.transitiveCombined, transitive.combined) |
| 1355 | } |
| 1356 | |
Colin Cross | 8676c8c | 2023-10-12 15:58:57 -0700 | [diff] [blame] | 1357 | if !testCase.dontVerifyShared { |
| 1358 | android.AssertPathsRelativeToTopEquals(t, "shared resources", testCase.sharedResources, shared.resources) |
| 1359 | android.AssertPathsRelativeToTopEquals(t, "shared overlays", testCase.sharedOverlays, shared.overlays) |
| 1360 | android.AssertPathsRelativeToTopEquals(t, "shared imports", testCase.sharedImports, shared.imports) |
| 1361 | android.AssertPathsRelativeToTopEquals(t, "shared srcjars", testCase.sharedSrcJars, shared.srcJars) |
| 1362 | android.AssertPathsRelativeToTopEquals(t, "shared classpath", testCase.sharedClasspath, shared.classpath) |
| 1363 | android.AssertPathsRelativeToTopEquals(t, "shared combined", testCase.sharedCombined, shared.combined) |
| 1364 | } |
| 1365 | |
Colin Cross | ff3ff7f | 2023-07-05 14:04:12 -0700 | [diff] [blame] | 1366 | if !testCase.dontVerifyDirectImport { |
| 1367 | android.AssertPathsRelativeToTopEquals(t, "direct_import resources", testCase.directImportResources, directImport.resources) |
| 1368 | android.AssertPathsRelativeToTopEquals(t, "direct_import overlays", testCase.directImportOverlays, directImport.overlays) |
| 1369 | android.AssertPathsRelativeToTopEquals(t, "direct_import imports", testCase.directImportImports, directImport.imports) |
| 1370 | } |
| 1371 | |
| 1372 | if !testCase.dontVerifyTransitiveImport { |
| 1373 | android.AssertPathsRelativeToTopEquals(t, "transitive_import resources", testCase.transitiveImportResources, transitiveImport.resources) |
| 1374 | android.AssertPathsRelativeToTopEquals(t, "transitive_import overlays", testCase.transitiveImportOverlays, transitiveImport.overlays) |
| 1375 | android.AssertPathsRelativeToTopEquals(t, "transitive_import imports", testCase.transitiveImportImports, transitiveImport.imports) |
| 1376 | } |
| 1377 | }) |
| 1378 | } |
| 1379 | } |
| 1380 | |
| 1381 | func TestAndroidResourceOverlays(t *testing.T) { |
Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 1382 | testCases := []struct { |
| 1383 | name string |
| 1384 | enforceRROTargets []string |
| 1385 | enforceRROExcludedOverlays []string |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 1386 | resourceFiles map[string][]string |
Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 1387 | overlayFiles map[string][]string |
| 1388 | rroDirs map[string][]string |
| 1389 | }{ |
| 1390 | { |
| 1391 | name: "no RRO", |
| 1392 | enforceRROTargets: nil, |
| 1393 | enforceRROExcludedOverlays: nil, |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 1394 | resourceFiles: map[string][]string{ |
| 1395 | "foo": nil, |
| 1396 | "bar": {"bar/res/res/values/strings.xml"}, |
| 1397 | "lib": nil, |
| 1398 | "lib2": {"lib2/res/res/values/strings.xml"}, |
| 1399 | }, |
Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 1400 | overlayFiles: map[string][]string{ |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 1401 | "foo": { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1402 | "out/soong/.intermediates/lib2/android_common/package-res.apk", |
| 1403 | "out/soong/.intermediates/lib/android_common/package-res.apk", |
| 1404 | "out/soong/.intermediates/lib3/android_common/package-res.apk", |
Colin Cross | 6ed7dea | 2019-01-31 14:44:30 -0800 | [diff] [blame] | 1405 | "foo/res/res/values/strings.xml", |
Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 1406 | "device/vendor/blah/static_overlay/foo/res/values/strings.xml", |
| 1407 | "device/vendor/blah/overlay/foo/res/values/strings.xml", |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 1408 | "product/vendor/blah/overlay/foo/res/values/strings.xml", |
Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 1409 | }, |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 1410 | "bar": { |
Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 1411 | "device/vendor/blah/static_overlay/bar/res/values/strings.xml", |
| 1412 | "device/vendor/blah/overlay/bar/res/values/strings.xml", |
| 1413 | }, |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 1414 | "lib": { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1415 | "out/soong/.intermediates/lib2/android_common/package-res.apk", |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 1416 | "lib/res/res/values/strings.xml", |
| 1417 | "device/vendor/blah/overlay/lib/res/values/strings.xml", |
| 1418 | }, |
Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 1419 | }, |
| 1420 | rroDirs: map[string][]string{ |
| 1421 | "foo": nil, |
| 1422 | "bar": nil, |
| 1423 | }, |
| 1424 | }, |
| 1425 | { |
| 1426 | name: "enforce RRO on foo", |
| 1427 | enforceRROTargets: []string{"foo"}, |
| 1428 | enforceRROExcludedOverlays: []string{"device/vendor/blah/static_overlay"}, |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 1429 | resourceFiles: map[string][]string{ |
| 1430 | "foo": nil, |
| 1431 | "bar": {"bar/res/res/values/strings.xml"}, |
| 1432 | "lib": nil, |
| 1433 | "lib2": {"lib2/res/res/values/strings.xml"}, |
| 1434 | }, |
Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 1435 | overlayFiles: map[string][]string{ |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 1436 | "foo": { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1437 | "out/soong/.intermediates/lib2/android_common/package-res.apk", |
| 1438 | "out/soong/.intermediates/lib/android_common/package-res.apk", |
| 1439 | "out/soong/.intermediates/lib3/android_common/package-res.apk", |
Colin Cross | 6ed7dea | 2019-01-31 14:44:30 -0800 | [diff] [blame] | 1440 | "foo/res/res/values/strings.xml", |
| 1441 | "device/vendor/blah/static_overlay/foo/res/values/strings.xml", |
| 1442 | }, |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 1443 | "bar": { |
Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 1444 | "device/vendor/blah/static_overlay/bar/res/values/strings.xml", |
| 1445 | "device/vendor/blah/overlay/bar/res/values/strings.xml", |
| 1446 | }, |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 1447 | "lib": { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1448 | "out/soong/.intermediates/lib2/android_common/package-res.apk", |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 1449 | "lib/res/res/values/strings.xml", |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 1450 | }, |
Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 1451 | }, |
Colin Cross | c1c3755 | 2019-01-31 11:42:41 -0800 | [diff] [blame] | 1452 | |
Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 1453 | rroDirs: map[string][]string{ |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 1454 | "foo": { |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 1455 | "device:device/vendor/blah/overlay/foo/res", |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 1456 | "product:product/vendor/blah/overlay/foo/res", |
Jaewoong Jung | c779cd4 | 2020-10-06 18:56:10 -0700 | [diff] [blame] | 1457 | "device:device/vendor/blah/overlay/lib/res", |
Colin Cross | c1c3755 | 2019-01-31 11:42:41 -0800 | [diff] [blame] | 1458 | }, |
Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 1459 | "bar": nil, |
Jaewoong Jung | c779cd4 | 2020-10-06 18:56:10 -0700 | [diff] [blame] | 1460 | "lib": {"device:device/vendor/blah/overlay/lib/res"}, |
Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 1461 | }, |
| 1462 | }, |
| 1463 | { |
| 1464 | name: "enforce RRO on all", |
| 1465 | enforceRROTargets: []string{"*"}, |
| 1466 | enforceRROExcludedOverlays: []string{ |
| 1467 | // Excluding specific apps/res directories also allowed. |
| 1468 | "device/vendor/blah/static_overlay/foo", |
| 1469 | "device/vendor/blah/static_overlay/bar/res", |
| 1470 | }, |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 1471 | resourceFiles: map[string][]string{ |
| 1472 | "foo": nil, |
| 1473 | "bar": {"bar/res/res/values/strings.xml"}, |
| 1474 | "lib": nil, |
| 1475 | "lib2": {"lib2/res/res/values/strings.xml"}, |
| 1476 | }, |
Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 1477 | overlayFiles: map[string][]string{ |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 1478 | "foo": { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1479 | "out/soong/.intermediates/lib2/android_common/package-res.apk", |
| 1480 | "out/soong/.intermediates/lib/android_common/package-res.apk", |
| 1481 | "out/soong/.intermediates/lib3/android_common/package-res.apk", |
Colin Cross | 6ed7dea | 2019-01-31 14:44:30 -0800 | [diff] [blame] | 1482 | "foo/res/res/values/strings.xml", |
| 1483 | "device/vendor/blah/static_overlay/foo/res/values/strings.xml", |
| 1484 | }, |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 1485 | "bar": {"device/vendor/blah/static_overlay/bar/res/values/strings.xml"}, |
| 1486 | "lib": { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1487 | "out/soong/.intermediates/lib2/android_common/package-res.apk", |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 1488 | "lib/res/res/values/strings.xml", |
| 1489 | }, |
Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 1490 | }, |
| 1491 | rroDirs: map[string][]string{ |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 1492 | "foo": { |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 1493 | "device:device/vendor/blah/overlay/foo/res", |
| 1494 | "product:product/vendor/blah/overlay/foo/res", |
| 1495 | // Lib dep comes after the direct deps |
| 1496 | "device:device/vendor/blah/overlay/lib/res", |
Colin Cross | c1c3755 | 2019-01-31 11:42:41 -0800 | [diff] [blame] | 1497 | }, |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 1498 | "bar": {"device:device/vendor/blah/overlay/bar/res"}, |
| 1499 | "lib": {"device:device/vendor/blah/overlay/lib/res"}, |
Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 1500 | }, |
| 1501 | }, |
| 1502 | } |
| 1503 | |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 1504 | deviceResourceOverlays := []string{ |
Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 1505 | "device/vendor/blah/overlay", |
| 1506 | "device/vendor/blah/overlay2", |
| 1507 | "device/vendor/blah/static_overlay", |
| 1508 | } |
| 1509 | |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 1510 | productResourceOverlays := []string{ |
| 1511 | "product/vendor/blah/overlay", |
| 1512 | } |
| 1513 | |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1514 | fs := android.MockFS{ |
Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 1515 | "foo/res/res/values/strings.xml": nil, |
| 1516 | "bar/res/res/values/strings.xml": nil, |
Colin Cross | 6ed7dea | 2019-01-31 14:44:30 -0800 | [diff] [blame] | 1517 | "lib/res/res/values/strings.xml": nil, |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 1518 | "lib2/res/res/values/strings.xml": nil, |
Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 1519 | "device/vendor/blah/overlay/foo/res/values/strings.xml": nil, |
| 1520 | "device/vendor/blah/overlay/bar/res/values/strings.xml": nil, |
Colin Cross | 6ed7dea | 2019-01-31 14:44:30 -0800 | [diff] [blame] | 1521 | "device/vendor/blah/overlay/lib/res/values/strings.xml": nil, |
Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 1522 | "device/vendor/blah/static_overlay/foo/res/values/strings.xml": nil, |
| 1523 | "device/vendor/blah/static_overlay/bar/res/values/strings.xml": nil, |
| 1524 | "device/vendor/blah/overlay2/res/values/strings.xml": nil, |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 1525 | "product/vendor/blah/overlay/foo/res/values/strings.xml": nil, |
Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 1526 | } |
| 1527 | |
| 1528 | bp := ` |
| 1529 | android_app { |
| 1530 | name: "foo", |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1531 | sdk_version: "current", |
Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 1532 | resource_dirs: ["foo/res"], |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 1533 | static_libs: ["lib", "lib3"], |
Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 1534 | } |
| 1535 | |
| 1536 | android_app { |
| 1537 | name: "bar", |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1538 | sdk_version: "current", |
Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 1539 | resource_dirs: ["bar/res"], |
| 1540 | } |
Colin Cross | 6ed7dea | 2019-01-31 14:44:30 -0800 | [diff] [blame] | 1541 | |
| 1542 | android_library { |
| 1543 | name: "lib", |
Jeongik Cha | 75b83b0 | 2019-11-01 15:28:00 +0900 | [diff] [blame] | 1544 | sdk_version: "current", |
Colin Cross | 6ed7dea | 2019-01-31 14:44:30 -0800 | [diff] [blame] | 1545 | resource_dirs: ["lib/res"], |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 1546 | static_libs: ["lib2"], |
| 1547 | } |
| 1548 | |
| 1549 | android_library { |
| 1550 | name: "lib2", |
Jeongik Cha | 75b83b0 | 2019-11-01 15:28:00 +0900 | [diff] [blame] | 1551 | sdk_version: "current", |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 1552 | resource_dirs: ["lib2/res"], |
Colin Cross | 6ed7dea | 2019-01-31 14:44:30 -0800 | [diff] [blame] | 1553 | } |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 1554 | |
| 1555 | // This library has the same resources as lib (should not lead to dupe RROs) |
| 1556 | android_library { |
| 1557 | name: "lib3", |
Jeongik Cha | 75b83b0 | 2019-11-01 15:28:00 +0900 | [diff] [blame] | 1558 | sdk_version: "current", |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 1559 | resource_dirs: ["lib/res"] |
| 1560 | } |
Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 1561 | ` |
| 1562 | |
Colin Cross | 5c4791c | 2019-02-01 11:44:44 -0800 | [diff] [blame] | 1563 | for _, testCase := range testCases { |
Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 1564 | t.Run(testCase.name, func(t *testing.T) { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1565 | result := android.GroupFixturePreparers( |
| 1566 | PrepareForTestWithJavaDefaultModules, |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1567 | fs.AddToFixture(), |
| 1568 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 1569 | variables.DeviceResourceOverlays = deviceResourceOverlays |
| 1570 | variables.ProductResourceOverlays = productResourceOverlays |
| 1571 | if testCase.enforceRROTargets != nil { |
| 1572 | variables.EnforceRROTargets = testCase.enforceRROTargets |
| 1573 | } |
| 1574 | if testCase.enforceRROExcludedOverlays != nil { |
| 1575 | variables.EnforceRROExcludedOverlays = testCase.enforceRROExcludedOverlays |
| 1576 | } |
| 1577 | }), |
| 1578 | ).RunTestWithBp(t, bp) |
Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 1579 | |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 1580 | resourceListToFiles := func(module android.TestingModule, list []string) (files []string) { |
| 1581 | for _, o := range list { |
| 1582 | res := module.MaybeOutput(o) |
| 1583 | if res.Rule != nil { |
| 1584 | // If the overlay is compiled as part of this module (i.e. a .arsc.flat file), |
| 1585 | // verify the inputs to the .arsc.flat rule. |
| 1586 | files = append(files, res.Inputs.Strings()...) |
| 1587 | } else { |
| 1588 | // Otherwise, verify the full path to the output of the other module |
| 1589 | files = append(files, o) |
Anton Hansson | 94c93f3 | 2019-01-30 16:03:37 +0000 | [diff] [blame] | 1590 | } |
Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 1591 | } |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 1592 | return files |
Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 1593 | } |
| 1594 | |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 1595 | getResources := func(moduleName string) (resourceFiles, overlayFiles, rroDirs []string) { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1596 | module := result.ModuleForTests(moduleName, "android_common") |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 1597 | resourceList := module.MaybeOutput("aapt2/res.list") |
| 1598 | if resourceList.Rule != nil { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1599 | resourceFiles = resourceListToFiles(module, android.PathsRelativeToTop(resourceList.Inputs)) |
Anton Hansson | 0375a4f | 2019-01-24 14:39:19 +0000 | [diff] [blame] | 1600 | } |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 1601 | overlayList := module.MaybeOutput("aapt2/overlay.list") |
| 1602 | if overlayList.Rule != nil { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1603 | overlayFiles = resourceListToFiles(module, android.PathsRelativeToTop(overlayList.Inputs)) |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 1604 | } |
| 1605 | |
Colin Cross | ab8d138 | 2023-07-14 17:23:41 +0000 | [diff] [blame] | 1606 | for _, d := range module.Module().(AndroidLibraryDependency).RRODirsDepSet().ToList() { |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 1607 | var prefix string |
| 1608 | if d.overlayType == device { |
| 1609 | prefix = "device:" |
| 1610 | } else if d.overlayType == product { |
| 1611 | prefix = "product:" |
| 1612 | } else { |
| 1613 | t.Fatalf("Unexpected overlayType %d", d.overlayType) |
| 1614 | } |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1615 | rroDirs = append(rroDirs, prefix+android.PathRelativeToTop(d.path)) |
Anton Hansson | 53c8844 | 2019-03-18 15:53:16 +0000 | [diff] [blame] | 1616 | } |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 1617 | |
| 1618 | return resourceFiles, overlayFiles, rroDirs |
| 1619 | } |
| 1620 | |
| 1621 | modules := []string{"foo", "bar", "lib", "lib2"} |
| 1622 | for _, module := range modules { |
| 1623 | resourceFiles, overlayFiles, rroDirs := getResources(module) |
| 1624 | |
| 1625 | if !reflect.DeepEqual(resourceFiles, testCase.resourceFiles[module]) { |
| 1626 | t.Errorf("expected %s resource files:\n %#v\n got:\n %#v", |
| 1627 | module, testCase.resourceFiles[module], resourceFiles) |
| 1628 | } |
| 1629 | if !reflect.DeepEqual(overlayFiles, testCase.overlayFiles[module]) { |
| 1630 | t.Errorf("expected %s overlay files:\n %#v\n got:\n %#v", |
| 1631 | module, testCase.overlayFiles[module], overlayFiles) |
| 1632 | } |
| 1633 | if !reflect.DeepEqual(rroDirs, testCase.rroDirs[module]) { |
Anton Hansson | 0375a4f | 2019-01-24 14:39:19 +0000 | [diff] [blame] | 1634 | t.Errorf("expected %s rroDirs: %#v\n got:\n %#v", |
Colin Cross | bec8530 | 2019-02-13 13:15:46 -0800 | [diff] [blame] | 1635 | module, testCase.rroDirs[module], rroDirs) |
Anton Hansson | 0375a4f | 2019-01-24 14:39:19 +0000 | [diff] [blame] | 1636 | } |
Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 1637 | } |
Colin Cross | 890ff55 | 2017-11-30 20:13:19 -0800 | [diff] [blame] | 1638 | }) |
| 1639 | } |
| 1640 | } |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 1641 | |
Paul Duffin | cdb88a9 | 2021-03-14 00:36:50 +0000 | [diff] [blame] | 1642 | func checkSdkVersion(t *testing.T, result *android.TestResult, expectedSdkVersion string) { |
| 1643 | foo := result.ModuleForTests("foo", "android_common") |
Jeongik Cha | 219141c | 2020-08-06 23:00:37 +0900 | [diff] [blame] | 1644 | link := foo.Output("package-res.apk") |
| 1645 | linkFlags := strings.Split(link.Args["flags"], " ") |
| 1646 | min := android.IndexList("--min-sdk-version", linkFlags) |
| 1647 | target := android.IndexList("--target-sdk-version", linkFlags) |
| 1648 | |
| 1649 | if min == -1 || target == -1 || min == len(linkFlags)-1 || target == len(linkFlags)-1 { |
| 1650 | t.Fatalf("missing --min-sdk-version or --target-sdk-version in link flags: %q", linkFlags) |
| 1651 | } |
| 1652 | |
| 1653 | gotMinSdkVersion := linkFlags[min+1] |
| 1654 | gotTargetSdkVersion := linkFlags[target+1] |
| 1655 | |
Paul Duffin | cdb88a9 | 2021-03-14 00:36:50 +0000 | [diff] [blame] | 1656 | android.AssertStringEquals(t, "incorrect --min-sdk-version", expectedSdkVersion, gotMinSdkVersion) |
Jeongik Cha | 219141c | 2020-08-06 23:00:37 +0900 | [diff] [blame] | 1657 | |
Paul Duffin | cdb88a9 | 2021-03-14 00:36:50 +0000 | [diff] [blame] | 1658 | android.AssertStringEquals(t, "incorrect --target-sdk-version", expectedSdkVersion, gotTargetSdkVersion) |
Jeongik Cha | 219141c | 2020-08-06 23:00:37 +0900 | [diff] [blame] | 1659 | } |
| 1660 | |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 1661 | func TestAppSdkVersion(t *testing.T) { |
| 1662 | testCases := []struct { |
| 1663 | name string |
| 1664 | sdkVersion string |
| 1665 | platformSdkInt int |
| 1666 | platformSdkCodename string |
| 1667 | platformSdkFinal bool |
Spandan Das | ffb31af | 2023-03-01 19:46:18 +0000 | [diff] [blame] | 1668 | minSdkVersionBp string |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 1669 | expectedMinSdkVersion string |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1670 | platformApis bool |
Dan Albert | 4f378d7 | 2020-07-23 17:32:15 -0700 | [diff] [blame] | 1671 | activeCodenames []string |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 1672 | }{ |
| 1673 | { |
| 1674 | name: "current final SDK", |
| 1675 | sdkVersion: "current", |
| 1676 | platformSdkInt: 27, |
| 1677 | platformSdkCodename: "REL", |
| 1678 | platformSdkFinal: true, |
| 1679 | expectedMinSdkVersion: "27", |
| 1680 | }, |
| 1681 | { |
| 1682 | name: "current non-final SDK", |
| 1683 | sdkVersion: "current", |
| 1684 | platformSdkInt: 27, |
| 1685 | platformSdkCodename: "OMR1", |
| 1686 | platformSdkFinal: false, |
| 1687 | expectedMinSdkVersion: "OMR1", |
Dan Albert | 4f378d7 | 2020-07-23 17:32:15 -0700 | [diff] [blame] | 1688 | activeCodenames: []string{"OMR1"}, |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 1689 | }, |
| 1690 | { |
| 1691 | name: "default final SDK", |
| 1692 | sdkVersion: "", |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1693 | platformApis: true, |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 1694 | platformSdkInt: 27, |
| 1695 | platformSdkCodename: "REL", |
| 1696 | platformSdkFinal: true, |
| 1697 | expectedMinSdkVersion: "27", |
| 1698 | }, |
| 1699 | { |
| 1700 | name: "default non-final SDK", |
| 1701 | sdkVersion: "", |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1702 | platformApis: true, |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 1703 | platformSdkInt: 27, |
| 1704 | platformSdkCodename: "OMR1", |
| 1705 | platformSdkFinal: false, |
| 1706 | expectedMinSdkVersion: "OMR1", |
Dan Albert | 4f378d7 | 2020-07-23 17:32:15 -0700 | [diff] [blame] | 1707 | activeCodenames: []string{"OMR1"}, |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 1708 | }, |
| 1709 | { |
| 1710 | name: "14", |
| 1711 | sdkVersion: "14", |
| 1712 | expectedMinSdkVersion: "14", |
Dan Albert | 4f378d7 | 2020-07-23 17:32:15 -0700 | [diff] [blame] | 1713 | platformSdkCodename: "S", |
| 1714 | activeCodenames: []string{"S"}, |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 1715 | }, |
Spandan Das | ffb31af | 2023-03-01 19:46:18 +0000 | [diff] [blame] | 1716 | { |
| 1717 | name: "two active SDKs", |
| 1718 | sdkVersion: "module_current", |
| 1719 | minSdkVersionBp: "UpsideDownCake", |
| 1720 | expectedMinSdkVersion: "UpsideDownCake", // And not VanillaIceCream |
| 1721 | platformSdkCodename: "VanillaIceCream", |
| 1722 | activeCodenames: []string{"UpsideDownCake", "VanillaIceCream"}, |
| 1723 | }, |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 1724 | } |
| 1725 | |
| 1726 | for _, moduleType := range []string{"android_app", "android_library"} { |
| 1727 | for _, test := range testCases { |
| 1728 | t.Run(moduleType+" "+test.name, func(t *testing.T) { |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1729 | platformApiProp := "" |
| 1730 | if test.platformApis { |
| 1731 | platformApiProp = "platform_apis: true," |
| 1732 | } |
Spandan Das | ffb31af | 2023-03-01 19:46:18 +0000 | [diff] [blame] | 1733 | minSdkVersionProp := "" |
| 1734 | if test.minSdkVersionBp != "" { |
| 1735 | minSdkVersionProp = fmt.Sprintf(` min_sdk_version: "%s",`, test.minSdkVersionBp) |
| 1736 | } |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 1737 | bp := fmt.Sprintf(`%s { |
| 1738 | name: "foo", |
| 1739 | srcs: ["a.java"], |
| 1740 | sdk_version: "%s", |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1741 | %s |
Spandan Das | ffb31af | 2023-03-01 19:46:18 +0000 | [diff] [blame] | 1742 | %s |
| 1743 | }`, moduleType, test.sdkVersion, platformApiProp, minSdkVersionProp) |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 1744 | |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame] | 1745 | result := android.GroupFixturePreparers( |
| 1746 | prepareForJavaTest, |
Paul Duffin | cdb88a9 | 2021-03-14 00:36:50 +0000 | [diff] [blame] | 1747 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 1748 | variables.Platform_sdk_version = &test.platformSdkInt |
| 1749 | variables.Platform_sdk_codename = &test.platformSdkCodename |
| 1750 | variables.Platform_version_active_codenames = test.activeCodenames |
| 1751 | variables.Platform_sdk_final = &test.platformSdkFinal |
| 1752 | }), |
Paul Duffin | 2645a29 | 2021-03-13 02:36:00 +0000 | [diff] [blame] | 1753 | FixtureWithPrebuiltApis(map[string][]string{ |
| 1754 | "14": {"foo"}, |
| 1755 | }), |
Paul Duffin | cdb88a9 | 2021-03-14 00:36:50 +0000 | [diff] [blame] | 1756 | ).RunTestWithBp(t, bp) |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 1757 | |
Paul Duffin | cdb88a9 | 2021-03-14 00:36:50 +0000 | [diff] [blame] | 1758 | checkSdkVersion(t, result, test.expectedMinSdkVersion) |
Colin Cross | d09b0b6 | 2018-04-18 11:06:47 -0700 | [diff] [blame] | 1759 | }) |
| 1760 | } |
| 1761 | } |
| 1762 | } |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 1763 | |
Jeongik Cha | 219141c | 2020-08-06 23:00:37 +0900 | [diff] [blame] | 1764 | func TestVendorAppSdkVersion(t *testing.T) { |
| 1765 | testCases := []struct { |
| 1766 | name string |
| 1767 | sdkVersion string |
| 1768 | platformSdkInt int |
| 1769 | platformSdkCodename string |
| 1770 | platformSdkFinal bool |
| 1771 | deviceCurrentApiLevelForVendorModules string |
| 1772 | expectedMinSdkVersion string |
| 1773 | }{ |
| 1774 | { |
| 1775 | name: "current final SDK", |
| 1776 | sdkVersion: "current", |
| 1777 | platformSdkInt: 29, |
| 1778 | platformSdkCodename: "REL", |
| 1779 | platformSdkFinal: true, |
| 1780 | deviceCurrentApiLevelForVendorModules: "29", |
| 1781 | expectedMinSdkVersion: "29", |
| 1782 | }, |
| 1783 | { |
| 1784 | name: "current final SDK", |
| 1785 | sdkVersion: "current", |
| 1786 | platformSdkInt: 29, |
| 1787 | platformSdkCodename: "REL", |
| 1788 | platformSdkFinal: true, |
| 1789 | deviceCurrentApiLevelForVendorModules: "28", |
| 1790 | expectedMinSdkVersion: "28", |
| 1791 | }, |
| 1792 | { |
| 1793 | name: "current final SDK", |
| 1794 | sdkVersion: "current", |
| 1795 | platformSdkInt: 29, |
| 1796 | platformSdkCodename: "Q", |
| 1797 | platformSdkFinal: false, |
Jeongik Cha | 219141c | 2020-08-06 23:00:37 +0900 | [diff] [blame] | 1798 | deviceCurrentApiLevelForVendorModules: "28", |
| 1799 | expectedMinSdkVersion: "28", |
| 1800 | }, |
| 1801 | } |
| 1802 | |
| 1803 | for _, moduleType := range []string{"android_app", "android_library"} { |
| 1804 | for _, sdkKind := range []string{"", "system_"} { |
| 1805 | for _, test := range testCases { |
| 1806 | t.Run(moduleType+" "+test.name, func(t *testing.T) { |
| 1807 | bp := fmt.Sprintf(`%s { |
| 1808 | name: "foo", |
| 1809 | srcs: ["a.java"], |
| 1810 | sdk_version: "%s%s", |
| 1811 | vendor: true, |
| 1812 | }`, moduleType, sdkKind, test.sdkVersion) |
| 1813 | |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame] | 1814 | result := android.GroupFixturePreparers( |
| 1815 | prepareForJavaTest, |
Paul Duffin | cdb88a9 | 2021-03-14 00:36:50 +0000 | [diff] [blame] | 1816 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 1817 | variables.Platform_sdk_version = &test.platformSdkInt |
| 1818 | variables.Platform_sdk_codename = &test.platformSdkCodename |
| 1819 | variables.Platform_sdk_final = &test.platformSdkFinal |
| 1820 | variables.DeviceCurrentApiLevelForVendorModules = &test.deviceCurrentApiLevelForVendorModules |
| 1821 | variables.DeviceSystemSdkVersions = []string{"28", "29"} |
| 1822 | }), |
Paul Duffin | 2645a29 | 2021-03-13 02:36:00 +0000 | [diff] [blame] | 1823 | FixtureWithPrebuiltApis(map[string][]string{ |
| 1824 | "28": {"foo"}, |
| 1825 | "29": {"foo"}, |
| 1826 | "current": {"foo"}, |
| 1827 | }), |
Paul Duffin | cdb88a9 | 2021-03-14 00:36:50 +0000 | [diff] [blame] | 1828 | ).RunTestWithBp(t, bp) |
| 1829 | |
| 1830 | checkSdkVersion(t, result, test.expectedMinSdkVersion) |
Jeongik Cha | 219141c | 2020-08-06 23:00:37 +0900 | [diff] [blame] | 1831 | }) |
| 1832 | } |
| 1833 | } |
| 1834 | } |
| 1835 | } |
| 1836 | |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 1837 | func TestJNIABI(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 1838 | ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+` |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 1839 | cc_library { |
| 1840 | name: "libjni", |
| 1841 | system_shared_libs: [], |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 1842 | sdk_version: "current", |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 1843 | stl: "none", |
| 1844 | } |
| 1845 | |
| 1846 | android_test { |
| 1847 | name: "test", |
| 1848 | sdk_version: "core_platform", |
| 1849 | jni_libs: ["libjni"], |
| 1850 | } |
| 1851 | |
| 1852 | android_test { |
| 1853 | name: "test_first", |
| 1854 | sdk_version: "core_platform", |
| 1855 | compile_multilib: "first", |
| 1856 | jni_libs: ["libjni"], |
| 1857 | } |
| 1858 | |
| 1859 | android_test { |
| 1860 | name: "test_both", |
| 1861 | sdk_version: "core_platform", |
| 1862 | compile_multilib: "both", |
| 1863 | jni_libs: ["libjni"], |
| 1864 | } |
| 1865 | |
| 1866 | android_test { |
| 1867 | name: "test_32", |
| 1868 | sdk_version: "core_platform", |
| 1869 | compile_multilib: "32", |
| 1870 | jni_libs: ["libjni"], |
| 1871 | } |
| 1872 | |
| 1873 | android_test { |
| 1874 | name: "test_64", |
| 1875 | sdk_version: "core_platform", |
| 1876 | compile_multilib: "64", |
| 1877 | jni_libs: ["libjni"], |
| 1878 | } |
| 1879 | `) |
| 1880 | |
| 1881 | testCases := []struct { |
| 1882 | name string |
| 1883 | abis []string |
| 1884 | }{ |
| 1885 | {"test", []string{"arm64-v8a"}}, |
| 1886 | {"test_first", []string{"arm64-v8a"}}, |
| 1887 | {"test_both", []string{"arm64-v8a", "armeabi-v7a"}}, |
| 1888 | {"test_32", []string{"armeabi-v7a"}}, |
| 1889 | {"test_64", []string{"arm64-v8a"}}, |
| 1890 | } |
| 1891 | |
| 1892 | for _, test := range testCases { |
| 1893 | t.Run(test.name, func(t *testing.T) { |
| 1894 | app := ctx.ModuleForTests(test.name, "android_common") |
Colin Cross | b3168ba | 2023-07-26 16:14:56 -0700 | [diff] [blame] | 1895 | jniLibZip := app.Output("jnilibs.zip") |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 1896 | var abis []string |
| 1897 | args := strings.Fields(jniLibZip.Args["jarArgs"]) |
| 1898 | for i := 0; i < len(args); i++ { |
| 1899 | if args[i] == "-P" { |
| 1900 | abis = append(abis, filepath.Base(args[i+1])) |
| 1901 | i++ |
| 1902 | } |
| 1903 | } |
| 1904 | if !reflect.DeepEqual(abis, test.abis) { |
| 1905 | t.Errorf("want abis %v, got %v", test.abis, abis) |
| 1906 | } |
| 1907 | }) |
| 1908 | } |
| 1909 | } |
| 1910 | |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 1911 | func TestAppSdkVersionByPartition(t *testing.T) { |
| 1912 | testJavaError(t, "sdk_version must have a value when the module is located at vendor or product", ` |
| 1913 | android_app { |
| 1914 | name: "foo", |
| 1915 | srcs: ["a.java"], |
| 1916 | vendor: true, |
| 1917 | platform_apis: true, |
| 1918 | } |
| 1919 | `) |
| 1920 | |
| 1921 | testJava(t, ` |
| 1922 | android_app { |
| 1923 | name: "bar", |
| 1924 | srcs: ["b.java"], |
| 1925 | platform_apis: true, |
| 1926 | } |
| 1927 | `) |
| 1928 | |
| 1929 | for _, enforce := range []bool{true, false} { |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 1930 | bp := ` |
| 1931 | android_app { |
| 1932 | name: "foo", |
| 1933 | srcs: ["a.java"], |
| 1934 | product_specific: true, |
| 1935 | platform_apis: true, |
| 1936 | } |
| 1937 | ` |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 1938 | |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1939 | errorHandler := android.FixtureExpectsNoErrors |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 1940 | if enforce { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1941 | errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern("sdk_version must have a value when the module is located at vendor or product") |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 1942 | } |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1943 | |
| 1944 | android.GroupFixturePreparers( |
| 1945 | PrepareForTestWithJavaDefaultModules, |
| 1946 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 1947 | variables.EnforceProductPartitionInterface = proptools.BoolPtr(enforce) |
| 1948 | }), |
| 1949 | ). |
| 1950 | ExtendWithErrorHandler(errorHandler). |
| 1951 | RunTestWithBp(t, bp) |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 1952 | } |
| 1953 | } |
| 1954 | |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 1955 | func TestJNIPackaging(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 1956 | ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+` |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 1957 | cc_library { |
| 1958 | name: "libjni", |
| 1959 | system_shared_libs: [], |
| 1960 | stl: "none", |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 1961 | sdk_version: "current", |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 1962 | } |
| 1963 | |
| 1964 | android_app { |
| 1965 | name: "app", |
| 1966 | jni_libs: ["libjni"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1967 | sdk_version: "current", |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 1968 | } |
| 1969 | |
| 1970 | android_app { |
| 1971 | name: "app_noembed", |
| 1972 | jni_libs: ["libjni"], |
| 1973 | use_embedded_native_libs: false, |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1974 | sdk_version: "current", |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 1975 | } |
| 1976 | |
| 1977 | android_app { |
| 1978 | name: "app_embed", |
| 1979 | jni_libs: ["libjni"], |
| 1980 | use_embedded_native_libs: true, |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 1981 | sdk_version: "current", |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 1982 | } |
| 1983 | |
| 1984 | android_test { |
| 1985 | name: "test", |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 1986 | sdk_version: "current", |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 1987 | jni_libs: ["libjni"], |
| 1988 | } |
| 1989 | |
| 1990 | android_test { |
| 1991 | name: "test_noembed", |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 1992 | sdk_version: "current", |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 1993 | jni_libs: ["libjni"], |
| 1994 | use_embedded_native_libs: false, |
| 1995 | } |
| 1996 | |
| 1997 | android_test_helper_app { |
| 1998 | name: "test_helper", |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 1999 | sdk_version: "current", |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 2000 | jni_libs: ["libjni"], |
| 2001 | } |
| 2002 | |
| 2003 | android_test_helper_app { |
| 2004 | name: "test_helper_noembed", |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 2005 | sdk_version: "current", |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 2006 | jni_libs: ["libjni"], |
| 2007 | use_embedded_native_libs: false, |
| 2008 | } |
| 2009 | `) |
| 2010 | |
| 2011 | testCases := []struct { |
| 2012 | name string |
| 2013 | packaged bool |
| 2014 | compressed bool |
| 2015 | }{ |
| 2016 | {"app", false, false}, |
| 2017 | {"app_noembed", false, false}, |
| 2018 | {"app_embed", true, false}, |
| 2019 | {"test", true, false}, |
| 2020 | {"test_noembed", true, true}, |
| 2021 | {"test_helper", true, false}, |
| 2022 | {"test_helper_noembed", true, true}, |
| 2023 | } |
| 2024 | |
| 2025 | for _, test := range testCases { |
| 2026 | t.Run(test.name, func(t *testing.T) { |
| 2027 | app := ctx.ModuleForTests(test.name, "android_common") |
Colin Cross | b3168ba | 2023-07-26 16:14:56 -0700 | [diff] [blame] | 2028 | jniLibZip := app.MaybeOutput("jnilibs.zip") |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 2029 | if g, w := (jniLibZip.Rule != nil), test.packaged; g != w { |
| 2030 | t.Errorf("expected jni packaged %v, got %v", w, g) |
| 2031 | } |
| 2032 | |
| 2033 | if jniLibZip.Rule != nil { |
| 2034 | if g, w := !strings.Contains(jniLibZip.Args["jarArgs"], "-L 0"), test.compressed; g != w { |
| 2035 | t.Errorf("expected jni compressed %v, got %v", w, g) |
| 2036 | } |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 2037 | |
| 2038 | if !strings.Contains(jniLibZip.Implicits[0].String(), "_sdk_") { |
| 2039 | t.Errorf("expected input %q to use sdk variant", jniLibZip.Implicits[0].String()) |
| 2040 | } |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 2041 | } |
| 2042 | }) |
| 2043 | } |
Colin Cross | 47fa9d3 | 2019-03-26 10:51:39 -0700 | [diff] [blame] | 2044 | } |
| 2045 | |
Colin Cross | 3c00770 | 2020-05-08 11:20:24 -0700 | [diff] [blame] | 2046 | func TestJNISDK(t *testing.T) { |
| 2047 | ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+` |
| 2048 | cc_library { |
| 2049 | name: "libjni", |
| 2050 | system_shared_libs: [], |
| 2051 | stl: "none", |
| 2052 | sdk_version: "current", |
| 2053 | } |
| 2054 | |
| 2055 | android_test { |
| 2056 | name: "app_platform", |
| 2057 | jni_libs: ["libjni"], |
| 2058 | platform_apis: true, |
| 2059 | } |
| 2060 | |
| 2061 | android_test { |
| 2062 | name: "app_sdk", |
| 2063 | jni_libs: ["libjni"], |
| 2064 | sdk_version: "current", |
| 2065 | } |
| 2066 | |
| 2067 | android_test { |
| 2068 | name: "app_force_platform", |
| 2069 | jni_libs: ["libjni"], |
| 2070 | sdk_version: "current", |
| 2071 | jni_uses_platform_apis: true, |
| 2072 | } |
| 2073 | |
| 2074 | android_test { |
| 2075 | name: "app_force_sdk", |
| 2076 | jni_libs: ["libjni"], |
| 2077 | platform_apis: true, |
| 2078 | jni_uses_sdk_apis: true, |
| 2079 | } |
Colin Cross | c2d2405 | 2020-05-13 11:05:02 -0700 | [diff] [blame] | 2080 | |
| 2081 | cc_library { |
| 2082 | name: "libvendorjni", |
| 2083 | system_shared_libs: [], |
| 2084 | stl: "none", |
| 2085 | vendor: true, |
| 2086 | } |
| 2087 | |
| 2088 | android_test { |
| 2089 | name: "app_vendor", |
| 2090 | jni_libs: ["libvendorjni"], |
| 2091 | sdk_version: "current", |
| 2092 | vendor: true, |
| 2093 | } |
Colin Cross | 3c00770 | 2020-05-08 11:20:24 -0700 | [diff] [blame] | 2094 | `) |
| 2095 | |
| 2096 | testCases := []struct { |
Colin Cross | c2d2405 | 2020-05-13 11:05:02 -0700 | [diff] [blame] | 2097 | name string |
| 2098 | sdkJNI bool |
| 2099 | vendorJNI bool |
Colin Cross | 3c00770 | 2020-05-08 11:20:24 -0700 | [diff] [blame] | 2100 | }{ |
Colin Cross | c2d2405 | 2020-05-13 11:05:02 -0700 | [diff] [blame] | 2101 | {name: "app_platform"}, |
| 2102 | {name: "app_sdk", sdkJNI: true}, |
| 2103 | {name: "app_force_platform"}, |
| 2104 | {name: "app_force_sdk", sdkJNI: true}, |
| 2105 | {name: "app_vendor", vendorJNI: true}, |
Colin Cross | 3c00770 | 2020-05-08 11:20:24 -0700 | [diff] [blame] | 2106 | } |
| 2107 | |
Colin Cross | c2d2405 | 2020-05-13 11:05:02 -0700 | [diff] [blame] | 2108 | platformJNI := ctx.ModuleForTests("libjni", "android_arm64_armv8-a_shared"). |
| 2109 | Output("libjni.so").Output.String() |
| 2110 | sdkJNI := ctx.ModuleForTests("libjni", "android_arm64_armv8-a_sdk_shared"). |
| 2111 | Output("libjni.so").Output.String() |
Kiyoung Kim | b5fdb2e | 2024-01-03 14:24:34 +0900 | [diff] [blame] | 2112 | vendorJNI := ctx.ModuleForTests("libvendorjni", "android_vendor_arm64_armv8-a_shared"). |
Colin Cross | c2d2405 | 2020-05-13 11:05:02 -0700 | [diff] [blame] | 2113 | Output("libvendorjni.so").Output.String() |
| 2114 | |
Colin Cross | 3c00770 | 2020-05-08 11:20:24 -0700 | [diff] [blame] | 2115 | for _, test := range testCases { |
| 2116 | t.Run(test.name, func(t *testing.T) { |
| 2117 | app := ctx.ModuleForTests(test.name, "android_common") |
Colin Cross | 3c00770 | 2020-05-08 11:20:24 -0700 | [diff] [blame] | 2118 | |
Colin Cross | b3168ba | 2023-07-26 16:14:56 -0700 | [diff] [blame] | 2119 | jniLibZip := app.MaybeOutput("jnilibs.zip") |
Colin Cross | 3c00770 | 2020-05-08 11:20:24 -0700 | [diff] [blame] | 2120 | if len(jniLibZip.Implicits) != 1 { |
| 2121 | t.Fatalf("expected exactly one jni library, got %q", jniLibZip.Implicits.Strings()) |
| 2122 | } |
| 2123 | gotJNI := jniLibZip.Implicits[0].String() |
| 2124 | |
| 2125 | if test.sdkJNI { |
| 2126 | if gotJNI != sdkJNI { |
| 2127 | t.Errorf("expected SDK JNI library %q, got %q", sdkJNI, gotJNI) |
| 2128 | } |
Colin Cross | c2d2405 | 2020-05-13 11:05:02 -0700 | [diff] [blame] | 2129 | } else if test.vendorJNI { |
| 2130 | if gotJNI != vendorJNI { |
| 2131 | t.Errorf("expected platform JNI library %q, got %q", vendorJNI, gotJNI) |
| 2132 | } |
Colin Cross | 3c00770 | 2020-05-08 11:20:24 -0700 | [diff] [blame] | 2133 | } else { |
| 2134 | if gotJNI != platformJNI { |
| 2135 | t.Errorf("expected platform JNI library %q, got %q", platformJNI, gotJNI) |
| 2136 | } |
| 2137 | } |
| 2138 | }) |
| 2139 | } |
| 2140 | |
| 2141 | t.Run("jni_uses_platform_apis_error", func(t *testing.T) { |
| 2142 | testJavaError(t, `jni_uses_platform_apis: can only be set for modules that set sdk_version`, ` |
| 2143 | android_test { |
| 2144 | name: "app_platform", |
| 2145 | platform_apis: true, |
| 2146 | jni_uses_platform_apis: true, |
| 2147 | } |
| 2148 | `) |
| 2149 | }) |
| 2150 | |
| 2151 | t.Run("jni_uses_sdk_apis_error", func(t *testing.T) { |
| 2152 | testJavaError(t, `jni_uses_sdk_apis: can only be set for modules that do not set sdk_version`, ` |
| 2153 | android_test { |
| 2154 | name: "app_sdk", |
| 2155 | sdk_version: "current", |
| 2156 | jni_uses_sdk_apis: true, |
| 2157 | } |
| 2158 | `) |
| 2159 | }) |
| 2160 | |
| 2161 | } |
| 2162 | |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 2163 | func TestCertificates(t *testing.T) { |
| 2164 | testCases := []struct { |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 2165 | name string |
| 2166 | bp string |
Colin Cross | 5caad2b | 2022-12-12 15:11:46 -0800 | [diff] [blame] | 2167 | allowMissingDependencies bool |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 2168 | certificateOverride string |
| 2169 | expectedCertSigningFlags string |
| 2170 | expectedCertificate string |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 2171 | }{ |
| 2172 | { |
| 2173 | name: "default", |
| 2174 | bp: ` |
| 2175 | android_app { |
| 2176 | name: "foo", |
| 2177 | srcs: ["a.java"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 2178 | sdk_version: "current", |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 2179 | } |
| 2180 | `, |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 2181 | certificateOverride: "", |
| 2182 | expectedCertSigningFlags: "", |
Colin Cross | 5caad2b | 2022-12-12 15:11:46 -0800 | [diff] [blame] | 2183 | expectedCertificate: "build/make/target/product/security/testkey", |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 2184 | }, |
| 2185 | { |
| 2186 | name: "module certificate property", |
| 2187 | bp: ` |
| 2188 | android_app { |
| 2189 | name: "foo", |
| 2190 | srcs: ["a.java"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 2191 | certificate: ":new_certificate", |
| 2192 | sdk_version: "current", |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 2193 | } |
| 2194 | |
| 2195 | android_app_certificate { |
| 2196 | name: "new_certificate", |
Colin Cross | 3c00770 | 2020-05-08 11:20:24 -0700 | [diff] [blame] | 2197 | certificate: "cert/new_cert", |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 2198 | } |
| 2199 | `, |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 2200 | certificateOverride: "", |
| 2201 | expectedCertSigningFlags: "", |
Colin Cross | 5caad2b | 2022-12-12 15:11:46 -0800 | [diff] [blame] | 2202 | expectedCertificate: "cert/new_cert", |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 2203 | }, |
| 2204 | { |
| 2205 | name: "path certificate property", |
| 2206 | bp: ` |
| 2207 | android_app { |
| 2208 | name: "foo", |
| 2209 | srcs: ["a.java"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 2210 | certificate: "expiredkey", |
| 2211 | sdk_version: "current", |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 2212 | } |
| 2213 | `, |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 2214 | certificateOverride: "", |
| 2215 | expectedCertSigningFlags: "", |
Colin Cross | 5caad2b | 2022-12-12 15:11:46 -0800 | [diff] [blame] | 2216 | expectedCertificate: "build/make/target/product/security/expiredkey", |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 2217 | }, |
| 2218 | { |
| 2219 | name: "certificate overrides", |
| 2220 | bp: ` |
| 2221 | android_app { |
| 2222 | name: "foo", |
| 2223 | srcs: ["a.java"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 2224 | certificate: "expiredkey", |
| 2225 | sdk_version: "current", |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 2226 | } |
| 2227 | |
| 2228 | android_app_certificate { |
| 2229 | name: "new_certificate", |
Colin Cross | 3c00770 | 2020-05-08 11:20:24 -0700 | [diff] [blame] | 2230 | certificate: "cert/new_cert", |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 2231 | } |
| 2232 | `, |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 2233 | certificateOverride: "foo:new_certificate", |
| 2234 | expectedCertSigningFlags: "", |
Colin Cross | 5caad2b | 2022-12-12 15:11:46 -0800 | [diff] [blame] | 2235 | expectedCertificate: "cert/new_cert", |
Liz Kammer | e2b27f4 | 2020-05-07 13:24:05 -0700 | [diff] [blame] | 2236 | }, |
| 2237 | { |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 2238 | name: "certificate signing flags", |
Liz Kammer | e2b27f4 | 2020-05-07 13:24:05 -0700 | [diff] [blame] | 2239 | bp: ` |
| 2240 | android_app { |
| 2241 | name: "foo", |
| 2242 | srcs: ["a.java"], |
| 2243 | certificate: ":new_certificate", |
| 2244 | lineage: "lineage.bin", |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 2245 | rotationMinSdkVersion: "32", |
Liz Kammer | e2b27f4 | 2020-05-07 13:24:05 -0700 | [diff] [blame] | 2246 | sdk_version: "current", |
| 2247 | } |
| 2248 | |
| 2249 | android_app_certificate { |
| 2250 | name: "new_certificate", |
| 2251 | certificate: "cert/new_cert", |
| 2252 | } |
| 2253 | `, |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 2254 | certificateOverride: "", |
| 2255 | expectedCertSigningFlags: "--lineage lineage.bin --rotation-min-sdk-version 32", |
Colin Cross | 5caad2b | 2022-12-12 15:11:46 -0800 | [diff] [blame] | 2256 | expectedCertificate: "cert/new_cert", |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 2257 | }, |
Jaewoong Jung | 1c1b6e6 | 2021-03-09 15:02:31 -0800 | [diff] [blame] | 2258 | { |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 2259 | name: "cert signing flags from filegroup", |
Jaewoong Jung | 1c1b6e6 | 2021-03-09 15:02:31 -0800 | [diff] [blame] | 2260 | bp: ` |
| 2261 | android_app { |
| 2262 | name: "foo", |
| 2263 | srcs: ["a.java"], |
| 2264 | certificate: ":new_certificate", |
| 2265 | lineage: ":lineage_bin", |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 2266 | rotationMinSdkVersion: "32", |
Jaewoong Jung | 1c1b6e6 | 2021-03-09 15:02:31 -0800 | [diff] [blame] | 2267 | sdk_version: "current", |
| 2268 | } |
| 2269 | |
| 2270 | android_app_certificate { |
| 2271 | name: "new_certificate", |
| 2272 | certificate: "cert/new_cert", |
| 2273 | } |
| 2274 | |
| 2275 | filegroup { |
| 2276 | name: "lineage_bin", |
| 2277 | srcs: ["lineage.bin"], |
| 2278 | } |
| 2279 | `, |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 2280 | certificateOverride: "", |
| 2281 | expectedCertSigningFlags: "--lineage lineage.bin --rotation-min-sdk-version 32", |
Colin Cross | 5caad2b | 2022-12-12 15:11:46 -0800 | [diff] [blame] | 2282 | expectedCertificate: "cert/new_cert", |
| 2283 | }, |
| 2284 | { |
| 2285 | name: "missing with AllowMissingDependencies", |
| 2286 | bp: ` |
| 2287 | android_app { |
| 2288 | name: "foo", |
| 2289 | srcs: ["a.java"], |
| 2290 | certificate: ":new_certificate", |
| 2291 | sdk_version: "current", |
| 2292 | } |
| 2293 | `, |
| 2294 | expectedCertificate: "out/soong/.intermediates/foo/android_common/missing", |
| 2295 | allowMissingDependencies: true, |
Jaewoong Jung | 1c1b6e6 | 2021-03-09 15:02:31 -0800 | [diff] [blame] | 2296 | }, |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 2297 | } |
| 2298 | |
| 2299 | for _, test := range testCases { |
| 2300 | t.Run(test.name, func(t *testing.T) { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 2301 | result := android.GroupFixturePreparers( |
| 2302 | PrepareForTestWithJavaDefaultModules, |
| 2303 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 2304 | if test.certificateOverride != "" { |
| 2305 | variables.CertificateOverrides = []string{test.certificateOverride} |
| 2306 | } |
Colin Cross | 5caad2b | 2022-12-12 15:11:46 -0800 | [diff] [blame] | 2307 | if test.allowMissingDependencies { |
| 2308 | variables.Allow_missing_dependencies = proptools.BoolPtr(true) |
| 2309 | } |
| 2310 | }), |
| 2311 | android.FixtureModifyContext(func(ctx *android.TestContext) { |
| 2312 | ctx.SetAllowMissingDependencies(test.allowMissingDependencies) |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 2313 | }), |
| 2314 | ).RunTestWithBp(t, test.bp) |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 2315 | |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 2316 | foo := result.ModuleForTests("foo", "android_common") |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 2317 | |
Colin Cross | 5caad2b | 2022-12-12 15:11:46 -0800 | [diff] [blame] | 2318 | certificate := foo.Module().(*AndroidApp).certificate |
| 2319 | android.AssertPathRelativeToTopEquals(t, "certificates key", test.expectedCertificate+".pk8", certificate.Key) |
| 2320 | // The sign_target_files_apks and check_target_files_signatures |
| 2321 | // tools require that certificates have a .x509.pem extension. |
| 2322 | android.AssertPathRelativeToTopEquals(t, "certificates pem", test.expectedCertificate+".x509.pem", certificate.Pem) |
Liz Kammer | e2b27f4 | 2020-05-07 13:24:05 -0700 | [diff] [blame] | 2323 | |
Colin Cross | 5caad2b | 2022-12-12 15:11:46 -0800 | [diff] [blame] | 2324 | signapk := foo.Output("foo.apk") |
| 2325 | if signapk.Rule != android.ErrorRule { |
| 2326 | signCertificateFlags := signapk.Args["certificates"] |
| 2327 | expectedFlags := certificate.Pem.String() + " " + certificate.Key.String() |
| 2328 | android.AssertStringEquals(t, "certificates flags", expectedFlags, signCertificateFlags) |
| 2329 | |
| 2330 | certSigningFlags := signapk.Args["flags"] |
| 2331 | android.AssertStringEquals(t, "cert signing flags", test.expectedCertSigningFlags, certSigningFlags) |
| 2332 | } |
Jaewoong Jung | 2ad817c | 2019-01-18 14:27:16 -0800 | [diff] [blame] | 2333 | }) |
| 2334 | } |
| 2335 | } |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 2336 | |
Songchun Fan | 688de9a | 2020-03-24 20:32:24 -0700 | [diff] [blame] | 2337 | func TestRequestV4SigningFlag(t *testing.T) { |
| 2338 | testCases := []struct { |
| 2339 | name string |
| 2340 | bp string |
| 2341 | expected string |
| 2342 | }{ |
| 2343 | { |
| 2344 | name: "default", |
| 2345 | bp: ` |
| 2346 | android_app { |
| 2347 | name: "foo", |
| 2348 | srcs: ["a.java"], |
| 2349 | sdk_version: "current", |
| 2350 | } |
| 2351 | `, |
| 2352 | expected: "", |
| 2353 | }, |
| 2354 | { |
| 2355 | name: "default", |
| 2356 | bp: ` |
| 2357 | android_app { |
| 2358 | name: "foo", |
| 2359 | srcs: ["a.java"], |
| 2360 | sdk_version: "current", |
| 2361 | v4_signature: false, |
| 2362 | } |
| 2363 | `, |
| 2364 | expected: "", |
| 2365 | }, |
| 2366 | { |
| 2367 | name: "module certificate property", |
| 2368 | bp: ` |
| 2369 | android_app { |
| 2370 | name: "foo", |
| 2371 | srcs: ["a.java"], |
| 2372 | sdk_version: "current", |
| 2373 | v4_signature: true, |
| 2374 | } |
| 2375 | `, |
| 2376 | expected: "--enable-v4", |
| 2377 | }, |
| 2378 | } |
| 2379 | |
| 2380 | for _, test := range testCases { |
| 2381 | t.Run(test.name, func(t *testing.T) { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 2382 | result := android.GroupFixturePreparers( |
| 2383 | PrepareForTestWithJavaDefaultModules, |
| 2384 | ).RunTestWithBp(t, test.bp) |
Songchun Fan | 688de9a | 2020-03-24 20:32:24 -0700 | [diff] [blame] | 2385 | |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 2386 | foo := result.ModuleForTests("foo", "android_common") |
Songchun Fan | 688de9a | 2020-03-24 20:32:24 -0700 | [diff] [blame] | 2387 | |
| 2388 | signapk := foo.Output("foo.apk") |
| 2389 | signFlags := signapk.Args["flags"] |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 2390 | android.AssertStringEquals(t, "signing flags", test.expected, signFlags) |
Songchun Fan | 688de9a | 2020-03-24 20:32:24 -0700 | [diff] [blame] | 2391 | }) |
| 2392 | } |
| 2393 | } |
| 2394 | |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 2395 | func TestPackageNameOverride(t *testing.T) { |
| 2396 | testCases := []struct { |
| 2397 | name string |
| 2398 | bp string |
| 2399 | packageNameOverride string |
| 2400 | expected []string |
| 2401 | }{ |
| 2402 | { |
| 2403 | name: "default", |
| 2404 | bp: ` |
| 2405 | android_app { |
| 2406 | name: "foo", |
| 2407 | srcs: ["a.java"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 2408 | sdk_version: "current", |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 2409 | } |
| 2410 | `, |
| 2411 | packageNameOverride: "", |
| 2412 | expected: []string{ |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 2413 | "out/soong/.intermediates/foo/android_common/foo.apk", |
| 2414 | "out/soong/target/product/test_device/system/app/foo/foo.apk", |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 2415 | }, |
| 2416 | }, |
| 2417 | { |
Jooyung Han | 29e2f6d | 2022-01-08 12:13:59 +0900 | [diff] [blame] | 2418 | name: "overridden via PRODUCT_PACKAGE_NAME_OVERRIDES", |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 2419 | bp: ` |
| 2420 | android_app { |
| 2421 | name: "foo", |
| 2422 | srcs: ["a.java"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 2423 | sdk_version: "current", |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 2424 | } |
| 2425 | `, |
| 2426 | packageNameOverride: "foo:bar", |
| 2427 | expected: []string{ |
| 2428 | // The package apk should be still be the original name for test dependencies. |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 2429 | "out/soong/.intermediates/foo/android_common/bar.apk", |
| 2430 | "out/soong/target/product/test_device/system/app/bar/bar.apk", |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 2431 | }, |
| 2432 | }, |
Jooyung Han | 29e2f6d | 2022-01-08 12:13:59 +0900 | [diff] [blame] | 2433 | { |
| 2434 | name: "overridden via stem", |
| 2435 | bp: ` |
| 2436 | android_app { |
| 2437 | name: "foo", |
| 2438 | srcs: ["a.java"], |
| 2439 | sdk_version: "current", |
| 2440 | stem: "bar", |
| 2441 | } |
| 2442 | `, |
| 2443 | packageNameOverride: "", |
| 2444 | expected: []string{ |
| 2445 | "out/soong/.intermediates/foo/android_common/bar.apk", |
| 2446 | "out/soong/target/product/test_device/system/app/bar/bar.apk", |
| 2447 | }, |
| 2448 | }, |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 2449 | } |
| 2450 | |
| 2451 | for _, test := range testCases { |
| 2452 | t.Run(test.name, func(t *testing.T) { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 2453 | result := android.GroupFixturePreparers( |
| 2454 | PrepareForTestWithJavaDefaultModules, |
| 2455 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 2456 | if test.packageNameOverride != "" { |
| 2457 | variables.PackageNameOverrides = []string{test.packageNameOverride} |
| 2458 | } |
| 2459 | }), |
| 2460 | ).RunTestWithBp(t, test.bp) |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 2461 | |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 2462 | foo := result.ModuleForTests("foo", "android_common") |
| 2463 | |
Lukacs T. Berki | fbaf725 | 2021-08-19 09:36:42 +0200 | [diff] [blame] | 2464 | outSoongDir := result.Config.SoongOutDir() |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 2465 | |
| 2466 | outputs := foo.AllOutputs() |
| 2467 | outputMap := make(map[string]bool) |
| 2468 | for _, o := range outputs { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 2469 | outputMap[android.StringPathRelativeToTop(outSoongDir, o)] = true |
Jaewoong Jung | 9d22a91 | 2019-01-23 16:27:47 -0800 | [diff] [blame] | 2470 | } |
| 2471 | for _, e := range test.expected { |
| 2472 | if _, exist := outputMap[e]; !exist { |
| 2473 | t.Errorf("Can't find %q in output files.\nAll outputs:%v", e, outputs) |
| 2474 | } |
| 2475 | } |
| 2476 | }) |
| 2477 | } |
| 2478 | } |
Jaewoong Jung | 4102e5d | 2019-02-27 16:26:28 -0800 | [diff] [blame] | 2479 | |
| 2480 | func TestInstrumentationTargetOverridden(t *testing.T) { |
| 2481 | bp := ` |
| 2482 | android_app { |
| 2483 | name: "foo", |
| 2484 | srcs: ["a.java"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 2485 | sdk_version: "current", |
Jaewoong Jung | 4102e5d | 2019-02-27 16:26:28 -0800 | [diff] [blame] | 2486 | } |
| 2487 | |
| 2488 | android_test { |
| 2489 | name: "bar", |
| 2490 | instrumentation_for: "foo", |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 2491 | sdk_version: "current", |
Jaewoong Jung | 4102e5d | 2019-02-27 16:26:28 -0800 | [diff] [blame] | 2492 | } |
| 2493 | ` |
Jaewoong Jung | 4102e5d | 2019-02-27 16:26:28 -0800 | [diff] [blame] | 2494 | |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 2495 | result := android.GroupFixturePreparers( |
| 2496 | PrepareForTestWithJavaDefaultModules, |
| 2497 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 2498 | variables.ManifestPackageNameOverrides = []string{"foo:org.dandroid.bp"} |
| 2499 | }), |
| 2500 | ).RunTestWithBp(t, bp) |
Jaewoong Jung | 4102e5d | 2019-02-27 16:26:28 -0800 | [diff] [blame] | 2501 | |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 2502 | bar := result.ModuleForTests("bar", "android_common") |
Jaewoong Jung | 4102e5d | 2019-02-27 16:26:28 -0800 | [diff] [blame] | 2503 | res := bar.Output("package-res.apk") |
| 2504 | aapt2Flags := res.Args["flags"] |
| 2505 | e := "--rename-instrumentation-target-package org.dandroid.bp" |
| 2506 | if !strings.Contains(aapt2Flags, e) { |
| 2507 | t.Errorf("target package renaming flag, %q is missing in aapt2 link flags, %q", e, aapt2Flags) |
| 2508 | } |
| 2509 | } |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 2510 | |
| 2511 | func TestOverrideAndroidApp(t *testing.T) { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 2512 | result := PrepareForTestWithJavaDefaultModules.RunTestWithBp( |
| 2513 | t, ` |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 2514 | android_app { |
| 2515 | name: "foo", |
| 2516 | srcs: ["a.java"], |
Jaewoong Jung | a641ee9 | 2019-03-27 11:17:14 -0700 | [diff] [blame] | 2517 | certificate: "expiredkey", |
Jaewoong Jung | b639a6a | 2019-05-10 15:16:29 -0700 | [diff] [blame] | 2518 | overrides: ["qux"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 2519 | sdk_version: "current", |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 2520 | } |
| 2521 | |
| 2522 | override_android_app { |
| 2523 | name: "bar", |
| 2524 | base: "foo", |
| 2525 | certificate: ":new_certificate", |
Liz Kammer | e2b27f4 | 2020-05-07 13:24:05 -0700 | [diff] [blame] | 2526 | lineage: "lineage.bin", |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 2527 | rotationMinSdkVersion: "32", |
Baligh Uddin | 5b16dfb | 2020-02-11 17:27:19 -0800 | [diff] [blame] | 2528 | logging_parent: "bah", |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 2529 | } |
| 2530 | |
| 2531 | android_app_certificate { |
| 2532 | name: "new_certificate", |
| 2533 | certificate: "cert/new_cert", |
| 2534 | } |
Jaewoong Jung | 6f373f6 | 2019-03-13 10:13:24 -0700 | [diff] [blame] | 2535 | |
| 2536 | override_android_app { |
| 2537 | name: "baz", |
| 2538 | base: "foo", |
| 2539 | package_name: "org.dandroid.bp", |
| 2540 | } |
Liz Kammer | 9f9fd02 | 2020-06-18 19:44:06 +0000 | [diff] [blame] | 2541 | |
| 2542 | override_android_app { |
| 2543 | name: "baz_no_rename_resources", |
| 2544 | base: "foo", |
| 2545 | package_name: "org.dandroid.bp", |
| 2546 | rename_resources_package: false, |
| 2547 | } |
| 2548 | |
| 2549 | android_app { |
| 2550 | name: "foo_no_rename_resources", |
| 2551 | srcs: ["a.java"], |
| 2552 | certificate: "expiredkey", |
| 2553 | overrides: ["qux"], |
| 2554 | rename_resources_package: false, |
| 2555 | sdk_version: "current", |
| 2556 | } |
| 2557 | |
| 2558 | override_android_app { |
| 2559 | name: "baz_base_no_rename_resources", |
| 2560 | base: "foo_no_rename_resources", |
| 2561 | package_name: "org.dandroid.bp", |
| 2562 | } |
| 2563 | |
| 2564 | override_android_app { |
| 2565 | name: "baz_override_base_rename_resources", |
| 2566 | base: "foo_no_rename_resources", |
| 2567 | package_name: "org.dandroid.bp", |
| 2568 | rename_resources_package: true, |
| 2569 | } |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 2570 | `) |
| 2571 | |
| 2572 | expectedVariants := []struct { |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 2573 | name string |
| 2574 | moduleName string |
| 2575 | variantName string |
| 2576 | apkName string |
| 2577 | apkPath string |
| 2578 | certFlag string |
| 2579 | certSigningFlags string |
| 2580 | overrides []string |
| 2581 | packageFlag string |
| 2582 | renameResources bool |
| 2583 | logging_parent string |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 2584 | }{ |
| 2585 | { |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 2586 | name: "foo", |
| 2587 | moduleName: "foo", |
| 2588 | variantName: "android_common", |
| 2589 | apkPath: "out/soong/target/product/test_device/system/app/foo/foo.apk", |
| 2590 | certFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8", |
| 2591 | certSigningFlags: "", |
| 2592 | overrides: []string{"qux"}, |
| 2593 | packageFlag: "", |
| 2594 | renameResources: false, |
| 2595 | logging_parent: "", |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 2596 | }, |
| 2597 | { |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 2598 | name: "foo", |
| 2599 | moduleName: "bar", |
| 2600 | variantName: "android_common_bar", |
| 2601 | apkPath: "out/soong/target/product/test_device/system/app/bar/bar.apk", |
| 2602 | certFlag: "cert/new_cert.x509.pem cert/new_cert.pk8", |
| 2603 | certSigningFlags: "--lineage lineage.bin --rotation-min-sdk-version 32", |
| 2604 | overrides: []string{"qux", "foo"}, |
| 2605 | packageFlag: "", |
| 2606 | renameResources: false, |
| 2607 | logging_parent: "bah", |
Jaewoong Jung | 6f373f6 | 2019-03-13 10:13:24 -0700 | [diff] [blame] | 2608 | }, |
| 2609 | { |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 2610 | name: "foo", |
| 2611 | moduleName: "baz", |
| 2612 | variantName: "android_common_baz", |
| 2613 | apkPath: "out/soong/target/product/test_device/system/app/baz/baz.apk", |
| 2614 | certFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8", |
| 2615 | certSigningFlags: "", |
| 2616 | overrides: []string{"qux", "foo"}, |
| 2617 | packageFlag: "org.dandroid.bp", |
| 2618 | renameResources: true, |
| 2619 | logging_parent: "", |
Liz Kammer | 9f9fd02 | 2020-06-18 19:44:06 +0000 | [diff] [blame] | 2620 | }, |
| 2621 | { |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 2622 | name: "foo", |
| 2623 | moduleName: "baz_no_rename_resources", |
| 2624 | variantName: "android_common_baz_no_rename_resources", |
| 2625 | apkPath: "out/soong/target/product/test_device/system/app/baz_no_rename_resources/baz_no_rename_resources.apk", |
| 2626 | certFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8", |
| 2627 | certSigningFlags: "", |
| 2628 | overrides: []string{"qux", "foo"}, |
| 2629 | packageFlag: "org.dandroid.bp", |
| 2630 | renameResources: false, |
| 2631 | logging_parent: "", |
Liz Kammer | 9f9fd02 | 2020-06-18 19:44:06 +0000 | [diff] [blame] | 2632 | }, |
| 2633 | { |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 2634 | name: "foo_no_rename_resources", |
| 2635 | moduleName: "baz_base_no_rename_resources", |
| 2636 | variantName: "android_common_baz_base_no_rename_resources", |
| 2637 | apkPath: "out/soong/target/product/test_device/system/app/baz_base_no_rename_resources/baz_base_no_rename_resources.apk", |
| 2638 | certFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8", |
| 2639 | certSigningFlags: "", |
| 2640 | overrides: []string{"qux", "foo_no_rename_resources"}, |
| 2641 | packageFlag: "org.dandroid.bp", |
| 2642 | renameResources: false, |
| 2643 | logging_parent: "", |
Liz Kammer | 9f9fd02 | 2020-06-18 19:44:06 +0000 | [diff] [blame] | 2644 | }, |
| 2645 | { |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 2646 | name: "foo_no_rename_resources", |
| 2647 | moduleName: "baz_override_base_rename_resources", |
| 2648 | variantName: "android_common_baz_override_base_rename_resources", |
| 2649 | apkPath: "out/soong/target/product/test_device/system/app/baz_override_base_rename_resources/baz_override_base_rename_resources.apk", |
| 2650 | certFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8", |
| 2651 | certSigningFlags: "", |
| 2652 | overrides: []string{"qux", "foo_no_rename_resources"}, |
| 2653 | packageFlag: "org.dandroid.bp", |
| 2654 | renameResources: true, |
| 2655 | logging_parent: "", |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 2656 | }, |
| 2657 | } |
| 2658 | for _, expected := range expectedVariants { |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 2659 | variant := result.ModuleForTests(expected.name, expected.variantName) |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 2660 | |
| 2661 | // Check the final apk name |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 2662 | variant.Output(expected.apkPath) |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 2663 | |
| 2664 | // Check the certificate paths |
Jaewoong Jung | 5a49881 | 2019-11-07 14:14:38 -0800 | [diff] [blame] | 2665 | signapk := variant.Output(expected.moduleName + ".apk") |
Liz Kammer | e2b27f4 | 2020-05-07 13:24:05 -0700 | [diff] [blame] | 2666 | certFlag := signapk.Args["certificates"] |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 2667 | android.AssertStringEquals(t, "certificates flags", expected.certFlag, certFlag) |
Liz Kammer | e2b27f4 | 2020-05-07 13:24:05 -0700 | [diff] [blame] | 2668 | |
Rupert Shuttleworth | 8eab869 | 2021-11-03 10:39:39 -0400 | [diff] [blame] | 2669 | // Check the cert signing flags |
| 2670 | certSigningFlags := signapk.Args["flags"] |
| 2671 | android.AssertStringEquals(t, "cert signing flags", expected.certSigningFlags, certSigningFlags) |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 2672 | |
Jaewoong Jung | 6f373f6 | 2019-03-13 10:13:24 -0700 | [diff] [blame] | 2673 | // Check if the overrides field values are correctly aggregated. |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 2674 | mod := variant.Module().(*AndroidApp) |
zhidou | a2ce78f | 2022-02-17 02:33:12 +0000 | [diff] [blame] | 2675 | android.AssertDeepEquals(t, "overrides property", expected.overrides, mod.overridableAppProperties.Overrides) |
Jaewoong Jung | 6f373f6 | 2019-03-13 10:13:24 -0700 | [diff] [blame] | 2676 | |
Baligh Uddin | 5b16dfb | 2020-02-11 17:27:19 -0800 | [diff] [blame] | 2677 | // Test Overridable property: Logging_parent |
| 2678 | logging_parent := mod.aapt.LoggingParent |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 2679 | android.AssertStringEquals(t, "overrides property value for logging parent", expected.logging_parent, logging_parent) |
Baligh Uddin | 5b16dfb | 2020-02-11 17:27:19 -0800 | [diff] [blame] | 2680 | |
Liz Kammer | 1d5983b | 2020-05-19 19:15:37 +0000 | [diff] [blame] | 2681 | // Check the package renaming flag, if exists. |
Jaewoong Jung | 6f373f6 | 2019-03-13 10:13:24 -0700 | [diff] [blame] | 2682 | res := variant.Output("package-res.apk") |
| 2683 | aapt2Flags := res.Args["flags"] |
Liz Kammer | 9f9fd02 | 2020-06-18 19:44:06 +0000 | [diff] [blame] | 2684 | checkAapt2LinkFlag(t, aapt2Flags, "rename-manifest-package", expected.packageFlag) |
| 2685 | expectedPackage := expected.packageFlag |
| 2686 | if !expected.renameResources { |
| 2687 | expectedPackage = "" |
Liz Kammer | 1d5983b | 2020-05-19 19:15:37 +0000 | [diff] [blame] | 2688 | } |
Liz Kammer | 9f9fd02 | 2020-06-18 19:44:06 +0000 | [diff] [blame] | 2689 | checkAapt2LinkFlag(t, aapt2Flags, "rename-resources-package", expectedPackage) |
Jaewoong Jung | 525443a | 2019-02-28 15:35:54 -0800 | [diff] [blame] | 2690 | } |
| 2691 | } |
Jaewoong Jung | ccbb393 | 2019-04-15 09:48:31 -0700 | [diff] [blame] | 2692 | |
zhidou | a2ce78f | 2022-02-17 02:33:12 +0000 | [diff] [blame] | 2693 | func TestOverrideAndroidAppOverrides(t *testing.T) { |
| 2694 | ctx, _ := testJava( |
| 2695 | t, ` |
| 2696 | android_app { |
| 2697 | name: "foo", |
| 2698 | srcs: ["a.java"], |
| 2699 | sdk_version: "current", |
| 2700 | overrides: ["qux"] |
| 2701 | } |
| 2702 | |
| 2703 | android_app { |
| 2704 | name: "bar", |
| 2705 | srcs: ["b.java"], |
| 2706 | sdk_version: "current", |
| 2707 | overrides: ["foo"] |
| 2708 | } |
| 2709 | |
| 2710 | override_android_app { |
| 2711 | name: "foo_override", |
| 2712 | base: "foo", |
| 2713 | overrides: ["bar"] |
| 2714 | } |
| 2715 | `) |
| 2716 | |
| 2717 | expectedVariants := []struct { |
| 2718 | name string |
| 2719 | moduleName string |
| 2720 | variantName string |
| 2721 | overrides []string |
| 2722 | }{ |
| 2723 | { |
| 2724 | name: "foo", |
| 2725 | moduleName: "foo", |
| 2726 | variantName: "android_common", |
| 2727 | overrides: []string{"qux"}, |
| 2728 | }, |
| 2729 | { |
| 2730 | name: "bar", |
| 2731 | moduleName: "bar", |
| 2732 | variantName: "android_common", |
| 2733 | overrides: []string{"foo"}, |
| 2734 | }, |
| 2735 | { |
| 2736 | name: "foo", |
| 2737 | moduleName: "foo_override", |
| 2738 | variantName: "android_common_foo_override", |
| 2739 | overrides: []string{"bar", "foo"}, |
| 2740 | }, |
| 2741 | } |
| 2742 | for _, expected := range expectedVariants { |
| 2743 | variant := ctx.ModuleForTests(expected.name, expected.variantName) |
| 2744 | |
| 2745 | // Check if the overrides field values are correctly aggregated. |
| 2746 | mod := variant.Module().(*AndroidApp) |
| 2747 | android.AssertDeepEquals(t, "overrides property", expected.overrides, mod.overridableAppProperties.Overrides) |
| 2748 | } |
| 2749 | } |
| 2750 | |
Colin Cross | aaa0c1f | 2022-05-16 16:19:54 -0700 | [diff] [blame] | 2751 | func TestOverrideAndroidAppWithPrebuilt(t *testing.T) { |
| 2752 | result := PrepareForTestWithJavaDefaultModules.RunTestWithBp( |
| 2753 | t, ` |
| 2754 | android_app { |
| 2755 | name: "foo", |
| 2756 | srcs: ["a.java"], |
| 2757 | sdk_version: "current", |
| 2758 | } |
| 2759 | |
| 2760 | override_android_app { |
| 2761 | name: "bar", |
| 2762 | base: "foo", |
| 2763 | } |
| 2764 | |
| 2765 | android_app_import { |
| 2766 | name: "bar", |
| 2767 | prefer: true, |
| 2768 | apk: "bar.apk", |
| 2769 | presigned: true, |
| 2770 | } |
| 2771 | `) |
| 2772 | |
| 2773 | // An app that has an override that also has a prebuilt should not be hidden. |
| 2774 | foo := result.ModuleForTests("foo", "android_common") |
| 2775 | if foo.Module().IsHideFromMake() { |
| 2776 | t.Errorf("expected foo to have HideFromMake false") |
| 2777 | } |
| 2778 | |
| 2779 | // An override that also has a prebuilt should be hidden. |
| 2780 | barOverride := result.ModuleForTests("foo", "android_common_bar") |
| 2781 | if !barOverride.Module().IsHideFromMake() { |
| 2782 | t.Errorf("expected bar override variant of foo to have HideFromMake true") |
| 2783 | } |
| 2784 | } |
| 2785 | |
Jooyung Han | 01d80d8 | 2022-01-08 12:16:32 +0900 | [diff] [blame] | 2786 | func TestOverrideAndroidAppStem(t *testing.T) { |
| 2787 | ctx, _ := testJava(t, ` |
| 2788 | android_app { |
| 2789 | name: "foo", |
| 2790 | srcs: ["a.java"], |
| 2791 | sdk_version: "current", |
| 2792 | } |
| 2793 | override_android_app { |
| 2794 | name: "bar", |
| 2795 | base: "foo", |
| 2796 | } |
| 2797 | override_android_app { |
| 2798 | name: "baz", |
| 2799 | base: "foo", |
| 2800 | stem: "baz_stem", |
| 2801 | } |
| 2802 | android_app { |
| 2803 | name: "foo2", |
| 2804 | srcs: ["a.java"], |
| 2805 | sdk_version: "current", |
| 2806 | stem: "foo2_stem", |
| 2807 | } |
| 2808 | override_android_app { |
| 2809 | name: "bar2", |
| 2810 | base: "foo2", |
| 2811 | } |
| 2812 | override_android_app { |
| 2813 | name: "baz2", |
| 2814 | base: "foo2", |
| 2815 | stem: "baz2_stem", |
| 2816 | } |
| 2817 | `) |
| 2818 | for _, expected := range []struct { |
| 2819 | moduleName string |
| 2820 | variantName string |
| 2821 | apkPath string |
| 2822 | }{ |
| 2823 | { |
| 2824 | moduleName: "foo", |
| 2825 | variantName: "android_common", |
| 2826 | apkPath: "out/soong/target/product/test_device/system/app/foo/foo.apk", |
| 2827 | }, |
| 2828 | { |
| 2829 | moduleName: "foo", |
| 2830 | variantName: "android_common_bar", |
| 2831 | apkPath: "out/soong/target/product/test_device/system/app/bar/bar.apk", |
| 2832 | }, |
| 2833 | { |
| 2834 | moduleName: "foo", |
| 2835 | variantName: "android_common_baz", |
| 2836 | apkPath: "out/soong/target/product/test_device/system/app/baz_stem/baz_stem.apk", |
| 2837 | }, |
| 2838 | { |
| 2839 | moduleName: "foo2", |
| 2840 | variantName: "android_common", |
| 2841 | apkPath: "out/soong/target/product/test_device/system/app/foo2_stem/foo2_stem.apk", |
| 2842 | }, |
| 2843 | { |
| 2844 | moduleName: "foo2", |
| 2845 | variantName: "android_common_bar2", |
| 2846 | // Note that this may cause the duplicate output error. |
| 2847 | apkPath: "out/soong/target/product/test_device/system/app/foo2_stem/foo2_stem.apk", |
| 2848 | }, |
| 2849 | { |
| 2850 | moduleName: "foo2", |
| 2851 | variantName: "android_common_baz2", |
| 2852 | apkPath: "out/soong/target/product/test_device/system/app/baz2_stem/baz2_stem.apk", |
| 2853 | }, |
| 2854 | } { |
| 2855 | variant := ctx.ModuleForTests(expected.moduleName, expected.variantName) |
| 2856 | variant.Output(expected.apkPath) |
| 2857 | } |
| 2858 | } |
| 2859 | |
Jaewoong Jung | b639a6a | 2019-05-10 15:16:29 -0700 | [diff] [blame] | 2860 | func TestOverrideAndroidAppDependency(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 2861 | ctx, _ := testJava(t, ` |
Jaewoong Jung | b639a6a | 2019-05-10 15:16:29 -0700 | [diff] [blame] | 2862 | android_app { |
| 2863 | name: "foo", |
| 2864 | srcs: ["a.java"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 2865 | sdk_version: "current", |
Jaewoong Jung | b639a6a | 2019-05-10 15:16:29 -0700 | [diff] [blame] | 2866 | } |
| 2867 | |
| 2868 | override_android_app { |
| 2869 | name: "bar", |
| 2870 | base: "foo", |
| 2871 | package_name: "org.dandroid.bp", |
| 2872 | } |
| 2873 | |
| 2874 | android_test { |
| 2875 | name: "baz", |
| 2876 | srcs: ["b.java"], |
| 2877 | instrumentation_for: "foo", |
| 2878 | } |
| 2879 | |
| 2880 | android_test { |
| 2881 | name: "qux", |
| 2882 | srcs: ["b.java"], |
| 2883 | instrumentation_for: "bar", |
| 2884 | } |
| 2885 | `) |
| 2886 | |
| 2887 | // Verify baz, which depends on the overridden module foo, has the correct classpath javac arg. |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 2888 | javac := ctx.ModuleForTests("baz", "android_common").Rule("javac") |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 2889 | fooTurbine := "out/soong/.intermediates/foo/android_common/turbine-combined/foo.jar" |
Jaewoong Jung | b639a6a | 2019-05-10 15:16:29 -0700 | [diff] [blame] | 2890 | if !strings.Contains(javac.Args["classpath"], fooTurbine) { |
| 2891 | t.Errorf("baz classpath %v does not contain %q", javac.Args["classpath"], fooTurbine) |
| 2892 | } |
| 2893 | |
| 2894 | // Verify qux, which depends on the overriding module bar, has the correct classpath javac arg. |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 2895 | javac = ctx.ModuleForTests("qux", "android_common").Rule("javac") |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 2896 | barTurbine := "out/soong/.intermediates/foo/android_common_bar/turbine-combined/foo.jar" |
Jaewoong Jung | b639a6a | 2019-05-10 15:16:29 -0700 | [diff] [blame] | 2897 | if !strings.Contains(javac.Args["classpath"], barTurbine) { |
| 2898 | t.Errorf("qux classpath %v does not contain %q", javac.Args["classpath"], barTurbine) |
| 2899 | } |
| 2900 | } |
| 2901 | |
Jaewoong Jung | 26dedd3 | 2019-06-06 08:45:58 -0700 | [diff] [blame] | 2902 | func TestOverrideAndroidTest(t *testing.T) { |
| 2903 | ctx, _ := testJava(t, ` |
| 2904 | android_app { |
| 2905 | name: "foo", |
| 2906 | srcs: ["a.java"], |
| 2907 | package_name: "com.android.foo", |
| 2908 | sdk_version: "current", |
| 2909 | } |
| 2910 | |
| 2911 | override_android_app { |
| 2912 | name: "bar", |
| 2913 | base: "foo", |
| 2914 | package_name: "com.android.bar", |
| 2915 | } |
| 2916 | |
| 2917 | android_test { |
| 2918 | name: "foo_test", |
| 2919 | srcs: ["b.java"], |
| 2920 | instrumentation_for: "foo", |
| 2921 | } |
| 2922 | |
| 2923 | override_android_test { |
| 2924 | name: "bar_test", |
| 2925 | base: "foo_test", |
| 2926 | package_name: "com.android.bar.test", |
| 2927 | instrumentation_for: "bar", |
| 2928 | instrumentation_target_package: "com.android.bar", |
| 2929 | } |
| 2930 | `) |
| 2931 | |
| 2932 | expectedVariants := []struct { |
| 2933 | moduleName string |
| 2934 | variantName string |
| 2935 | apkPath string |
| 2936 | overrides []string |
| 2937 | targetVariant string |
| 2938 | packageFlag string |
| 2939 | targetPackageFlag string |
| 2940 | }{ |
| 2941 | { |
| 2942 | variantName: "android_common", |
Jaewoong Jung | 326a941 | 2019-11-21 10:41:00 -0800 | [diff] [blame] | 2943 | apkPath: "/target/product/test_device/testcases/foo_test/arm64/foo_test.apk", |
Jaewoong Jung | 26dedd3 | 2019-06-06 08:45:58 -0700 | [diff] [blame] | 2944 | overrides: nil, |
| 2945 | targetVariant: "android_common", |
| 2946 | packageFlag: "", |
| 2947 | targetPackageFlag: "", |
| 2948 | }, |
| 2949 | { |
| 2950 | variantName: "android_common_bar_test", |
Jaewoong Jung | 326a941 | 2019-11-21 10:41:00 -0800 | [diff] [blame] | 2951 | apkPath: "/target/product/test_device/testcases/bar_test/arm64/bar_test.apk", |
Jaewoong Jung | 26dedd3 | 2019-06-06 08:45:58 -0700 | [diff] [blame] | 2952 | overrides: []string{"foo_test"}, |
| 2953 | targetVariant: "android_common_bar", |
| 2954 | packageFlag: "com.android.bar.test", |
| 2955 | targetPackageFlag: "com.android.bar", |
| 2956 | }, |
| 2957 | } |
| 2958 | for _, expected := range expectedVariants { |
| 2959 | variant := ctx.ModuleForTests("foo_test", expected.variantName) |
| 2960 | |
| 2961 | // Check the final apk name |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 2962 | variant.Output("out/soong" + expected.apkPath) |
Jaewoong Jung | 26dedd3 | 2019-06-06 08:45:58 -0700 | [diff] [blame] | 2963 | |
| 2964 | // Check if the overrides field values are correctly aggregated. |
| 2965 | mod := variant.Module().(*AndroidTest) |
zhidou | a2ce78f | 2022-02-17 02:33:12 +0000 | [diff] [blame] | 2966 | if !reflect.DeepEqual(expected.overrides, mod.overridableAppProperties.Overrides) { |
Jaewoong Jung | 26dedd3 | 2019-06-06 08:45:58 -0700 | [diff] [blame] | 2967 | t.Errorf("Incorrect overrides property value, expected: %q, got: %q", |
zhidou | a2ce78f | 2022-02-17 02:33:12 +0000 | [diff] [blame] | 2968 | expected.overrides, mod.overridableAppProperties.Overrides) |
Jaewoong Jung | 26dedd3 | 2019-06-06 08:45:58 -0700 | [diff] [blame] | 2969 | } |
| 2970 | |
| 2971 | // Check if javac classpath has the correct jar file path. This checks instrumentation_for overrides. |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 2972 | javac := variant.Rule("javac") |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 2973 | turbine := filepath.Join("out", "soong", ".intermediates", "foo", expected.targetVariant, "turbine-combined", "foo.jar") |
Jaewoong Jung | 26dedd3 | 2019-06-06 08:45:58 -0700 | [diff] [blame] | 2974 | if !strings.Contains(javac.Args["classpath"], turbine) { |
| 2975 | t.Errorf("classpath %q does not contain %q", javac.Args["classpath"], turbine) |
| 2976 | } |
| 2977 | |
| 2978 | // Check aapt2 flags. |
| 2979 | res := variant.Output("package-res.apk") |
| 2980 | aapt2Flags := res.Args["flags"] |
| 2981 | checkAapt2LinkFlag(t, aapt2Flags, "rename-manifest-package", expected.packageFlag) |
Liz Kammer | 9f9fd02 | 2020-06-18 19:44:06 +0000 | [diff] [blame] | 2982 | checkAapt2LinkFlag(t, aapt2Flags, "rename-resources-package", expected.packageFlag) |
Jaewoong Jung | 26dedd3 | 2019-06-06 08:45:58 -0700 | [diff] [blame] | 2983 | checkAapt2LinkFlag(t, aapt2Flags, "rename-instrumentation-target-package", expected.targetPackageFlag) |
| 2984 | } |
| 2985 | } |
| 2986 | |
Jaewoong Jung | 3998234 | 2020-01-14 10:27:18 -0800 | [diff] [blame] | 2987 | func TestAndroidTest_FixTestConfig(t *testing.T) { |
| 2988 | ctx, _ := testJava(t, ` |
| 2989 | android_app { |
| 2990 | name: "foo", |
| 2991 | srcs: ["a.java"], |
| 2992 | package_name: "com.android.foo", |
| 2993 | sdk_version: "current", |
| 2994 | } |
| 2995 | |
| 2996 | android_test { |
| 2997 | name: "foo_test", |
| 2998 | srcs: ["b.java"], |
| 2999 | instrumentation_for: "foo", |
| 3000 | } |
| 3001 | |
| 3002 | android_test { |
| 3003 | name: "bar_test", |
| 3004 | srcs: ["b.java"], |
| 3005 | package_name: "com.android.bar.test", |
| 3006 | instrumentation_for: "foo", |
Seth Moore | c6f4b53 | 2023-02-02 13:22:26 -0800 | [diff] [blame] | 3007 | mainline_package_name: "com.android.bar", |
Jaewoong Jung | 3998234 | 2020-01-14 10:27:18 -0800 | [diff] [blame] | 3008 | } |
| 3009 | |
| 3010 | override_android_test { |
| 3011 | name: "baz_test", |
| 3012 | base: "foo_test", |
| 3013 | package_name: "com.android.baz.test", |
Seth Moore | c6f4b53 | 2023-02-02 13:22:26 -0800 | [diff] [blame] | 3014 | mainline_package_name: "com.android.baz", |
Jaewoong Jung | 3998234 | 2020-01-14 10:27:18 -0800 | [diff] [blame] | 3015 | } |
| 3016 | `) |
| 3017 | |
| 3018 | testCases := []struct { |
| 3019 | moduleName string |
| 3020 | variantName string |
| 3021 | expectedFlags []string |
| 3022 | }{ |
| 3023 | { |
| 3024 | moduleName: "foo_test", |
| 3025 | variantName: "android_common", |
| 3026 | }, |
| 3027 | { |
| 3028 | moduleName: "bar_test", |
| 3029 | variantName: "android_common", |
| 3030 | expectedFlags: []string{ |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 3031 | "--manifest out/soong/.intermediates/bar_test/android_common/manifest_fixer/AndroidManifest.xml", |
Jaewoong Jung | 3998234 | 2020-01-14 10:27:18 -0800 | [diff] [blame] | 3032 | "--package-name com.android.bar.test", |
Seth Moore | c6f4b53 | 2023-02-02 13:22:26 -0800 | [diff] [blame] | 3033 | "--mainline-package-name com.android.bar", |
Jaewoong Jung | 3998234 | 2020-01-14 10:27:18 -0800 | [diff] [blame] | 3034 | }, |
| 3035 | }, |
| 3036 | { |
| 3037 | moduleName: "foo_test", |
| 3038 | variantName: "android_common_baz_test", |
| 3039 | expectedFlags: []string{ |
Paul Duffin | fb0fe9f | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 3040 | "--manifest out/soong/.intermediates/foo_test/android_common_baz_test/manifest_fixer/AndroidManifest.xml", |
Jaewoong Jung | 3998234 | 2020-01-14 10:27:18 -0800 | [diff] [blame] | 3041 | "--package-name com.android.baz.test", |
| 3042 | "--test-file-name baz_test.apk", |
Seth Moore | c6f4b53 | 2023-02-02 13:22:26 -0800 | [diff] [blame] | 3043 | "out/soong/.intermediates/foo_test/android_common_baz_test/test_config_fixer/AndroidTest.xml", |
| 3044 | "--mainline-package-name com.android.baz", |
Jaewoong Jung | 3998234 | 2020-01-14 10:27:18 -0800 | [diff] [blame] | 3045 | }, |
| 3046 | }, |
| 3047 | } |
| 3048 | |
| 3049 | for _, test := range testCases { |
| 3050 | variant := ctx.ModuleForTests(test.moduleName, test.variantName) |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 3051 | params := variant.MaybeOutput("test_config_fixer/AndroidTest.xml") |
Jaewoong Jung | 3998234 | 2020-01-14 10:27:18 -0800 | [diff] [blame] | 3052 | |
| 3053 | if len(test.expectedFlags) > 0 { |
| 3054 | if params.Rule == nil { |
| 3055 | t.Errorf("test_config_fixer was expected to run, but didn't") |
| 3056 | } else { |
| 3057 | for _, flag := range test.expectedFlags { |
| 3058 | if !strings.Contains(params.RuleParams.Command, flag) { |
| 3059 | t.Errorf("Flag %q was not found in command: %q", flag, params.RuleParams.Command) |
| 3060 | } |
| 3061 | } |
| 3062 | } |
| 3063 | } else { |
| 3064 | if params.Rule != nil { |
| 3065 | t.Errorf("test_config_fixer was not expected to run, but did: %q", params.RuleParams.Command) |
| 3066 | } |
| 3067 | } |
Jaewoong Jung | 3998234 | 2020-01-14 10:27:18 -0800 | [diff] [blame] | 3068 | } |
| 3069 | } |
| 3070 | |
Paul Duffin | 53a70a4 | 2022-01-11 14:35:55 +0000 | [diff] [blame] | 3071 | func TestInstrumentationTargetPrebuilt(t *testing.T) { |
| 3072 | bp := ` |
| 3073 | android_app_import { |
| 3074 | name: "foo", |
| 3075 | apk: "foo.apk", |
| 3076 | presigned: true, |
| 3077 | } |
| 3078 | |
| 3079 | android_test { |
| 3080 | name: "bar", |
| 3081 | srcs: ["a.java"], |
| 3082 | instrumentation_for: "foo", |
| 3083 | sdk_version: "current", |
| 3084 | } |
| 3085 | ` |
| 3086 | |
| 3087 | android.GroupFixturePreparers( |
| 3088 | PrepareForTestWithJavaDefaultModules, |
| 3089 | ).ExtendWithErrorHandler( |
| 3090 | android.FixtureExpectsAtLeastOneErrorMatchingPattern( |
| 3091 | "instrumentation_for: dependency \"foo\" of type \"android_app_import\" does not provide JavaInfo so is unsuitable for use with this property")). |
| 3092 | RunTestWithBp(t, bp) |
| 3093 | } |
| 3094 | |
Jaewoong Jung | bc625cd | 2019-05-06 15:48:44 -0700 | [diff] [blame] | 3095 | func TestStl(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 3096 | ctx, _ := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+` |
Jaewoong Jung | bc625cd | 2019-05-06 15:48:44 -0700 | [diff] [blame] | 3097 | cc_library { |
| 3098 | name: "libjni", |
Peter Collingbourne | ad84f97 | 2019-12-17 16:46:18 -0800 | [diff] [blame] | 3099 | sdk_version: "current", |
| 3100 | stl: "c++_shared", |
Jaewoong Jung | bc625cd | 2019-05-06 15:48:44 -0700 | [diff] [blame] | 3101 | } |
| 3102 | |
| 3103 | android_test { |
| 3104 | name: "stl", |
| 3105 | jni_libs: ["libjni"], |
| 3106 | compile_multilib: "both", |
| 3107 | sdk_version: "current", |
| 3108 | stl: "c++_shared", |
| 3109 | } |
| 3110 | |
| 3111 | android_test { |
| 3112 | name: "system", |
| 3113 | jni_libs: ["libjni"], |
| 3114 | compile_multilib: "both", |
| 3115 | sdk_version: "current", |
| 3116 | } |
| 3117 | `) |
| 3118 | |
| 3119 | testCases := []struct { |
| 3120 | name string |
| 3121 | jnis []string |
| 3122 | }{ |
| 3123 | {"stl", |
| 3124 | []string{ |
| 3125 | "libjni.so", |
Jaewoong Jung | 710756a | 2019-06-04 11:53:47 -0700 | [diff] [blame] | 3126 | "libc++_shared.so", |
Jaewoong Jung | bc625cd | 2019-05-06 15:48:44 -0700 | [diff] [blame] | 3127 | }, |
| 3128 | }, |
| 3129 | {"system", |
| 3130 | []string{ |
| 3131 | "libjni.so", |
| 3132 | }, |
| 3133 | }, |
| 3134 | } |
| 3135 | |
| 3136 | for _, test := range testCases { |
| 3137 | t.Run(test.name, func(t *testing.T) { |
| 3138 | app := ctx.ModuleForTests(test.name, "android_common") |
Colin Cross | b3168ba | 2023-07-26 16:14:56 -0700 | [diff] [blame] | 3139 | jniLibZip := app.Output("jnilibs.zip") |
Jaewoong Jung | bc625cd | 2019-05-06 15:48:44 -0700 | [diff] [blame] | 3140 | var jnis []string |
| 3141 | args := strings.Fields(jniLibZip.Args["jarArgs"]) |
| 3142 | for i := 0; i < len(args); i++ { |
| 3143 | if args[i] == "-f" { |
| 3144 | jnis = append(jnis, args[i+1]) |
| 3145 | i += 1 |
| 3146 | } |
| 3147 | } |
| 3148 | jnisJoined := strings.Join(jnis, " ") |
| 3149 | for _, jni := range test.jnis { |
| 3150 | if !strings.Contains(jnisJoined, jni) { |
| 3151 | t.Errorf("missing jni %q in %q", jni, jnis) |
| 3152 | } |
| 3153 | } |
| 3154 | }) |
| 3155 | } |
| 3156 | } |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 3157 | |
| 3158 | func TestUsesLibraries(t *testing.T) { |
| 3159 | bp := ` |
| 3160 | java_sdk_library { |
| 3161 | name: "foo", |
| 3162 | srcs: ["a.java"], |
| 3163 | api_packages: ["foo"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 3164 | sdk_version: "current", |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 3165 | } |
| 3166 | |
| 3167 | java_sdk_library { |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 3168 | name: "qux", |
| 3169 | srcs: ["a.java"], |
| 3170 | api_packages: ["qux"], |
| 3171 | sdk_version: "current", |
| 3172 | } |
| 3173 | |
| 3174 | java_sdk_library { |
| 3175 | name: "quuz", |
| 3176 | srcs: ["a.java"], |
| 3177 | api_packages: ["quuz"], |
| 3178 | sdk_version: "current", |
| 3179 | } |
| 3180 | |
| 3181 | java_sdk_library { |
Ulya Trafimovich | 65b0319 | 2020-12-03 16:50:22 +0000 | [diff] [blame] | 3182 | name: "fred", |
| 3183 | srcs: ["a.java"], |
| 3184 | api_packages: ["fred"], |
| 3185 | sdk_version: "current", |
| 3186 | } |
| 3187 | |
| 3188 | java_sdk_library { |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 3189 | name: "bar", |
| 3190 | srcs: ["a.java"], |
| 3191 | api_packages: ["bar"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 3192 | sdk_version: "current", |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 3193 | } |
| 3194 | |
Ulya Trafimovich | 4b6d4c1 | 2020-08-19 14:58:01 +0100 | [diff] [blame] | 3195 | java_sdk_library { |
| 3196 | name: "runtime-library", |
| 3197 | srcs: ["a.java"], |
| 3198 | sdk_version: "current", |
| 3199 | } |
| 3200 | |
| 3201 | java_library { |
| 3202 | name: "static-runtime-helper", |
| 3203 | srcs: ["a.java"], |
| 3204 | libs: ["runtime-library"], |
| 3205 | sdk_version: "current", |
| 3206 | } |
| 3207 | |
Ulya Trafimovich | e443287 | 2021-08-18 16:57:11 +0100 | [diff] [blame] | 3208 | java_library { |
| 3209 | name: "runtime-required-x", |
| 3210 | srcs: ["a.java"], |
| 3211 | installable: true, |
| 3212 | sdk_version: "current", |
| 3213 | } |
| 3214 | |
| 3215 | java_library { |
| 3216 | name: "runtime-optional-x", |
| 3217 | srcs: ["a.java"], |
| 3218 | installable: true, |
| 3219 | sdk_version: "current", |
| 3220 | } |
| 3221 | |
| 3222 | android_library { |
| 3223 | name: "static-x", |
| 3224 | uses_libs: ["runtime-required-x"], |
| 3225 | optional_uses_libs: ["runtime-optional-x"], |
| 3226 | sdk_version: "current", |
| 3227 | } |
| 3228 | |
| 3229 | java_library { |
| 3230 | name: "runtime-required-y", |
| 3231 | srcs: ["a.java"], |
| 3232 | installable: true, |
| 3233 | sdk_version: "current", |
| 3234 | } |
| 3235 | |
| 3236 | java_library { |
| 3237 | name: "runtime-optional-y", |
| 3238 | srcs: ["a.java"], |
| 3239 | installable: true, |
| 3240 | sdk_version: "current", |
| 3241 | } |
| 3242 | |
| 3243 | java_library { |
| 3244 | name: "static-y", |
| 3245 | srcs: ["a.java"], |
| 3246 | uses_libs: ["runtime-required-y"], |
| 3247 | optional_uses_libs: ["runtime-optional-y"], |
| 3248 | sdk_version: "current", |
| 3249 | } |
| 3250 | |
Ulya Trafimovich | 861a896 | 2021-02-26 14:49:07 +0000 | [diff] [blame] | 3251 | // A library that has to use "provides_uses_lib", because: |
| 3252 | // - it is not an SDK library |
| 3253 | // - its library name is different from its module name |
| 3254 | java_library { |
| 3255 | name: "non-sdk-lib", |
| 3256 | provides_uses_lib: "com.non.sdk.lib", |
| 3257 | installable: true, |
| 3258 | srcs: ["a.java"], |
| 3259 | } |
| 3260 | |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 3261 | android_app { |
| 3262 | name: "app", |
| 3263 | srcs: ["a.java"], |
Ulya Trafimovich | 861a896 | 2021-02-26 14:49:07 +0000 | [diff] [blame] | 3264 | libs: [ |
| 3265 | "qux", |
| 3266 | "quuz.stubs" |
| 3267 | ], |
Ulya Trafimovich | 65b0319 | 2020-12-03 16:50:22 +0000 | [diff] [blame] | 3268 | static_libs: [ |
| 3269 | "static-runtime-helper", |
| 3270 | // statically linked component libraries should not pull their SDK libraries, |
| 3271 | // so "fred" should not be added to class loader context |
| 3272 | "fred.stubs", |
Ulya Trafimovich | e443287 | 2021-08-18 16:57:11 +0100 | [diff] [blame] | 3273 | "static-x", |
| 3274 | "static-y", |
Ulya Trafimovich | 65b0319 | 2020-12-03 16:50:22 +0000 | [diff] [blame] | 3275 | ], |
Ulya Trafimovich | 861a896 | 2021-02-26 14:49:07 +0000 | [diff] [blame] | 3276 | uses_libs: [ |
| 3277 | "foo", |
| 3278 | "non-sdk-lib" |
| 3279 | ], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 3280 | sdk_version: "current", |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 3281 | optional_uses_libs: [ |
| 3282 | "bar", |
| 3283 | "baz", |
| 3284 | ], |
| 3285 | } |
| 3286 | |
| 3287 | android_app_import { |
| 3288 | name: "prebuilt", |
| 3289 | apk: "prebuilts/apk/app.apk", |
| 3290 | certificate: "platform", |
Ulya Trafimovich | 861a896 | 2021-02-26 14:49:07 +0000 | [diff] [blame] | 3291 | uses_libs: [ |
| 3292 | "foo", |
| 3293 | "non-sdk-lib", |
| 3294 | "android.test.runner" |
| 3295 | ], |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 3296 | optional_uses_libs: [ |
| 3297 | "bar", |
| 3298 | "baz", |
| 3299 | ], |
| 3300 | } |
| 3301 | ` |
| 3302 | |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame] | 3303 | result := android.GroupFixturePreparers( |
| 3304 | prepareForJavaTest, |
Paul Duffin | 2645a29 | 2021-03-13 02:36:00 +0000 | [diff] [blame] | 3305 | PrepareForTestWithJavaSdkLibraryFiles, |
| 3306 | FixtureWithLastReleaseApis("runtime-library", "foo", "quuz", "qux", "bar", "fred"), |
Jiakai Zhang | 48203e3 | 2023-06-02 23:42:21 +0100 | [diff] [blame] | 3307 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 3308 | variables.BuildWarningBadOptionalUsesLibsAllowlist = []string{"app", "prebuilt"} |
| 3309 | }), |
Paul Duffin | d234b41 | 2021-03-12 23:04:46 +0000 | [diff] [blame] | 3310 | ).RunTestWithBp(t, bp) |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 3311 | |
Paul Duffin | d234b41 | 2021-03-12 23:04:46 +0000 | [diff] [blame] | 3312 | app := result.ModuleForTests("app", "android_common") |
| 3313 | prebuilt := result.ModuleForTests("prebuilt", "android_common") |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 3314 | |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 3315 | // Test that implicit dependencies on java_sdk_library instances are passed to the manifest. |
Ulya Trafimovich | f5d91bb | 2022-05-04 12:00:02 +0100 | [diff] [blame] | 3316 | // These also include explicit `uses_libs`/`optional_uses_libs` entries, as they may be |
| 3317 | // propagated from dependencies. |
Ulya Trafimovich | 2eaf5c5 | 2021-02-26 12:05:11 +0000 | [diff] [blame] | 3318 | actualManifestFixerArgs := app.Output("manifest_fixer/AndroidManifest.xml").Args["args"] |
| 3319 | expectManifestFixerArgs := `--extract-native-libs=true ` + |
| 3320 | `--uses-library qux ` + |
| 3321 | `--uses-library quuz ` + |
Ulya Trafimovich | f5d91bb | 2022-05-04 12:00:02 +0100 | [diff] [blame] | 3322 | `--uses-library foo ` + |
| 3323 | `--uses-library com.non.sdk.lib ` + |
| 3324 | `--uses-library runtime-library ` + |
| 3325 | `--uses-library runtime-required-x ` + |
| 3326 | `--uses-library runtime-required-y ` + |
| 3327 | `--optional-uses-library bar ` + |
| 3328 | `--optional-uses-library runtime-optional-x ` + |
| 3329 | `--optional-uses-library runtime-optional-y` |
Gurpreet Singh | 75d65f3 | 2022-01-24 17:44:05 +0000 | [diff] [blame] | 3330 | android.AssertStringDoesContain(t, "manifest_fixer args", actualManifestFixerArgs, expectManifestFixerArgs) |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 3331 | |
Ulya Trafimovich | 2eaf5c5 | 2021-02-26 12:05:11 +0000 | [diff] [blame] | 3332 | // Test that all libraries are verified (library order matters). |
| 3333 | verifyCmd := app.Rule("verify_uses_libraries").RuleParams.Command |
| 3334 | verifyArgs := `--uses-library foo ` + |
Ulya Trafimovich | eea486a | 2021-02-26 11:38:21 +0000 | [diff] [blame] | 3335 | `--uses-library com.non.sdk.lib ` + |
Ulya Trafimovich | 2eaf5c5 | 2021-02-26 12:05:11 +0000 | [diff] [blame] | 3336 | `--uses-library qux ` + |
| 3337 | `--uses-library quuz ` + |
| 3338 | `--uses-library runtime-library ` + |
Ulya Trafimovich | e443287 | 2021-08-18 16:57:11 +0100 | [diff] [blame] | 3339 | `--uses-library runtime-required-x ` + |
| 3340 | `--uses-library runtime-required-y ` + |
Ulya Trafimovich | 2eaf5c5 | 2021-02-26 12:05:11 +0000 | [diff] [blame] | 3341 | `--optional-uses-library bar ` + |
Ulya Trafimovich | e443287 | 2021-08-18 16:57:11 +0100 | [diff] [blame] | 3342 | `--optional-uses-library baz ` + |
| 3343 | `--optional-uses-library runtime-optional-x ` + |
| 3344 | `--optional-uses-library runtime-optional-y ` |
Paul Duffin | d234b41 | 2021-03-12 23:04:46 +0000 | [diff] [blame] | 3345 | android.AssertStringDoesContain(t, "verify cmd args", verifyCmd, verifyArgs) |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 3346 | |
Ulya Trafimovich | 2eaf5c5 | 2021-02-26 12:05:11 +0000 | [diff] [blame] | 3347 | // Test that all libraries are verified for an APK (library order matters). |
| 3348 | verifyApkCmd := prebuilt.Rule("verify_uses_libraries").RuleParams.Command |
Ulya Trafimovich | 0aba252 | 2021-03-03 16:38:37 +0000 | [diff] [blame] | 3349 | verifyApkArgs := `--uses-library foo ` + |
| 3350 | `--uses-library com.non.sdk.lib ` + |
| 3351 | `--uses-library android.test.runner ` + |
| 3352 | `--optional-uses-library bar ` + |
| 3353 | `--optional-uses-library baz ` |
Paul Duffin | d234b41 | 2021-03-12 23:04:46 +0000 | [diff] [blame] | 3354 | android.AssertStringDoesContain(t, "verify apk cmd args", verifyApkCmd, verifyApkArgs) |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 3355 | |
Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 3356 | // Test that necessary args are passed for constructing CLC in Ninja phase. |
Ulya Trafimovich | 2eaf5c5 | 2021-02-26 12:05:11 +0000 | [diff] [blame] | 3357 | cmd := app.Rule("dexpreopt").RuleParams.Command |
Jiakai Zhang | a449678 | 2023-05-17 16:57:30 +0100 | [diff] [blame] | 3358 | android.AssertStringDoesContain(t, "dexpreopt app cmd context", cmd, "--context-json=") |
| 3359 | android.AssertStringDoesContain(t, "dexpreopt app cmd product_packages", cmd, |
Spandan Das | 2069c3f | 2023-12-06 19:40:24 +0000 | [diff] [blame] | 3360 | "--product-packages=out/soong/.intermediates/app/android_common/dexpreopt/app/product_packages.txt") |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 3361 | } |
Jaewoong Jung | c27ab66 | 2019-05-30 15:51:14 -0700 | [diff] [blame] | 3362 | |
Ulya Trafimovich | 9023b02 | 2021-03-22 16:02:28 +0000 | [diff] [blame] | 3363 | func TestDexpreoptBcp(t *testing.T) { |
| 3364 | bp := ` |
| 3365 | java_sdk_library { |
| 3366 | name: "foo", |
| 3367 | srcs: ["a.java"], |
| 3368 | api_packages: ["foo"], |
| 3369 | sdk_version: "current", |
| 3370 | } |
| 3371 | |
| 3372 | java_sdk_library { |
| 3373 | name: "bar", |
| 3374 | srcs: ["a.java"], |
| 3375 | api_packages: ["bar"], |
| 3376 | permitted_packages: ["bar"], |
| 3377 | sdk_version: "current", |
| 3378 | } |
| 3379 | |
| 3380 | android_app { |
| 3381 | name: "app", |
| 3382 | srcs: ["a.java"], |
| 3383 | sdk_version: "current", |
| 3384 | } |
| 3385 | ` |
| 3386 | |
| 3387 | testCases := []struct { |
| 3388 | name string |
| 3389 | with bool |
| 3390 | expect string |
| 3391 | }{ |
| 3392 | { |
| 3393 | name: "with updatable bcp", |
| 3394 | with: true, |
| 3395 | expect: "/system/framework/foo.jar:/system/framework/bar.jar", |
| 3396 | }, |
| 3397 | { |
| 3398 | name: "without updatable bcp", |
| 3399 | with: false, |
| 3400 | expect: "/system/framework/foo.jar", |
| 3401 | }, |
| 3402 | } |
| 3403 | |
| 3404 | for _, test := range testCases { |
| 3405 | t.Run(test.name, func(t *testing.T) { |
| 3406 | result := android.GroupFixturePreparers( |
| 3407 | prepareForJavaTest, |
| 3408 | PrepareForTestWithJavaSdkLibraryFiles, |
| 3409 | FixtureWithLastReleaseApis("runtime-library", "foo", "bar"), |
| 3410 | dexpreopt.FixtureSetBootJars("platform:foo"), |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 3411 | dexpreopt.FixtureSetApexBootJars("platform:bar"), |
Ulya Trafimovich | 9023b02 | 2021-03-22 16:02:28 +0000 | [diff] [blame] | 3412 | dexpreopt.FixtureSetPreoptWithUpdatableBcp(test.with), |
| 3413 | ).RunTestWithBp(t, bp) |
| 3414 | |
| 3415 | app := result.ModuleForTests("app", "android_common") |
| 3416 | cmd := app.Rule("dexpreopt").RuleParams.Command |
| 3417 | bcp := " -Xbootclasspath-locations:" + test.expect + " " // space at the end matters |
| 3418 | android.AssertStringDoesContain(t, "dexpreopt app bcp", cmd, bcp) |
| 3419 | }) |
| 3420 | } |
| 3421 | } |
| 3422 | |
Jaewoong Jung | c27ab66 | 2019-05-30 15:51:14 -0700 | [diff] [blame] | 3423 | func TestCodelessApp(t *testing.T) { |
| 3424 | testCases := []struct { |
| 3425 | name string |
| 3426 | bp string |
| 3427 | noCode bool |
| 3428 | }{ |
| 3429 | { |
| 3430 | name: "normal", |
| 3431 | bp: ` |
| 3432 | android_app { |
| 3433 | name: "foo", |
| 3434 | srcs: ["a.java"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 3435 | sdk_version: "current", |
Jaewoong Jung | c27ab66 | 2019-05-30 15:51:14 -0700 | [diff] [blame] | 3436 | } |
| 3437 | `, |
| 3438 | noCode: false, |
| 3439 | }, |
| 3440 | { |
| 3441 | name: "app without sources", |
| 3442 | bp: ` |
| 3443 | android_app { |
| 3444 | name: "foo", |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 3445 | sdk_version: "current", |
Jaewoong Jung | c27ab66 | 2019-05-30 15:51:14 -0700 | [diff] [blame] | 3446 | } |
| 3447 | `, |
| 3448 | noCode: true, |
| 3449 | }, |
| 3450 | { |
| 3451 | name: "app with libraries", |
| 3452 | bp: ` |
| 3453 | android_app { |
| 3454 | name: "foo", |
| 3455 | static_libs: ["lib"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 3456 | sdk_version: "current", |
Jaewoong Jung | c27ab66 | 2019-05-30 15:51:14 -0700 | [diff] [blame] | 3457 | } |
| 3458 | |
| 3459 | java_library { |
| 3460 | name: "lib", |
| 3461 | srcs: ["a.java"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 3462 | sdk_version: "current", |
Jaewoong Jung | c27ab66 | 2019-05-30 15:51:14 -0700 | [diff] [blame] | 3463 | } |
| 3464 | `, |
| 3465 | noCode: false, |
| 3466 | }, |
| 3467 | { |
| 3468 | name: "app with sourceless libraries", |
| 3469 | bp: ` |
| 3470 | android_app { |
| 3471 | name: "foo", |
| 3472 | static_libs: ["lib"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 3473 | sdk_version: "current", |
Jaewoong Jung | c27ab66 | 2019-05-30 15:51:14 -0700 | [diff] [blame] | 3474 | } |
| 3475 | |
| 3476 | java_library { |
| 3477 | name: "lib", |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 3478 | sdk_version: "current", |
Jaewoong Jung | c27ab66 | 2019-05-30 15:51:14 -0700 | [diff] [blame] | 3479 | } |
| 3480 | `, |
| 3481 | // TODO(jungjw): this should probably be true |
| 3482 | noCode: false, |
| 3483 | }, |
| 3484 | } |
| 3485 | |
| 3486 | for _, test := range testCases { |
| 3487 | t.Run(test.name, func(t *testing.T) { |
| 3488 | ctx := testApp(t, test.bp) |
| 3489 | |
| 3490 | foo := ctx.ModuleForTests("foo", "android_common") |
| 3491 | manifestFixerArgs := foo.Output("manifest_fixer/AndroidManifest.xml").Args["args"] |
| 3492 | if strings.Contains(manifestFixerArgs, "--has-no-code") != test.noCode { |
| 3493 | t.Errorf("unexpected manifest_fixer args: %q", manifestFixerArgs) |
| 3494 | } |
| 3495 | }) |
| 3496 | } |
| 3497 | } |
Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 3498 | |
Colin Cross | 53a87f5 | 2019-06-25 13:35:30 -0700 | [diff] [blame] | 3499 | func TestUncompressDex(t *testing.T) { |
| 3500 | testCases := []struct { |
| 3501 | name string |
| 3502 | bp string |
| 3503 | |
| 3504 | uncompressedPlatform bool |
| 3505 | uncompressedUnbundled bool |
| 3506 | }{ |
| 3507 | { |
| 3508 | name: "normal", |
| 3509 | bp: ` |
| 3510 | android_app { |
| 3511 | name: "foo", |
| 3512 | srcs: ["a.java"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 3513 | sdk_version: "current", |
Colin Cross | 53a87f5 | 2019-06-25 13:35:30 -0700 | [diff] [blame] | 3514 | } |
| 3515 | `, |
| 3516 | uncompressedPlatform: true, |
| 3517 | uncompressedUnbundled: false, |
| 3518 | }, |
| 3519 | { |
| 3520 | name: "use_embedded_dex", |
| 3521 | bp: ` |
| 3522 | android_app { |
| 3523 | name: "foo", |
| 3524 | use_embedded_dex: true, |
| 3525 | srcs: ["a.java"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 3526 | sdk_version: "current", |
Colin Cross | 53a87f5 | 2019-06-25 13:35:30 -0700 | [diff] [blame] | 3527 | } |
| 3528 | `, |
| 3529 | uncompressedPlatform: true, |
| 3530 | uncompressedUnbundled: true, |
| 3531 | }, |
| 3532 | { |
| 3533 | name: "privileged", |
| 3534 | bp: ` |
| 3535 | android_app { |
| 3536 | name: "foo", |
| 3537 | privileged: true, |
| 3538 | srcs: ["a.java"], |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 3539 | sdk_version: "current", |
Colin Cross | 53a87f5 | 2019-06-25 13:35:30 -0700 | [diff] [blame] | 3540 | } |
| 3541 | `, |
| 3542 | uncompressedPlatform: true, |
| 3543 | uncompressedUnbundled: true, |
| 3544 | }, |
David Srbecky | e033cba | 2020-05-20 22:20:28 +0100 | [diff] [blame] | 3545 | { |
| 3546 | name: "normal_uncompress_dex_true", |
| 3547 | bp: ` |
| 3548 | android_app { |
| 3549 | name: "foo", |
| 3550 | srcs: ["a.java"], |
| 3551 | sdk_version: "current", |
| 3552 | uncompress_dex: true, |
| 3553 | } |
| 3554 | `, |
| 3555 | uncompressedPlatform: true, |
| 3556 | uncompressedUnbundled: true, |
| 3557 | }, |
| 3558 | { |
| 3559 | name: "normal_uncompress_dex_false", |
| 3560 | bp: ` |
| 3561 | android_app { |
| 3562 | name: "foo", |
| 3563 | srcs: ["a.java"], |
| 3564 | sdk_version: "current", |
| 3565 | uncompress_dex: false, |
| 3566 | } |
| 3567 | `, |
| 3568 | uncompressedPlatform: false, |
| 3569 | uncompressedUnbundled: false, |
| 3570 | }, |
Colin Cross | 53a87f5 | 2019-06-25 13:35:30 -0700 | [diff] [blame] | 3571 | } |
| 3572 | |
| 3573 | test := func(t *testing.T, bp string, want bool, unbundled bool) { |
| 3574 | t.Helper() |
| 3575 | |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame] | 3576 | result := android.GroupFixturePreparers( |
| 3577 | prepareForJavaTest, |
Paul Duffin | 2645a29 | 2021-03-13 02:36:00 +0000 | [diff] [blame] | 3578 | PrepareForTestWithPrebuiltsOfCurrentApi, |
Paul Duffin | cdb88a9 | 2021-03-14 00:36:50 +0000 | [diff] [blame] | 3579 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 3580 | if unbundled { |
| 3581 | variables.Unbundled_build = proptools.BoolPtr(true) |
| 3582 | variables.Always_use_prebuilt_sdks = proptools.BoolPtr(true) |
| 3583 | } |
| 3584 | }), |
| 3585 | ).RunTestWithBp(t, bp) |
Colin Cross | 53a87f5 | 2019-06-25 13:35:30 -0700 | [diff] [blame] | 3586 | |
Paul Duffin | cdb88a9 | 2021-03-14 00:36:50 +0000 | [diff] [blame] | 3587 | foo := result.ModuleForTests("foo", "android_common") |
Colin Cross | 53a87f5 | 2019-06-25 13:35:30 -0700 | [diff] [blame] | 3588 | dex := foo.Rule("r8") |
| 3589 | uncompressedInDexJar := strings.Contains(dex.Args["zipFlags"], "-L 0") |
| 3590 | aligned := foo.MaybeRule("zipalign").Rule != nil |
| 3591 | |
Paul Duffin | cdb88a9 | 2021-03-14 00:36:50 +0000 | [diff] [blame] | 3592 | android.AssertBoolEquals(t, "uncompressed in dex", want, uncompressedInDexJar) |
Colin Cross | 53a87f5 | 2019-06-25 13:35:30 -0700 | [diff] [blame] | 3593 | |
Paul Duffin | cdb88a9 | 2021-03-14 00:36:50 +0000 | [diff] [blame] | 3594 | android.AssertBoolEquals(t, "aligne", want, aligned) |
Colin Cross | 53a87f5 | 2019-06-25 13:35:30 -0700 | [diff] [blame] | 3595 | } |
| 3596 | |
| 3597 | for _, tt := range testCases { |
| 3598 | t.Run(tt.name, func(t *testing.T) { |
| 3599 | t.Run("platform", func(t *testing.T) { |
| 3600 | test(t, tt.bp, tt.uncompressedPlatform, false) |
| 3601 | }) |
| 3602 | t.Run("unbundled", func(t *testing.T) { |
| 3603 | test(t, tt.bp, tt.uncompressedUnbundled, true) |
| 3604 | }) |
| 3605 | }) |
| 3606 | } |
| 3607 | } |
Jaewoong Jung | 26dedd3 | 2019-06-06 08:45:58 -0700 | [diff] [blame] | 3608 | |
| 3609 | func checkAapt2LinkFlag(t *testing.T, aapt2Flags, flagName, expectedValue string) { |
| 3610 | if expectedValue != "" { |
| 3611 | expectedFlag := "--" + flagName + " " + expectedValue |
| 3612 | if !strings.Contains(aapt2Flags, expectedFlag) { |
| 3613 | t.Errorf("%q is missing in aapt2 link flags, %q", expectedFlag, aapt2Flags) |
| 3614 | } |
| 3615 | } else { |
| 3616 | unexpectedFlag := "--" + flagName |
| 3617 | if strings.Contains(aapt2Flags, unexpectedFlag) { |
| 3618 | t.Errorf("unexpected flag, %q is found in aapt2 link flags, %q", unexpectedFlag, aapt2Flags) |
| 3619 | } |
| 3620 | } |
| 3621 | } |
Jaewoong Jung | 9befb0c | 2020-01-18 10:33:43 -0800 | [diff] [blame] | 3622 | |
Cole Faust | 9a63131 | 2020-10-22 21:05:24 +0000 | [diff] [blame] | 3623 | func TestExportedProguardFlagFiles(t *testing.T) { |
| 3624 | ctx, _ := testJava(t, ` |
| 3625 | android_app { |
| 3626 | name: "foo", |
| 3627 | sdk_version: "current", |
| 3628 | static_libs: ["lib1"], |
| 3629 | } |
| 3630 | |
| 3631 | android_library { |
| 3632 | name: "lib1", |
| 3633 | sdk_version: "current", |
| 3634 | optimize: { |
| 3635 | proguard_flags_files: ["lib1proguard.cfg"], |
| 3636 | } |
| 3637 | } |
| 3638 | `) |
| 3639 | |
| 3640 | m := ctx.ModuleForTests("foo", "android_common") |
| 3641 | hasLib1Proguard := false |
| 3642 | for _, s := range m.Rule("java.r8").Implicits.Strings() { |
| 3643 | if s == "lib1proguard.cfg" { |
| 3644 | hasLib1Proguard = true |
| 3645 | break |
| 3646 | } |
| 3647 | } |
| 3648 | |
| 3649 | if !hasLib1Proguard { |
| 3650 | t.Errorf("App does not use library proguard config") |
| 3651 | } |
| 3652 | } |
Spandan Das | c8cb0c3 | 2021-12-08 17:00:38 +0000 | [diff] [blame] | 3653 | |
| 3654 | func TestTargetSdkVersionManifestFixer(t *testing.T) { |
| 3655 | platform_sdk_codename := "Tiramisu" |
Spandan Das | fb6a1ee | 2023-04-27 16:08:26 +0000 | [diff] [blame] | 3656 | platform_sdk_version := 33 |
Spandan Das | c8cb0c3 | 2021-12-08 17:00:38 +0000 | [diff] [blame] | 3657 | testCases := []struct { |
| 3658 | name string |
| 3659 | targetSdkVersionInBp string |
| 3660 | targetSdkVersionExpected string |
| 3661 | unbundledBuild bool |
Spandan Das | fb6a1ee | 2023-04-27 16:08:26 +0000 | [diff] [blame] | 3662 | platformSdkFinal bool |
Spandan Das | c8cb0c3 | 2021-12-08 17:00:38 +0000 | [diff] [blame] | 3663 | }{ |
| 3664 | { |
| 3665 | name: "Non-Unbundled build: Android.bp has targetSdkVersion", |
| 3666 | targetSdkVersionInBp: "30", |
| 3667 | targetSdkVersionExpected: "30", |
| 3668 | unbundledBuild: false, |
| 3669 | }, |
| 3670 | { |
| 3671 | name: "Unbundled build: Android.bp has targetSdkVersion", |
| 3672 | targetSdkVersionInBp: "30", |
| 3673 | targetSdkVersionExpected: "30", |
| 3674 | unbundledBuild: true, |
| 3675 | }, |
| 3676 | { |
| 3677 | name: "Non-Unbundled build: Android.bp has targetSdkVersion equal to platform_sdk_codename", |
| 3678 | targetSdkVersionInBp: platform_sdk_codename, |
| 3679 | targetSdkVersionExpected: platform_sdk_codename, |
| 3680 | unbundledBuild: false, |
| 3681 | }, |
| 3682 | { |
| 3683 | name: "Unbundled build: Android.bp has targetSdkVersion equal to platform_sdk_codename", |
| 3684 | targetSdkVersionInBp: platform_sdk_codename, |
| 3685 | targetSdkVersionExpected: "10000", |
| 3686 | unbundledBuild: true, |
| 3687 | }, |
| 3688 | |
| 3689 | { |
| 3690 | name: "Non-Unbundled build: Android.bp has no targetSdkVersion", |
| 3691 | targetSdkVersionExpected: platform_sdk_codename, |
| 3692 | unbundledBuild: false, |
| 3693 | }, |
| 3694 | { |
| 3695 | name: "Unbundled build: Android.bp has no targetSdkVersion", |
| 3696 | targetSdkVersionExpected: "10000", |
| 3697 | unbundledBuild: true, |
| 3698 | }, |
Spandan Das | fb6a1ee | 2023-04-27 16:08:26 +0000 | [diff] [blame] | 3699 | { |
| 3700 | name: "Bundled build in REL branches", |
| 3701 | targetSdkVersionExpected: "33", |
| 3702 | unbundledBuild: false, |
| 3703 | platformSdkFinal: true, |
| 3704 | }, |
Spandan Das | c8cb0c3 | 2021-12-08 17:00:38 +0000 | [diff] [blame] | 3705 | } |
| 3706 | for _, testCase := range testCases { |
Spandan Das | ca70fc4 | 2023-03-01 23:38:49 +0000 | [diff] [blame] | 3707 | targetSdkVersionTemplate := "" |
| 3708 | if testCase.targetSdkVersionInBp != "" { |
| 3709 | targetSdkVersionTemplate = fmt.Sprintf(`target_sdk_version: "%s",`, testCase.targetSdkVersionInBp) |
| 3710 | } |
Spandan Das | c8cb0c3 | 2021-12-08 17:00:38 +0000 | [diff] [blame] | 3711 | bp := fmt.Sprintf(` |
| 3712 | android_app { |
| 3713 | name: "foo", |
| 3714 | sdk_version: "current", |
Spandan Das | ca70fc4 | 2023-03-01 23:38:49 +0000 | [diff] [blame] | 3715 | %s |
Spandan Das | c8cb0c3 | 2021-12-08 17:00:38 +0000 | [diff] [blame] | 3716 | } |
Spandan Das | ca70fc4 | 2023-03-01 23:38:49 +0000 | [diff] [blame] | 3717 | `, targetSdkVersionTemplate) |
Spandan Das | c8cb0c3 | 2021-12-08 17:00:38 +0000 | [diff] [blame] | 3718 | fixture := android.GroupFixturePreparers( |
| 3719 | prepareForJavaTest, |
| 3720 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
Spandan Das | fb6a1ee | 2023-04-27 16:08:26 +0000 | [diff] [blame] | 3721 | if testCase.platformSdkFinal { |
| 3722 | variables.Platform_sdk_final = proptools.BoolPtr(true) |
| 3723 | } |
Spandan Das | c8cb0c3 | 2021-12-08 17:00:38 +0000 | [diff] [blame] | 3724 | // explicitly set platform_sdk_codename to make the test deterministic |
| 3725 | variables.Platform_sdk_codename = &platform_sdk_codename |
Spandan Das | fb6a1ee | 2023-04-27 16:08:26 +0000 | [diff] [blame] | 3726 | variables.Platform_sdk_version = &platform_sdk_version |
Spandan Das | c8cb0c3 | 2021-12-08 17:00:38 +0000 | [diff] [blame] | 3727 | variables.Platform_version_active_codenames = []string{platform_sdk_codename} |
| 3728 | // create a non-empty list if unbundledBuild==true |
| 3729 | if testCase.unbundledBuild { |
| 3730 | variables.Unbundled_build_apps = []string{"apex_a", "apex_b"} |
| 3731 | } |
| 3732 | }), |
| 3733 | ) |
| 3734 | |
| 3735 | result := fixture.RunTestWithBp(t, bp) |
| 3736 | foo := result.ModuleForTests("foo", "android_common") |
| 3737 | |
Gurpreet Singh | 75d65f3 | 2022-01-24 17:44:05 +0000 | [diff] [blame] | 3738 | manifestFixerArgs := foo.Output("manifest_fixer/AndroidManifest.xml").Args["args"] |
| 3739 | android.AssertStringDoesContain(t, testCase.name, manifestFixerArgs, "--targetSdkVersion "+testCase.targetSdkVersionExpected) |
Spandan Das | c8cb0c3 | 2021-12-08 17:00:38 +0000 | [diff] [blame] | 3740 | } |
| 3741 | } |
Colin Cross | 412436f | 2022-04-07 17:40:07 -0700 | [diff] [blame] | 3742 | |
Harshit Mahajan | 5b8b730 | 2022-06-10 11:24:05 +0000 | [diff] [blame] | 3743 | func TestDefaultAppTargetSdkVersionForUpdatableModules(t *testing.T) { |
| 3744 | platform_sdk_codename := "Tiramisu" |
| 3745 | platform_sdk_version := 33 |
| 3746 | testCases := []struct { |
| 3747 | name string |
| 3748 | platform_sdk_final bool |
| 3749 | targetSdkVersionInBp *string |
| 3750 | targetSdkVersionExpected *string |
| 3751 | updatable bool |
| 3752 | }{ |
| 3753 | { |
| 3754 | name: "Non-Updatable Module: Android.bp has older targetSdkVersion", |
| 3755 | targetSdkVersionInBp: proptools.StringPtr("29"), |
| 3756 | targetSdkVersionExpected: proptools.StringPtr("29"), |
| 3757 | updatable: false, |
| 3758 | }, |
| 3759 | { |
| 3760 | name: "Updatable Module: Android.bp has older targetSdkVersion", |
| 3761 | targetSdkVersionInBp: proptools.StringPtr("30"), |
| 3762 | targetSdkVersionExpected: proptools.StringPtr("30"), |
| 3763 | updatable: true, |
| 3764 | }, |
| 3765 | { |
| 3766 | name: "Updatable Module: Android.bp has no targetSdkVersion", |
| 3767 | targetSdkVersionExpected: proptools.StringPtr("10000"), |
| 3768 | updatable: true, |
| 3769 | }, |
| 3770 | { |
| 3771 | name: "[SDK finalised] Non-Updatable Module: Android.bp has older targetSdkVersion", |
| 3772 | platform_sdk_final: true, |
| 3773 | targetSdkVersionInBp: proptools.StringPtr("30"), |
| 3774 | targetSdkVersionExpected: proptools.StringPtr("30"), |
| 3775 | updatable: false, |
| 3776 | }, |
| 3777 | { |
| 3778 | name: "[SDK finalised] Updatable Module: Android.bp has older targetSdkVersion", |
| 3779 | platform_sdk_final: true, |
| 3780 | targetSdkVersionInBp: proptools.StringPtr("30"), |
| 3781 | targetSdkVersionExpected: proptools.StringPtr("30"), |
| 3782 | updatable: true, |
| 3783 | }, |
| 3784 | { |
| 3785 | name: "[SDK finalised] Updatable Module: Android.bp has targetSdkVersion as platform sdk codename", |
| 3786 | platform_sdk_final: true, |
| 3787 | targetSdkVersionInBp: proptools.StringPtr(platform_sdk_codename), |
| 3788 | targetSdkVersionExpected: proptools.StringPtr("33"), |
| 3789 | updatable: true, |
| 3790 | }, |
| 3791 | { |
| 3792 | name: "[SDK finalised] Updatable Module: Android.bp has no targetSdkVersion", |
| 3793 | platform_sdk_final: true, |
| 3794 | targetSdkVersionExpected: proptools.StringPtr("33"), |
| 3795 | updatable: true, |
| 3796 | }, |
| 3797 | } |
| 3798 | for _, testCase := range testCases { |
Spandan Das | ca70fc4 | 2023-03-01 23:38:49 +0000 | [diff] [blame] | 3799 | targetSdkVersionTemplate := "" |
| 3800 | if testCase.targetSdkVersionInBp != nil { |
| 3801 | targetSdkVersionTemplate = fmt.Sprintf(`target_sdk_version: "%s",`, *testCase.targetSdkVersionInBp) |
| 3802 | } |
Harshit Mahajan | 5b8b730 | 2022-06-10 11:24:05 +0000 | [diff] [blame] | 3803 | bp := fmt.Sprintf(` |
| 3804 | android_app { |
| 3805 | name: "foo", |
| 3806 | sdk_version: "current", |
| 3807 | min_sdk_version: "29", |
Spandan Das | ca70fc4 | 2023-03-01 23:38:49 +0000 | [diff] [blame] | 3808 | %s |
Harshit Mahajan | 5b8b730 | 2022-06-10 11:24:05 +0000 | [diff] [blame] | 3809 | updatable: %t, |
| 3810 | enforce_default_target_sdk_version: %t |
| 3811 | } |
Spandan Das | ca70fc4 | 2023-03-01 23:38:49 +0000 | [diff] [blame] | 3812 | `, targetSdkVersionTemplate, testCase.updatable, testCase.updatable) // enforce default target sdk version if app is updatable |
Harshit Mahajan | 5b8b730 | 2022-06-10 11:24:05 +0000 | [diff] [blame] | 3813 | |
| 3814 | fixture := android.GroupFixturePreparers( |
| 3815 | PrepareForTestWithJavaDefaultModules, |
| 3816 | android.PrepareForTestWithAllowMissingDependencies, |
| 3817 | android.PrepareForTestWithAndroidMk, |
| 3818 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 3819 | // explicitly set following platform variables to make the test deterministic |
| 3820 | variables.Platform_sdk_final = &testCase.platform_sdk_final |
| 3821 | variables.Platform_sdk_version = &platform_sdk_version |
| 3822 | variables.Platform_sdk_codename = &platform_sdk_codename |
| 3823 | variables.Platform_version_active_codenames = []string{platform_sdk_codename} |
Harshit Mahajan | 18845d0 | 2023-01-11 18:39:12 +0000 | [diff] [blame] | 3824 | variables.Unbundled_build = proptools.BoolPtr(true) |
Harshit Mahajan | 5b8b730 | 2022-06-10 11:24:05 +0000 | [diff] [blame] | 3825 | variables.Unbundled_build_apps = []string{"sampleModule"} |
| 3826 | }), |
| 3827 | ) |
| 3828 | |
| 3829 | result := fixture.RunTestWithBp(t, bp) |
| 3830 | foo := result.ModuleForTests("foo", "android_common") |
| 3831 | |
| 3832 | manifestFixerArgs := foo.Output("manifest_fixer/AndroidManifest.xml").Args["args"] |
| 3833 | android.AssertStringDoesContain(t, testCase.name, manifestFixerArgs, "--targetSdkVersion "+*testCase.targetSdkVersionExpected) |
| 3834 | } |
| 3835 | } |
| 3836 | |
| 3837 | func TestEnforceDefaultAppTargetSdkVersionFlag(t *testing.T) { |
| 3838 | platform_sdk_codename := "Tiramisu" |
| 3839 | platform_sdk_version := 33 |
| 3840 | testCases := []struct { |
| 3841 | name string |
| 3842 | enforceDefaultTargetSdkVersion bool |
| 3843 | expectedError string |
| 3844 | platform_sdk_final bool |
| 3845 | targetSdkVersionInBp string |
| 3846 | targetSdkVersionExpected string |
| 3847 | updatable bool |
| 3848 | }{ |
| 3849 | { |
| 3850 | name: "Not enforcing Target SDK Version: Android.bp has older targetSdkVersion", |
| 3851 | enforceDefaultTargetSdkVersion: false, |
| 3852 | targetSdkVersionInBp: "29", |
| 3853 | targetSdkVersionExpected: "29", |
| 3854 | updatable: false, |
| 3855 | }, |
| 3856 | { |
| 3857 | name: "[SDK finalised] Enforce Target SDK Version: Android.bp has current targetSdkVersion", |
| 3858 | enforceDefaultTargetSdkVersion: true, |
| 3859 | platform_sdk_final: true, |
| 3860 | targetSdkVersionInBp: "current", |
| 3861 | targetSdkVersionExpected: "33", |
| 3862 | updatable: true, |
| 3863 | }, |
| 3864 | { |
Harshit Mahajan | 8f202ad | 2023-01-09 20:45:55 +0000 | [diff] [blame] | 3865 | name: "Enforce Target SDK Version: Android.bp has current targetSdkVersion", |
Harshit Mahajan | 5b8b730 | 2022-06-10 11:24:05 +0000 | [diff] [blame] | 3866 | enforceDefaultTargetSdkVersion: true, |
| 3867 | platform_sdk_final: false, |
| 3868 | targetSdkVersionInBp: "current", |
| 3869 | targetSdkVersionExpected: "10000", |
| 3870 | updatable: false, |
| 3871 | }, |
| 3872 | { |
| 3873 | name: "Not enforcing Target SDK Version for Updatable app", |
| 3874 | enforceDefaultTargetSdkVersion: false, |
| 3875 | expectedError: "Updatable apps must enforce default target sdk version", |
| 3876 | targetSdkVersionInBp: "29", |
| 3877 | targetSdkVersionExpected: "29", |
| 3878 | updatable: true, |
| 3879 | }, |
| 3880 | } |
| 3881 | for _, testCase := range testCases { |
| 3882 | errExpected := testCase.expectedError != "" |
| 3883 | bp := fmt.Sprintf(` |
| 3884 | android_app { |
| 3885 | name: "foo", |
| 3886 | enforce_default_target_sdk_version: %t, |
| 3887 | sdk_version: "current", |
| 3888 | min_sdk_version: "29", |
| 3889 | target_sdk_version: "%v", |
| 3890 | updatable: %t |
| 3891 | } |
| 3892 | `, testCase.enforceDefaultTargetSdkVersion, testCase.targetSdkVersionInBp, testCase.updatable) |
| 3893 | |
| 3894 | fixture := android.GroupFixturePreparers( |
| 3895 | PrepareForTestWithJavaDefaultModules, |
| 3896 | android.PrepareForTestWithAllowMissingDependencies, |
| 3897 | android.PrepareForTestWithAndroidMk, |
| 3898 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 3899 | // explicitly set following platform variables to make the test deterministic |
| 3900 | variables.Platform_sdk_final = &testCase.platform_sdk_final |
| 3901 | variables.Platform_sdk_version = &platform_sdk_version |
| 3902 | variables.Platform_sdk_codename = &platform_sdk_codename |
Harshit Mahajan | 18845d0 | 2023-01-11 18:39:12 +0000 | [diff] [blame] | 3903 | variables.Unbundled_build = proptools.BoolPtr(true) |
Harshit Mahajan | 5b8b730 | 2022-06-10 11:24:05 +0000 | [diff] [blame] | 3904 | variables.Unbundled_build_apps = []string{"sampleModule"} |
| 3905 | }), |
| 3906 | ) |
| 3907 | |
| 3908 | errorHandler := android.FixtureExpectsNoErrors |
| 3909 | if errExpected { |
| 3910 | errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern(testCase.expectedError) |
| 3911 | } |
| 3912 | result := fixture.ExtendWithErrorHandler(errorHandler).RunTestWithBp(t, bp) |
| 3913 | |
| 3914 | if !errExpected { |
| 3915 | foo := result.ModuleForTests("foo", "android_common") |
| 3916 | manifestFixerArgs := foo.Output("manifest_fixer/AndroidManifest.xml").Args["args"] |
| 3917 | android.AssertStringDoesContain(t, testCase.name, manifestFixerArgs, "--targetSdkVersion "+testCase.targetSdkVersionExpected) |
| 3918 | } |
| 3919 | } |
| 3920 | } |
| 3921 | |
Harshit Mahajan | 8f202ad | 2023-01-09 20:45:55 +0000 | [diff] [blame] | 3922 | func TestEnforceDefaultAppTargetSdkVersionFlagForTests(t *testing.T) { |
| 3923 | platform_sdk_codename := "Tiramisu" |
| 3924 | platform_sdk_version := 33 |
| 3925 | testCases := []struct { |
| 3926 | name string |
| 3927 | enforceDefaultTargetSdkVersion bool |
| 3928 | expectedError string |
| 3929 | platform_sdk_final bool |
| 3930 | targetSdkVersionInBp string |
| 3931 | targetSdkVersionExpected string |
| 3932 | }{ |
| 3933 | { |
| 3934 | name: "Not enforcing Target SDK Version: Android.bp has older targetSdkVersion", |
| 3935 | enforceDefaultTargetSdkVersion: false, |
| 3936 | targetSdkVersionInBp: "29", |
| 3937 | targetSdkVersionExpected: "29", |
| 3938 | }, |
| 3939 | { |
| 3940 | name: "[SDK finalised] Enforce Target SDK Version: Android.bp has current targetSdkVersion", |
| 3941 | enforceDefaultTargetSdkVersion: true, |
| 3942 | platform_sdk_final: true, |
| 3943 | targetSdkVersionInBp: "current", |
| 3944 | targetSdkVersionExpected: "33", |
| 3945 | }, |
| 3946 | { |
| 3947 | name: "Enforce Target SDK Version: Android.bp has current targetSdkVersion", |
| 3948 | enforceDefaultTargetSdkVersion: true, |
| 3949 | platform_sdk_final: false, |
| 3950 | targetSdkVersionInBp: "current", |
| 3951 | targetSdkVersionExpected: "10000", |
| 3952 | }, |
| 3953 | } |
| 3954 | for _, testCase := range testCases { |
| 3955 | errExpected := testCase.expectedError != "" |
| 3956 | bp := fmt.Sprintf(` |
| 3957 | android_test { |
| 3958 | name: "foo", |
| 3959 | enforce_default_target_sdk_version: %t, |
| 3960 | min_sdk_version: "29", |
| 3961 | target_sdk_version: "%v", |
| 3962 | } |
| 3963 | `, testCase.enforceDefaultTargetSdkVersion, testCase.targetSdkVersionInBp) |
| 3964 | |
| 3965 | fixture := android.GroupFixturePreparers( |
| 3966 | PrepareForTestWithJavaDefaultModules, |
| 3967 | android.PrepareForTestWithAllowMissingDependencies, |
| 3968 | android.PrepareForTestWithAndroidMk, |
| 3969 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 3970 | // explicitly set following platform variables to make the test deterministic |
| 3971 | variables.Platform_sdk_final = &testCase.platform_sdk_final |
| 3972 | variables.Platform_sdk_version = &platform_sdk_version |
| 3973 | variables.Platform_sdk_codename = &platform_sdk_codename |
Harshit Mahajan | 18845d0 | 2023-01-11 18:39:12 +0000 | [diff] [blame] | 3974 | variables.Unbundled_build = proptools.BoolPtr(true) |
Harshit Mahajan | 8f202ad | 2023-01-09 20:45:55 +0000 | [diff] [blame] | 3975 | variables.Unbundled_build_apps = []string{"sampleModule"} |
| 3976 | }), |
| 3977 | ) |
| 3978 | |
| 3979 | errorHandler := android.FixtureExpectsNoErrors |
| 3980 | if errExpected { |
| 3981 | errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern(testCase.expectedError) |
| 3982 | } |
| 3983 | result := fixture.ExtendWithErrorHandler(errorHandler).RunTestWithBp(t, bp) |
| 3984 | |
| 3985 | if !errExpected { |
| 3986 | foo := result.ModuleForTests("foo", "android_common") |
| 3987 | manifestFixerArgs := foo.Output("manifest_fixer/AndroidManifest.xml").Args["args"] |
| 3988 | android.AssertStringDoesContain(t, testCase.name, manifestFixerArgs, "--targetSdkVersion "+testCase.targetSdkVersionExpected) |
| 3989 | } |
| 3990 | } |
| 3991 | } |
| 3992 | |
Colin Cross | 412436f | 2022-04-07 17:40:07 -0700 | [diff] [blame] | 3993 | func TestAppMissingCertificateAllowMissingDependencies(t *testing.T) { |
| 3994 | result := android.GroupFixturePreparers( |
| 3995 | PrepareForTestWithJavaDefaultModules, |
| 3996 | android.PrepareForTestWithAllowMissingDependencies, |
| 3997 | android.PrepareForTestWithAndroidMk, |
| 3998 | ).RunTestWithBp(t, ` |
| 3999 | android_app { |
| 4000 | name: "foo", |
| 4001 | srcs: ["a.java"], |
| 4002 | certificate: ":missing_certificate", |
| 4003 | sdk_version: "current", |
Zyan Wu | b7550aa | 2023-05-18 15:46:31 +0800 | [diff] [blame] | 4004 | } |
| 4005 | |
| 4006 | android_app { |
| 4007 | name: "bar", |
| 4008 | srcs: ["a.java"], |
| 4009 | certificate: ":missing_certificate", |
| 4010 | product_specific: true, |
| 4011 | sdk_version: "current", |
Colin Cross | 412436f | 2022-04-07 17:40:07 -0700 | [diff] [blame] | 4012 | }`) |
| 4013 | |
| 4014 | foo := result.ModuleForTests("foo", "android_common") |
| 4015 | fooApk := foo.Output("foo.apk") |
| 4016 | if fooApk.Rule != android.ErrorRule { |
| 4017 | t.Fatalf("expected ErrorRule for foo.apk, got %s", fooApk.Rule.String()) |
| 4018 | } |
| 4019 | android.AssertStringDoesContain(t, "expected error rule message", fooApk.Args["error"], "missing dependencies: missing_certificate\n") |
| 4020 | } |
Sam Delmerico | 8260249 | 2022-06-10 17:05:42 +0000 | [diff] [blame] | 4021 | |
| 4022 | func TestAppIncludesJniPackages(t *testing.T) { |
| 4023 | ctx := android.GroupFixturePreparers( |
| 4024 | PrepareForTestWithJavaDefaultModules, |
| 4025 | ).RunTestWithBp(t, ` |
| 4026 | android_library_import { |
| 4027 | name: "aary-nodeps", |
| 4028 | aars: ["aary.aar"], |
| 4029 | extract_jni: true, |
| 4030 | } |
| 4031 | |
| 4032 | android_library { |
| 4033 | name: "aary-lib", |
| 4034 | sdk_version: "current", |
| 4035 | min_sdk_version: "21", |
| 4036 | static_libs: ["aary-nodeps"], |
| 4037 | } |
| 4038 | |
| 4039 | android_app { |
| 4040 | name: "aary-lib-dep", |
| 4041 | sdk_version: "current", |
| 4042 | min_sdk_version: "21", |
| 4043 | manifest: "AndroidManifest.xml", |
| 4044 | static_libs: ["aary-lib"], |
| 4045 | use_embedded_native_libs: true, |
| 4046 | } |
| 4047 | |
| 4048 | android_app { |
| 4049 | name: "aary-import-dep", |
| 4050 | sdk_version: "current", |
| 4051 | min_sdk_version: "21", |
| 4052 | manifest: "AndroidManifest.xml", |
| 4053 | static_libs: ["aary-nodeps"], |
| 4054 | use_embedded_native_libs: true, |
| 4055 | } |
| 4056 | |
| 4057 | android_app { |
| 4058 | name: "aary-no-use-embedded", |
| 4059 | sdk_version: "current", |
| 4060 | min_sdk_version: "21", |
| 4061 | manifest: "AndroidManifest.xml", |
| 4062 | static_libs: ["aary-nodeps"], |
| 4063 | }`) |
| 4064 | |
| 4065 | testCases := []struct { |
| 4066 | name string |
| 4067 | hasPackage bool |
| 4068 | }{ |
| 4069 | { |
| 4070 | name: "aary-import-dep", |
| 4071 | hasPackage: true, |
| 4072 | }, |
| 4073 | { |
| 4074 | name: "aary-lib-dep", |
| 4075 | hasPackage: true, |
| 4076 | }, |
| 4077 | { |
| 4078 | name: "aary-no-use-embedded", |
| 4079 | hasPackage: false, |
| 4080 | }, |
| 4081 | } |
| 4082 | |
| 4083 | for _, tc := range testCases { |
| 4084 | t.Run(tc.name, func(t *testing.T) { |
| 4085 | app := ctx.ModuleForTests(tc.name, "android_common") |
| 4086 | |
| 4087 | outputFile := "jnilibs.zip" |
| 4088 | jniOutputLibZip := app.MaybeOutput(outputFile) |
| 4089 | if jniOutputLibZip.Rule == nil && !tc.hasPackage { |
| 4090 | return |
| 4091 | } |
| 4092 | |
| 4093 | jniPackage := "arm64-v8a_jni.zip" |
| 4094 | inputs := jniOutputLibZip.Inputs |
| 4095 | foundPackage := false |
| 4096 | for i := 0; i < len(inputs); i++ { |
| 4097 | if strings.Contains(inputs[i].String(), jniPackage) { |
| 4098 | foundPackage = true |
| 4099 | } |
| 4100 | } |
| 4101 | if foundPackage != tc.hasPackage { |
| 4102 | t.Errorf("expected to find %v in %v inputs; inputs = %v", jniPackage, outputFile, inputs) |
| 4103 | } |
| 4104 | }) |
| 4105 | } |
| 4106 | } |
Spandan Das | 9f7ae7f | 2022-07-25 00:34:18 +0000 | [diff] [blame] | 4107 | |
| 4108 | func TestTargetSdkVersionMtsTests(t *testing.T) { |
| 4109 | platformSdkCodename := "Tiramisu" |
| 4110 | android_test := "android_test" |
| 4111 | android_test_helper_app := "android_test_helper_app" |
| 4112 | bpTemplate := ` |
| 4113 | %v { |
| 4114 | name: "mytest", |
| 4115 | target_sdk_version: "%v", |
| 4116 | test_suites: ["othersuite", "%v"], |
| 4117 | } |
| 4118 | ` |
| 4119 | testCases := []struct { |
| 4120 | desc string |
| 4121 | moduleType string |
| 4122 | targetSdkVersionInBp string |
| 4123 | targetSdkVersionExpected string |
| 4124 | testSuites string |
| 4125 | }{ |
| 4126 | { |
| 4127 | desc: "Non-MTS android_test_apps targeting current should not be upgraded to 10000", |
| 4128 | moduleType: android_test, |
| 4129 | targetSdkVersionInBp: "current", |
| 4130 | targetSdkVersionExpected: platformSdkCodename, |
| 4131 | testSuites: "non-mts-suite", |
| 4132 | }, |
| 4133 | { |
| 4134 | desc: "MTS android_test_apps targeting released sdks should not be upgraded to 10000", |
| 4135 | moduleType: android_test, |
| 4136 | targetSdkVersionInBp: "29", |
| 4137 | targetSdkVersionExpected: "29", |
| 4138 | testSuites: "mts-suite", |
| 4139 | }, |
| 4140 | { |
| 4141 | desc: "MTS android_test_apps targeting current should be upgraded to 10000", |
| 4142 | moduleType: android_test, |
| 4143 | targetSdkVersionInBp: "current", |
| 4144 | targetSdkVersionExpected: "10000", |
| 4145 | testSuites: "mts-suite", |
| 4146 | }, |
| 4147 | { |
| 4148 | desc: "MTS android_test_helper_apps targeting current should be upgraded to 10000", |
| 4149 | moduleType: android_test_helper_app, |
| 4150 | targetSdkVersionInBp: "current", |
| 4151 | targetSdkVersionExpected: "10000", |
| 4152 | testSuites: "mts-suite", |
| 4153 | }, |
| 4154 | } |
| 4155 | fixture := android.GroupFixturePreparers( |
| 4156 | prepareForJavaTest, |
| 4157 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 4158 | variables.Platform_sdk_codename = &platformSdkCodename |
| 4159 | variables.Platform_version_active_codenames = []string{platformSdkCodename} |
| 4160 | }), |
| 4161 | ) |
| 4162 | for _, testCase := range testCases { |
| 4163 | result := fixture.RunTestWithBp(t, fmt.Sprintf(bpTemplate, testCase.moduleType, testCase.targetSdkVersionInBp, testCase.testSuites)) |
| 4164 | mytest := result.ModuleForTests("mytest", "android_common") |
| 4165 | manifestFixerArgs := mytest.Output("manifest_fixer/AndroidManifest.xml").Args["args"] |
| 4166 | android.AssertStringDoesContain(t, testCase.desc, manifestFixerArgs, "--targetSdkVersion "+testCase.targetSdkVersionExpected) |
| 4167 | } |
| 4168 | } |
Andrei Onea | 580636b | 2022-08-17 16:53:46 +0000 | [diff] [blame] | 4169 | |
| 4170 | func TestPrivappAllowlist(t *testing.T) { |
| 4171 | testJavaError(t, "privileged must be set in order to use privapp_allowlist", ` |
| 4172 | android_app { |
| 4173 | name: "foo", |
| 4174 | srcs: ["a.java"], |
| 4175 | privapp_allowlist: "perms.xml", |
| 4176 | } |
| 4177 | `) |
| 4178 | |
| 4179 | result := PrepareForTestWithJavaDefaultModules.RunTestWithBp( |
| 4180 | t, |
| 4181 | ` |
| 4182 | android_app { |
| 4183 | name: "foo", |
| 4184 | srcs: ["a.java"], |
Sam Delmerico | 15809f8 | 2023-05-15 17:21:47 -0400 | [diff] [blame] | 4185 | privapp_allowlist: "privapp_allowlist_com.android.foo.xml", |
Andrei Onea | 580636b | 2022-08-17 16:53:46 +0000 | [diff] [blame] | 4186 | privileged: true, |
Andrei Onea | 580636b | 2022-08-17 16:53:46 +0000 | [diff] [blame] | 4187 | sdk_version: "current", |
| 4188 | } |
| 4189 | override_android_app { |
| 4190 | name: "bar", |
| 4191 | base: "foo", |
| 4192 | package_name: "com.google.android.foo", |
| 4193 | } |
| 4194 | `, |
| 4195 | ) |
| 4196 | app := result.ModuleForTests("foo", "android_common") |
| 4197 | overrideApp := result.ModuleForTests("foo", "android_common_bar") |
| 4198 | |
Sam Delmerico | 15809f8 | 2023-05-15 17:21:47 -0400 | [diff] [blame] | 4199 | // verify that privapp allowlist is created for override apps |
Andrei Onea | 580636b | 2022-08-17 16:53:46 +0000 | [diff] [blame] | 4200 | overrideApp.Output("out/soong/.intermediates/foo/android_common_bar/privapp_allowlist_com.google.android.foo.xml") |
Sam Delmerico | 15809f8 | 2023-05-15 17:21:47 -0400 | [diff] [blame] | 4201 | expectedAllowlistInput := "privapp_allowlist_com.android.foo.xml" |
| 4202 | overrideActualAllowlistInput := overrideApp.Rule("modifyAllowlist").Input.String() |
| 4203 | if expectedAllowlistInput != overrideActualAllowlistInput { |
| 4204 | t.Errorf("expected override allowlist to be %q; got %q", expectedAllowlistInput, overrideActualAllowlistInput) |
Andrei Onea | 580636b | 2022-08-17 16:53:46 +0000 | [diff] [blame] | 4205 | } |
| 4206 | |
| 4207 | // verify that permissions are copied to device |
Anton Hansson | 0e486a4 | 2023-06-01 16:38:35 +0000 | [diff] [blame] | 4208 | app.Output("out/soong/target/product/test_device/system/etc/permissions/foo.xml") |
| 4209 | overrideApp.Output("out/soong/target/product/test_device/system/etc/permissions/bar.xml") |
Andrei Onea | 580636b | 2022-08-17 16:53:46 +0000 | [diff] [blame] | 4210 | } |
Sam Delmerico | b1daccd | 2023-05-25 14:45:30 -0400 | [diff] [blame] | 4211 | |
| 4212 | func TestPrivappAllowlistAndroidMk(t *testing.T) { |
| 4213 | result := android.GroupFixturePreparers( |
| 4214 | PrepareForTestWithJavaDefaultModules, |
| 4215 | android.PrepareForTestWithAndroidMk, |
| 4216 | ).RunTestWithBp( |
| 4217 | t, |
| 4218 | ` |
| 4219 | android_app { |
| 4220 | name: "foo", |
| 4221 | srcs: ["a.java"], |
| 4222 | privapp_allowlist: "privapp_allowlist_com.android.foo.xml", |
| 4223 | privileged: true, |
| 4224 | sdk_version: "current", |
| 4225 | } |
| 4226 | override_android_app { |
| 4227 | name: "bar", |
| 4228 | base: "foo", |
| 4229 | package_name: "com.google.android.foo", |
| 4230 | } |
| 4231 | `, |
| 4232 | ) |
| 4233 | baseApp := result.ModuleForTests("foo", "android_common") |
| 4234 | overrideApp := result.ModuleForTests("foo", "android_common_bar") |
| 4235 | |
| 4236 | baseAndroidApp := baseApp.Module().(*AndroidApp) |
| 4237 | baseEntries := android.AndroidMkEntriesForTest(t, result.TestContext, baseAndroidApp)[0] |
| 4238 | android.AssertStringMatches( |
| 4239 | t, |
| 4240 | "androidmk has incorrect LOCAL_SOONG_INSTALLED_MODULE; expected to find foo.apk", |
| 4241 | baseEntries.EntryMap["LOCAL_SOONG_INSTALLED_MODULE"][0], |
| 4242 | "\\S+foo.apk", |
| 4243 | ) |
| 4244 | android.AssertStringMatches( |
| 4245 | t, |
| 4246 | "androidmk has incorrect LOCAL_SOONG_INSTALL_PAIRS; expected to it to include foo.apk", |
| 4247 | baseEntries.EntryMap["LOCAL_SOONG_INSTALL_PAIRS"][0], |
| 4248 | "\\S+foo.apk", |
| 4249 | ) |
| 4250 | android.AssertStringMatches( |
| 4251 | t, |
| 4252 | "androidmk has incorrect LOCAL_SOONG_INSTALL_PAIRS; expected to it to include app", |
| 4253 | baseEntries.EntryMap["LOCAL_SOONG_INSTALL_PAIRS"][0], |
| 4254 | "\\S+foo.apk:\\S+/target/product/test_device/system/priv-app/foo/foo.apk", |
| 4255 | ) |
| 4256 | android.AssertStringMatches( |
| 4257 | t, |
| 4258 | "androidmk has incorrect LOCAL_SOONG_INSTALL_PAIRS; expected to it to include privapp_allowlist", |
| 4259 | baseEntries.EntryMap["LOCAL_SOONG_INSTALL_PAIRS"][0], |
Anton Hansson | 0e486a4 | 2023-06-01 16:38:35 +0000 | [diff] [blame] | 4260 | "privapp_allowlist_com.android.foo.xml:\\S+/target/product/test_device/system/etc/permissions/foo.xml", |
Sam Delmerico | b1daccd | 2023-05-25 14:45:30 -0400 | [diff] [blame] | 4261 | ) |
| 4262 | |
| 4263 | overrideAndroidApp := overrideApp.Module().(*AndroidApp) |
| 4264 | overrideEntries := android.AndroidMkEntriesForTest(t, result.TestContext, overrideAndroidApp)[0] |
| 4265 | android.AssertStringMatches( |
| 4266 | t, |
| 4267 | "androidmk has incorrect LOCAL_SOONG_INSTALLED_MODULE; expected to find bar.apk", |
| 4268 | overrideEntries.EntryMap["LOCAL_SOONG_INSTALLED_MODULE"][0], |
| 4269 | "\\S+bar.apk", |
| 4270 | ) |
| 4271 | android.AssertStringMatches( |
| 4272 | t, |
| 4273 | "androidmk has incorrect LOCAL_SOONG_INSTALL_PAIRS; expected to it to include bar.apk", |
| 4274 | overrideEntries.EntryMap["LOCAL_SOONG_INSTALL_PAIRS"][0], |
| 4275 | "\\S+bar.apk", |
| 4276 | ) |
| 4277 | android.AssertStringMatches( |
| 4278 | t, |
| 4279 | "androidmk has incorrect LOCAL_SOONG_INSTALL_PAIRS; expected to it to include app", |
| 4280 | overrideEntries.EntryMap["LOCAL_SOONG_INSTALL_PAIRS"][0], |
| 4281 | "\\S+bar.apk:\\S+/target/product/test_device/system/priv-app/bar/bar.apk", |
| 4282 | ) |
| 4283 | android.AssertStringMatches( |
| 4284 | t, |
| 4285 | "androidmk has incorrect LOCAL_SOONG_INSTALL_PAIRS; expected to it to include privapp_allowlist", |
| 4286 | overrideEntries.EntryMap["LOCAL_SOONG_INSTALL_PAIRS"][0], |
Anton Hansson | 0e486a4 | 2023-06-01 16:38:35 +0000 | [diff] [blame] | 4287 | "\\S+soong/.intermediates/foo/android_common_bar/privapp_allowlist_com.google.android.foo.xml:\\S+/target/product/test_device/system/etc/permissions/bar.xml", |
Sam Delmerico | b1daccd | 2023-05-25 14:45:30 -0400 | [diff] [blame] | 4288 | ) |
| 4289 | } |
Sam Delmerico | 0e0d96e | 2023-08-18 22:43:28 +0000 | [diff] [blame] | 4290 | |
| 4291 | func TestApexGlobalMinSdkVersionOverride(t *testing.T) { |
| 4292 | result := android.GroupFixturePreparers( |
| 4293 | PrepareForTestWithJavaDefaultModules, |
| 4294 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 4295 | variables.ApexGlobalMinSdkVersionOverride = proptools.StringPtr("Tiramisu") |
| 4296 | }), |
| 4297 | ).RunTestWithBp(t, ` |
| 4298 | android_app { |
| 4299 | name: "com.android.bar", |
| 4300 | srcs: ["a.java"], |
| 4301 | sdk_version: "current", |
| 4302 | } |
| 4303 | android_app { |
| 4304 | name: "com.android.foo", |
| 4305 | srcs: ["a.java"], |
| 4306 | sdk_version: "current", |
| 4307 | min_sdk_version: "S", |
| 4308 | updatable: true, |
| 4309 | } |
| 4310 | override_android_app { |
| 4311 | name: "com.android.go.foo", |
| 4312 | base: "com.android.foo", |
| 4313 | } |
| 4314 | `) |
| 4315 | foo := result.ModuleForTests("com.android.foo", "android_common").Rule("manifestFixer") |
| 4316 | fooOverride := result.ModuleForTests("com.android.foo", "android_common_com.android.go.foo").Rule("manifestFixer") |
| 4317 | bar := result.ModuleForTests("com.android.bar", "android_common").Rule("manifestFixer") |
| 4318 | |
| 4319 | android.AssertStringDoesContain(t, |
| 4320 | "expected manifest fixer to set com.android.bar minSdkVersion to S", |
| 4321 | bar.BuildParams.Args["args"], |
| 4322 | "--minSdkVersion S", |
| 4323 | ) |
| 4324 | android.AssertStringDoesContain(t, |
| 4325 | "com.android.foo: expected manifest fixer to set minSdkVersion to T", |
| 4326 | foo.BuildParams.Args["args"], |
| 4327 | "--minSdkVersion T", |
| 4328 | ) |
| 4329 | android.AssertStringDoesContain(t, |
| 4330 | "com.android.go.foo: expected manifest fixer to set minSdkVersion to T", |
| 4331 | fooOverride.BuildParams.Args["args"], |
| 4332 | "--minSdkVersion T", |
| 4333 | ) |
| 4334 | |
| 4335 | } |
Jihoon Kang | 84b2589 | 2023-12-01 22:01:06 +0000 | [diff] [blame] | 4336 | |
| 4337 | func TestAppFlagsPackages(t *testing.T) { |
| 4338 | ctx := testApp(t, ` |
| 4339 | android_app { |
| 4340 | name: "foo", |
| 4341 | srcs: ["a.java"], |
| 4342 | sdk_version: "current", |
| 4343 | flags_packages: [ |
| 4344 | "bar", |
| 4345 | "baz", |
| 4346 | ], |
| 4347 | } |
| 4348 | aconfig_declarations { |
| 4349 | name: "bar", |
Dennis Shen | 4e7773d | 2024-01-05 19:06:50 +0000 | [diff] [blame] | 4350 | package: "com.example.package.bar", |
Jihoon Kang | 84b2589 | 2023-12-01 22:01:06 +0000 | [diff] [blame] | 4351 | srcs: [ |
| 4352 | "bar.aconfig", |
| 4353 | ], |
| 4354 | } |
| 4355 | aconfig_declarations { |
| 4356 | name: "baz", |
Dennis Shen | 4e7773d | 2024-01-05 19:06:50 +0000 | [diff] [blame] | 4357 | package: "com.example.package.baz", |
Jihoon Kang | 84b2589 | 2023-12-01 22:01:06 +0000 | [diff] [blame] | 4358 | srcs: [ |
| 4359 | "baz.aconfig", |
| 4360 | ], |
| 4361 | } |
| 4362 | `) |
| 4363 | |
| 4364 | foo := ctx.ModuleForTests("foo", "android_common") |
| 4365 | |
| 4366 | // android_app module depends on aconfig_declarations listed in flags_packages |
| 4367 | android.AssertBoolEquals(t, "foo expected to depend on bar", true, |
| 4368 | CheckModuleHasDependency(t, ctx, "foo", "android_common", "bar")) |
| 4369 | |
| 4370 | android.AssertBoolEquals(t, "foo expected to depend on baz", true, |
| 4371 | CheckModuleHasDependency(t, ctx, "foo", "android_common", "baz")) |
| 4372 | |
| 4373 | aapt2LinkRule := foo.Rule("android/soong/java.aapt2Link") |
| 4374 | linkInFlags := aapt2LinkRule.Args["inFlags"] |
| 4375 | android.AssertStringDoesContain(t, |
| 4376 | "aapt2 link command expected to pass feature flags arguments", |
| 4377 | linkInFlags, |
| 4378 | "--feature-flags @out/soong/.intermediates/bar/intermediate.txt --feature-flags @out/soong/.intermediates/baz/intermediate.txt", |
| 4379 | ) |
| 4380 | } |
Spandan Das | 0727ba7 | 2024-02-13 16:37:43 +0000 | [diff] [blame] | 4381 | |
| 4382 | // Test that dexpreopt is disabled if an optional_uses_libs exists, but does not provide an implementation. |
| 4383 | func TestNoDexpreoptOptionalUsesLibDoesNotHaveImpl(t *testing.T) { |
| 4384 | bp := ` |
| 4385 | java_sdk_library_import { |
| 4386 | name: "sdklib_noimpl", |
| 4387 | public: { |
| 4388 | jars: ["stub.jar"], |
| 4389 | }, |
| 4390 | } |
| 4391 | android_app { |
| 4392 | name: "app", |
| 4393 | srcs: ["a.java"], |
| 4394 | sdk_version: "current", |
| 4395 | optional_uses_libs: [ |
| 4396 | "sdklib_noimpl", |
| 4397 | ], |
| 4398 | } |
| 4399 | ` |
| 4400 | result := prepareForJavaTest.RunTestWithBp(t, bp) |
| 4401 | dexpreopt := result.ModuleForTests("app", "android_common").MaybeRule("dexpreopt").Rule |
| 4402 | android.AssertBoolEquals(t, "dexpreopt should be disabled if optional_uses_libs does not have an implementation", true, dexpreopt == nil) |
| 4403 | } |
yangbill | 2af0b6e | 2024-03-15 09:29:29 +0000 | [diff] [blame] | 4404 | |
| 4405 | func TestAppStem(t *testing.T) { |
| 4406 | ctx := testApp(t, ` |
| 4407 | android_app { |
| 4408 | name: "foo", |
| 4409 | srcs: ["a.java"], |
| 4410 | stem: "foo-new", |
| 4411 | sdk_version: "current", |
| 4412 | }`) |
| 4413 | |
| 4414 | foo := ctx.ModuleForTests("foo", "android_common") |
| 4415 | |
| 4416 | outputs := fmt.Sprint(foo.AllOutputs()) |
| 4417 | if !strings.Contains(outputs, "foo-new.apk") { |
| 4418 | t.Errorf("Module output does not contain expected apk %s", "foo-new.apk") |
| 4419 | } |
| 4420 | } |