blob: 3aa1258a35ca0e316f9a0d42c974cc125e57db28 [file] [log] [blame]
Paul Duffin3451e162021-01-20 15:16:56 +00001// 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
15package java
16
17import (
Paul Duffin3f1ae0b2022-07-27 16:27:42 +000018 "strings"
Paul Duffin3451e162021-01-20 15:16:56 +000019 "testing"
Paul Duffin837486d2021-03-23 23:13:53 +000020
21 "android/soong/android"
22 "android/soong/dexpreopt"
Paul Duffin3451e162021-01-20 15:16:56 +000023)
24
Paul Duffin7771eba2021-04-23 14:25:28 +010025// Contains some simple tests for bootclasspath_fragment logic, additional tests can be found in
26// apex/bootclasspath_fragment_test.go as the ART boot image requires modules from the ART apex.
Paul Duffin3451e162021-01-20 15:16:56 +000027
Paul Duffin7771eba2021-04-23 14:25:28 +010028var prepareForTestWithBootclasspathFragment = android.GroupFixturePreparers(
Paul Duffin837486d2021-03-23 23:13:53 +000029 PrepareForTestWithJavaDefaultModules,
30 dexpreopt.PrepareForTestByEnablingDexpreopt,
31)
32
Paul Duffin8018e502021-05-21 19:28:09 +010033func TestBootclasspathFragment_UnknownImageName(t *testing.T) {
Paul Duffin7771eba2021-04-23 14:25:28 +010034 prepareForTestWithBootclasspathFragment.
Paul Duffin837486d2021-03-23 23:13:53 +000035 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
Paul Duffin8018e502021-05-21 19:28:09 +010036 `\Qimage_name: unknown image name "unknown", expected "art"\E`)).
Paul Duffin837486d2021-03-23 23:13:53 +000037 RunTestWithBp(t, `
Paul Duffin7771eba2021-04-23 14:25:28 +010038 bootclasspath_fragment {
39 name: "unknown-bootclasspath-fragment",
Paul Duffin837486d2021-03-23 23:13:53 +000040 image_name: "unknown",
Paul Duffin8018e502021-05-21 19:28:09 +010041 contents: ["foo"],
Paul Duffin837486d2021-03-23 23:13:53 +000042 }
Jiakai Zhangb69e8952023-07-11 14:31:22 +010043
44 java_library {
45 name: "foo",
46 srcs: ["foo.java"],
47 installable: true,
48 }
Paul Duffin837486d2021-03-23 23:13:53 +000049 `)
Paul Duffin3451e162021-01-20 15:16:56 +000050}
Paul Duffinf7f65da2021-03-10 15:00:46 +000051
Paul Duffin8018e502021-05-21 19:28:09 +010052func TestPrebuiltBootclasspathFragment_UnknownImageName(t *testing.T) {
Paul Duffin7771eba2021-04-23 14:25:28 +010053 prepareForTestWithBootclasspathFragment.
Paul Duffin4b64ba02021-03-29 11:02:53 +010054 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
Paul Duffin8018e502021-05-21 19:28:09 +010055 `\Qimage_name: unknown image name "unknown", expected "art"\E`)).
Paul Duffin837486d2021-03-23 23:13:53 +000056 RunTestWithBp(t, `
Paul Duffin7771eba2021-04-23 14:25:28 +010057 prebuilt_bootclasspath_fragment {
58 name: "unknown-bootclasspath-fragment",
Paul Duffin837486d2021-03-23 23:13:53 +000059 image_name: "unknown",
Paul Duffin8018e502021-05-21 19:28:09 +010060 contents: ["foo"],
Paul Duffin837486d2021-03-23 23:13:53 +000061 }
Jiakai Zhangb69e8952023-07-11 14:31:22 +010062
63 java_import {
64 name: "foo",
65 jars: ["foo.jar"],
66 }
Paul Duffin837486d2021-03-23 23:13:53 +000067 `)
Paul Duffinf7f65da2021-03-10 15:00:46 +000068}
Paul Duffinc7ef9892021-03-23 23:21:59 +000069
Paul Duffin7771eba2021-04-23 14:25:28 +010070func TestBootclasspathFragmentInconsistentArtConfiguration_Platform(t *testing.T) {
Paul Duffinc7ef9892021-03-23 23:21:59 +000071 android.GroupFixturePreparers(
Paul Duffin7771eba2021-04-23 14:25:28 +010072 prepareForTestWithBootclasspathFragment,
Paul Duffinc7ef9892021-03-23 23:21:59 +000073 dexpreopt.FixtureSetArtBootJars("platform:foo", "apex:bar"),
74 ).
75 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
76 `\QArtApexJars is invalid as it requests a platform variant of "foo"\E`)).
77 RunTestWithBp(t, `
Paul Duffin7771eba2021-04-23 14:25:28 +010078 bootclasspath_fragment {
79 name: "bootclasspath-fragment",
Paul Duffinc7ef9892021-03-23 23:21:59 +000080 image_name: "art",
Paul Duffin8018e502021-05-21 19:28:09 +010081 contents: ["foo", "bar"],
Paul Duffinc7ef9892021-03-23 23:21:59 +000082 apex_available: [
83 "apex",
84 ],
85 }
Jiakai Zhangb69e8952023-07-11 14:31:22 +010086
87 java_library {
88 name: "foo",
89 srcs: ["foo.java"],
90 installable: true,
91 }
92
93 java_library {
94 name: "bar",
95 srcs: ["bar.java"],
96 installable: true,
97 }
Paul Duffinc7ef9892021-03-23 23:21:59 +000098 `)
99}
100
Paul Duffin7771eba2021-04-23 14:25:28 +0100101func TestBootclasspathFragmentInconsistentArtConfiguration_ApexMixture(t *testing.T) {
Paul Duffinc7ef9892021-03-23 23:21:59 +0000102 android.GroupFixturePreparers(
Paul Duffin7771eba2021-04-23 14:25:28 +0100103 prepareForTestWithBootclasspathFragment,
Paul Duffinc7ef9892021-03-23 23:21:59 +0000104 dexpreopt.FixtureSetArtBootJars("apex1:foo", "apex2:bar"),
105 ).
106 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
107 `\QArtApexJars configuration is inconsistent, expected all jars to be in the same apex but it specifies apex "apex1" and "apex2"\E`)).
108 RunTestWithBp(t, `
Paul Duffin7771eba2021-04-23 14:25:28 +0100109 bootclasspath_fragment {
110 name: "bootclasspath-fragment",
Paul Duffinc7ef9892021-03-23 23:21:59 +0000111 image_name: "art",
Paul Duffin8018e502021-05-21 19:28:09 +0100112 contents: ["foo", "bar"],
Paul Duffinc7ef9892021-03-23 23:21:59 +0000113 apex_available: [
114 "apex1",
115 "apex2",
116 ],
117 }
Jiakai Zhangb69e8952023-07-11 14:31:22 +0100118
119 java_library {
120 name: "foo",
121 srcs: ["foo.java"],
122 installable: true,
123 }
124
125 java_library {
126 name: "bar",
127 srcs: ["bar.java"],
128 installable: true,
129 }
Paul Duffinc7ef9892021-03-23 23:21:59 +0000130 `)
131}
Paul Duffin82886d62021-03-24 01:34:57 +0000132
Paul Duffinc7d16442021-04-23 13:55:49 +0100133func TestBootclasspathFragment_Coverage(t *testing.T) {
Paul Duffinc7d16442021-04-23 13:55:49 +0100134 prepareWithBp := android.FixtureWithRootAndroidBp(`
135 bootclasspath_fragment {
136 name: "myfragment",
137 contents: [
138 "mybootlib",
139 ],
Paul Duffin895c7142021-04-25 13:40:15 +0100140 api: {
141 stub_libs: [
142 "mysdklibrary",
143 ],
144 },
Paul Duffinc7d16442021-04-23 13:55:49 +0100145 coverage: {
146 contents: [
147 "coveragelib",
148 ],
Paul Duffin895c7142021-04-25 13:40:15 +0100149 api: {
150 stub_libs: [
151 "mycoveragestubs",
152 ],
153 },
Paul Duffinc7d16442021-04-23 13:55:49 +0100154 },
Paul Duffin9fd56472022-03-31 15:42:30 +0100155 hidden_api: {
156 split_packages: ["*"],
157 },
Paul Duffinc7d16442021-04-23 13:55:49 +0100158 }
159
160 java_library {
161 name: "mybootlib",
162 srcs: ["Test.java"],
163 system_modules: "none",
164 sdk_version: "none",
165 compile_dex: true,
166 }
167
168 java_library {
169 name: "coveragelib",
170 srcs: ["Test.java"],
171 system_modules: "none",
172 sdk_version: "none",
173 compile_dex: true,
174 }
Paul Duffin895c7142021-04-25 13:40:15 +0100175
176 java_sdk_library {
177 name: "mysdklibrary",
178 srcs: ["Test.java"],
179 compile_dex: true,
180 public: {enabled: true},
181 system: {enabled: true},
182 }
183
184 java_sdk_library {
185 name: "mycoveragestubs",
186 srcs: ["Test.java"],
187 compile_dex: true,
188 public: {enabled: true},
189 }
Paul Duffinc7d16442021-04-23 13:55:49 +0100190 `)
191
192 checkContents := func(t *testing.T, result *android.TestResult, expected ...string) {
193 module := result.Module("myfragment", "android_common").(*BootclasspathFragmentModule)
Spandan Das7103c4f2024-11-11 22:31:55 +0000194 eval := module.ConfigurableEvaluator(android.PanickingConfigAndErrorContext(result.TestContext))
195 android.AssertArrayString(t, "contents property", expected, module.properties.Contents.GetOrDefault(eval, nil))
Paul Duffinc7d16442021-04-23 13:55:49 +0100196 }
197
Paul Duffin895c7142021-04-25 13:40:15 +0100198 preparer := android.GroupFixturePreparers(
199 prepareForTestWithBootclasspathFragment,
200 PrepareForTestWithJavaSdkLibraryFiles,
201 FixtureWithLastReleaseApis("mysdklibrary", "mycoveragestubs"),
satayevabcd5972021-08-06 17:49:46 +0100202 FixtureConfigureApexBootJars("someapex:mybootlib"),
Paul Duffin895c7142021-04-25 13:40:15 +0100203 prepareWithBp,
204 )
205
Paul Duffinc7d16442021-04-23 13:55:49 +0100206 t.Run("without coverage", func(t *testing.T) {
Paul Duffin895c7142021-04-25 13:40:15 +0100207 result := preparer.RunTest(t)
Paul Duffinc7d16442021-04-23 13:55:49 +0100208 checkContents(t, result, "mybootlib")
209 })
210
211 t.Run("with coverage", func(t *testing.T) {
212 result := android.GroupFixturePreparers(
Sam Delmerico1e3f78f2022-09-07 12:07:07 -0400213 prepareForTestWithFrameworkJacocoInstrumentation,
Paul Duffin895c7142021-04-25 13:40:15 +0100214 preparer,
Paul Duffinc7d16442021-04-23 13:55:49 +0100215 ).RunTest(t)
216 checkContents(t, result, "mybootlib", "coveragelib")
217 })
218}
Paul Duffin10931582021-04-25 10:13:54 +0100219
220func TestBootclasspathFragment_StubLibs(t *testing.T) {
221 result := android.GroupFixturePreparers(
222 prepareForTestWithBootclasspathFragment,
223 PrepareForTestWithJavaSdkLibraryFiles,
Paul Duffin34827d42021-05-13 21:25:05 +0100224 FixtureWithLastReleaseApis("mysdklibrary", "myothersdklibrary", "mycoreplatform"),
satayevabcd5972021-08-06 17:49:46 +0100225 FixtureConfigureApexBootJars("someapex:mysdklibrary"),
Colin Crossa66b4632024-08-08 15:50:47 -0700226 android.PrepareForTestWithBuildFlag("RELEASE_HIDDEN_API_EXPORTABLE_STUBS", "true"),
Paul Duffin10931582021-04-25 10:13:54 +0100227 ).RunTestWithBp(t, `
228 bootclasspath_fragment {
229 name: "myfragment",
230 contents: ["mysdklibrary"],
231 api: {
232 stub_libs: [
233 "mystublib",
Paul Duffin34827d42021-05-13 21:25:05 +0100234 "myothersdklibrary",
Paul Duffin10931582021-04-25 10:13:54 +0100235 ],
236 },
237 core_platform_api: {
Paul Duffin3f0290e2021-06-30 18:25:36 +0100238 stub_libs: ["mycoreplatform.stubs"],
Paul Duffin10931582021-04-25 10:13:54 +0100239 },
Paul Duffin9fd56472022-03-31 15:42:30 +0100240 hidden_api: {
241 split_packages: ["*"],
242 },
Paul Duffin10931582021-04-25 10:13:54 +0100243 }
244
245 java_library {
246 name: "mystublib",
247 srcs: ["Test.java"],
248 system_modules: "none",
249 sdk_version: "none",
250 compile_dex: true,
251 }
252
253 java_sdk_library {
254 name: "mysdklibrary",
255 srcs: ["a.java"],
Paul Duffinf4600f62021-05-13 22:34:45 +0100256 shared_library: false,
Paul Duffin10931582021-04-25 10:13:54 +0100257 public: {enabled: true},
258 system: {enabled: true},
259 }
260
261 java_sdk_library {
Paul Duffin34827d42021-05-13 21:25:05 +0100262 name: "myothersdklibrary",
263 srcs: ["a.java"],
264 shared_library: false,
265 public: {enabled: true},
266 }
267
268 java_sdk_library {
Paul Duffin10931582021-04-25 10:13:54 +0100269 name: "mycoreplatform",
270 srcs: ["a.java"],
Paul Duffinf4600f62021-05-13 22:34:45 +0100271 shared_library: false,
Paul Duffin10931582021-04-25 10:13:54 +0100272 public: {enabled: true},
273 }
274 `)
275
276 fragment := result.Module("myfragment", "android_common")
Yu Liu663e4502024-08-12 18:23:59 +0000277 info, _ := android.OtherModuleProvider(result, fragment, HiddenAPIInfoProvider)
Paul Duffin10931582021-04-25 10:13:54 +0100278
279 stubsJar := "out/soong/.intermediates/mystublib/android_common/dex/mystublib.jar"
280
Paul Duffin34827d42021-05-13 21:25:05 +0100281 // Stubs jars for mysdklibrary
Jihoon Kangbd093452023-12-26 19:08:01 +0000282 publicStubsJar := "out/soong/.intermediates/mysdklibrary.stubs.exportable/android_common/dex/mysdklibrary.stubs.exportable.jar"
283 systemStubsJar := "out/soong/.intermediates/mysdklibrary.stubs.exportable.system/android_common/dex/mysdklibrary.stubs.exportable.system.jar"
Paul Duffin10931582021-04-25 10:13:54 +0100284
Paul Duffin34827d42021-05-13 21:25:05 +0100285 // Stubs jars for myothersdklibrary
Jihoon Kangbd093452023-12-26 19:08:01 +0000286 otherPublicStubsJar := "out/soong/.intermediates/myothersdklibrary.stubs.exportable/android_common/dex/myothersdklibrary.stubs.exportable.jar"
Paul Duffin34827d42021-05-13 21:25:05 +0100287
288 // Check that SdkPublic uses public stubs for all sdk libraries.
Paul Duffin280a31a2021-06-27 20:28:29 +0100289 android.AssertPathsRelativeToTopEquals(t, "public dex stubs jar", []string{otherPublicStubsJar, publicStubsJar, stubsJar}, info.TransitiveStubDexJarsByScope.StubDexJarsForScope(PublicHiddenAPIScope))
Paul Duffin34827d42021-05-13 21:25:05 +0100290
291 // Check that SdkSystem uses system stubs for mysdklibrary and public stubs for myothersdklibrary
292 // as it does not provide system stubs.
Paul Duffin280a31a2021-06-27 20:28:29 +0100293 android.AssertPathsRelativeToTopEquals(t, "system dex stubs jar", []string{otherPublicStubsJar, systemStubsJar, stubsJar}, info.TransitiveStubDexJarsByScope.StubDexJarsForScope(SystemHiddenAPIScope))
Paul Duffin34827d42021-05-13 21:25:05 +0100294
295 // Check that SdkTest also uses system stubs for mysdklibrary as it does not provide test stubs
296 // and public stubs for myothersdklibrary as it does not provide test stubs either.
Paul Duffin280a31a2021-06-27 20:28:29 +0100297 android.AssertPathsRelativeToTopEquals(t, "test dex stubs jar", []string{otherPublicStubsJar, systemStubsJar, stubsJar}, info.TransitiveStubDexJarsByScope.StubDexJarsForScope(TestHiddenAPIScope))
Paul Duffin10931582021-04-25 10:13:54 +0100298
299 // Check that SdkCorePlatform uses public stubs from the mycoreplatform library.
300 corePlatformStubsJar := "out/soong/.intermediates/mycoreplatform.stubs/android_common/dex/mycoreplatform.stubs.jar"
Paul Duffin280a31a2021-06-27 20:28:29 +0100301 android.AssertPathsRelativeToTopEquals(t, "core platform dex stubs jar", []string{corePlatformStubsJar}, info.TransitiveStubDexJarsByScope.StubDexJarsForScope(CorePlatformHiddenAPIScope))
Paul Duffind2b1e0c2021-06-27 20:53:39 +0100302
Paul Duffin280a31a2021-06-27 20:28:29 +0100303 // Check the widest stubs.. The list contains the widest stub dex jar provided by each module.
304 expectedWidestPaths := []string{
305 // mycoreplatform's widest API is core platform.
306 corePlatformStubsJar,
307
308 // myothersdklibrary's widest API is public.
309 otherPublicStubsJar,
310
311 // sdklibrary's widest API is system.
312 systemStubsJar,
313
314 // mystublib's only provides one API and so it must be the widest.
315 stubsJar,
316 }
317
318 android.AssertPathsRelativeToTopEquals(t, "widest dex stubs jar", expectedWidestPaths, info.TransitiveStubDexJarsByScope.StubDexJarsForWidestAPIScope())
Paul Duffin10931582021-04-25 10:13:54 +0100319}
Paul Duffinc15b9e92022-03-31 15:42:30 +0100320
Jihoon Kang244d42a2023-10-06 16:54:58 +0000321func TestFromTextWidestApiScope(t *testing.T) {
322 result := android.GroupFixturePreparers(
323 prepareForTestWithBootclasspathFragment,
324 PrepareForTestWithJavaSdkLibraryFiles,
325 android.FixtureModifyConfig(func(config android.Config) {
326 config.SetBuildFromTextStub(true)
327 }),
328 FixtureWithLastReleaseApis("mysdklibrary", "android-non-updatable"),
329 FixtureConfigureApexBootJars("someapex:mysdklibrary"),
330 ).RunTestWithBp(t, `
331 bootclasspath_fragment {
332 name: "myfragment",
333 contents: ["mysdklibrary"],
334 additional_stubs: [
335 "android-non-updatable",
336 ],
337 hidden_api: {
338 split_packages: ["*"],
339 },
340 }
341 java_sdk_library {
342 name: "mysdklibrary",
343 srcs: ["a.java"],
344 shared_library: false,
345 public: {enabled: true},
346 system: {enabled: true},
347 }
348 java_sdk_library {
349 name: "android-non-updatable",
350 srcs: ["b.java"],
351 compile_dex: true,
352 public: {
353 enabled: true,
354 },
355 system: {
356 enabled: true,
357 },
358 test: {
359 enabled: true,
360 },
361 module_lib: {
362 enabled: true,
363 },
364 }
365 `)
366
367 fragment := result.ModuleForTests("myfragment", "android_common")
368 dependencyStubDexFlag := "--dependency-stub-dex=out/soong/.intermediates/default/java/android-non-updatable.stubs.test_module_lib/android_common/dex/android-non-updatable.stubs.test_module_lib.jar"
369 stubFlagsCommand := fragment.Output("modular-hiddenapi/stub-flags.csv").RuleParams.Command
370 android.AssertStringDoesContain(t,
371 "Stub flags generating command does not include the expected dependency stub dex file",
372 stubFlagsCommand, dependencyStubDexFlag)
373}
374
Paul Duffin3f1ae0b2022-07-27 16:27:42 +0000375func TestSnapshotWithBootclasspathFragment_HiddenAPI(t *testing.T) {
376 result := android.GroupFixturePreparers(
377 prepareForTestWithBootclasspathFragment,
378 PrepareForTestWithJavaSdkLibraryFiles,
379 FixtureWithLastReleaseApis("mysdklibrary", "mynewlibrary"),
380 FixtureConfigureApexBootJars("myapex:mybootlib", "myapex:mynewlibrary"),
381 android.MockFS{
382 "my-blocked.txt": nil,
383 "my-max-target-o-low-priority.txt": nil,
384 "my-max-target-p.txt": nil,
385 "my-max-target-q.txt": nil,
386 "my-max-target-r-low-priority.txt": nil,
387 "my-removed.txt": nil,
388 "my-unsupported-packages.txt": nil,
389 "my-unsupported.txt": nil,
390 "my-new-max-target-q.txt": nil,
391 }.AddToFixture(),
392 android.FixtureWithRootAndroidBp(`
393 bootclasspath_fragment {
394 name: "mybootclasspathfragment",
395 apex_available: ["myapex"],
396 contents: ["mybootlib", "mynewlibrary"],
397 hidden_api: {
398 unsupported: [
399 "my-unsupported.txt",
400 ],
401 removed: [
402 "my-removed.txt",
403 ],
404 max_target_r_low_priority: [
405 "my-max-target-r-low-priority.txt",
406 ],
407 max_target_q: [
408 "my-max-target-q.txt",
409 ],
410 max_target_p: [
411 "my-max-target-p.txt",
412 ],
413 max_target_o_low_priority: [
414 "my-max-target-o-low-priority.txt",
415 ],
416 blocked: [
417 "my-blocked.txt",
418 ],
419 unsupported_packages: [
420 "my-unsupported-packages.txt",
421 ],
422 split_packages: ["sdklibrary"],
423 package_prefixes: ["sdklibrary.all.mine"],
424 single_packages: ["sdklibrary.mine"],
425 },
426 }
427
428 java_library {
429 name: "mybootlib",
430 apex_available: ["myapex"],
431 srcs: ["Test.java"],
432 system_modules: "none",
433 sdk_version: "none",
434 min_sdk_version: "1",
435 compile_dex: true,
436 permitted_packages: ["mybootlib"],
437 }
438
439 java_sdk_library {
440 name: "mynewlibrary",
441 apex_available: ["myapex"],
442 srcs: ["Test.java"],
443 min_sdk_version: "10",
444 compile_dex: true,
445 public: {enabled: true},
446 permitted_packages: ["mysdklibrary"],
447 hidden_api: {
448 max_target_q: [
449 "my-new-max-target-q.txt",
450 ],
451 split_packages: ["sdklibrary", "newlibrary"],
452 package_prefixes: ["newlibrary.all.mine"],
453 single_packages: ["newlibrary.mine"],
454 },
455 }
456 `),
457 ).RunTest(t)
458
459 // Make sure that the library exports hidden API properties for use by the bootclasspath_fragment.
460 library := result.Module("mynewlibrary", "android_common")
Yu Liu663e4502024-08-12 18:23:59 +0000461 info, _ := android.OtherModuleProvider(result, library, hiddenAPIPropertyInfoProvider)
Paul Duffin3f1ae0b2022-07-27 16:27:42 +0000462 android.AssertArrayString(t, "split packages", []string{"sdklibrary", "newlibrary"}, info.SplitPackages)
463 android.AssertArrayString(t, "package prefixes", []string{"newlibrary.all.mine"}, info.PackagePrefixes)
464 android.AssertArrayString(t, "single packages", []string{"newlibrary.mine"}, info.SinglePackages)
465 for _, c := range HiddenAPIFlagFileCategories {
466 expectedMaxTargetQPaths := []string(nil)
Cole Faust22e8abc2024-01-23 17:52:13 -0800467 if c.PropertyName() == "max_target_q" {
Paul Duffin3f1ae0b2022-07-27 16:27:42 +0000468 expectedMaxTargetQPaths = []string{"my-new-max-target-q.txt"}
469 }
Cole Faust22e8abc2024-01-23 17:52:13 -0800470 android.AssertPathsRelativeToTopEquals(t, c.PropertyName(), expectedMaxTargetQPaths, info.FlagFilesByCategory[c])
Paul Duffin3f1ae0b2022-07-27 16:27:42 +0000471 }
472
473 // Make sure that the signature-patterns.csv is passed all the appropriate package properties
474 // from the bootclasspath_fragment and its contents.
475 fragment := result.ModuleForTests("mybootclasspathfragment", "android_common")
476 rule := fragment.Output("modular-hiddenapi/signature-patterns.csv")
477 expectedCommand := strings.Join([]string{
478 "--split-package newlibrary",
479 "--split-package sdklibrary",
480 "--package-prefix newlibrary.all.mine",
481 "--package-prefix sdklibrary.all.mine",
482 "--single-package newlibrary.mine",
483 "--single-package sdklibrary",
484 }, " ")
485 android.AssertStringDoesContain(t, "signature patterns command", rule.RuleParams.Command, expectedCommand)
486}
487
Paul Duffinc15b9e92022-03-31 15:42:30 +0100488func TestBootclasspathFragment_Test(t *testing.T) {
489 result := android.GroupFixturePreparers(
490 prepareForTestWithBootclasspathFragment,
491 PrepareForTestWithJavaSdkLibraryFiles,
492 FixtureWithLastReleaseApis("mysdklibrary"),
493 ).RunTestWithBp(t, `
494 bootclasspath_fragment {
495 name: "myfragment",
496 contents: ["mysdklibrary"],
497 hidden_api: {
498 split_packages: [],
499 },
500 }
501
502 bootclasspath_fragment_test {
503 name: "a_test_fragment",
504 contents: ["mysdklibrary"],
505 hidden_api: {
506 split_packages: [],
507 },
508 }
509
510
511 java_sdk_library {
512 name: "mysdklibrary",
513 srcs: ["a.java"],
514 shared_library: false,
515 public: {enabled: true},
516 system: {enabled: true},
517 }
518 `)
519
520 fragment := result.Module("myfragment", "android_common").(*BootclasspathFragmentModule)
521 android.AssertBoolEquals(t, "not a test fragment", false, fragment.isTestFragment())
522
523 fragment = result.Module("a_test_fragment", "android_common").(*BootclasspathFragmentModule)
524 android.AssertBoolEquals(t, "is a test fragment by type", true, fragment.isTestFragment())
525}