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") |
Yu Liu | 663e450 | 2024-08-12 18:23:59 +0000 | [diff] [blame] | 157 | info, _ := android.OtherModuleProvider(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") |
Yu Liu | 663e450 | 2024-08-12 18:23:59 +0000 | [diff] [blame] | 239 | info, _ := android.OtherModuleProvider(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, |
Jihoon Kang | 85bc193 | 2024-07-01 17:04:46 +0000 | [diff] [blame] | 296 | sdk_version: "core_current", |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | // Add a java_import that is not preferred and so won't have an appropriate apex variant created |
| 300 | // for it to make sure that the platform_bootclasspath doesn't try and add a dependency onto it. |
| 301 | java_import { |
| 302 | name: "baz", |
| 303 | apex_available: [ |
| 304 | "com.android.art", |
| 305 | ], |
| 306 | jars: ["b.jar"], |
| 307 | } |
| 308 | |
| 309 | java_library { |
| 310 | name: "quuz", |
| 311 | apex_available: [ |
| 312 | "com.android.art", |
| 313 | ], |
| 314 | srcs: ["b.java"], |
| 315 | installable: true, |
| 316 | } |
| 317 | |
| 318 | apex { |
| 319 | name: "myapex", |
| 320 | key: "myapex.key", |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 321 | bootclasspath_fragments: [ |
| 322 | "my-bootclasspath-fragment", |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 323 | ], |
| 324 | updatable: false, |
| 325 | } |
| 326 | |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 327 | bootclasspath_fragment { |
| 328 | name: "my-bootclasspath-fragment", |
| 329 | contents: ["bar"], |
| 330 | apex_available: ["myapex"], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 331 | hidden_api: { |
| 332 | split_packages: ["*"], |
| 333 | }, |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 334 | } |
| 335 | |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 336 | apex_key { |
| 337 | name: "myapex.key", |
| 338 | public_key: "testkey.avbpubkey", |
| 339 | private_key: "testkey.pem", |
| 340 | } |
| 341 | |
| 342 | java_sdk_library { |
| 343 | name: "foo", |
| 344 | srcs: ["b.java"], |
| 345 | } |
| 346 | |
| 347 | java_library { |
| 348 | name: "bar", |
| 349 | srcs: ["b.java"], |
| 350 | installable: true, |
| 351 | apex_available: ["myapex"], |
| 352 | permitted_packages: ["bar"], |
| 353 | } |
| 354 | |
| 355 | platform_bootclasspath { |
| 356 | name: "myplatform-bootclasspath", |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 357 | |
| 358 | fragments: [ |
| 359 | { |
| 360 | apex: "com.android.art", |
| 361 | module: "art-bootclasspath-fragment", |
| 362 | }, |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 363 | { |
| 364 | apex: "myapex", |
| 365 | module: "my-bootclasspath-fragment", |
| 366 | }, |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 367 | ], |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 368 | } |
| 369 | `, |
| 370 | ) |
| 371 | |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 372 | java.CheckPlatformBootclasspathModules(t, result, "myplatform-bootclasspath", []string{ |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 373 | // The configured contents of BootJars. |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 374 | "com.android.art:baz", |
| 375 | "com.android.art:quuz", |
| 376 | "platform:foo", |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 377 | |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 378 | // The configured contents of ApexBootJars. |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 379 | "myapex:bar", |
| 380 | }) |
| 381 | |
| 382 | java.CheckPlatformBootclasspathFragments(t, result, "myplatform-bootclasspath", []string{ |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 383 | "com.android.art:art-bootclasspath-fragment", |
| 384 | "myapex:my-bootclasspath-fragment", |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 385 | }) |
| 386 | |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 387 | // Make sure that the myplatform-bootclasspath has the correct dependencies. |
| 388 | CheckModuleDependencies(t, result.TestContext, "myplatform-bootclasspath", "android_common", []string{ |
Spandan Das | 64c9e0c | 2023-12-20 20:13:34 +0000 | [diff] [blame] | 389 | // source vs prebuilt selection metadata module |
| 390 | `platform:all_apex_contributions`, |
| 391 | |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 392 | // The following are stubs. |
Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 393 | `platform:android_stubs_current_exportable`, |
| 394 | `platform:android_system_stubs_current_exportable`, |
| 395 | `platform:android_test_stubs_current_exportable`, |
| 396 | `platform:legacy.core.platform.api.stubs.exportable`, |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 397 | |
| 398 | // Needed for generating the boot image. |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 399 | `platform:dex2oatd`, |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 400 | |
| 401 | // The configured contents of BootJars. |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 402 | `com.android.art:baz`, |
| 403 | `com.android.art:quuz`, |
| 404 | `platform:foo`, |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 405 | |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 406 | // The configured contents of ApexBootJars. |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 407 | `myapex:bar`, |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 408 | |
| 409 | // The fragments. |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 410 | `com.android.art:art-bootclasspath-fragment`, |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 411 | `myapex:my-bootclasspath-fragment`, |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 412 | }) |
| 413 | } |
| 414 | |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 415 | // TestPlatformBootclasspath_AlwaysUsePrebuiltSdks verifies that the build does not fail when |
Martin Stjernholm | b1e61cb | 2021-09-08 21:56:18 +0100 | [diff] [blame] | 416 | // AlwaysUsePrebuiltSdk() returns true. |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 417 | func TestPlatformBootclasspath_AlwaysUsePrebuiltSdks(t *testing.T) { |
| 418 | result := android.GroupFixturePreparers( |
| 419 | prepareForTestWithPlatformBootclasspath, |
| 420 | prepareForTestWithMyapex, |
| 421 | // 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] | 422 | // of AlwaysUsePrebuiltsSdk(). The second is a normal library that is unaffected. The order |
| 423 | // matters, so that the dependencies resolved by the platform_bootclasspath matches the |
| 424 | // configured list. |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 425 | java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"), |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 426 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 427 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 428 | variables.Always_use_prebuilt_sdks = proptools.BoolPtr(true) |
| 429 | }), |
Colin Cross | a66b463 | 2024-08-08 15:50:47 -0700 | [diff] [blame] | 430 | android.PrepareForTestWithBuildFlag("RELEASE_HIDDEN_API_EXPORTABLE_STUBS", "true"), |
| 431 | |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 432 | java.FixtureWithPrebuiltApis(map[string][]string{ |
| 433 | "current": {}, |
| 434 | "30": {"foo"}, |
| 435 | }), |
| 436 | ).RunTestWithBp(t, ` |
| 437 | apex { |
| 438 | name: "myapex", |
| 439 | key: "myapex.key", |
| 440 | bootclasspath_fragments: [ |
| 441 | "mybootclasspath-fragment", |
| 442 | ], |
| 443 | updatable: false, |
| 444 | } |
| 445 | |
| 446 | apex_key { |
| 447 | name: "myapex.key", |
| 448 | public_key: "testkey.avbpubkey", |
| 449 | private_key: "testkey.pem", |
| 450 | } |
| 451 | |
| 452 | java_library { |
| 453 | name: "bar", |
| 454 | srcs: ["b.java"], |
| 455 | installable: true, |
| 456 | apex_available: ["myapex"], |
| 457 | permitted_packages: ["bar"], |
| 458 | } |
| 459 | |
| 460 | java_sdk_library { |
| 461 | name: "foo", |
| 462 | srcs: ["b.java"], |
| 463 | shared_library: false, |
| 464 | public: { |
| 465 | enabled: true, |
| 466 | }, |
| 467 | apex_available: ["myapex"], |
| 468 | permitted_packages: ["foo"], |
| 469 | } |
| 470 | |
Martin Stjernholm | b1e61cb | 2021-09-08 21:56:18 +0100 | [diff] [blame] | 471 | prebuilt_apex { |
| 472 | name: "myapex", |
| 473 | src: "myapex.apex", |
| 474 | exported_bootclasspath_fragments: ["mybootclasspath-fragment"], |
| 475 | } |
| 476 | |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 477 | // A prebuilt java_sdk_library_import that is not preferred by default but will be preferred |
| 478 | // because AlwaysUsePrebuiltSdks() is true. |
| 479 | java_sdk_library_import { |
| 480 | name: "foo", |
| 481 | prefer: false, |
| 482 | shared_library: false, |
Paul Duffin | 630b11e | 2021-07-15 13:35:26 +0100 | [diff] [blame] | 483 | permitted_packages: ["foo"], |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 484 | public: { |
| 485 | jars: ["sdk_library/public/foo-stubs.jar"], |
| 486 | stub_srcs: ["sdk_library/public/foo_stub_sources"], |
| 487 | current_api: "sdk_library/public/foo.txt", |
| 488 | removed_api: "sdk_library/public/foo-removed.txt", |
| 489 | sdk_version: "current", |
| 490 | }, |
| 491 | apex_available: ["myapex"], |
| 492 | } |
| 493 | |
| 494 | // This always depends on the source foo module, its dependencies are not affected by the |
| 495 | // AlwaysUsePrebuiltSdks(). |
| 496 | bootclasspath_fragment { |
| 497 | name: "mybootclasspath-fragment", |
| 498 | apex_available: [ |
| 499 | "myapex", |
| 500 | ], |
| 501 | contents: [ |
| 502 | "foo", "bar", |
| 503 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 504 | hidden_api: { |
| 505 | split_packages: ["*"], |
| 506 | }, |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 507 | } |
| 508 | |
Martin Stjernholm | b1e61cb | 2021-09-08 21:56:18 +0100 | [diff] [blame] | 509 | prebuilt_bootclasspath_fragment { |
| 510 | name: "mybootclasspath-fragment", |
| 511 | apex_available: [ |
| 512 | "myapex", |
| 513 | ], |
| 514 | contents: [ |
| 515 | "foo", |
| 516 | ], |
| 517 | hidden_api: { |
| 518 | stub_flags: "", |
| 519 | annotation_flags: "", |
| 520 | metadata: "", |
| 521 | index: "", |
| 522 | all_flags: "", |
| 523 | }, |
| 524 | } |
| 525 | |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 526 | platform_bootclasspath { |
| 527 | name: "myplatform-bootclasspath", |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 528 | fragments: [ |
| 529 | { |
| 530 | apex: "myapex", |
| 531 | module:"mybootclasspath-fragment", |
| 532 | }, |
| 533 | ], |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 534 | } |
| 535 | `, |
| 536 | ) |
| 537 | |
| 538 | java.CheckPlatformBootclasspathModules(t, result, "myplatform-bootclasspath", []string{ |
| 539 | // The configured contents of BootJars. |
Martin Stjernholm | b1e61cb | 2021-09-08 21:56:18 +0100 | [diff] [blame] | 540 | "myapex:prebuilt_foo", |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 541 | "myapex:bar", |
| 542 | }) |
| 543 | |
| 544 | // Make sure that the myplatform-bootclasspath has the correct dependencies. |
| 545 | CheckModuleDependencies(t, result.TestContext, "myplatform-bootclasspath", "android_common", []string{ |
Spandan Das | 64c9e0c | 2023-12-20 20:13:34 +0000 | [diff] [blame] | 546 | // source vs prebuilt selection metadata module |
| 547 | `platform:all_apex_contributions`, |
| 548 | |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 549 | // The following are stubs. |
| 550 | "platform:prebuilt_sdk_public_current_android", |
| 551 | "platform:prebuilt_sdk_system_current_android", |
| 552 | "platform:prebuilt_sdk_test_current_android", |
| 553 | |
| 554 | // Not a prebuilt as no prebuilt existed when it was added. |
Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 555 | "platform:legacy.core.platform.api.stubs.exportable", |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 556 | |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 557 | // The platform_bootclasspath intentionally adds dependencies on both source and prebuilt |
| 558 | // 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] | 559 | "myapex:foo", |
Martin Stjernholm | b1e61cb | 2021-09-08 21:56:18 +0100 | [diff] [blame] | 560 | "myapex:prebuilt_foo", |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 561 | |
| 562 | // Only a source module exists. |
| 563 | "myapex:bar", |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 564 | |
| 565 | // The fragments. |
| 566 | "myapex:mybootclasspath-fragment", |
Martin Stjernholm | b1e61cb | 2021-09-08 21:56:18 +0100 | [diff] [blame] | 567 | "myapex:prebuilt_mybootclasspath-fragment", |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 568 | }) |
| 569 | } |
| 570 | |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 571 | // CheckModuleDependencies checks the dependencies of the selected module against the expected list. |
| 572 | // |
| 573 | // The expected list must be a list of strings of the form "<apex>:<module>", where <apex> is the |
| 574 | // name of the apex, or platform is it is not part of an apex and <module> is the module name. |
| 575 | func CheckModuleDependencies(t *testing.T, ctx *android.TestContext, name, variant string, expected []string) { |
| 576 | t.Helper() |
| 577 | module := ctx.ModuleForTests(name, variant).Module() |
| 578 | modules := []android.Module{} |
| 579 | ctx.VisitDirectDeps(module, func(m blueprint.Module) { |
| 580 | modules = append(modules, m.(android.Module)) |
| 581 | }) |
| 582 | |
| 583 | pairs := java.ApexNamePairsFromModules(ctx, modules) |
| 584 | android.AssertDeepEquals(t, "module dependencies", expected, pairs) |
| 585 | } |
satayev | b309050 | 2021-06-15 17:49:10 +0100 | [diff] [blame] | 586 | |
| 587 | // TestPlatformBootclasspath_IncludesRemainingApexJars verifies that any apex boot jar is present in |
| 588 | // platform_bootclasspath's classpaths.proto config, if the apex does not generate its own config |
| 589 | // by setting generate_classpaths_proto property to false. |
| 590 | func TestPlatformBootclasspath_IncludesRemainingApexJars(t *testing.T) { |
| 591 | result := android.GroupFixturePreparers( |
| 592 | prepareForTestWithPlatformBootclasspath, |
| 593 | prepareForTestWithMyapex, |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 594 | java.FixtureConfigureApexBootJars("myapex:foo"), |
satayev | b309050 | 2021-06-15 17:49:10 +0100 | [diff] [blame] | 595 | android.FixtureWithRootAndroidBp(` |
| 596 | platform_bootclasspath { |
| 597 | name: "platform-bootclasspath", |
| 598 | fragments: [ |
| 599 | { |
| 600 | apex: "myapex", |
| 601 | module:"foo-fragment", |
| 602 | }, |
| 603 | ], |
| 604 | } |
| 605 | |
| 606 | apex { |
| 607 | name: "myapex", |
| 608 | key: "myapex.key", |
| 609 | bootclasspath_fragments: ["foo-fragment"], |
| 610 | updatable: false, |
| 611 | } |
| 612 | |
| 613 | apex_key { |
| 614 | name: "myapex.key", |
| 615 | public_key: "testkey.avbpubkey", |
| 616 | private_key: "testkey.pem", |
| 617 | } |
| 618 | |
| 619 | bootclasspath_fragment { |
| 620 | name: "foo-fragment", |
| 621 | generate_classpaths_proto: false, |
| 622 | contents: ["foo"], |
| 623 | apex_available: ["myapex"], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 624 | hidden_api: { |
| 625 | split_packages: ["*"], |
| 626 | }, |
satayev | b309050 | 2021-06-15 17:49:10 +0100 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | java_library { |
| 630 | name: "foo", |
| 631 | srcs: ["a.java"], |
| 632 | system_modules: "none", |
| 633 | sdk_version: "none", |
| 634 | compile_dex: true, |
| 635 | apex_available: ["myapex"], |
| 636 | permitted_packages: ["foo"], |
| 637 | } |
| 638 | `), |
| 639 | ).RunTest(t) |
| 640 | |
| 641 | java.CheckClasspathFragmentProtoContentInfoProvider(t, result, |
| 642 | true, // proto should be generated |
| 643 | "myapex:foo", // apex doesn't generate its own config, so must be in platform_bootclasspath |
| 644 | "bootclasspath.pb", |
| 645 | "out/soong/target/product/test_device/system/etc/classpaths", |
| 646 | ) |
| 647 | } |
satayev | d34eb0c | 2021-08-06 13:20:28 +0100 | [diff] [blame] | 648 | |
| 649 | func TestBootJarNotInApex(t *testing.T) { |
| 650 | android.GroupFixturePreparers( |
| 651 | prepareForTestWithPlatformBootclasspath, |
| 652 | PrepareForTestWithApexBuildComponents, |
| 653 | prepareForTestWithMyapex, |
| 654 | java.FixtureConfigureApexBootJars("myapex:foo"), |
| 655 | ).ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern( |
| 656 | `dependency "foo" of "myplatform-bootclasspath" missing variant`)). |
| 657 | RunTestWithBp(t, ` |
| 658 | apex { |
| 659 | name: "myapex", |
| 660 | key: "myapex.key", |
| 661 | updatable: false, |
| 662 | } |
| 663 | |
| 664 | apex_key { |
| 665 | name: "myapex.key", |
| 666 | public_key: "testkey.avbpubkey", |
| 667 | private_key: "testkey.pem", |
| 668 | } |
| 669 | |
| 670 | java_library { |
| 671 | name: "foo", |
| 672 | srcs: ["b.java"], |
| 673 | installable: true, |
| 674 | apex_available: [ |
| 675 | "myapex", |
| 676 | ], |
| 677 | } |
| 678 | |
| 679 | bootclasspath_fragment { |
| 680 | name: "not-in-apex-fragment", |
| 681 | contents: [ |
| 682 | "foo", |
| 683 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 684 | hidden_api: { |
| 685 | split_packages: ["*"], |
| 686 | }, |
satayev | d34eb0c | 2021-08-06 13:20:28 +0100 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | platform_bootclasspath { |
| 690 | name: "myplatform-bootclasspath", |
| 691 | } |
| 692 | `) |
| 693 | } |
| 694 | |
| 695 | func TestBootFragmentNotInApex(t *testing.T) { |
| 696 | android.GroupFixturePreparers( |
| 697 | prepareForTestWithPlatformBootclasspath, |
| 698 | PrepareForTestWithApexBuildComponents, |
| 699 | prepareForTestWithMyapex, |
| 700 | java.FixtureConfigureApexBootJars("myapex:foo"), |
| 701 | ).ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern( |
| 702 | `library foo.*have no corresponding fragment.*`)).RunTestWithBp(t, ` |
| 703 | apex { |
| 704 | name: "myapex", |
| 705 | key: "myapex.key", |
| 706 | java_libs: ["foo"], |
| 707 | updatable: false, |
| 708 | } |
| 709 | |
| 710 | apex_key { |
| 711 | name: "myapex.key", |
| 712 | public_key: "testkey.avbpubkey", |
| 713 | private_key: "testkey.pem", |
| 714 | } |
| 715 | |
| 716 | java_library { |
| 717 | name: "foo", |
| 718 | srcs: ["b.java"], |
| 719 | installable: true, |
| 720 | apex_available: ["myapex"], |
| 721 | permitted_packages: ["foo"], |
| 722 | } |
| 723 | |
| 724 | bootclasspath_fragment { |
| 725 | name: "not-in-apex-fragment", |
| 726 | contents: ["foo"], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 727 | hidden_api: { |
| 728 | split_packages: ["*"], |
| 729 | }, |
satayev | d34eb0c | 2021-08-06 13:20:28 +0100 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | platform_bootclasspath { |
| 733 | name: "myplatform-bootclasspath", |
| 734 | } |
| 735 | `) |
| 736 | } |
| 737 | |
| 738 | func TestNonBootJarInFragment(t *testing.T) { |
| 739 | android.GroupFixturePreparers( |
| 740 | prepareForTestWithPlatformBootclasspath, |
| 741 | PrepareForTestWithApexBuildComponents, |
| 742 | prepareForTestWithMyapex, |
| 743 | java.FixtureConfigureApexBootJars("myapex:foo"), |
| 744 | ).ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern( |
| 745 | `in contents must also be declared in PRODUCT_APEX_BOOT_JARS`)). |
| 746 | RunTestWithBp(t, ` |
| 747 | apex { |
| 748 | name: "myapex", |
| 749 | key: "myapex.key", |
| 750 | bootclasspath_fragments: ["apex-fragment"], |
| 751 | updatable: false, |
| 752 | } |
| 753 | |
| 754 | apex_key { |
| 755 | name: "myapex.key", |
| 756 | public_key: "testkey.avbpubkey", |
| 757 | private_key: "testkey.pem", |
| 758 | } |
| 759 | |
| 760 | java_library { |
| 761 | name: "foo", |
| 762 | srcs: ["b.java"], |
| 763 | installable: true, |
| 764 | apex_available: ["myapex"], |
| 765 | permitted_packages: ["foo"], |
| 766 | } |
| 767 | |
| 768 | java_library { |
| 769 | name: "bar", |
| 770 | srcs: ["b.java"], |
| 771 | installable: true, |
| 772 | apex_available: ["myapex"], |
| 773 | permitted_packages: ["bar"], |
| 774 | } |
| 775 | |
| 776 | bootclasspath_fragment { |
| 777 | name: "apex-fragment", |
| 778 | contents: ["foo", "bar"], |
| 779 | apex_available:[ "myapex" ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 780 | hidden_api: { |
| 781 | split_packages: ["*"], |
| 782 | }, |
satayev | d34eb0c | 2021-08-06 13:20:28 +0100 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | platform_bootclasspath { |
| 786 | name: "myplatform-bootclasspath", |
| 787 | fragments: [{ |
| 788 | apex: "myapex", |
| 789 | module:"apex-fragment", |
| 790 | }], |
| 791 | } |
| 792 | `) |
| 793 | } |
Spandan Das | 3d0d31a | 2024-05-03 21:36:48 +0000 | [diff] [blame] | 794 | |
Spandan Das | ed7a030 | 2024-08-26 18:06:25 +0000 | [diff] [blame] | 795 | // Skip bcp_fragment content validation of source apexes if prebuilts are active. |
| 796 | func TestNonBootJarInPrebuilts(t *testing.T) { |
| 797 | testCases := []struct { |
| 798 | description string |
| 799 | selectedApexContributions string |
| 800 | expectedError string |
| 801 | }{ |
| 802 | { |
| 803 | description: "source is active", |
| 804 | selectedApexContributions: "", |
| 805 | expectedError: "in contents must also be declared in PRODUCT_APEX_BOOT_JARS", |
| 806 | }, |
| 807 | { |
| 808 | description: "prebuilts are active", |
| 809 | selectedApexContributions: "myapex.prebuilt.contributions", |
| 810 | expectedError: "", // skip content validation of source bcp fragment |
| 811 | }, |
| 812 | } |
| 813 | bp := ` |
| 814 | // Source |
| 815 | apex { |
| 816 | name: "myapex", |
| 817 | key: "myapex.key", |
| 818 | bootclasspath_fragments: ["apex-fragment"], |
| 819 | updatable: false, |
| 820 | min_sdk_version: "29", |
| 821 | } |
| 822 | |
| 823 | override_apex { |
| 824 | name: "myapex.override", // overrides the min_sdk_version, thereby creating different variants of its transitive deps |
| 825 | base: "myapex", |
| 826 | min_sdk_version: "34", |
| 827 | } |
| 828 | |
| 829 | apex_key { |
| 830 | name: "myapex.key", |
| 831 | public_key: "testkey.avbpubkey", |
| 832 | private_key: "testkey.pem", |
| 833 | } |
| 834 | |
| 835 | java_library { |
| 836 | name: "foo", |
| 837 | srcs: ["b.java"], |
| 838 | installable: true, |
| 839 | apex_available: ["myapex"], |
| 840 | permitted_packages: ["foo"], |
| 841 | min_sdk_version: "29", |
| 842 | } |
| 843 | |
| 844 | java_library { |
| 845 | name: "bar", |
| 846 | srcs: ["b.java"], |
| 847 | installable: true, |
| 848 | apex_available: ["myapex"], |
| 849 | permitted_packages: ["bar"], |
| 850 | min_sdk_version: "29", |
| 851 | } |
| 852 | |
| 853 | bootclasspath_fragment { |
| 854 | name: "apex-fragment", |
| 855 | contents: ["foo", "bar"], |
| 856 | apex_available:[ "myapex" ], |
| 857 | hidden_api: { |
| 858 | split_packages: ["*"], |
| 859 | }, |
| 860 | } |
| 861 | |
| 862 | platform_bootclasspath { |
| 863 | name: "myplatform-bootclasspath", |
| 864 | fragments: [{ |
| 865 | apex: "myapex", |
| 866 | module:"apex-fragment", |
| 867 | }], |
| 868 | } |
| 869 | |
| 870 | // prebuilts |
| 871 | prebuilt_apex { |
| 872 | name: "myapex", |
| 873 | apex_name: "myapex", |
| 874 | src: "myapex.apex", |
| 875 | exported_bootclasspath_fragments: ["apex-fragment"], |
| 876 | } |
| 877 | |
| 878 | prebuilt_bootclasspath_fragment { |
| 879 | name: "apex-fragment", |
| 880 | contents: ["foo"], |
| 881 | hidden_api: { |
| 882 | annotation_flags: "my-bootclasspath-fragment/annotation-flags.csv", |
| 883 | metadata: "my-bootclasspath-fragment/metadata.csv", |
| 884 | index: "my-bootclasspath-fragment/index.csv", |
| 885 | stub_flags: "my-bootclasspath-fragment/stub-flags.csv", |
| 886 | all_flags: "my-bootclasspath-fragment/all-flags.csv", |
| 887 | }, |
| 888 | } |
| 889 | java_import { |
| 890 | name: "foo", |
| 891 | jars: ["foo.jar"], |
| 892 | } |
| 893 | |
| 894 | apex_contributions { |
| 895 | name: "myapex.prebuilt.contributions", |
| 896 | api_domain: "myapex", |
| 897 | contents: ["prebuilt_myapex"], |
| 898 | } |
| 899 | ` |
| 900 | |
| 901 | for _, tc := range testCases { |
| 902 | fixture := android.GroupFixturePreparers( |
| 903 | prepareForTestWithPlatformBootclasspath, |
| 904 | PrepareForTestWithApexBuildComponents, |
| 905 | prepareForTestWithMyapex, |
| 906 | java.FixtureConfigureApexBootJars("myapex:foo"), |
| 907 | android.PrepareForTestWithBuildFlag("RELEASE_APEX_CONTRIBUTIONS_ADSERVICES", tc.selectedApexContributions), |
| 908 | ) |
| 909 | if tc.expectedError != "" { |
| 910 | fixture = fixture.ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(tc.expectedError)) |
| 911 | } |
| 912 | fixture.RunTestWithBp(t, bp) |
| 913 | } |
| 914 | |
| 915 | } |
| 916 | |
Spandan Das | 3d0d31a | 2024-05-03 21:36:48 +0000 | [diff] [blame] | 917 | // Source and prebuilt apex provide different set of boot jars |
| 918 | func TestNonBootJarMissingInPrebuiltFragment(t *testing.T) { |
| 919 | bp := ` |
| 920 | apex { |
| 921 | name: "myapex", |
| 922 | key: "myapex.key", |
| 923 | bootclasspath_fragments: ["apex-fragment"], |
| 924 | updatable: false, |
| 925 | } |
| 926 | |
| 927 | apex_key { |
| 928 | name: "myapex.key", |
| 929 | public_key: "testkey.avbpubkey", |
| 930 | private_key: "testkey.pem", |
| 931 | } |
| 932 | |
| 933 | java_library { |
| 934 | name: "foo", |
| 935 | srcs: ["b.java"], |
| 936 | installable: true, |
| 937 | apex_available: ["myapex"], |
| 938 | permitted_packages: ["foo"], |
| 939 | } |
| 940 | |
| 941 | java_library { |
| 942 | name: "bar", |
| 943 | srcs: ["b.java"], |
| 944 | installable: true, |
| 945 | apex_available: ["myapex"], |
| 946 | permitted_packages: ["bar"], |
| 947 | } |
| 948 | |
| 949 | bootclasspath_fragment { |
| 950 | name: "apex-fragment", |
| 951 | contents: ["foo", "bar"], |
| 952 | apex_available:[ "myapex" ], |
| 953 | hidden_api: { |
| 954 | split_packages: ["*"], |
| 955 | }, |
| 956 | } |
| 957 | |
| 958 | prebuilt_apex { |
| 959 | name: "com.google.android.myapex", // mainline prebuilt selection logic in soong relies on the naming convention com.google.android |
| 960 | apex_name: "myapex", |
| 961 | source_apex_name: "myapex", |
| 962 | src: "myapex.apex", |
| 963 | exported_bootclasspath_fragments: ["apex-fragment"], |
| 964 | } |
| 965 | |
| 966 | java_import { |
| 967 | name: "foo", |
| 968 | jars: ["foo.jar"], |
| 969 | apex_available: ["myapex"], |
| 970 | permitted_packages: ["foo"], |
| 971 | } |
| 972 | |
| 973 | prebuilt_bootclasspath_fragment { |
| 974 | name: "apex-fragment", |
| 975 | contents: ["foo"], // Unlike the source fragment, this is missing bar |
| 976 | apex_available:[ "myapex" ], |
| 977 | hidden_api: { |
| 978 | annotation_flags: "my-bootclasspath-fragment/annotation-flags.csv", |
| 979 | metadata: "my-bootclasspath-fragment/metadata.csv", |
| 980 | index: "my-bootclasspath-fragment/index.csv", |
| 981 | stub_flags: "my-bootclasspath-fragment/stub-flags.csv", |
| 982 | all_flags: "my-bootclasspath-fragment/all-flags.csv", |
| 983 | }, |
| 984 | } |
| 985 | |
Spandan Das | 5f1f940 | 2024-05-21 18:59:23 +0000 | [diff] [blame] | 986 | // Another prebuilt apex, but this is not selected during the build. |
| 987 | prebuilt_apex { |
| 988 | name: "com.google.android.myapex.v2", // mainline prebuilt selection logic in soong relies on the naming convention com.google.android |
| 989 | apex_name: "myapex", |
| 990 | source_apex_name: "myapex", |
| 991 | src: "myapex.apex", |
| 992 | exported_bootclasspath_fragments: ["apex-fragment.v2"], |
| 993 | } |
| 994 | |
| 995 | java_import { |
| 996 | name: "bar", |
| 997 | jars: ["bar.jar"], |
| 998 | apex_available: ["myapex"], |
| 999 | permitted_packages: ["bar"], |
| 1000 | } |
| 1001 | |
| 1002 | prebuilt_bootclasspath_fragment { |
| 1003 | name: "apex-fragment.v2", |
| 1004 | contents: ["bar"], // Unlike the source fragment, this is missing foo |
| 1005 | apex_available:[ "myapex" ], |
| 1006 | hidden_api: { |
| 1007 | annotation_flags: "my-bootclasspath-fragment/annotation-flags.csv", |
| 1008 | metadata: "my-bootclasspath-fragment/metadata.csv", |
| 1009 | index: "my-bootclasspath-fragment/index.csv", |
| 1010 | stub_flags: "my-bootclasspath-fragment/stub-flags.csv", |
| 1011 | all_flags: "my-bootclasspath-fragment/all-flags.csv", |
| 1012 | }, |
| 1013 | } |
| 1014 | |
| 1015 | |
Spandan Das | 3d0d31a | 2024-05-03 21:36:48 +0000 | [diff] [blame] | 1016 | apex_contributions { |
| 1017 | name: "my_apex_contributions", |
| 1018 | api_domain: "myapex", |
| 1019 | contents: [%v], |
| 1020 | } |
| 1021 | ` |
| 1022 | testCases := []struct { |
| 1023 | desc string |
| 1024 | configuredBootJars []string |
| 1025 | apexContributionContents string |
| 1026 | errorExpected bool |
| 1027 | }{ |
| 1028 | { |
| 1029 | desc: "Source apex is selected, and APEX_BOOT_JARS is correctly configured for source apex builds", |
| 1030 | configuredBootJars: []string{"myapex:foo", "myapex:bar"}, |
| 1031 | }, |
| 1032 | { |
| 1033 | desc: "Source apex is selected, and APEX_BOOT_JARS is missing bar", |
| 1034 | configuredBootJars: []string{"myapex:foo"}, |
| 1035 | errorExpected: true, |
| 1036 | }, |
| 1037 | { |
| 1038 | desc: "Prebuilt apex is selected, and APEX_BOOT_JARS is correctly configured for prebuilt apex build", |
| 1039 | configuredBootJars: []string{"myapex:foo"}, |
| 1040 | apexContributionContents: `"prebuilt_com.google.android.myapex"`, |
| 1041 | }, |
| 1042 | { |
| 1043 | desc: "Prebuilt apex is selected, and APEX_BOOT_JARS is missing foo", |
| 1044 | configuredBootJars: []string{"myapex:bar"}, |
| 1045 | apexContributionContents: `"prebuilt_com.google.android.myapex"`, |
| 1046 | errorExpected: true, |
| 1047 | }, |
| 1048 | } |
| 1049 | |
| 1050 | for _, tc := range testCases { |
| 1051 | fixture := android.GroupFixturePreparers( |
| 1052 | prepareForTestWithPlatformBootclasspath, |
| 1053 | PrepareForTestWithApexBuildComponents, |
| 1054 | prepareForTestWithMyapex, |
| 1055 | java.FixtureConfigureApexBootJars(tc.configuredBootJars...), |
Colin Cross | a66b463 | 2024-08-08 15:50:47 -0700 | [diff] [blame] | 1056 | android.PrepareForTestWithBuildFlag("RELEASE_APEX_CONTRIBUTIONS_ART", "my_apex_contributions"), |
Spandan Das | 3d0d31a | 2024-05-03 21:36:48 +0000 | [diff] [blame] | 1057 | ) |
| 1058 | if tc.errorExpected { |
| 1059 | fixture = fixture.ExtendWithErrorHandler( |
| 1060 | android.FixtureExpectsAtLeastOneErrorMatchingPattern(`in contents.*must also be declared in PRODUCT_APEX_BOOT_JARS`), |
| 1061 | ) |
| 1062 | } |
| 1063 | fixture.RunTestWithBp(t, fmt.Sprintf(bp, tc.apexContributionContents)) |
| 1064 | } |
| 1065 | } |