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