blob: 416dce62c9a5ceffaf355c434d2cccf4392cad52 [file] [log] [blame]
Jiyong Parkd1063c12019-07-17 20:08:41 +09001// Copyright 2019 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package sdk
16
17import (
Martin Stjernholm3ff2e662020-07-15 14:38:15 +010018 "log"
19 "os"
Colin Cross0c66bc62021-07-20 09:47:41 -070020 "runtime"
Jiyong Parkd1063c12019-07-17 20:08:41 +090021 "testing"
Paul Duffinb07fa512020-03-10 22:17:04 +000022
Colin Cross0c66bc62021-07-20 09:47:41 -070023 "android/soong/android"
Paul Duffin39abf8f2021-09-24 14:58:27 +010024 "android/soong/java"
Colin Cross0c66bc62021-07-20 09:47:41 -070025
Paul Duffinb07fa512020-03-10 22:17:04 +000026 "github.com/google/blueprint/proptools"
Jiyong Parkd1063c12019-07-17 20:08:41 +090027)
28
Paul Duffin82d90432019-11-30 09:24:33 +000029// Needed in an _test.go file in this package to ensure tests run correctly, particularly in IDE.
30func TestMain(m *testing.M) {
Colin Cross0c66bc62021-07-20 09:47:41 -070031 if runtime.GOOS != "linux" {
Martin Stjernholm3ff2e662020-07-15 14:38:15 +010032 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
Colin Cross0c66bc62021-07-20 09:47:41 -070033 log.Printf("Skipping as sdk snapshot generation is only supported on linux not %s", runtime.GOOS)
Martin Stjernholm3ff2e662020-07-15 14:38:15 +010034 os.Exit(0)
35 }
36
Paul Duffinabbf63d2021-03-18 01:47:31 +000037 os.Exit(m.Run())
Jiyong Parkd1063c12019-07-17 20:08:41 +090038}
39
Paul Duffin593b3c92019-12-05 14:31:48 +000040// Ensure that prebuilt modules have the same effective visibility as the source
41// modules.
42func TestSnapshotVisibility(t *testing.T) {
43 packageBp := `
44 package {
45 default_visibility: ["//other/foo"],
46 }
47
48 sdk {
49 name: "mysdk",
50 visibility: [
51 "//other/foo",
52 // This short form will be replaced with //package:__subpackages__ in the
53 // generated sdk_snapshot.
54 ":__subpackages__",
55 ],
Paul Duffin157f40f2020-09-29 16:01:08 +010056 prebuilt_visibility: [
57 "//prebuilts/mysdk",
58 ],
Paul Duffin593b3c92019-12-05 14:31:48 +000059 java_header_libs: [
60 "myjavalib",
61 "mypublicjavalib",
62 "mydefaultedjavalib",
Martin Stjernholm64aeaad2020-05-13 22:11:40 +010063 "myprivatejavalib",
Paul Duffin593b3c92019-12-05 14:31:48 +000064 ],
65 }
66
67 java_library {
68 name: "myjavalib",
69 // Uses package default visibility
70 srcs: ["Test.java"],
71 system_modules: "none",
72 sdk_version: "none",
73 }
74
Paul Duffin44885e22020-02-19 16:10:09 +000075 java_defaults {
76 name: "java-defaults",
Jooyung Han5e9013b2020-03-10 06:23:13 +090077 visibility: ["//other/bar"],
Paul Duffin44885e22020-02-19 16:10:09 +000078 }
79
Paul Duffin593b3c92019-12-05 14:31:48 +000080 java_library {
81 name: "mypublicjavalib",
Paul Duffin44885e22020-02-19 16:10:09 +000082 defaults: ["java-defaults"],
Paul Duffin593b3c92019-12-05 14:31:48 +000083 visibility: ["//visibility:public"],
84 srcs: ["Test.java"],
85 system_modules: "none",
86 sdk_version: "none",
87 }
88
89 java_defaults {
90 name: "myjavadefaults",
91 visibility: ["//other/bar"],
92 }
93
94 java_library {
95 name: "mydefaultedjavalib",
96 defaults: ["myjavadefaults"],
97 srcs: ["Test.java"],
98 system_modules: "none",
99 sdk_version: "none",
100 }
Martin Stjernholm64aeaad2020-05-13 22:11:40 +0100101
102 java_library {
103 name: "myprivatejavalib",
104 srcs: ["Test.java"],
105 visibility: ["//visibility:private"],
106 system_modules: "none",
107 sdk_version: "none",
108 }
Paul Duffin593b3c92019-12-05 14:31:48 +0000109 `
110
111 result := testSdkWithFs(t, ``,
112 map[string][]byte{
113 "package/Test.java": nil,
114 "package/Android.bp": []byte(packageBp),
115 })
116
Paul Duffin36474d32021-03-12 12:19:43 +0000117 CheckSnapshot(t, result, "mysdk", "package",
Paul Duffin593b3c92019-12-05 14:31:48 +0000118 checkAndroidBpContents(`
119// This is auto-generated. DO NOT EDIT.
120
Spandan Dasa5e26d32024-03-06 14:04:36 +0000121apex_contributions_defaults {
122 name: "mysdk.contributions",
123 contents: [
124 "prebuilt_myjavalib",
125 "prebuilt_mypublicjavalib",
126 "prebuilt_mydefaultedjavalib",
127 "prebuilt_myprivatejavalib",
128 ],
129}
130
Paul Duffin593b3c92019-12-05 14:31:48 +0000131java_import {
Paul Duffin593b3c92019-12-05 14:31:48 +0000132 name: "myjavalib",
133 prefer: false,
Spandan Das2c207262024-08-30 18:56:39 +0000134 visibility: ["//visibility:public"],
Martin Stjernholm1e041092020-11-03 00:11:09 +0000135 apex_available: ["//apex_available:platform"],
Paul Duffin593b3c92019-12-05 14:31:48 +0000136 jars: ["java/myjavalib.jar"],
137}
138
139java_import {
Paul Duffin593b3c92019-12-05 14:31:48 +0000140 name: "mypublicjavalib",
141 prefer: false,
142 visibility: ["//visibility:public"],
Martin Stjernholm1e041092020-11-03 00:11:09 +0000143 apex_available: ["//apex_available:platform"],
Paul Duffin593b3c92019-12-05 14:31:48 +0000144 jars: ["java/mypublicjavalib.jar"],
145}
146
147java_import {
Paul Duffin593b3c92019-12-05 14:31:48 +0000148 name: "mydefaultedjavalib",
149 prefer: false,
Spandan Das2c207262024-08-30 18:56:39 +0000150 visibility: ["//visibility:public"],
Martin Stjernholm1e041092020-11-03 00:11:09 +0000151 apex_available: ["//apex_available:platform"],
Paul Duffin593b3c92019-12-05 14:31:48 +0000152 jars: ["java/mydefaultedjavalib.jar"],
153}
154
Martin Stjernholm64aeaad2020-05-13 22:11:40 +0100155java_import {
Martin Stjernholm64aeaad2020-05-13 22:11:40 +0100156 name: "myprivatejavalib",
157 prefer: false,
Spandan Das2c207262024-08-30 18:56:39 +0000158 visibility: ["//visibility:public"],
Martin Stjernholm1e041092020-11-03 00:11:09 +0000159 apex_available: ["//apex_available:platform"],
Martin Stjernholm64aeaad2020-05-13 22:11:40 +0100160 jars: ["java/myprivatejavalib.jar"],
161}
Paul Duffin593b3c92019-12-05 14:31:48 +0000162`))
163}
Nicolas Geoffray1228e9c2020-02-27 13:45:35 +0000164
Paul Duffin157f40f2020-09-29 16:01:08 +0100165func TestPrebuiltVisibilityProperty_IsValidated(t *testing.T) {
166 testSdkError(t, `prebuilt_visibility: cannot mix "//visibility:private" with any other visibility rules`, `
167 sdk {
168 name: "mysdk",
169 prebuilt_visibility: [
170 "//foo",
171 "//visibility:private",
172 ],
173 }
174`)
175}
176
Paul Duffin8edc99c2021-03-09 23:02:20 +0000177func TestSdkInstall(t *testing.T) {
Nicolas Geoffray1228e9c2020-02-27 13:45:35 +0000178 sdk := `
179 sdk {
180 name: "mysdk",
181 }
182 `
Paul Duffin8edc99c2021-03-09 23:02:20 +0000183 result := testSdkWithFs(t, sdk, nil)
Nicolas Geoffray1228e9c2020-02-27 13:45:35 +0000184
Paul Duffin36474d32021-03-12 12:19:43 +0000185 CheckSnapshot(t, result, "mysdk", "",
Paul Duffinc6ba1822022-05-06 09:38:02 +0000186 checkAllOtherCopyRules(`
187.intermediates/mysdk/common_os/mysdk-current.info -> mysdk-current.info
188.intermediates/mysdk/common_os/mysdk-current.zip -> mysdk-current.zip
189`))
Nicolas Geoffray1228e9c2020-02-27 13:45:35 +0000190}
Paul Duffinb07fa512020-03-10 22:17:04 +0000191
192type EmbeddedPropertiesStruct struct {
Paul Duffin864e1b42020-05-06 10:23:19 +0100193 S_Embedded_Common string `android:"arch_variant"`
194 S_Embedded_Different string `android:"arch_variant"`
Paul Duffinb07fa512020-03-10 22:17:04 +0000195}
196
197type testPropertiesStruct struct {
Paul Duffin02e25c82022-09-22 15:30:58 +0100198 name string
199 private string
200 Public_Ignore string `sdk:"ignore"`
Paul Duffinbfdca962022-09-22 16:21:54 +0100201 Public_Keep string `sdk:"keep"`
Paul Duffin02e25c82022-09-22 15:30:58 +0100202 S_Common string
203 S_Different string `android:"arch_variant"`
204 A_Common []string
205 A_Different []string `android:"arch_variant"`
206 F_Common *bool
207 F_Different *bool `android:"arch_variant"`
Paul Duffinb07fa512020-03-10 22:17:04 +0000208 EmbeddedPropertiesStruct
209}
210
Paul Duffinf34f6d82020-04-30 15:48:31 +0100211func (p *testPropertiesStruct) optimizableProperties() interface{} {
212 return p
213}
214
Paul Duffin4b8b7932020-05-06 12:35:38 +0100215func (p *testPropertiesStruct) String() string {
216 return p.name
217}
218
219var _ propertiesContainer = (*testPropertiesStruct)(nil)
220
Paul Duffinb07fa512020-03-10 22:17:04 +0000221func TestCommonValueOptimization(t *testing.T) {
Paul Duffin4b8b7932020-05-06 12:35:38 +0100222 common := &testPropertiesStruct{name: "common"}
Paul Duffinf34f6d82020-04-30 15:48:31 +0100223 structs := []propertiesContainer{
Paul Duffinb07fa512020-03-10 22:17:04 +0000224 &testPropertiesStruct{
Paul Duffin02e25c82022-09-22 15:30:58 +0100225 name: "struct-0",
226 private: "common",
227 Public_Ignore: "common",
Paul Duffinbfdca962022-09-22 16:21:54 +0100228 Public_Keep: "keep",
Paul Duffin02e25c82022-09-22 15:30:58 +0100229 S_Common: "common",
230 S_Different: "upper",
231 A_Common: []string{"first", "second"},
232 A_Different: []string{"alpha", "beta"},
233 F_Common: proptools.BoolPtr(false),
234 F_Different: proptools.BoolPtr(false),
Paul Duffinb07fa512020-03-10 22:17:04 +0000235 EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{
236 S_Embedded_Common: "embedded_common",
237 S_Embedded_Different: "embedded_upper",
238 },
239 },
240 &testPropertiesStruct{
Paul Duffin02e25c82022-09-22 15:30:58 +0100241 name: "struct-1",
242 private: "common",
243 Public_Ignore: "common",
Paul Duffinbfdca962022-09-22 16:21:54 +0100244 Public_Keep: "keep",
Paul Duffin02e25c82022-09-22 15:30:58 +0100245 S_Common: "common",
246 S_Different: "lower",
247 A_Common: []string{"first", "second"},
248 A_Different: []string{"alpha", "delta"},
249 F_Common: proptools.BoolPtr(false),
250 F_Different: proptools.BoolPtr(true),
Paul Duffinb07fa512020-03-10 22:17:04 +0000251 EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{
252 S_Embedded_Common: "embedded_common",
253 S_Embedded_Different: "embedded_lower",
254 },
255 },
256 }
257
258 extractor := newCommonValueExtractor(common)
Paul Duffinb07fa512020-03-10 22:17:04 +0000259
Paul Duffinc459f892020-04-30 18:08:29 +0100260 err := extractor.extractCommonProperties(common, structs)
Paul Duffin36474d32021-03-12 12:19:43 +0000261 android.AssertDeepEquals(t, "unexpected error", nil, err)
Paul Duffinc459f892020-04-30 18:08:29 +0100262
Paul Duffin36474d32021-03-12 12:19:43 +0000263 android.AssertDeepEquals(t, "common properties not correct",
Paul Duffinb07fa512020-03-10 22:17:04 +0000264 &testPropertiesStruct{
Paul Duffin02e25c82022-09-22 15:30:58 +0100265 name: "common",
266 private: "",
267 Public_Ignore: "",
Paul Duffinbfdca962022-09-22 16:21:54 +0100268 Public_Keep: "keep",
Paul Duffin02e25c82022-09-22 15:30:58 +0100269 S_Common: "common",
270 S_Different: "",
271 A_Common: []string{"first", "second"},
272 A_Different: []string(nil),
273 F_Common: proptools.BoolPtr(false),
274 F_Different: nil,
Paul Duffinb07fa512020-03-10 22:17:04 +0000275 EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{
276 S_Embedded_Common: "embedded_common",
277 S_Embedded_Different: "",
278 },
Paul Duffin1d6c0df2020-05-06 12:50:19 +0100279 },
280 common)
Paul Duffinb07fa512020-03-10 22:17:04 +0000281
Paul Duffin36474d32021-03-12 12:19:43 +0000282 android.AssertDeepEquals(t, "updated properties[0] not correct",
Paul Duffinb07fa512020-03-10 22:17:04 +0000283 &testPropertiesStruct{
Paul Duffin02e25c82022-09-22 15:30:58 +0100284 name: "struct-0",
285 private: "common",
286 Public_Ignore: "common",
Paul Duffinbfdca962022-09-22 16:21:54 +0100287 Public_Keep: "keep",
Paul Duffin02e25c82022-09-22 15:30:58 +0100288 S_Common: "",
289 S_Different: "upper",
290 A_Common: nil,
291 A_Different: []string{"alpha", "beta"},
292 F_Common: nil,
293 F_Different: proptools.BoolPtr(false),
Paul Duffinb07fa512020-03-10 22:17:04 +0000294 EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{
295 S_Embedded_Common: "",
296 S_Embedded_Different: "embedded_upper",
297 },
Paul Duffin1d6c0df2020-05-06 12:50:19 +0100298 },
299 structs[0])
Paul Duffinb07fa512020-03-10 22:17:04 +0000300
Paul Duffin36474d32021-03-12 12:19:43 +0000301 android.AssertDeepEquals(t, "updated properties[1] not correct",
Paul Duffinb07fa512020-03-10 22:17:04 +0000302 &testPropertiesStruct{
Paul Duffin02e25c82022-09-22 15:30:58 +0100303 name: "struct-1",
304 private: "common",
305 Public_Ignore: "common",
Paul Duffinbfdca962022-09-22 16:21:54 +0100306 Public_Keep: "keep",
Paul Duffin02e25c82022-09-22 15:30:58 +0100307 S_Common: "",
308 S_Different: "lower",
309 A_Common: nil,
310 A_Different: []string{"alpha", "delta"},
311 F_Common: nil,
312 F_Different: proptools.BoolPtr(true),
Paul Duffinb07fa512020-03-10 22:17:04 +0000313 EmbeddedPropertiesStruct: EmbeddedPropertiesStruct{
314 S_Embedded_Common: "",
315 S_Embedded_Different: "embedded_lower",
316 },
Paul Duffin1d6c0df2020-05-06 12:50:19 +0100317 },
318 structs[1])
Paul Duffinb07fa512020-03-10 22:17:04 +0000319}
Paul Duffin864e1b42020-05-06 10:23:19 +0100320
321func TestCommonValueOptimization_InvalidArchSpecificVariants(t *testing.T) {
322 common := &testPropertiesStruct{name: "common"}
323 structs := []propertiesContainer{
324 &testPropertiesStruct{
325 name: "struct-0",
326 S_Common: "should-be-but-is-not-common0",
327 },
328 &testPropertiesStruct{
329 name: "struct-1",
330 S_Common: "should-be-but-is-not-common1",
331 },
332 }
333
334 extractor := newCommonValueExtractor(common)
335
Paul Duffin864e1b42020-05-06 10:23:19 +0100336 err := extractor.extractCommonProperties(common, structs)
Paul Duffin36474d32021-03-12 12:19:43 +0000337 android.AssertErrorMessageEquals(t, "unexpected error", `field "S_Common" is not tagged as "arch_variant" but has arch specific properties:
Paul Duffin864e1b42020-05-06 10:23:19 +0100338 "struct-0" has value "should-be-but-is-not-common0"
339 "struct-1" has value "should-be-but-is-not-common1"`, err)
340}
Paul Duffin62035b52021-05-05 21:35:49 +0100341
342// Ensure that sdk snapshot related environment variables work correctly.
343func TestSnapshot_EnvConfiguration(t *testing.T) {
344 bp := `
345 sdk {
346 name: "mysdk",
347 java_header_libs: ["myjavalib"],
348 }
349
350 java_library {
351 name: "myjavalib",
352 srcs: ["Test.java"],
353 system_modules: "none",
354 sdk_version: "none",
355 compile_dex: true,
356 host_supported: true,
357 }
358 `
359 preparer := android.GroupFixturePreparers(
360 prepareForSdkTestWithJava,
361 android.FixtureWithRootAndroidBp(bp),
362 )
363
364 checkZipFile := func(t *testing.T, result *android.TestResult, expected string) {
365 zipRule := result.ModuleForTests("mysdk", "common_os").Rule("SnapshotZipFiles")
366 android.AssertStringEquals(t, "snapshot zip file", expected, zipRule.Output.String())
367 }
368
369 t.Run("no env variables", func(t *testing.T) {
370 result := preparer.RunTest(t)
371
372 checkZipFile(t, result, "out/soong/.intermediates/mysdk/common_os/mysdk-current.zip")
373
374 CheckSnapshot(t, result, "mysdk", "",
375 checkAndroidBpContents(`
376// This is auto-generated. DO NOT EDIT.
377
Spandan Dasa5e26d32024-03-06 14:04:36 +0000378apex_contributions_defaults {
379 name: "mysdk.contributions",
380 contents: ["prebuilt_myjavalib"],
381}
382
Paul Duffin62035b52021-05-05 21:35:49 +0100383java_import {
Paul Duffin62035b52021-05-05 21:35:49 +0100384 name: "myjavalib",
385 prefer: false,
386 visibility: ["//visibility:public"],
387 apex_available: ["//apex_available:platform"],
388 jars: ["java/myjavalib.jar"],
389}
Paul Duffin62035b52021-05-05 21:35:49 +0100390 `),
391 )
392 })
Paul Duffin64fb5262021-05-05 21:36:04 +0100393
Paul Duffin39abf8f2021-09-24 14:58:27 +0100394 t.Run("SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE=S", func(t *testing.T) {
395 result := android.GroupFixturePreparers(
396 prepareForSdkTestWithJava,
397 java.PrepareForTestWithJavaDefaultModules,
398 java.PrepareForTestWithJavaSdkLibraryFiles,
399 java.FixtureWithLastReleaseApis("mysdklibrary"),
400 android.FixtureWithRootAndroidBp(`
401 sdk {
402 name: "mysdk",
403 bootclasspath_fragments: ["mybootclasspathfragment"],
404 }
405
406 bootclasspath_fragment {
407 name: "mybootclasspathfragment",
408 apex_available: ["myapex"],
409 contents: ["mysdklibrary"],
Paul Duffin9fd56472022-03-31 15:42:30 +0100410 hidden_api: {
411 split_packages: ["*"],
412 },
Paul Duffin39abf8f2021-09-24 14:58:27 +0100413 }
414
415 java_sdk_library {
416 name: "mysdklibrary",
417 srcs: ["Test.java"],
418 compile_dex: true,
Paul Duffin1938dba2022-07-26 23:53:00 +0000419 sdk_version: "S",
Paul Duffin39abf8f2021-09-24 14:58:27 +0100420 public: {enabled: true},
421 permitted_packages: ["mysdklibrary"],
422 }
423 `),
424 android.FixtureMergeEnv(map[string]string{
425 "SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE": "S",
426 }),
Colin Crossa66b4632024-08-08 15:50:47 -0700427 android.PrepareForTestWithBuildFlag("RELEASE_HIDDEN_API_EXPORTABLE_STUBS", "true"),
Paul Duffin39abf8f2021-09-24 14:58:27 +0100428 ).RunTest(t)
429
430 CheckSnapshot(t, result, "mysdk", "",
Paul Duffinb01ac4b2022-05-24 20:10:05 +0000431 checkAndroidBpContents(`
Paul Duffin39abf8f2021-09-24 14:58:27 +0100432// This is auto-generated. DO NOT EDIT.
433
Spandan Dasa5e26d32024-03-06 14:04:36 +0000434apex_contributions_defaults {
435 name: "mysdk.contributions",
436 contents: ["prebuilt_mysdklibrary"],
437}
438
Paul Duffin39abf8f2021-09-24 14:58:27 +0100439prebuilt_bootclasspath_fragment {
440 name: "mybootclasspathfragment",
441 prefer: false,
442 visibility: ["//visibility:public"],
443 apex_available: ["myapex"],
444 contents: ["mysdklibrary"],
445 hidden_api: {
446 annotation_flags: "hiddenapi/annotation-flags.csv",
447 metadata: "hiddenapi/metadata.csv",
448 index: "hiddenapi/index.csv",
Paul Duffin191be3a2021-08-10 16:14:16 +0100449 stub_flags: "hiddenapi/stub-flags.csv",
450 all_flags: "hiddenapi/all-flags.csv",
Paul Duffin39abf8f2021-09-24 14:58:27 +0100451 },
452}
453
454java_sdk_library_import {
455 name: "mysdklibrary",
456 prefer: false,
457 visibility: ["//visibility:public"],
458 apex_available: ["//apex_available:platform"],
459 shared_library: true,
460 compile_dex: true,
461 permitted_packages: ["mysdklibrary"],
462 public: {
463 jars: ["sdk_library/public/mysdklibrary-stubs.jar"],
464 stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"],
465 current_api: "sdk_library/public/mysdklibrary.txt",
466 removed_api: "sdk_library/public/mysdklibrary-removed.txt",
467 sdk_version: "current",
468 },
469}
470`),
471
472 checkAllCopyRules(`
473.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/annotation-flags.csv -> hiddenapi/annotation-flags.csv
474.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/metadata.csv -> hiddenapi/metadata.csv
475.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/index.csv -> hiddenapi/index.csv
Paul Duffin191be3a2021-08-10 16:14:16 +0100476.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/stub-flags.csv -> hiddenapi/stub-flags.csv
477.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/all-flags.csv -> hiddenapi/all-flags.csv
Jihoon Kangf55a5f72024-01-08 08:56:20 +0000478.intermediates/mysdklibrary.stubs.exportable/android_common/combined/mysdklibrary.stubs.exportable.jar -> sdk_library/public/mysdklibrary-stubs.jar
479.intermediates/mysdklibrary.stubs.source/android_common/exportable/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt
480.intermediates/mysdklibrary.stubs.source/android_common/exportable/mysdklibrary.stubs.source_removed.txt -> sdk_library/public/mysdklibrary-removed.txt
Paul Duffin39abf8f2021-09-24 14:58:27 +0100481`),
482 )
483 })
484
Jihoon Kang98aa8fa2024-06-07 11:06:57 +0000485 t.Run("test replacing exportable module", func(t *testing.T) {
486 result := android.GroupFixturePreparers(
487 prepareForSdkTestWithJava,
488 java.PrepareForTestWithJavaDefaultModules,
489 java.PrepareForTestWithJavaSdkLibraryFiles,
490 java.FixtureWithLastReleaseApis("mysdklibrary", "anothersdklibrary"),
491 android.FixtureWithRootAndroidBp(`
492 sdk {
493 name: "mysdk",
494 bootclasspath_fragments: ["mybootclasspathfragment"],
495 }
496
497 bootclasspath_fragment {
498 name: "mybootclasspathfragment",
499 apex_available: ["myapex"],
500 contents: ["mysdklibrary"],
501 hidden_api: {
502 split_packages: ["*"],
503 },
504 core_platform_api: {
505 stub_libs: [
506 "anothersdklibrary.stubs.exportable",
507 ],
508 },
509 api: {
510 stub_libs: [
511 "anothersdklibrary",
512 ],
513 },
514 }
515
516 java_sdk_library {
517 name: "mysdklibrary",
518 srcs: ["Test.java"],
519 compile_dex: true,
520 min_sdk_version: "S",
521 public: {enabled: true},
522 permitted_packages: ["mysdklibrary"],
523 }
524
525 java_sdk_library {
526 name: "anothersdklibrary",
527 srcs: ["Test.java"],
528 compile_dex: true,
529 min_sdk_version: "S",
530 public: {enabled: true},
531 system: {enabled: true},
532 module_lib: {enabled: true},
533 }
534 `),
535 android.FixtureMergeEnv(map[string]string{
536 "SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE": "S",
537 }),
538 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
Jihoon Kang98aa8fa2024-06-07 11:06:57 +0000539 variables.Platform_version_active_codenames = []string{"UpsideDownCake", "Tiramisu", "S-V2"}
540 }),
Colin Crossa66b4632024-08-08 15:50:47 -0700541 android.PrepareForTestWithBuildFlag("RELEASE_HIDDEN_API_EXPORTABLE_STUBS", "true"),
Jihoon Kang98aa8fa2024-06-07 11:06:57 +0000542 ).RunTest(t)
543
544 CheckSnapshot(t, result, "mysdk", "",
545 checkAndroidBpContents(`
546// This is auto-generated. DO NOT EDIT.
547
548prebuilt_bootclasspath_fragment {
549 name: "mybootclasspathfragment",
550 prefer: false,
551 visibility: ["//visibility:public"],
552 apex_available: ["myapex"],
553 contents: ["mysdklibrary"],
554 api: {
555 stub_libs: ["anothersdklibrary"],
556 },
557 core_platform_api: {
558 stub_libs: ["anothersdklibrary.stubs"],
559 },
560 hidden_api: {
561 annotation_flags: "hiddenapi/annotation-flags.csv",
562 metadata: "hiddenapi/metadata.csv",
563 index: "hiddenapi/index.csv",
564 stub_flags: "hiddenapi/stub-flags.csv",
565 all_flags: "hiddenapi/all-flags.csv",
566 },
567}
568
569java_sdk_library_import {
570 name: "mysdklibrary",
571 prefer: false,
572 visibility: ["//visibility:public"],
573 apex_available: ["//apex_available:platform"],
574 shared_library: true,
575 compile_dex: true,
576 permitted_packages: ["mysdklibrary"],
577 public: {
578 jars: ["sdk_library/public/mysdklibrary-stubs.jar"],
579 stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"],
580 current_api: "sdk_library/public/mysdklibrary.txt",
581 removed_api: "sdk_library/public/mysdklibrary-removed.txt",
582 sdk_version: "current",
583 },
584}
585
586java_sdk_library_import {
587 name: "anothersdklibrary",
588 prefer: false,
589 visibility: ["//visibility:public"],
590 apex_available: ["//apex_available:platform"],
591 shared_library: true,
592 compile_dex: true,
593 public: {
594 jars: ["sdk_library/public/anothersdklibrary-stubs.jar"],
595 stub_srcs: ["sdk_library/public/anothersdklibrary_stub_sources"],
596 current_api: "sdk_library/public/anothersdklibrary.txt",
597 removed_api: "sdk_library/public/anothersdklibrary-removed.txt",
598 sdk_version: "current",
599 },
600 system: {
601 jars: ["sdk_library/system/anothersdklibrary-stubs.jar"],
602 stub_srcs: ["sdk_library/system/anothersdklibrary_stub_sources"],
603 current_api: "sdk_library/system/anothersdklibrary.txt",
604 removed_api: "sdk_library/system/anothersdklibrary-removed.txt",
605 sdk_version: "system_current",
606 },
607 module_lib: {
608 jars: ["sdk_library/module-lib/anothersdklibrary-stubs.jar"],
609 stub_srcs: ["sdk_library/module-lib/anothersdklibrary_stub_sources"],
610 current_api: "sdk_library/module-lib/anothersdklibrary.txt",
611 removed_api: "sdk_library/module-lib/anothersdklibrary-removed.txt",
612 sdk_version: "module_current",
613 },
614}
615`),
616 )
617 })
618
Paul Duffin62035b52021-05-05 21:35:49 +0100619}