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//
16// Definitions for building the Android core libraries, i.e. ART, I18n and
17// Conscrypt.
18//
19// These are here as the definitions are used by the build itself and include
20// parts from all three of those modules.
21//
22
23// A stubs target containing the parts of the public SDK API provided by the
24// core libraries.
25//
26// Don't use this directly, use "sdk_version: core_current".
27package {
28    default_applicable_licenses: ["Android-Apache-2.0"],
29}
30
31dist_targets = [
32    "sdk",
33    "win_sdk",
34]
35
36java_defaults {
37    name: "core.current.stubs.defaults",
38    visibility: ["//visibility:public"],
39    sdk_version: "none",
40    system_modules: "none",
41}
42
43java_library {
44    name: "core.current.stubs.from-source",
45    defaults: [
46        "core.current.stubs.defaults",
47    ],
48    static_libs: [
49        "art.module.public.api.stubs",
50        "conscrypt.module.public.api.stubs",
51        "i18n.module.public.api.stubs",
52    ],
53}
54
55java_api_library {
56    name: "core.current.stubs.from-text",
57    api_surface: "core",
58    api_contributions: [
59        "art.module.public.api.stubs.source.api.contribution",
60        "conscrypt.module.public.api.stubs.source.api.contribution",
61        "i18n.module.public.api.stubs.source.api.contribution",
62    ],
63    libs: [
64        "stub-annotations",
65    ],
66    enable_validation: false,
67    stubs_type: "everything",
68}
69
70java_library {
71    name: "core.current.stubs",
72    defaults: [
73        "core.current.stubs.defaults",
74    ],
75    static_libs: [
76        "core.current.stubs.from-source",
77    ],
78    product_variables: {
79        build_from_text_stub: {
80            static_libs: [
81                "core.current.stubs.from-text",
82            ],
83            exclude_static_libs: [
84                "core.current.stubs.from-source",
85            ],
86        },
87    },
88}
89
90java_library {
91    name: "core.current.stubs.exportable.from-source",
92    defaults: [
93        "core.current.stubs.defaults",
94    ],
95    static_libs: [
96        "art.module.public.api.stubs.exportable",
97        "conscrypt.module.public.api.stubs.exportable",
98        "i18n.module.public.api.stubs.exportable",
99    ],
100    dist: {
101        targets: dist_targets,
102        dest: "core.current.stubs.jar",
103    },
104}
105
106java_library {
107    name: "core.current.stubs.exportable",
108    defaults: [
109        "core.current.stubs.defaults",
110    ],
111    static_libs: [
112        "core.current.stubs.exportable.from-source",
113    ],
114}
115
116// Distributed with the SDK for turning into system modules to compile apps
117// against.
118//
119// Also, produces dist files that are used by the
120// prebuilts/sdk/update_prebuilts.py script to update the prebuilts/sdk
121// directory.
122java_library {
123    name: "core-current-stubs-for-system-modules",
124    visibility: ["//development/sdk"],
125    static_libs: [
126        "core.current.stubs",
127        // This one is not on device but it's needed when javac compiles code
128        // containing lambdas.
129        "core-lambda-stubs-for-system-modules",
130    ],
131    sdk_version: "none",
132    system_modules: "none",
133    dists: [
134        {
135            // Legacy dist location for the public file.
136            dest: "core-for-system-modules.jar",
137            targets: dist_targets,
138        },
139        {
140            dest: "system-modules/public/core-for-system-modules.jar",
141            targets: dist_targets,
142        },
143    ],
144}
145
146// Defaults module to strip out android annotations
147java_defaults {
148    name: "system-modules-no-annotations",
149    sdk_version: "none",
150    system_modules: "none",
151    jarjar_rules: "jarjar-strip-annotations-rules.txt",
152}
153
154// Same as core-current-stubs-for-system-modules, but android annotations are
155// stripped.
156java_library {
157    name: "core-current-stubs-for-system-modules-no-annotations",
158    visibility: ["//development/sdk"],
159    defaults: [
160        "system-modules-no-annotations",
161    ],
162    static_libs: [
163        "core-current-stubs-for-system-modules",
164    ],
165    dists: [
166        {
167            // Legacy dist location for the public file.
168            dest: "core-for-system-modules-no-annotations.jar",
169            targets: dist_targets,
170        },
171        {
172            dest: "system-modules/public/core-for-system-modules-no-annotations.jar",
173            targets: dist_targets,
174        },
175    ],
176}
177
178// Used when compiling higher-level code against core.current.stubs.
179java_system_modules {
180    name: "core-public-stubs-system-modules",
181    visibility: ["//visibility:public"],
182    libs: [
183        "core-current-stubs-for-system-modules-no-annotations",
184    ],
185}
186
187java_defaults {
188    name: "core.module_lib.stubs.defaults",
189    visibility: ["//visibility:private"],
190    sdk_version: "none",
191    system_modules: "none",
192}
193
194// A stubs target containing the parts of the public SDK & @SystemApi(MODULE_LIBRARIES) API
195// provided by the core libraries.
196//
197// Don't use this directly, use "sdk_version: module_current".
198java_library {
199    name: "core.module_lib.stubs",
200    defaults: [
201        "core.module_lib.stubs.defaults",
202    ],
203    static_libs: [
204        "core.module_lib.stubs.from-source",
205    ],
206    product_variables: {
207        build_from_text_stub: {
208            static_libs: [
209                "core.module_lib.stubs.from-text",
210            ],
211            exclude_static_libs: [
212                "core.module_lib.stubs.from-source",
213            ],
214        },
215    },
216}
217
218java_library {
219    name: "core.module_lib.stubs.from-source",
220    defaults: [
221        "core.module_lib.stubs.defaults",
222    ],
223    static_libs: [
224        "art.module.public.api.stubs.module_lib",
225
226        // Replace the following with the module-lib correspondence when Conscrypt or i18N module
227        // provides @SystemApi(MODULE_LIBRARIES). Currently, assume that only ART module provides
228        // @SystemApi(MODULE_LIBRARIES).
229        "conscrypt.module.public.api.stubs",
230        "i18n.module.public.api.stubs",
231    ],
232}
233
234java_api_library {
235    name: "core.module_lib.stubs.from-text",
236    api_surface: "module-lib",
237    api_contributions: [
238        "art.module.public.api.stubs.source.api.contribution",
239        "art.module.public.api.stubs.source.system.api.contribution",
240        "art.module.public.api.stubs.source.module_lib.api.contribution",
241
242        // Add the module-lib correspondence when Conscrypt or i18N module
243        // provides @SystemApi(MODULE_LIBRARIES). Currently, assume that only ART module provides
244        // @SystemApi(MODULE_LIBRARIES).
245        "conscrypt.module.public.api.stubs.source.api.contribution",
246        "i18n.module.public.api.stubs.source.api.contribution",
247    ],
248    libs: [
249        "stub-annotations",
250    ],
251    visibility: ["//visibility:private"],
252    stubs_type: "everything",
253}
254
255// Produces a dist file that is used by the
256// prebuilts/sdk/update_prebuilts.py script to update the prebuilts/sdk
257// directory.
258java_library {
259    name: "core-module-lib-stubs-for-system-modules",
260    visibility: ["//visibility:private"],
261    static_libs: [
262        "core.module_lib.stubs",
263        // This one is not on device but it's needed when javac compiles code
264        // containing lambdas.
265        "core-lambda-stubs-for-system-modules",
266    ],
267    sdk_version: "none",
268    system_modules: "none",
269    dist: {
270        dest: "system-modules/module-lib/core-for-system-modules.jar",
271        targets: dist_targets,
272    },
273}
274
275// Same as core-module-lib-stubs-for-system-modules, but android annotations are
276// stripped. This is used by the Java toolchain, while the annotated stub is to
277// be used by Kotlin one.
278java_library {
279    name: "core-module-lib-stubs-for-system-modules-no-annotations",
280    visibility: ["//visibility:private"],
281    defaults: [
282        "system-modules-no-annotations",
283    ],
284    static_libs: [
285        "core-module-lib-stubs-for-system-modules",
286    ],
287    dist: {
288        dest: "system-modules/module-lib/core-for-system-modules-no-annotations.jar",
289        targets: dist_targets,
290    },
291}
292
293// Used when compiling higher-level code with sdk_version "module_current"
294java_system_modules {
295    name: "core-module-lib-stubs-system-modules",
296    libs: [
297        "core-module-lib-stubs-for-system-modules-no-annotations",
298    ],
299    visibility: ["//visibility:public"],
300}
301
302// Ideally this should be a restricted allowlist but there are hundreds of modules that depend on
303// this.
304// TODO(http://b/134561230) - limit the number of dependents on this.
305core_platform_visibility = ["//visibility:public"]
306
307// Libraries containing the core platform API stubs for the core libraries.
308//
309// Although this stubs library is primarily used by the Java compiler / build to indicate
310// the core platform API surface area, compile_dex: true is used so that the Core Platform
311// API annotations are available to the dex tools that enable enforcement of runtime
312// accessibility. b/119068555
313java_library {
314    name: "legacy.core.platform.api.stubs.from-source",
315    visibility: core_platform_visibility,
316    defaults: [
317        "core.platform.api.stubs.defaults",
318    ],
319    static_libs: [
320        "art.module.public.api.stubs.module_lib",
321        "conscrypt.module.platform.api.stubs",
322        "legacy.i18n.module.platform.api.stubs",
323    ],
324}
325
326java_library {
327    name: "legacy.core.platform.api.stubs.exportable.from-source",
328    visibility: core_platform_visibility,
329    defaults: [
330        "core.platform.api.stubs.defaults",
331    ],
332    static_libs: [
333        "art.module.public.api.stubs.exportable.module_lib",
334        "conscrypt.module.platform.api.stubs.exportable",
335        "legacy.i18n.module.platform.api.stubs.exportable",
336    ],
337}
338
339java_defaults {
340    name: "android_core_platform_stubs_current_contributions",
341    api_surface: "core_platform",
342    api_contributions: [
343        "art.module.public.api.stubs.source.api.contribution",
344        "art.module.public.api.stubs.source.system.api.contribution",
345        "art.module.public.api.stubs.source.module_lib.api.contribution",
346        "conscrypt.module.platform.api.stubs.source.api.contribution",
347        "i18n.module.public.api.stubs.source.api.contribution",
348    ],
349}
350
351java_api_library {
352    name: "legacy.core.platform.api.stubs.from-text",
353    api_surface: "core_platform",
354    defaults: [
355        "android_core_platform_stubs_current_contributions",
356    ],
357    api_contributions: [
358        "legacy.i18n.module.platform.api.stubs.source.api.contribution",
359    ],
360    libs: [
361        "stub-annotations",
362    ],
363    stubs_type: "everything",
364}
365
366java_library {
367    name: "legacy.core.platform.api.stubs",
368    visibility: core_platform_visibility,
369    defaults: [
370        "core.platform.api.stubs.defaults",
371    ],
372    static_libs: [
373        "legacy.core.platform.api.stubs.from-source",
374    ],
375    product_variables: {
376        build_from_text_stub: {
377            static_libs: [
378                "legacy.core.platform.api.stubs.from-text",
379            ],
380            exclude_static_libs: [
381                "legacy.core.platform.api.stubs.from-source",
382            ],
383        },
384    },
385}
386
387java_library {
388    name: "legacy.core.platform.api.stubs.exportable",
389    visibility: core_platform_visibility,
390    defaults: [
391        "core.platform.api.stubs.defaults",
392    ],
393    static_libs: [
394        "legacy.core.platform.api.stubs.exportable.from-source",
395    ],
396}
397
398java_defaults {
399    name: "core.platform.api.stubs.defaults",
400    hostdex: true,
401    compile_dex: true,
402
403    sdk_version: "none",
404    system_modules: "none",
405    patch_module: "java.base",
406}
407
408// Same as legacy.core.platform.api.stubs, but android annotations are
409// stripped. This is used by the Java toolchain, while the annotated stub is to
410// be used by Kotlin one.
411java_library {
412    name: "legacy.core.platform.api.no.annotations.stubs",
413    visibility: core_platform_visibility,
414    defaults: [
415        "system-modules-no-annotations",
416    ],
417    hostdex: true,
418    compile_dex: true,
419
420    static_libs: [
421        "legacy.core.platform.api.stubs",
422    ],
423    patch_module: "java.base",
424}
425
426java_library {
427    name: "stable.core.platform.api.stubs.from-source",
428    visibility: core_platform_visibility,
429    defaults: [
430        "core.platform.api.stubs.defaults",
431    ],
432    static_libs: [
433        "art.module.public.api.stubs.module_lib",
434        // conscrypt only has a stable version, so it is okay to depend on it here:
435        "conscrypt.module.platform.api.stubs",
436        "stable.i18n.module.platform.api.stubs",
437    ],
438}
439
440java_api_library {
441    name: "stable.core.platform.api.stubs.from-text",
442    api_surface: "core_platform",
443    defaults: [
444        "android_core_platform_stubs_current_contributions",
445    ],
446    api_contributions: [
447        "stable.i18n.module.platform.api.stubs.source.api.contribution",
448    ],
449    libs: [
450        "stub-annotations",
451    ],
452    stubs_type: "everything",
453}
454
455java_library {
456    name: "stable.core.platform.api.stubs",
457    visibility: core_platform_visibility,
458    defaults: [
459        "core.platform.api.stubs.defaults",
460    ],
461    static_libs: [
462        "stable.core.platform.api.stubs.from-source",
463    ],
464    product_variables: {
465        build_from_text_stub: {
466            static_libs: [
467                "stable.core.platform.api.stubs.from-text",
468            ],
469            exclude_static_libs: [
470                "stable.core.platform.api.stubs.from-source",
471            ],
472        },
473    },
474}
475
476// Same as stable.core.platform.api.stubs, but android annotations are
477// stripped. This is used by the Java toolchain, while the annotated stub is to
478// be used by Kotlin one.
479java_library {
480    name: "stable.core.platform.api.no.annotations.stubs",
481    visibility: core_platform_visibility,
482    defaults: [
483        "system-modules-no-annotations",
484    ],
485    hostdex: true,
486    compile_dex: true,
487
488    static_libs: [
489        "stable.core.platform.api.stubs",
490    ],
491    patch_module: "java.base",
492}
493
494// Used when compiling higher-level code against *.core.platform.api.stubs.
495java_system_modules {
496    name: "legacy-core-platform-api-stubs-system-modules",
497    visibility: core_platform_visibility,
498    libs: [
499        "legacy.core.platform.api.no.annotations.stubs",
500        // This one is not on device but it's needed when javac compiles code
501        // containing lambdas.
502        "core-lambda-stubs-for-system-modules",
503    ],
504}
505
506java_system_modules {
507    name: "stable-core-platform-api-stubs-system-modules",
508    visibility: core_platform_visibility,
509    libs: [
510        "stable.core.platform.api.no.annotations.stubs",
511        // This one is not on device but it's needed when javac compiles code
512        // containing lambdas.
513        "core-lambda-stubs-for-system-modules",
514    ],
515}
516
517// Used when compiling higher-level code against art.module.public.api.stubs.
518// This abstraction should come from the inner tree linking against the stubs
519// and not from an "sdk", since parts of this abstraction do not belong to an
520// official API (e.g. stub-annotations).
521//
522// This is only intended for use within core libraries and must not be used
523// from outside.
524java_system_modules {
525    name: "art-module-public-api-stubs-system-modules",
526    visibility: [
527        "//art/build/sdk",
528        "//external/conscrypt",
529        "//external/icu/android_icu4j",
530        "//external/wycheproof",
531    ],
532    libs: [
533        "art.module.public.api.stubs",
534        // This one is not on device but it's needed when javac compiles code
535        // containing lambdas.
536        "core-lambda-stubs-for-system-modules",
537
538        // Ensure that core libraries that depend on the public API can access
539        // the UnsupportedAppUsage, CorePlatformApi and IntraCoreApi
540        // annotations.
541        "art.module.api.annotations.for.system.modules",
542    ],
543}
544
545// Used when compiling higher-level code against art.module.public.api.stubs.module_lib.
546//
547// This is only intended for use within core libraries and must not be used
548// from outside.
549java_system_modules {
550    name: "art-module-lib-api-stubs-system-modules",
551    visibility: [
552        "//art/build/sdk",
553        "//external/conscrypt",
554        "//external/icu/android_icu4j",
555    ],
556    libs: [
557        "art.module.public.api.stubs.module_lib",
558    ],
559}
560
561// Used when compiling against art.module.intra.core.api.stubs.
562java_system_modules {
563    name: "art-module-intra-core-api-stubs-system-modules",
564    visibility: [
565        "//art/build/sdk",
566        "//external/bouncycastle",
567        "//external/conscrypt",
568        "//external/icu/android_icu4j",
569    ],
570    libs: [
571        // The intra core API stubs library.
572        "art.module.intra.core.api.stubs",
573
574        // Additional classes needed by javac but which are not present in the stubs.
575        "art-module-intra-core-api-stubs-system-modules-lib",
576    ],
577}
578