Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 1 | // Copyright (C) 2021 The Android Open Source Project |
| 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 apex |
| 16 | |
| 17 | import ( |
Paul Duffin | ffa8375 | 2021-06-09 14:32:53 +0100 | [diff] [blame] | 18 | "fmt" |
| 19 | "strings" |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 20 | "testing" |
| 21 | |
| 22 | "android/soong/android" |
Jiakai Zhang | b95998b | 2023-05-11 16:39:27 +0100 | [diff] [blame] | 23 | "android/soong/dexpreopt" |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 24 | "android/soong/java" |
Martin Stjernholm | b1e61cb | 2021-09-08 21:56:18 +0100 | [diff] [blame] | 25 | |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 26 | "github.com/google/blueprint" |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 27 | "github.com/google/blueprint/proptools" |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 28 | ) |
| 29 | |
| 30 | // Contains tests for platform_bootclasspath logic from java/platform_bootclasspath.go that requires |
| 31 | // apexes. |
| 32 | |
| 33 | var prepareForTestWithPlatformBootclasspath = android.GroupFixturePreparers( |
Jiakai Zhang | b95998b | 2023-05-11 16:39:27 +0100 | [diff] [blame] | 34 | java.PrepareForTestWithJavaDefaultModules, |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 35 | PrepareForTestWithApexBuildComponents, |
| 36 | ) |
| 37 | |
Paul Duffin | ffa8375 | 2021-06-09 14:32:53 +0100 | [diff] [blame] | 38 | func TestPlatformBootclasspath_Fragments(t *testing.T) { |
| 39 | result := android.GroupFixturePreparers( |
| 40 | prepareForTestWithPlatformBootclasspath, |
Paul Duffin | dc3f956 | 2021-06-09 15:31:05 +0100 | [diff] [blame] | 41 | prepareForTestWithMyapex, |
Paul Duffin | ffa8375 | 2021-06-09 14:32:53 +0100 | [diff] [blame] | 42 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 43 | java.FixtureWithLastReleaseApis("foo"), |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 44 | java.FixtureConfigureApexBootJars("myapex:bar"), |
Paul Duffin | ffa8375 | 2021-06-09 14:32:53 +0100 | [diff] [blame] | 45 | android.FixtureWithRootAndroidBp(` |
| 46 | platform_bootclasspath { |
| 47 | name: "platform-bootclasspath", |
| 48 | fragments: [ |
Paul Duffin | dc3f956 | 2021-06-09 15:31:05 +0100 | [diff] [blame] | 49 | { |
| 50 | apex: "myapex", |
| 51 | module:"bar-fragment", |
| 52 | }, |
Paul Duffin | ffa8375 | 2021-06-09 14:32:53 +0100 | [diff] [blame] | 53 | ], |
| 54 | hidden_api: { |
| 55 | unsupported: [ |
| 56 | "unsupported.txt", |
| 57 | ], |
| 58 | removed: [ |
| 59 | "removed.txt", |
| 60 | ], |
| 61 | max_target_r_low_priority: [ |
| 62 | "max-target-r-low-priority.txt", |
| 63 | ], |
| 64 | max_target_q: [ |
| 65 | "max-target-q.txt", |
| 66 | ], |
| 67 | max_target_p: [ |
| 68 | "max-target-p.txt", |
| 69 | ], |
| 70 | max_target_o_low_priority: [ |
| 71 | "max-target-o-low-priority.txt", |
| 72 | ], |
| 73 | blocked: [ |
| 74 | "blocked.txt", |
| 75 | ], |
| 76 | unsupported_packages: [ |
| 77 | "unsupported-packages.txt", |
| 78 | ], |
| 79 | }, |
| 80 | } |
| 81 | |
Paul Duffin | dc3f956 | 2021-06-09 15:31:05 +0100 | [diff] [blame] | 82 | apex { |
| 83 | name: "myapex", |
| 84 | key: "myapex.key", |
| 85 | bootclasspath_fragments: [ |
| 86 | "bar-fragment", |
| 87 | ], |
| 88 | updatable: false, |
Spandan Das | 38c64f6 | 2024-02-12 15:00:15 +0000 | [diff] [blame] | 89 | min_sdk_version: "30", // R |
Paul Duffin | dc3f956 | 2021-06-09 15:31:05 +0100 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | apex_key { |
| 93 | name: "myapex.key", |
| 94 | public_key: "testkey.avbpubkey", |
| 95 | private_key: "testkey.pem", |
| 96 | } |
| 97 | |
Paul Duffin | ffa8375 | 2021-06-09 14:32:53 +0100 | [diff] [blame] | 98 | bootclasspath_fragment { |
| 99 | name: "bar-fragment", |
| 100 | contents: ["bar"], |
Paul Duffin | dc3f956 | 2021-06-09 15:31:05 +0100 | [diff] [blame] | 101 | apex_available: ["myapex"], |
Paul Duffin | ffa8375 | 2021-06-09 14:32:53 +0100 | [diff] [blame] | 102 | api: { |
| 103 | stub_libs: ["foo"], |
| 104 | }, |
| 105 | hidden_api: { |
| 106 | unsupported: [ |
| 107 | "bar-unsupported.txt", |
| 108 | ], |
| 109 | removed: [ |
| 110 | "bar-removed.txt", |
| 111 | ], |
| 112 | max_target_r_low_priority: [ |
| 113 | "bar-max-target-r-low-priority.txt", |
| 114 | ], |
| 115 | max_target_q: [ |
| 116 | "bar-max-target-q.txt", |
| 117 | ], |
| 118 | max_target_p: [ |
| 119 | "bar-max-target-p.txt", |
| 120 | ], |
| 121 | max_target_o_low_priority: [ |
| 122 | "bar-max-target-o-low-priority.txt", |
| 123 | ], |
| 124 | blocked: [ |
| 125 | "bar-blocked.txt", |
| 126 | ], |
| 127 | unsupported_packages: [ |
| 128 | "bar-unsupported-packages.txt", |
| 129 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 130 | split_packages: ["*"], |
Paul Duffin | ffa8375 | 2021-06-09 14:32:53 +0100 | [diff] [blame] | 131 | }, |
| 132 | } |
| 133 | |
| 134 | java_library { |
| 135 | name: "bar", |
Paul Duffin | dc3f956 | 2021-06-09 15:31:05 +0100 | [diff] [blame] | 136 | apex_available: ["myapex"], |
Paul Duffin | ffa8375 | 2021-06-09 14:32:53 +0100 | [diff] [blame] | 137 | srcs: ["a.java"], |
| 138 | system_modules: "none", |
| 139 | sdk_version: "none", |
| 140 | compile_dex: true, |
Paul Duffin | dc3f956 | 2021-06-09 15:31:05 +0100 | [diff] [blame] | 141 | permitted_packages: ["bar"], |
Spandan Das | 38c64f6 | 2024-02-12 15:00:15 +0000 | [diff] [blame] | 142 | min_sdk_version: "30", // R |
Paul Duffin | ffa8375 | 2021-06-09 14:32:53 +0100 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | java_sdk_library { |
| 146 | name: "foo", |
| 147 | srcs: ["a.java"], |
| 148 | public: { |
| 149 | enabled: true, |
| 150 | }, |
| 151 | compile_dex: true, |
| 152 | } |
| 153 | `), |
| 154 | ).RunTest(t) |
| 155 | |
| 156 | pbcp := result.Module("platform-bootclasspath", "android_common") |
Colin Cross | 5a37718 | 2023-12-14 14:46:23 -0800 | [diff] [blame] | 157 | info, _ := android.SingletonModuleProvider(result, pbcp, java.MonolithicHiddenAPIInfoProvider) |
Paul Duffin | ffa8375 | 2021-06-09 14:32:53 +0100 | [diff] [blame] | 158 | |
| 159 | for _, category := range java.HiddenAPIFlagFileCategories { |
Cole Faust | 22e8abc | 2024-01-23 17:52:13 -0800 | [diff] [blame] | 160 | name := category.PropertyName() |
Paul Duffin | ffa8375 | 2021-06-09 14:32:53 +0100 | [diff] [blame] | 161 | message := fmt.Sprintf("category %s", name) |
| 162 | filename := strings.ReplaceAll(name, "_", "-") |
| 163 | expected := []string{fmt.Sprintf("%s.txt", filename), fmt.Sprintf("bar-%s.txt", filename)} |
| 164 | android.AssertPathsRelativeToTopEquals(t, message, expected, info.FlagsFilesByCategory[category]) |
| 165 | } |
| 166 | |
Spandan Das | 38c64f6 | 2024-02-12 15:00:15 +0000 | [diff] [blame] | 167 | android.AssertPathsRelativeToTopEquals(t, "annotation flags", []string{"out/soong/.intermediates/bar-fragment/android_common_apex30/modular-hiddenapi/annotation-flags.csv"}, info.AnnotationFlagsPaths) |
| 168 | android.AssertPathsRelativeToTopEquals(t, "metadata flags", []string{"out/soong/.intermediates/bar-fragment/android_common_apex30/modular-hiddenapi/metadata.csv"}, info.MetadataPaths) |
| 169 | android.AssertPathsRelativeToTopEquals(t, "index flags", []string{"out/soong/.intermediates/bar-fragment/android_common_apex30/modular-hiddenapi/index.csv"}, info.IndexPaths) |
Paul Duffin | 67b9d61 | 2021-07-21 17:38:47 +0100 | [diff] [blame] | 170 | |
Spandan Das | 38c64f6 | 2024-02-12 15:00:15 +0000 | [diff] [blame] | 171 | android.AssertArrayString(t, "stub flags", []string{"out/soong/.intermediates/bar-fragment/android_common_apex30/modular-hiddenapi/filtered-stub-flags.csv:out/soong/.intermediates/bar-fragment/android_common_apex30/modular-hiddenapi/signature-patterns.csv"}, info.StubFlagSubsets.RelativeToTop()) |
| 172 | android.AssertArrayString(t, "all flags", []string{"out/soong/.intermediates/bar-fragment/android_common_apex30/modular-hiddenapi/filtered-flags.csv:out/soong/.intermediates/bar-fragment/android_common_apex30/modular-hiddenapi/signature-patterns.csv"}, info.FlagSubsets.RelativeToTop()) |
Paul Duffin | ffa8375 | 2021-06-09 14:32:53 +0100 | [diff] [blame] | 173 | } |
| 174 | |
Paul Duffin | 191be3a | 2021-08-10 16:14:16 +0100 | [diff] [blame] | 175 | // TestPlatformBootclasspath_LegacyPrebuiltFragment verifies that the |
| 176 | // prebuilt_bootclasspath_fragment falls back to using the complete stub-flags/all-flags if the |
| 177 | // filtered files are not provided. |
| 178 | // |
| 179 | // TODO: Remove once all prebuilts use the filtered_... properties. |
| 180 | func TestPlatformBootclasspath_LegacyPrebuiltFragment(t *testing.T) { |
| 181 | result := android.GroupFixturePreparers( |
| 182 | prepareForTestWithPlatformBootclasspath, |
| 183 | java.FixtureConfigureApexBootJars("myapex:foo"), |
| 184 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 185 | ).RunTestWithBp(t, ` |
| 186 | prebuilt_apex { |
| 187 | name: "myapex", |
| 188 | src: "myapex.apex", |
| 189 | exported_bootclasspath_fragments: ["mybootclasspath-fragment"], |
| 190 | } |
| 191 | |
| 192 | // A prebuilt java_sdk_library_import that is not preferred by default but will be preferred |
| 193 | // because AlwaysUsePrebuiltSdks() is true. |
| 194 | java_sdk_library_import { |
| 195 | name: "foo", |
| 196 | prefer: false, |
| 197 | shared_library: false, |
| 198 | permitted_packages: ["foo"], |
| 199 | public: { |
| 200 | jars: ["sdk_library/public/foo-stubs.jar"], |
| 201 | stub_srcs: ["sdk_library/public/foo_stub_sources"], |
| 202 | current_api: "sdk_library/public/foo.txt", |
| 203 | removed_api: "sdk_library/public/foo-removed.txt", |
| 204 | sdk_version: "current", |
| 205 | }, |
| 206 | apex_available: ["myapex"], |
| 207 | } |
| 208 | |
| 209 | prebuilt_bootclasspath_fragment { |
| 210 | name: "mybootclasspath-fragment", |
| 211 | apex_available: [ |
| 212 | "myapex", |
| 213 | ], |
| 214 | contents: [ |
| 215 | "foo", |
| 216 | ], |
| 217 | hidden_api: { |
| 218 | stub_flags: "prebuilt-stub-flags.csv", |
| 219 | annotation_flags: "prebuilt-annotation-flags.csv", |
| 220 | metadata: "prebuilt-metadata.csv", |
| 221 | index: "prebuilt-index.csv", |
| 222 | all_flags: "prebuilt-all-flags.csv", |
| 223 | }, |
| 224 | } |
| 225 | |
| 226 | platform_bootclasspath { |
| 227 | name: "myplatform-bootclasspath", |
| 228 | fragments: [ |
| 229 | { |
| 230 | apex: "myapex", |
| 231 | module:"mybootclasspath-fragment", |
| 232 | }, |
| 233 | ], |
| 234 | } |
| 235 | `, |
| 236 | ) |
| 237 | |
| 238 | pbcp := result.Module("myplatform-bootclasspath", "android_common") |
Colin Cross | 5a37718 | 2023-12-14 14:46:23 -0800 | [diff] [blame] | 239 | info, _ := android.SingletonModuleProvider(result, pbcp, java.MonolithicHiddenAPIInfoProvider) |
Paul Duffin | 191be3a | 2021-08-10 16:14:16 +0100 | [diff] [blame] | 240 | |
| 241 | android.AssertArrayString(t, "stub flags", []string{"prebuilt-stub-flags.csv:out/soong/.intermediates/mybootclasspath-fragment/android_common_myapex/modular-hiddenapi/signature-patterns.csv"}, info.StubFlagSubsets.RelativeToTop()) |
| 242 | android.AssertArrayString(t, "all flags", []string{"prebuilt-all-flags.csv:out/soong/.intermediates/mybootclasspath-fragment/android_common_myapex/modular-hiddenapi/signature-patterns.csv"}, info.FlagSubsets.RelativeToTop()) |
| 243 | } |
| 244 | |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 245 | func TestPlatformBootclasspathDependencies(t *testing.T) { |
| 246 | result := android.GroupFixturePreparers( |
| 247 | prepareForTestWithPlatformBootclasspath, |
| 248 | prepareForTestWithArtApex, |
| 249 | prepareForTestWithMyapex, |
| 250 | // Configure some libraries in the art and framework boot images. |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 251 | java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz", "platform:foo"), |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 252 | java.FixtureConfigureApexBootJars("myapex:bar"), |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 253 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 254 | java.FixtureWithLastReleaseApis("foo"), |
Jiakai Zhang | b95998b | 2023-05-11 16:39:27 +0100 | [diff] [blame] | 255 | java.PrepareForTestWithDexpreopt, |
| 256 | dexpreopt.FixtureDisableDexpreoptBootImages(false), |
Colin Cross | a66b463 | 2024-08-08 15:50:47 -0700 | [diff] [blame] | 257 | android.PrepareForTestWithBuildFlag("RELEASE_HIDDEN_API_EXPORTABLE_STUBS", "true"), |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 258 | ).RunTestWithBp(t, ` |
| 259 | apex { |
| 260 | name: "com.android.art", |
| 261 | key: "com.android.art.key", |
| 262 | bootclasspath_fragments: [ |
| 263 | "art-bootclasspath-fragment", |
| 264 | ], |
| 265 | updatable: false, |
| 266 | } |
| 267 | |
| 268 | apex_key { |
| 269 | name: "com.android.art.key", |
| 270 | public_key: "com.android.art.avbpubkey", |
| 271 | private_key: "com.android.art.pem", |
| 272 | } |
| 273 | |
| 274 | bootclasspath_fragment { |
| 275 | name: "art-bootclasspath-fragment", |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 276 | image_name: "art", |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 277 | apex_available: [ |
| 278 | "com.android.art", |
| 279 | ], |
| 280 | contents: [ |
| 281 | "baz", |
| 282 | "quuz", |
| 283 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 284 | hidden_api: { |
| 285 | split_packages: ["*"], |
| 286 | }, |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | java_library { |
| 290 | name: "baz", |
| 291 | apex_available: [ |
| 292 | "com.android.art", |
| 293 | ], |
| 294 | srcs: ["b.java"], |
| 295 | installable: true, |
| 296 | } |
| 297 | |
| 298 | // Add a java_import that is not preferred and so won't have an appropriate apex variant created |
| 299 | // for it to make sure that the platform_bootclasspath doesn't try and add a dependency onto it. |
| 300 | java_import { |
| 301 | name: "baz", |
| 302 | apex_available: [ |
| 303 | "com.android.art", |
| 304 | ], |
| 305 | jars: ["b.jar"], |
| 306 | } |
| 307 | |
| 308 | java_library { |
| 309 | name: "quuz", |
| 310 | apex_available: [ |
| 311 | "com.android.art", |
| 312 | ], |
| 313 | srcs: ["b.java"], |
| 314 | installable: true, |
| 315 | } |
| 316 | |
| 317 | apex { |
| 318 | name: "myapex", |
| 319 | key: "myapex.key", |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 320 | bootclasspath_fragments: [ |
| 321 | "my-bootclasspath-fragment", |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 322 | ], |
| 323 | updatable: false, |
| 324 | } |
| 325 | |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 326 | bootclasspath_fragment { |
| 327 | name: "my-bootclasspath-fragment", |
| 328 | contents: ["bar"], |
| 329 | apex_available: ["myapex"], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 330 | hidden_api: { |
| 331 | split_packages: ["*"], |
| 332 | }, |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 333 | } |
| 334 | |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 335 | apex_key { |
| 336 | name: "myapex.key", |
| 337 | public_key: "testkey.avbpubkey", |
| 338 | private_key: "testkey.pem", |
| 339 | } |
| 340 | |
| 341 | java_sdk_library { |
| 342 | name: "foo", |
| 343 | srcs: ["b.java"], |
| 344 | } |
| 345 | |
| 346 | java_library { |
| 347 | name: "bar", |
| 348 | srcs: ["b.java"], |
| 349 | installable: true, |
| 350 | apex_available: ["myapex"], |
| 351 | permitted_packages: ["bar"], |
| 352 | } |
| 353 | |
| 354 | platform_bootclasspath { |
| 355 | name: "myplatform-bootclasspath", |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 356 | |
| 357 | fragments: [ |
| 358 | { |
| 359 | apex: "com.android.art", |
| 360 | module: "art-bootclasspath-fragment", |
| 361 | }, |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 362 | { |
| 363 | apex: "myapex", |
| 364 | module: "my-bootclasspath-fragment", |
| 365 | }, |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 366 | ], |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 367 | } |
| 368 | `, |
| 369 | ) |
| 370 | |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 371 | java.CheckPlatformBootclasspathModules(t, result, "myplatform-bootclasspath", []string{ |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 372 | // The configured contents of BootJars. |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 373 | "com.android.art:baz", |
| 374 | "com.android.art:quuz", |
| 375 | "platform:foo", |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 376 | |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 377 | // The configured contents of ApexBootJars. |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 378 | "myapex:bar", |
| 379 | }) |
| 380 | |
| 381 | java.CheckPlatformBootclasspathFragments(t, result, "myplatform-bootclasspath", []string{ |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 382 | "com.android.art:art-bootclasspath-fragment", |
| 383 | "myapex:my-bootclasspath-fragment", |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 384 | }) |
| 385 | |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 386 | // Make sure that the myplatform-bootclasspath has the correct dependencies. |
| 387 | CheckModuleDependencies(t, result.TestContext, "myplatform-bootclasspath", "android_common", []string{ |
Spandan Das | 64c9e0c | 2023-12-20 20:13:34 +0000 | [diff] [blame] | 388 | // source vs prebuilt selection metadata module |
| 389 | `platform:all_apex_contributions`, |
| 390 | |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 391 | // The following are stubs. |
Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 392 | `platform:android_stubs_current_exportable`, |
| 393 | `platform:android_system_stubs_current_exportable`, |
| 394 | `platform:android_test_stubs_current_exportable`, |
| 395 | `platform:legacy.core.platform.api.stubs.exportable`, |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 396 | |
| 397 | // Needed for generating the boot image. |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 398 | `platform:dex2oatd`, |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 399 | |
| 400 | // The configured contents of BootJars. |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 401 | `com.android.art:baz`, |
| 402 | `com.android.art:quuz`, |
| 403 | `platform:foo`, |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 404 | |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 405 | // The configured contents of ApexBootJars. |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 406 | `myapex:bar`, |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 407 | |
| 408 | // The fragments. |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 409 | `com.android.art:art-bootclasspath-fragment`, |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 410 | `myapex:my-bootclasspath-fragment`, |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 411 | }) |
| 412 | } |
| 413 | |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 414 | // TestPlatformBootclasspath_AlwaysUsePrebuiltSdks verifies that the build does not fail when |
Martin Stjernholm | b1e61cb | 2021-09-08 21:56:18 +0100 | [diff] [blame] | 415 | // AlwaysUsePrebuiltSdk() returns true. |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 416 | func TestPlatformBootclasspath_AlwaysUsePrebuiltSdks(t *testing.T) { |
| 417 | result := android.GroupFixturePreparers( |
| 418 | prepareForTestWithPlatformBootclasspath, |
| 419 | prepareForTestWithMyapex, |
| 420 | // Configure two libraries, the first is a java_sdk_library whose prebuilt will be used because |
Martin Stjernholm | b1e61cb | 2021-09-08 21:56:18 +0100 | [diff] [blame] | 421 | // of AlwaysUsePrebuiltsSdk(). The second is a normal library that is unaffected. The order |
| 422 | // matters, so that the dependencies resolved by the platform_bootclasspath matches the |
| 423 | // configured list. |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 424 | java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"), |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 425 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 426 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 427 | variables.Always_use_prebuilt_sdks = proptools.BoolPtr(true) |
| 428 | }), |
Colin Cross | a66b463 | 2024-08-08 15:50:47 -0700 | [diff] [blame] | 429 | android.PrepareForTestWithBuildFlag("RELEASE_HIDDEN_API_EXPORTABLE_STUBS", "true"), |
| 430 | |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 431 | java.FixtureWithPrebuiltApis(map[string][]string{ |
| 432 | "current": {}, |
| 433 | "30": {"foo"}, |
| 434 | }), |
| 435 | ).RunTestWithBp(t, ` |
| 436 | apex { |
| 437 | name: "myapex", |
| 438 | key: "myapex.key", |
| 439 | bootclasspath_fragments: [ |
| 440 | "mybootclasspath-fragment", |
| 441 | ], |
| 442 | updatable: false, |
| 443 | } |
| 444 | |
| 445 | apex_key { |
| 446 | name: "myapex.key", |
| 447 | public_key: "testkey.avbpubkey", |
| 448 | private_key: "testkey.pem", |
| 449 | } |
| 450 | |
| 451 | java_library { |
| 452 | name: "bar", |
| 453 | srcs: ["b.java"], |
| 454 | installable: true, |
| 455 | apex_available: ["myapex"], |
| 456 | permitted_packages: ["bar"], |
| 457 | } |
| 458 | |
| 459 | java_sdk_library { |
| 460 | name: "foo", |
| 461 | srcs: ["b.java"], |
| 462 | shared_library: false, |
| 463 | public: { |
| 464 | enabled: true, |
| 465 | }, |
| 466 | apex_available: ["myapex"], |
| 467 | permitted_packages: ["foo"], |
| 468 | } |
| 469 | |
Martin Stjernholm | b1e61cb | 2021-09-08 21:56:18 +0100 | [diff] [blame] | 470 | prebuilt_apex { |
| 471 | name: "myapex", |
| 472 | src: "myapex.apex", |
| 473 | exported_bootclasspath_fragments: ["mybootclasspath-fragment"], |
| 474 | } |
| 475 | |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 476 | // A prebuilt java_sdk_library_import that is not preferred by default but will be preferred |
| 477 | // because AlwaysUsePrebuiltSdks() is true. |
| 478 | java_sdk_library_import { |
| 479 | name: "foo", |
| 480 | prefer: false, |
| 481 | shared_library: false, |
Paul Duffin | 630b11e | 2021-07-15 13:35:26 +0100 | [diff] [blame] | 482 | permitted_packages: ["foo"], |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 483 | public: { |
| 484 | jars: ["sdk_library/public/foo-stubs.jar"], |
| 485 | stub_srcs: ["sdk_library/public/foo_stub_sources"], |
| 486 | current_api: "sdk_library/public/foo.txt", |
| 487 | removed_api: "sdk_library/public/foo-removed.txt", |
| 488 | sdk_version: "current", |
| 489 | }, |
| 490 | apex_available: ["myapex"], |
| 491 | } |
| 492 | |
| 493 | // This always depends on the source foo module, its dependencies are not affected by the |
| 494 | // AlwaysUsePrebuiltSdks(). |
| 495 | bootclasspath_fragment { |
| 496 | name: "mybootclasspath-fragment", |
| 497 | apex_available: [ |
| 498 | "myapex", |
| 499 | ], |
| 500 | contents: [ |
| 501 | "foo", "bar", |
| 502 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 503 | hidden_api: { |
| 504 | split_packages: ["*"], |
| 505 | }, |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 506 | } |
| 507 | |
Martin Stjernholm | b1e61cb | 2021-09-08 21:56:18 +0100 | [diff] [blame] | 508 | prebuilt_bootclasspath_fragment { |
| 509 | name: "mybootclasspath-fragment", |
| 510 | apex_available: [ |
| 511 | "myapex", |
| 512 | ], |
| 513 | contents: [ |
| 514 | "foo", |
| 515 | ], |
| 516 | hidden_api: { |
| 517 | stub_flags: "", |
| 518 | annotation_flags: "", |
| 519 | metadata: "", |
| 520 | index: "", |
| 521 | all_flags: "", |
| 522 | }, |
| 523 | } |
| 524 | |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 525 | platform_bootclasspath { |
| 526 | name: "myplatform-bootclasspath", |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 527 | fragments: [ |
| 528 | { |
| 529 | apex: "myapex", |
| 530 | module:"mybootclasspath-fragment", |
| 531 | }, |
| 532 | ], |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 533 | } |
| 534 | `, |
| 535 | ) |
| 536 | |
| 537 | java.CheckPlatformBootclasspathModules(t, result, "myplatform-bootclasspath", []string{ |
| 538 | // The configured contents of BootJars. |
Martin Stjernholm | b1e61cb | 2021-09-08 21:56:18 +0100 | [diff] [blame] | 539 | "myapex:prebuilt_foo", |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 540 | "myapex:bar", |
| 541 | }) |
| 542 | |
| 543 | // Make sure that the myplatform-bootclasspath has the correct dependencies. |
| 544 | CheckModuleDependencies(t, result.TestContext, "myplatform-bootclasspath", "android_common", []string{ |
Spandan Das | 64c9e0c | 2023-12-20 20:13:34 +0000 | [diff] [blame] | 545 | // source vs prebuilt selection metadata module |
| 546 | `platform:all_apex_contributions`, |
| 547 | |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 548 | // The following are stubs. |
| 549 | "platform:prebuilt_sdk_public_current_android", |
| 550 | "platform:prebuilt_sdk_system_current_android", |
| 551 | "platform:prebuilt_sdk_test_current_android", |
| 552 | |
| 553 | // Not a prebuilt as no prebuilt existed when it was added. |
Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 554 | "platform:legacy.core.platform.api.stubs.exportable", |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 555 | |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 556 | // The platform_bootclasspath intentionally adds dependencies on both source and prebuilt |
| 557 | // modules when available as it does not know which one will be preferred. |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 558 | "myapex:foo", |
Martin Stjernholm | b1e61cb | 2021-09-08 21:56:18 +0100 | [diff] [blame] | 559 | "myapex:prebuilt_foo", |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 560 | |
| 561 | // Only a source module exists. |
| 562 | "myapex:bar", |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 563 | |
| 564 | // The fragments. |
| 565 | "myapex:mybootclasspath-fragment", |
Martin Stjernholm | b1e61cb | 2021-09-08 21:56:18 +0100 | [diff] [blame] | 566 | "myapex:prebuilt_mybootclasspath-fragment", |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 567 | }) |
| 568 | } |
| 569 | |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 570 | // CheckModuleDependencies checks the dependencies of the selected module against the expected list. |
| 571 | // |
| 572 | // The expected list must be a list of strings of the form "<apex>:<module>", where <apex> is the |
| 573 | // name of the apex, or platform is it is not part of an apex and <module> is the module name. |
| 574 | func CheckModuleDependencies(t *testing.T, ctx *android.TestContext, name, variant string, expected []string) { |
| 575 | t.Helper() |
| 576 | module := ctx.ModuleForTests(name, variant).Module() |
| 577 | modules := []android.Module{} |
| 578 | ctx.VisitDirectDeps(module, func(m blueprint.Module) { |
| 579 | modules = append(modules, m.(android.Module)) |
| 580 | }) |
| 581 | |
| 582 | pairs := java.ApexNamePairsFromModules(ctx, modules) |
| 583 | android.AssertDeepEquals(t, "module dependencies", expected, pairs) |
| 584 | } |
satayev | b309050 | 2021-06-15 17:49:10 +0100 | [diff] [blame] | 585 | |
| 586 | // TestPlatformBootclasspath_IncludesRemainingApexJars verifies that any apex boot jar is present in |
| 587 | // platform_bootclasspath's classpaths.proto config, if the apex does not generate its own config |
| 588 | // by setting generate_classpaths_proto property to false. |
| 589 | func TestPlatformBootclasspath_IncludesRemainingApexJars(t *testing.T) { |
| 590 | result := android.GroupFixturePreparers( |
| 591 | prepareForTestWithPlatformBootclasspath, |
| 592 | prepareForTestWithMyapex, |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 593 | java.FixtureConfigureApexBootJars("myapex:foo"), |
satayev | b309050 | 2021-06-15 17:49:10 +0100 | [diff] [blame] | 594 | android.FixtureWithRootAndroidBp(` |
| 595 | platform_bootclasspath { |
| 596 | name: "platform-bootclasspath", |
| 597 | fragments: [ |
| 598 | { |
| 599 | apex: "myapex", |
| 600 | module:"foo-fragment", |
| 601 | }, |
| 602 | ], |
| 603 | } |
| 604 | |
| 605 | apex { |
| 606 | name: "myapex", |
| 607 | key: "myapex.key", |
| 608 | bootclasspath_fragments: ["foo-fragment"], |
| 609 | updatable: false, |
| 610 | } |
| 611 | |
| 612 | apex_key { |
| 613 | name: "myapex.key", |
| 614 | public_key: "testkey.avbpubkey", |
| 615 | private_key: "testkey.pem", |
| 616 | } |
| 617 | |
| 618 | bootclasspath_fragment { |
| 619 | name: "foo-fragment", |
| 620 | generate_classpaths_proto: false, |
| 621 | contents: ["foo"], |
| 622 | apex_available: ["myapex"], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 623 | hidden_api: { |
| 624 | split_packages: ["*"], |
| 625 | }, |
satayev | b309050 | 2021-06-15 17:49:10 +0100 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | java_library { |
| 629 | name: "foo", |
| 630 | srcs: ["a.java"], |
| 631 | system_modules: "none", |
| 632 | sdk_version: "none", |
| 633 | compile_dex: true, |
| 634 | apex_available: ["myapex"], |
| 635 | permitted_packages: ["foo"], |
| 636 | } |
| 637 | `), |
| 638 | ).RunTest(t) |
| 639 | |
| 640 | java.CheckClasspathFragmentProtoContentInfoProvider(t, result, |
| 641 | true, // proto should be generated |
| 642 | "myapex:foo", // apex doesn't generate its own config, so must be in platform_bootclasspath |
| 643 | "bootclasspath.pb", |
| 644 | "out/soong/target/product/test_device/system/etc/classpaths", |
| 645 | ) |
| 646 | } |
satayev | d34eb0c | 2021-08-06 13:20:28 +0100 | [diff] [blame] | 647 | |
| 648 | func TestBootJarNotInApex(t *testing.T) { |
| 649 | android.GroupFixturePreparers( |
| 650 | prepareForTestWithPlatformBootclasspath, |
| 651 | PrepareForTestWithApexBuildComponents, |
| 652 | prepareForTestWithMyapex, |
| 653 | java.FixtureConfigureApexBootJars("myapex:foo"), |
| 654 | ).ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern( |
| 655 | `dependency "foo" of "myplatform-bootclasspath" missing variant`)). |
| 656 | RunTestWithBp(t, ` |
| 657 | apex { |
| 658 | name: "myapex", |
| 659 | key: "myapex.key", |
| 660 | updatable: false, |
| 661 | } |
| 662 | |
| 663 | apex_key { |
| 664 | name: "myapex.key", |
| 665 | public_key: "testkey.avbpubkey", |
| 666 | private_key: "testkey.pem", |
| 667 | } |
| 668 | |
| 669 | java_library { |
| 670 | name: "foo", |
| 671 | srcs: ["b.java"], |
| 672 | installable: true, |
| 673 | apex_available: [ |
| 674 | "myapex", |
| 675 | ], |
| 676 | } |
| 677 | |
| 678 | bootclasspath_fragment { |
| 679 | name: "not-in-apex-fragment", |
| 680 | contents: [ |
| 681 | "foo", |
| 682 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 683 | hidden_api: { |
| 684 | split_packages: ["*"], |
| 685 | }, |
satayev | d34eb0c | 2021-08-06 13:20:28 +0100 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | platform_bootclasspath { |
| 689 | name: "myplatform-bootclasspath", |
| 690 | } |
| 691 | `) |
| 692 | } |
| 693 | |
| 694 | func TestBootFragmentNotInApex(t *testing.T) { |
| 695 | android.GroupFixturePreparers( |
| 696 | prepareForTestWithPlatformBootclasspath, |
| 697 | PrepareForTestWithApexBuildComponents, |
| 698 | prepareForTestWithMyapex, |
| 699 | java.FixtureConfigureApexBootJars("myapex:foo"), |
| 700 | ).ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern( |
| 701 | `library foo.*have no corresponding fragment.*`)).RunTestWithBp(t, ` |
| 702 | apex { |
| 703 | name: "myapex", |
| 704 | key: "myapex.key", |
| 705 | java_libs: ["foo"], |
| 706 | updatable: false, |
| 707 | } |
| 708 | |
| 709 | apex_key { |
| 710 | name: "myapex.key", |
| 711 | public_key: "testkey.avbpubkey", |
| 712 | private_key: "testkey.pem", |
| 713 | } |
| 714 | |
| 715 | java_library { |
| 716 | name: "foo", |
| 717 | srcs: ["b.java"], |
| 718 | installable: true, |
| 719 | apex_available: ["myapex"], |
| 720 | permitted_packages: ["foo"], |
| 721 | } |
| 722 | |
| 723 | bootclasspath_fragment { |
| 724 | name: "not-in-apex-fragment", |
| 725 | contents: ["foo"], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 726 | hidden_api: { |
| 727 | split_packages: ["*"], |
| 728 | }, |
satayev | d34eb0c | 2021-08-06 13:20:28 +0100 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | platform_bootclasspath { |
| 732 | name: "myplatform-bootclasspath", |
| 733 | } |
| 734 | `) |
| 735 | } |
| 736 | |
| 737 | func TestNonBootJarInFragment(t *testing.T) { |
| 738 | android.GroupFixturePreparers( |
| 739 | prepareForTestWithPlatformBootclasspath, |
| 740 | PrepareForTestWithApexBuildComponents, |
| 741 | prepareForTestWithMyapex, |
| 742 | java.FixtureConfigureApexBootJars("myapex:foo"), |
| 743 | ).ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern( |
| 744 | `in contents must also be declared in PRODUCT_APEX_BOOT_JARS`)). |
| 745 | RunTestWithBp(t, ` |
| 746 | apex { |
| 747 | name: "myapex", |
| 748 | key: "myapex.key", |
| 749 | bootclasspath_fragments: ["apex-fragment"], |
| 750 | updatable: false, |
| 751 | } |
| 752 | |
| 753 | apex_key { |
| 754 | name: "myapex.key", |
| 755 | public_key: "testkey.avbpubkey", |
| 756 | private_key: "testkey.pem", |
| 757 | } |
| 758 | |
| 759 | java_library { |
| 760 | name: "foo", |
| 761 | srcs: ["b.java"], |
| 762 | installable: true, |
| 763 | apex_available: ["myapex"], |
| 764 | permitted_packages: ["foo"], |
| 765 | } |
| 766 | |
| 767 | java_library { |
| 768 | name: "bar", |
| 769 | srcs: ["b.java"], |
| 770 | installable: true, |
| 771 | apex_available: ["myapex"], |
| 772 | permitted_packages: ["bar"], |
| 773 | } |
| 774 | |
| 775 | bootclasspath_fragment { |
| 776 | name: "apex-fragment", |
| 777 | contents: ["foo", "bar"], |
| 778 | apex_available:[ "myapex" ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 779 | hidden_api: { |
| 780 | split_packages: ["*"], |
| 781 | }, |
satayev | d34eb0c | 2021-08-06 13:20:28 +0100 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | platform_bootclasspath { |
| 785 | name: "myplatform-bootclasspath", |
| 786 | fragments: [{ |
| 787 | apex: "myapex", |
| 788 | module:"apex-fragment", |
| 789 | }], |
| 790 | } |
| 791 | `) |
| 792 | } |
Spandan Das | 3d0d31a | 2024-05-03 21:36:48 +0000 | [diff] [blame] | 793 | |
| 794 | // Source and prebuilt apex provide different set of boot jars |
| 795 | func TestNonBootJarMissingInPrebuiltFragment(t *testing.T) { |
| 796 | bp := ` |
| 797 | apex { |
| 798 | name: "myapex", |
| 799 | key: "myapex.key", |
| 800 | bootclasspath_fragments: ["apex-fragment"], |
| 801 | updatable: false, |
| 802 | } |
| 803 | |
| 804 | apex_key { |
| 805 | name: "myapex.key", |
| 806 | public_key: "testkey.avbpubkey", |
| 807 | private_key: "testkey.pem", |
| 808 | } |
| 809 | |
| 810 | java_library { |
| 811 | name: "foo", |
| 812 | srcs: ["b.java"], |
| 813 | installable: true, |
| 814 | apex_available: ["myapex"], |
| 815 | permitted_packages: ["foo"], |
| 816 | } |
| 817 | |
| 818 | java_library { |
| 819 | name: "bar", |
| 820 | srcs: ["b.java"], |
| 821 | installable: true, |
| 822 | apex_available: ["myapex"], |
| 823 | permitted_packages: ["bar"], |
| 824 | } |
| 825 | |
| 826 | bootclasspath_fragment { |
| 827 | name: "apex-fragment", |
| 828 | contents: ["foo", "bar"], |
| 829 | apex_available:[ "myapex" ], |
| 830 | hidden_api: { |
| 831 | split_packages: ["*"], |
| 832 | }, |
| 833 | } |
| 834 | |
| 835 | prebuilt_apex { |
| 836 | name: "com.google.android.myapex", // mainline prebuilt selection logic in soong relies on the naming convention com.google.android |
| 837 | apex_name: "myapex", |
| 838 | source_apex_name: "myapex", |
| 839 | src: "myapex.apex", |
| 840 | exported_bootclasspath_fragments: ["apex-fragment"], |
| 841 | } |
| 842 | |
| 843 | java_import { |
| 844 | name: "foo", |
| 845 | jars: ["foo.jar"], |
| 846 | apex_available: ["myapex"], |
| 847 | permitted_packages: ["foo"], |
| 848 | } |
| 849 | |
| 850 | prebuilt_bootclasspath_fragment { |
| 851 | name: "apex-fragment", |
| 852 | contents: ["foo"], // Unlike the source fragment, this is missing bar |
| 853 | apex_available:[ "myapex" ], |
| 854 | hidden_api: { |
| 855 | annotation_flags: "my-bootclasspath-fragment/annotation-flags.csv", |
| 856 | metadata: "my-bootclasspath-fragment/metadata.csv", |
| 857 | index: "my-bootclasspath-fragment/index.csv", |
| 858 | stub_flags: "my-bootclasspath-fragment/stub-flags.csv", |
| 859 | all_flags: "my-bootclasspath-fragment/all-flags.csv", |
| 860 | }, |
| 861 | } |
| 862 | |
Spandan Das | 5f1f940 | 2024-05-21 18:59:23 +0000 | [diff] [blame] | 863 | // Another prebuilt apex, but this is not selected during the build. |
| 864 | prebuilt_apex { |
| 865 | name: "com.google.android.myapex.v2", // mainline prebuilt selection logic in soong relies on the naming convention com.google.android |
| 866 | apex_name: "myapex", |
| 867 | source_apex_name: "myapex", |
| 868 | src: "myapex.apex", |
| 869 | exported_bootclasspath_fragments: ["apex-fragment.v2"], |
| 870 | } |
| 871 | |
| 872 | java_import { |
| 873 | name: "bar", |
| 874 | jars: ["bar.jar"], |
| 875 | apex_available: ["myapex"], |
| 876 | permitted_packages: ["bar"], |
| 877 | } |
| 878 | |
| 879 | prebuilt_bootclasspath_fragment { |
| 880 | name: "apex-fragment.v2", |
| 881 | contents: ["bar"], // Unlike the source fragment, this is missing foo |
| 882 | apex_available:[ "myapex" ], |
| 883 | hidden_api: { |
| 884 | annotation_flags: "my-bootclasspath-fragment/annotation-flags.csv", |
| 885 | metadata: "my-bootclasspath-fragment/metadata.csv", |
| 886 | index: "my-bootclasspath-fragment/index.csv", |
| 887 | stub_flags: "my-bootclasspath-fragment/stub-flags.csv", |
| 888 | all_flags: "my-bootclasspath-fragment/all-flags.csv", |
| 889 | }, |
| 890 | } |
| 891 | |
| 892 | |
Spandan Das | 3d0d31a | 2024-05-03 21:36:48 +0000 | [diff] [blame] | 893 | apex_contributions { |
| 894 | name: "my_apex_contributions", |
| 895 | api_domain: "myapex", |
| 896 | contents: [%v], |
| 897 | } |
| 898 | ` |
| 899 | testCases := []struct { |
| 900 | desc string |
| 901 | configuredBootJars []string |
| 902 | apexContributionContents string |
| 903 | errorExpected bool |
| 904 | }{ |
| 905 | { |
| 906 | desc: "Source apex is selected, and APEX_BOOT_JARS is correctly configured for source apex builds", |
| 907 | configuredBootJars: []string{"myapex:foo", "myapex:bar"}, |
| 908 | }, |
| 909 | { |
| 910 | desc: "Source apex is selected, and APEX_BOOT_JARS is missing bar", |
| 911 | configuredBootJars: []string{"myapex:foo"}, |
| 912 | errorExpected: true, |
| 913 | }, |
| 914 | { |
| 915 | desc: "Prebuilt apex is selected, and APEX_BOOT_JARS is correctly configured for prebuilt apex build", |
| 916 | configuredBootJars: []string{"myapex:foo"}, |
| 917 | apexContributionContents: `"prebuilt_com.google.android.myapex"`, |
| 918 | }, |
| 919 | { |
| 920 | desc: "Prebuilt apex is selected, and APEX_BOOT_JARS is missing foo", |
| 921 | configuredBootJars: []string{"myapex:bar"}, |
| 922 | apexContributionContents: `"prebuilt_com.google.android.myapex"`, |
| 923 | errorExpected: true, |
| 924 | }, |
| 925 | } |
| 926 | |
| 927 | for _, tc := range testCases { |
| 928 | fixture := android.GroupFixturePreparers( |
| 929 | prepareForTestWithPlatformBootclasspath, |
| 930 | PrepareForTestWithApexBuildComponents, |
| 931 | prepareForTestWithMyapex, |
| 932 | java.FixtureConfigureApexBootJars(tc.configuredBootJars...), |
Colin Cross | a66b463 | 2024-08-08 15:50:47 -0700 | [diff] [blame] | 933 | android.PrepareForTestWithBuildFlag("RELEASE_APEX_CONTRIBUTIONS_ART", "my_apex_contributions"), |
Spandan Das | 3d0d31a | 2024-05-03 21:36:48 +0000 | [diff] [blame] | 934 | ) |
| 935 | if tc.errorExpected { |
| 936 | fixture = fixture.ExtendWithErrorHandler( |
| 937 | android.FixtureExpectsAtLeastOneErrorMatchingPattern(`in contents.*must also be declared in PRODUCT_APEX_BOOT_JARS`), |
| 938 | ) |
| 939 | } |
| 940 | fixture.RunTestWithBp(t, fmt.Sprintf(bp, tc.apexContributionContents)) |
| 941 | } |
| 942 | } |