blob: 780d091bf1eb90b21d79bf54a71cf46d2eca6fcc [file] [log] [blame]
Jiyong Park9d452992018-10-03 00:38:19 +09001// Copyright 2018 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 android
16
Jiyong Park0ddfcd12018-12-11 01:35:25 +090017import (
Jooyung Han03b51852020-02-26 22:45:42 +090018 "fmt"
Colin Cross9132ced2024-04-15 15:32:38 -070019 "slices"
Jooyung Han03b51852020-02-26 22:45:42 +090020 "strconv"
Artur Satayev872a1442020-04-27 17:08:37 +010021 "strings"
Jiyong Park0ddfcd12018-12-11 01:35:25 +090022 "sync"
Paul Duffindddd5462020-04-07 15:25:44 +010023
24 "github.com/google/blueprint"
Jiyong Park0ddfcd12018-12-11 01:35:25 +090025)
Jiyong Park25fc6a92018-11-18 18:02:45 +090026
Dan Albertc8060532020-07-22 22:32:17 -070027var (
Jiyong Parke4758ed2020-11-18 01:34:22 +090028 // This is the sdk version when APEX was first introduced
Dan Albertc8060532020-07-22 22:32:17 -070029 SdkVersion_Android10 = uncheckedFinalApiLevel(29)
Jooyung Han5417f772020-03-12 18:37:20 +090030)
31
Jiyong Parke4758ed2020-11-18 01:34:22 +090032// ApexInfo describes the metadata about one or more apexBundles that an apex variant of a module is
33// part of. When an apex variant is created, the variant is associated with one apexBundle. But
34// when multiple apex variants are merged for deduping (see mergeApexVariations), this holds the
35// information about the apexBundles that are merged together.
36// Accessible via `ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)`
Peter Collingbournedc4f9862020-02-12 17:13:25 -080037type ApexInfo struct {
Jiyong Parke4758ed2020-11-18 01:34:22 +090038 // Name of the apex variation that this module (i.e. the apex variant of the module) is
Spandan Das50801e22024-05-13 18:29:45 +000039 // mutated into, or "" for a platform (i.e. non-APEX) variant.
Jiyong Parkab50b072021-05-12 17:13:56 +090040 //
41 // Also note that a module can be included in multiple APEXes, in which case, the module is
42 // mutated into one or more variants, each of which is for an APEX. The variants then can
43 // later be deduped if they don't need to be compiled differently. This is an optimization
44 // done in mergeApexVariations.
Colin Crosse07f2312020-08-13 11:24:56 -070045 ApexVariationName string
Peter Collingbournedc4f9862020-02-12 17:13:25 -080046
Jiyong Park4eab21d2021-04-15 15:17:54 +090047 // ApiLevel that this module has to support at minimum.
48 MinSdkVersion ApiLevel
Colin Crossaede88c2020-08-11 12:17:01 -070049
Jiyong Parke4758ed2020-11-18 01:34:22 +090050 // True if this module comes from an updatable apexBundle.
51 Updatable bool
52
Jiyong Park9477c262021-06-22 20:23:05 +090053 // True if this module can use private platform APIs. Only non-updatable APEX can set this
54 // to true.
55 UsePlatformApis bool
56
Paul Duffin064b70c2020-11-02 17:32:38 +000057 // True if this is for a prebuilt_apex.
58 //
59 // If true then this will customize the apex processing to make it suitable for handling
60 // prebuilt_apex, e.g. it will prevent ApexInfos from being merged together.
61 //
Colin Cross1cea5302024-12-03 16:40:08 -080062 // Unlike the source apex module type the prebuilt_apex module type cannot share compatible variants
63 // across prebuilt_apex modules. That is because there is no way to determine whether two
64 // prebuilt_apex modules that export files for the same module are compatible. e.g. they could have
65 // been built from different source at different times or they could have been built with different
66 // build options that affect the libraries.
67 //
68 // While it may be possible to provide sufficient information to determine whether two prebuilt_apex
69 // modules were compatible it would be a lot of work and would not provide much benefit for a couple
70 // of reasons:
71 // - The number of prebuilt_apex modules that will be exporting files for the same module will be
72 // low as the prebuilt_apex only exports files for the direct dependencies that require it and
73 // very few modules are direct dependencies of multiple prebuilt_apex modules, e.g. there are a
74 // few com.android.art* apex files that contain the same contents and could export files for the
75 // same modules but only one of them needs to do so. Contrast that with source apex modules which
76 // need apex specific variants for every module that contributes code to the apex, whether direct
77 // or indirect.
78 // - The build cost of a prebuilt_apex variant is generally low as at worst it will involve some
79 // extra copying of files. Contrast that with source apex modules that has to build each variant
80 // from source.
Paul Duffin064b70c2020-11-02 17:32:38 +000081 ForPrebuiltApex bool
Spandan Dase8173a82023-04-12 17:14:11 +000082
Spandan Das33bbeb22024-06-18 23:28:25 +000083 // Returns the name of the overridden apex (com.android.foo)
84 BaseApexName string
Spandan Das003452f2024-09-06 00:56:25 +000085
86 // Returns the value of `apex_available_name`
87 ApexAvailableName string
Colin Cross1cea5302024-12-03 16:40:08 -080088}
Yu Liub73c3a62024-12-10 00:58:06 +000089
Colin Cross1cea5302024-12-03 16:40:08 -080090func (a ApexInfo) Variation() string {
91 return a.ApexVariationName
92}
93
94// Minimize is called during a transition from a module with a unique variation per apex to a module that should
95// share variations between apexes. It returns a minimized ApexInfo that removes any apex names and replaces
96// the variation name with one computed from the remaining properties.
97func (a ApexInfo) Minimize() ApexInfo {
98 info := ApexInfo{
99 MinSdkVersion: a.MinSdkVersion,
100 UsePlatformApis: a.UsePlatformApis,
101 }
102 info.ApexVariationName = info.mergedName()
103 return info
104}
105
106type ApexAvailableInfo struct {
Yu Liub73c3a62024-12-10 00:58:06 +0000107 // Returns the apex names that this module is available for
108 ApexAvailableFor []string
Colin Crossaede88c2020-08-11 12:17:01 -0700109}
110
Colin Cross7c035062024-03-28 12:18:42 -0700111var ApexInfoProvider = blueprint.NewMutatorProvider[ApexInfo]("apex_mutate")
Colin Cross1cea5302024-12-03 16:40:08 -0800112var ApexAvailableInfoProvider = blueprint.NewMutatorProvider[ApexAvailableInfo]("apex_mutate")
Colin Cross56a83212020-09-15 18:30:11 -0700113
Lukacs T. Berkid18d8ca2021-06-25 09:11:22 +0200114func (i ApexInfo) AddJSONData(d *map[string]interface{}) {
115 (*d)["Apex"] = map[string]interface{}{
116 "ApexVariationName": i.ApexVariationName,
117 "MinSdkVersion": i.MinSdkVersion,
Lukacs T. Berkid18d8ca2021-06-25 09:11:22 +0200118 "ForPrebuiltApex": i.ForPrebuiltApex,
119 }
120}
121
Jiyong Parke4758ed2020-11-18 01:34:22 +0900122// mergedName gives the name of the alias variation that will be used when multiple apex variations
123// of a module can be deduped into one variation. For example, if libfoo is included in both apex.a
124// and apex.b, and if the two APEXes have the same min_sdk_version (say 29), then libfoo doesn't
125// have to be built twice, but only once. In that case, the two apex variations apex.a and apex.b
Jiyong Park9477c262021-06-22 20:23:05 +0900126// are configured to have the same alias variation named apex29. Whether platform APIs is allowed
127// or not also matters; if two APEXes don't have the same allowance, they get different names and
128// thus wouldn't be merged.
Colin Cross9132ced2024-04-15 15:32:38 -0700129func (i ApexInfo) mergedName() string {
Jiyong Park4eab21d2021-04-15 15:17:54 +0900130 name := "apex" + strconv.Itoa(i.MinSdkVersion.FinalOrFutureInt())
Colin Cross1115b4b2025-01-21 15:38:58 -0800131 if i.UsePlatformApis {
132 name += "_p"
133 }
Colin Crossaede88c2020-08-11 12:17:01 -0700134 return name
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800135}
136
Jiyong Parke4758ed2020-11-18 01:34:22 +0900137// IsForPlatform tells whether this module is for the platform or not. If false is returned, it
138// means that this apex variant of the module is built for an APEX.
Colin Cross56a83212020-09-15 18:30:11 -0700139func (i ApexInfo) IsForPlatform() bool {
140 return i.ApexVariationName == ""
141}
142
Jihoon Kang85bc1932024-07-01 17:04:46 +0000143// To satisfy the comparable interface
144func (i ApexInfo) Equal(other any) bool {
145 otherApexInfo, ok := other.(ApexInfo)
146 return ok && i.ApexVariationName == otherApexInfo.ApexVariationName &&
147 i.MinSdkVersion == otherApexInfo.MinSdkVersion &&
148 i.Updatable == otherApexInfo.Updatable &&
Colin Cross1cea5302024-12-03 16:40:08 -0800149 i.UsePlatformApis == otherApexInfo.UsePlatformApis
Jihoon Kang85bc1932024-07-01 17:04:46 +0000150}
151
Spandan Dasf5e03f12024-01-25 19:25:42 +0000152// ApexBundleInfo contains information about the dependencies of an apex
153type ApexBundleInfo struct {
Spandan Dasf5e03f12024-01-25 19:25:42 +0000154}
155
Colin Cross1cea5302024-12-03 16:40:08 -0800156var ApexBundleInfoProvider = blueprint.NewMutatorProvider[ApexBundleInfo]("apex_mutate")
Spandan Dasf5e03f12024-01-25 19:25:42 +0000157
Yu Liuf1806032025-02-07 00:23:34 +0000158// DepInSameApexChecker defines an interface that should be used to determine whether a given dependency
159// should be considered as part of the same APEX as the current module or not.
160type DepInSameApexChecker interface {
Colin Crossf7bbd2f2024-12-05 13:57:10 -0800161 // OutgoingDepIsInSameApex tests if the module depended on via 'tag' is considered as part of
162 // the same APEX as this module. For example, a static lib dependency usually returns true here, while a
Jiyong Parke4758ed2020-11-18 01:34:22 +0900163 // shared lib dependency to a stub library returns false.
Paul Duffin4c3e8e22021-03-18 15:41:29 +0000164 //
165 // This method must not be called directly without first ignoring dependencies whose tags
166 // implement ExcludeFromApexContentsTag. Calls from within the func passed to WalkPayloadDeps()
167 // are fine as WalkPayloadDeps() will ignore those dependencies automatically. Otherwise, use
168 // IsDepInSameApex instead.
Colin Crossf7bbd2f2024-12-05 13:57:10 -0800169 OutgoingDepIsInSameApex(tag blueprint.DependencyTag) bool
170
171 // IncomingDepIsInSameApex tests if this module depended on via 'tag' is considered as part of
172 // the same APEX as the depending module module. For example, a static lib dependency usually
173 // returns true here, while a shared lib dependency to a stub library returns false.
174 //
175 // This method must not be called directly without first ignoring dependencies whose tags
176 // implement ExcludeFromApexContentsTag. Calls from within the func passed to WalkPayloadDeps()
177 // are fine as WalkPayloadDeps() will ignore those dependencies automatically. Otherwise, use
178 // IsDepInSameApex instead.
179 IncomingDepIsInSameApex(tag blueprint.DependencyTag) bool
Paul Duffin923e8a52020-03-30 15:33:32 +0100180}
181
Yu Liuf1806032025-02-07 00:23:34 +0000182// DepInSameApexInfo is a provider that wraps around a DepInSameApexChecker that can be
183// used to check if a dependency belongs to the same apex as the module when walking
184// through the dependencies of a module.
185type DepInSameApexInfo struct {
186 Checker DepInSameApexChecker
187}
188
189var DepInSameApexInfoProvider = blueprint.NewMutatorProvider[DepInSameApexInfo]("apex_unique")
190
Paul Duffin4c3e8e22021-03-18 15:41:29 +0000191func IsDepInSameApex(ctx BaseModuleContext, module, dep Module) bool {
192 depTag := ctx.OtherModuleDependencyTag(dep)
193 if _, ok := depTag.(ExcludeFromApexContentsTag); ok {
194 // The tag defines a dependency that never requires the child module to be part of the same
195 // apex as the parent.
196 return false
197 }
Colin Crossf7bbd2f2024-12-05 13:57:10 -0800198
Yu Liuf1806032025-02-07 00:23:34 +0000199 if !ctx.EqualModules(ctx.Module(), module) {
200 if moduleInfo, ok := OtherModuleProvider(ctx, module, DepInSameApexInfoProvider); ok {
201 if !moduleInfo.Checker.OutgoingDepIsInSameApex(depTag) {
202 return false
203 }
204 }
205 } else {
206 if m, ok := ctx.Module().(ApexModule); ok && !m.GetDepInSameApexChecker().OutgoingDepIsInSameApex(depTag) {
207 return false
208 }
Colin Crossf7bbd2f2024-12-05 13:57:10 -0800209 }
Yu Liuf1806032025-02-07 00:23:34 +0000210 if depInfo, ok := OtherModuleProvider(ctx, dep, DepInSameApexInfoProvider); ok {
211 if !depInfo.Checker.IncomingDepIsInSameApex(depTag) {
212 return false
213 }
Colin Crossf7bbd2f2024-12-05 13:57:10 -0800214 }
Yu Liuf1806032025-02-07 00:23:34 +0000215
Colin Crossf7bbd2f2024-12-05 13:57:10 -0800216 return true
Paul Duffin4c3e8e22021-03-18 15:41:29 +0000217}
218
Jiyong Parke4758ed2020-11-18 01:34:22 +0900219// ApexModule is the interface that a module type is expected to implement if the module has to be
220// built differently depending on whether the module is destined for an APEX or not (i.e., installed
221// to one of the regular partitions).
Jiyong Park9d452992018-10-03 00:38:19 +0900222//
Jiyong Parke4758ed2020-11-18 01:34:22 +0900223// Native shared libraries are one such module type; when it is built for an APEX, it should depend
224// only on stable interfaces such as NDK, stable AIDL, or C APIs from other APEXes.
Jiyong Park9d452992018-10-03 00:38:19 +0900225//
Jiyong Parke4758ed2020-11-18 01:34:22 +0900226// A module implementing this interface will be mutated into multiple variations by apex.apexMutator
227// if it is directly or indirectly included in one or more APEXes. Specifically, if a module is
228// included in apex.foo and apex.bar then three apex variants are created: platform, apex.foo and
229// apex.bar. The platform variant is for the regular partitions (e.g., /system or /vendor, etc.)
230// while the other two are for the APEXs, respectively. The latter two variations can be merged (see
231// mergedName) when the two APEXes have the same min_sdk_version requirement.
Jiyong Park9d452992018-10-03 00:38:19 +0900232type ApexModule interface {
233 Module
Paul Duffin923e8a52020-03-30 15:33:32 +0100234
Jiyong Park9d452992018-10-03 00:38:19 +0900235 apexModuleBase() *ApexModuleBase
236
Jiyong Parke4758ed2020-11-18 01:34:22 +0900237 // Marks that this module should be built for the specified APEX. Call this BEFORE
238 // apex.apexMutator is run.
Jooyung Han698dd9f2020-07-22 15:17:19 +0900239 BuildForApex(apex ApexInfo)
Jiyong Parkf760cae2020-02-12 07:53:12 +0900240
Jiyong Parke4758ed2020-11-18 01:34:22 +0900241 // Returns true if this module is present in any APEX either directly or indirectly. Call
242 // this after apex.apexMutator is run.
Colin Cross56a83212020-09-15 18:30:11 -0700243 InAnyApex() bool
Jiyong Park9d452992018-10-03 00:38:19 +0900244
Colin Cross0c19b692024-11-06 13:50:21 -0800245 // NotInPlatform returns true if the module is not available to the platform due to
246 // apex_available being set and not containing "//apex_available:platform".
Jiyong Parkf7c3bbe2020-12-09 21:18:56 +0900247 NotInPlatform() bool
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900248
Jiyong Parke4758ed2020-11-18 01:34:22 +0900249 // Tests if this module could have APEX variants. Even when a module type implements
250 // ApexModule interface, APEX variants are created only for the module instances that return
251 // true here. This is useful for not creating APEX variants for certain types of shared
252 // libraries such as NDK stubs.
Jiyong Park9d452992018-10-03 00:38:19 +0900253 CanHaveApexVariants() bool
254
Jiyong Parke4758ed2020-11-18 01:34:22 +0900255 // Tests if this module can be installed to APEX as a file. For example, this would return
256 // true for shared libs while return false for static libs because static libs are not
257 // installable module (but it can still be mutated for APEX)
Jiyong Park9d452992018-10-03 00:38:19 +0900258 IsInstallableToApex() bool
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900259
Jiyong Parke4758ed2020-11-18 01:34:22 +0900260 // Tests if this module is available for the specified APEX or ":platform". This is from the
261 // apex_available property of the module.
Jiyong Park127b40b2019-09-30 16:04:35 +0900262 AvailableFor(what string) bool
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900263
Yu Liub73c3a62024-12-10 00:58:06 +0000264 // Returns the apexes that are available for this module, valid values include
265 // "//apex_available:platform", "//apex_available:anyapex" and specific apexes.
266 // There are some differences between this one and the ApexAvailable on
267 // ApexModuleBase for cc, java library and sdkLibraryXml.
268 ApexAvailableFor() []string
269
Paul Duffinb5769c12021-05-12 16:16:51 +0100270 // AlwaysRequiresPlatformApexVariant allows the implementing module to determine whether an
271 // APEX mutator should always be created for it.
272 //
273 // Returns false by default.
274 AlwaysRequiresPlatformApexVariant() bool
275
Jiyong Parke4758ed2020-11-18 01:34:22 +0900276 // Returns true if this module is not available to platform (i.e. apex_available property
277 // doesn't have "//apex_available:platform"), or shouldn't be available to platform, which
278 // is the case when this module depends on other module that isn't available to platform.
Jiyong Park89e850a2020-04-07 16:37:39 +0900279 NotAvailableForPlatform() bool
280
Jiyong Parke4758ed2020-11-18 01:34:22 +0900281 // Marks that this module is not available to platform. Set by the
Jiyong Park89e850a2020-04-07 16:37:39 +0900282 // check-platform-availability mutator in the apex package.
283 SetNotAvailableForPlatform()
284
Jiyong Parke4758ed2020-11-18 01:34:22 +0900285 // Returns nil (success) if this module should support the given sdk version. Returns an
286 // error if not. No default implementation is provided for this method. A module type
287 // implementing this interface should provide an implementation. A module supports an sdk
288 // version when the module's min_sdk_version is equal to or less than the given sdk version.
Dan Albertc8060532020-07-22 22:32:17 -0700289 ShouldSupportSdkVersion(ctx BaseModuleContext, sdkVersion ApiLevel) error
Colin Crossaede88c2020-08-11 12:17:01 -0700290
Jiyong Parke4758ed2020-11-18 01:34:22 +0900291 // Returns true if this module needs a unique variation per apex, effectively disabling the
292 // deduping. This is turned on when, for example if use_apex_name_macro is set so that each
293 // apex variant should be built with different macro definitions.
Colin Crossaede88c2020-08-11 12:17:01 -0700294 UniqueApexVariations() bool
Yu Liuf1806032025-02-07 00:23:34 +0000295
296 GetDepInSameApexChecker() DepInSameApexChecker
Jiyong Park9d452992018-10-03 00:38:19 +0900297}
298
Jiyong Parke4758ed2020-11-18 01:34:22 +0900299// Properties that are common to all module types implementing ApexModule interface.
Jiyong Park9d452992018-10-03 00:38:19 +0900300type ApexProperties struct {
Jiyong Parke4758ed2020-11-18 01:34:22 +0900301 // Availability of this module in APEXes. Only the listed APEXes can contain this module. If
302 // the module has stubs then other APEXes and the platform may access it through them
303 // (subject to visibility).
Martin Stjernholm06ca82d2020-01-17 13:02:56 +0000304 //
Jiyong Park127b40b2019-09-30 16:04:35 +0900305 // "//apex_available:anyapex" is a pseudo APEX name that matches to any APEX.
306 // "//apex_available:platform" refers to non-APEX partitions like "system.img".
Jooyung Han9a419e22024-08-16 17:14:21 +0900307 // Prefix pattern (com.foo.*) can be used to match with any APEX name with the prefix(com.foo.).
Jiyong Park9a1e14e2020-02-13 02:30:45 +0900308 // Default is ["//apex_available:platform"].
Jiyong Park127b40b2019-09-30 16:04:35 +0900309 Apex_available []string
310
Jiyong Parke4758ed2020-11-18 01:34:22 +0900311 // See ApexModule.NotAvailableForPlatform()
Jiyong Park89e850a2020-04-07 16:37:39 +0900312 NotAvailableForPlatform bool `blueprint:"mutated"`
Colin Crossaede88c2020-08-11 12:17:01 -0700313
Jiyong Parke4758ed2020-11-18 01:34:22 +0900314 // See ApexModule.UniqueApexVariants()
Colin Crossaede88c2020-08-11 12:17:01 -0700315 UniqueApexVariationsForDeps bool `blueprint:"mutated"`
Jiyong Park9d452992018-10-03 00:38:19 +0900316}
317
Jiyong Parke4758ed2020-11-18 01:34:22 +0900318// Marker interface that identifies dependencies that are excluded from APEX contents.
Paul Duffin573989d2021-03-17 13:25:29 +0000319//
Paul Duffin4c3e8e22021-03-18 15:41:29 +0000320// At the moment the sdk.sdkRequirementsMutator relies on the fact that the existing tags which
321// implement this interface do not define dependencies onto members of an sdk_snapshot. If that
322// changes then sdk.sdkRequirementsMutator will need fixing.
Paul Duffindddd5462020-04-07 15:25:44 +0100323type ExcludeFromApexContentsTag interface {
324 blueprint.DependencyTag
325
326 // Method that differentiates this interface from others.
327 ExcludeFromApexContents()
328}
329
Cindy Zhou18417cb2020-12-10 07:12:38 -0800330// Interface that identifies dependencies to skip Apex dependency check
331type SkipApexAllowedDependenciesCheck interface {
332 // Returns true to skip the Apex dependency check, which limits the allowed dependency in build.
333 SkipApexAllowedDependenciesCheck() bool
334}
335
Jiyong Parke4758ed2020-11-18 01:34:22 +0900336// ApexModuleBase provides the default implementation for the ApexModule interface. APEX-aware
Jiyong Park9d452992018-10-03 00:38:19 +0900337// modules are expected to include this struct and call InitApexModule().
338type ApexModuleBase struct {
Jihoon Kang46d66de2024-05-22 22:42:39 +0000339 ApexProperties ApexProperties
340 apexPropertiesLock sync.Mutex // protects ApexProperties during parallel apexDirectlyInAnyMutator
Jiyong Park9d452992018-10-03 00:38:19 +0900341
342 canHaveApexVariants bool
Colin Crosscefa94bd2019-06-03 15:07:03 -0700343
Jiyong Parke4758ed2020-11-18 01:34:22 +0900344 apexInfos []ApexInfo
Paul Duffin949abc02020-12-08 10:34:30 +0000345 apexInfosLock sync.Mutex // protects apexInfos during parallel apexInfoMutator
Jiyong Park9d452992018-10-03 00:38:19 +0900346}
347
Colin Cross1cea5302024-12-03 16:40:08 -0800348func (m *ApexModuleBase) ApexTransitionMutatorSplit(ctx BaseModuleContext) []ApexInfo {
349 return []ApexInfo{{}}
350}
351
352func (m *ApexModuleBase) ApexTransitionMutatorOutgoing(ctx OutgoingTransitionContext, info ApexInfo) ApexInfo {
Yu Liuf1806032025-02-07 00:23:34 +0000353 if !ctx.Module().(ApexModule).GetDepInSameApexChecker().OutgoingDepIsInSameApex(ctx.DepTag()) {
Colin Cross1cea5302024-12-03 16:40:08 -0800354 return ApexInfo{}
355 }
356 return info
357}
358
359func (m *ApexModuleBase) ApexTransitionMutatorIncoming(ctx IncomingTransitionContext, info ApexInfo) ApexInfo {
360 module := ctx.Module().(ApexModule)
361 if !module.CanHaveApexVariants() {
362 return ApexInfo{}
363 }
364
Yu Liuf1806032025-02-07 00:23:34 +0000365 if !ctx.Module().(ApexModule).GetDepInSameApexChecker().IncomingDepIsInSameApex(ctx.DepTag()) {
Colin Cross1cea5302024-12-03 16:40:08 -0800366 return ApexInfo{}
367 }
368
369 if info.ApexVariationName == "" {
370 return ApexInfo{}
371 }
372
373 if !ctx.Module().(ApexModule).UniqueApexVariations() && !m.ApexProperties.UniqueApexVariationsForDeps && !info.ForPrebuiltApex {
374 return info.Minimize()
375 }
376 return info
377}
378
379func (m *ApexModuleBase) ApexTransitionMutatorMutate(ctx BottomUpMutatorContext, info ApexInfo) {
380 SetProvider(ctx, ApexInfoProvider, info)
381
382 module := ctx.Module().(ApexModule)
383 base := module.apexModuleBase()
384
385 platformVariation := info.ApexVariationName == ""
386 if !platformVariation {
387 // Do some validity checks.
388 // TODO(jiyong): is this the right place?
389 base.checkApexAvailableProperty(ctx)
390
391 SetProvider(ctx, ApexAvailableInfoProvider, ApexAvailableInfo{
392 ApexAvailableFor: module.ApexAvailableFor(),
393 })
394 }
395 if platformVariation && !ctx.Host() && !module.AvailableFor(AvailableToPlatform) && module.NotAvailableForPlatform() {
396 // Do not install the module for platform, but still allow it to output
397 // uninstallable AndroidMk entries in certain cases when they have side
398 // effects. TODO(jiyong): move this routine to somewhere else
399 module.MakeUninstallable()
400 }
401}
402
Jiyong Parke4758ed2020-11-18 01:34:22 +0900403// Initializes ApexModuleBase struct. Not calling this (even when inheriting from ApexModuleBase)
404// prevents the module from being mutated for apexBundle.
405func InitApexModule(m ApexModule) {
406 base := m.apexModuleBase()
407 base.canHaveApexVariants = true
408
409 m.AddProperties(&base.ApexProperties)
410}
411
412// Implements ApexModule
Jiyong Park9d452992018-10-03 00:38:19 +0900413func (m *ApexModuleBase) apexModuleBase() *ApexModuleBase {
414 return m
415}
416
Spandan Das8e6386e2023-04-11 19:08:18 +0000417var (
418 availableToPlatformList = []string{AvailableToPlatform}
419)
420
Jiyong Parke4758ed2020-11-18 01:34:22 +0900421// Implements ApexModule
Paul Duffinbefa4b92020-03-04 14:22:45 +0000422func (m *ApexModuleBase) ApexAvailable() []string {
Spandan Das8e6386e2023-04-11 19:08:18 +0000423 aa := m.ApexProperties.Apex_available
424 if len(aa) > 0 {
425 return aa
426 }
427 // Default is availability to platform
428 return CopyOf(availableToPlatformList)
Paul Duffinbefa4b92020-03-04 14:22:45 +0000429}
430
Yu Liub73c3a62024-12-10 00:58:06 +0000431func (m *ApexModuleBase) ApexAvailableFor() []string {
432 return m.ApexAvailable()
433}
434
Jiyong Parke4758ed2020-11-18 01:34:22 +0900435// Implements ApexModule
Jooyung Han698dd9f2020-07-22 15:17:19 +0900436func (m *ApexModuleBase) BuildForApex(apex ApexInfo) {
Jiyong Parke4758ed2020-11-18 01:34:22 +0900437 m.apexInfosLock.Lock()
438 defer m.apexInfosLock.Unlock()
Colin Crossf6978172024-11-19 11:29:46 -0800439 if slices.ContainsFunc(m.apexInfos, func(existing ApexInfo) bool {
440 return existing.ApexVariationName == apex.ApexVariationName
441 }) {
442 return
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900443 }
Jiyong Parke4758ed2020-11-18 01:34:22 +0900444 m.apexInfos = append(m.apexInfos, apex)
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900445}
446
Jiyong Parke4758ed2020-11-18 01:34:22 +0900447// Implements ApexModule
Colin Cross56a83212020-09-15 18:30:11 -0700448func (m *ApexModuleBase) InAnyApex() bool {
Colin Cross2dcbca62024-11-20 14:55:14 -0800449 for _, apex_name := range m.ApexProperties.Apex_available {
450 if apex_name != AvailableToPlatform {
451 return true
452 }
453 }
454 return false
Jiyong Park9d452992018-10-03 00:38:19 +0900455}
456
Jiyong Parke4758ed2020-11-18 01:34:22 +0900457// Implements ApexModule
Jiyong Parkf7c3bbe2020-12-09 21:18:56 +0900458func (m *ApexModuleBase) NotInPlatform() bool {
Colin Cross0c19b692024-11-06 13:50:21 -0800459 return !m.AvailableFor(AvailableToPlatform)
Jiyong Parke4758ed2020-11-18 01:34:22 +0900460}
461
462// Implements ApexModule
Jiyong Park9d452992018-10-03 00:38:19 +0900463func (m *ApexModuleBase) CanHaveApexVariants() bool {
464 return m.canHaveApexVariants
465}
466
Jiyong Parke4758ed2020-11-18 01:34:22 +0900467// Implements ApexModule
Jiyong Park9d452992018-10-03 00:38:19 +0900468func (m *ApexModuleBase) IsInstallableToApex() bool {
Jiyong Parke4758ed2020-11-18 01:34:22 +0900469 // If needed, this will bel overridden by concrete types inheriting
470 // ApexModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900471 return false
472}
473
Jiyong Parke4758ed2020-11-18 01:34:22 +0900474// Implements ApexModule
475func (m *ApexModuleBase) UniqueApexVariations() bool {
476 // If needed, this will bel overridden by concrete types inheriting
477 // ApexModuleBase
478 return false
479}
480
481// Implements ApexModule
Yu Liuf1806032025-02-07 00:23:34 +0000482func (m *ApexModuleBase) GetDepInSameApexChecker() DepInSameApexChecker {
483 return BaseDepInSameApexChecker{}
484}
485
486type BaseDepInSameApexChecker struct{}
487
488func (m BaseDepInSameApexChecker) OutgoingDepIsInSameApex(tag blueprint.DependencyTag) bool {
Colin Crossf7bbd2f2024-12-05 13:57:10 -0800489 return true
490}
491
Yu Liuf1806032025-02-07 00:23:34 +0000492func (m BaseDepInSameApexChecker) IncomingDepIsInSameApex(tag blueprint.DependencyTag) bool {
Jiyong Parke4758ed2020-11-18 01:34:22 +0900493 return true
494}
495
Jiyong Park127b40b2019-09-30 16:04:35 +0900496const (
Jiyong Parkb02bb402019-12-03 00:43:57 +0900497 AvailableToPlatform = "//apex_available:platform"
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000498 AvailableToAnyApex = "//apex_available:anyapex"
Jiyong Park127b40b2019-09-30 16:04:35 +0900499)
500
Jiyong Parke4758ed2020-11-18 01:34:22 +0900501// CheckAvailableForApex provides the default algorithm for checking the apex availability. When the
502// availability is empty, it defaults to ["//apex_available:platform"] which means "available to the
503// platform but not available to any APEX". When the list is not empty, `what` is matched against
504// the list. If there is any matching element in the list, thus function returns true. The special
505// availability "//apex_available:anyapex" matches with anything except for
506// "//apex_available:platform".
Jiyong Parka90ca002019-10-07 15:47:24 +0900507func CheckAvailableForApex(what string, apex_available []string) bool {
508 if len(apex_available) == 0 {
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000509 return what == AvailableToPlatform
Jiyong Park127b40b2019-09-30 16:04:35 +0900510 }
Jooyung Han9a419e22024-08-16 17:14:21 +0900511
512 // TODO b/248601389
513 if what == "com.google.mainline.primary.libs" || what == "com.google.mainline.go.primary.libs" {
514 return true
515 }
516
517 for _, apex_name := range apex_available {
518 // exact match.
519 if apex_name == what {
520 return true
521 }
522 // //apex_available:anyapex matches with any apex name, but not //apex_available:platform
523 if apex_name == AvailableToAnyApex && what != AvailableToPlatform {
524 return true
525 }
526 // prefix match.
527 if strings.HasSuffix(apex_name, ".*") && strings.HasPrefix(what, strings.TrimSuffix(apex_name, "*")) {
528 return true
529 }
William Escandea345bba2024-12-12 14:00:01 -0800530 // TODO b/383863941: Remove once legacy name is no longer used
531 if (apex_name == "com.android.btservices" && what == "com.android.bt") || (apex_name == "com.android.bt" && what == "com.android.btservices") {
532 return true
533 }
Jooyung Han9a419e22024-08-16 17:14:21 +0900534 }
535 return false
Jiyong Parka90ca002019-10-07 15:47:24 +0900536}
537
Jiyong Parke4758ed2020-11-18 01:34:22 +0900538// Implements ApexModule
Jiyong Parka90ca002019-10-07 15:47:24 +0900539func (m *ApexModuleBase) AvailableFor(what string) bool {
Yu Liub73c3a62024-12-10 00:58:06 +0000540 return CheckAvailableForApex(what, m.ApexAvailableFor())
Jiyong Park127b40b2019-09-30 16:04:35 +0900541}
542
Jiyong Parke4758ed2020-11-18 01:34:22 +0900543// Implements ApexModule
Paul Duffinb5769c12021-05-12 16:16:51 +0100544func (m *ApexModuleBase) AlwaysRequiresPlatformApexVariant() bool {
545 return false
546}
547
548// Implements ApexModule
Jiyong Park89e850a2020-04-07 16:37:39 +0900549func (m *ApexModuleBase) NotAvailableForPlatform() bool {
550 return m.ApexProperties.NotAvailableForPlatform
551}
552
Jiyong Parke4758ed2020-11-18 01:34:22 +0900553// Implements ApexModule
Jiyong Park89e850a2020-04-07 16:37:39 +0900554func (m *ApexModuleBase) SetNotAvailableForPlatform() {
555 m.ApexProperties.NotAvailableForPlatform = true
556}
557
Jiyong Parke4758ed2020-11-18 01:34:22 +0900558// This function makes sure that the apex_available property is valid
Jiyong Park127b40b2019-09-30 16:04:35 +0900559func (m *ApexModuleBase) checkApexAvailableProperty(mctx BaseModuleContext) {
560 for _, n := range m.ApexProperties.Apex_available {
Jooyung Han40b79172024-08-16 16:00:33 +0900561 if n == AvailableToPlatform || n == AvailableToAnyApex {
Jiyong Park127b40b2019-09-30 16:04:35 +0900562 continue
563 }
Jooyung Han9a419e22024-08-16 17:14:21 +0900564 // Prefix pattern should end with .* and has at least two components.
565 if strings.Contains(n, "*") {
566 if !strings.HasSuffix(n, ".*") {
567 mctx.PropertyErrorf("apex_available", "Wildcard should end with .* like com.foo.*")
568 }
569 if strings.Count(n, ".") < 2 {
570 mctx.PropertyErrorf("apex_available", "Wildcard requires two or more components like com.foo.*")
571 }
572 if strings.Count(n, "*") != 1 {
573 mctx.PropertyErrorf("apex_available", "Wildcard is not allowed in the middle.")
574 }
575 continue
576 }
Orion Hodson4b5438a2019-10-08 10:40:51 +0100577 if !mctx.OtherModuleExists(n) && !mctx.Config().AllowMissingDependencies() {
Jiyong Park127b40b2019-09-30 16:04:35 +0900578 mctx.PropertyErrorf("apex_available", "%q is not a valid module name", n)
579 }
580 }
581}
582
Martin Stjernholm4e6c2692021-03-25 01:25:06 +0000583// AvailableToSameApexes returns true if the two modules are apex_available to
584// exactly the same set of APEXes (and platform), i.e. if their apex_available
585// properties have the same elements.
586func AvailableToSameApexes(mod1, mod2 ApexModule) bool {
Spandan Das8a8714c2023-04-25 18:03:54 +0000587 mod1ApexAvail := SortedUniqueStrings(mod1.apexModuleBase().ApexProperties.Apex_available)
588 mod2ApexAvail := SortedUniqueStrings(mod2.apexModuleBase().ApexProperties.Apex_available)
Martin Stjernholm4e6c2692021-03-25 01:25:06 +0000589 if len(mod1ApexAvail) != len(mod2ApexAvail) {
590 return false
591 }
592 for i, v := range mod1ApexAvail {
593 if v != mod2ApexAvail[i] {
594 return false
595 }
596 }
597 return true
598}
599
Jiyong Parke4758ed2020-11-18 01:34:22 +0900600// UpdateUniqueApexVariationsForDeps sets UniqueApexVariationsForDeps if any dependencies that are
601// in the same APEX have unique APEX variations so that the module can link against the right
602// variant.
Colin Cross56a83212020-09-15 18:30:11 -0700603func UpdateUniqueApexVariationsForDeps(mctx BottomUpMutatorContext, am ApexModule) {
Jiyong Parke4758ed2020-11-18 01:34:22 +0900604 // If any of the dependencies requires unique apex variations, so does this module.
Colin Cross56a83212020-09-15 18:30:11 -0700605 mctx.VisitDirectDeps(func(dep Module) {
606 if depApexModule, ok := dep.(ApexModule); ok {
Colin Cross1cea5302024-12-03 16:40:08 -0800607 if IsDepInSameApex(mctx, am, depApexModule) &&
Colin Cross56a83212020-09-15 18:30:11 -0700608 (depApexModule.UniqueApexVariations() ||
609 depApexModule.apexModuleBase().ApexProperties.UniqueApexVariationsForDeps) {
610 am.apexModuleBase().ApexProperties.UniqueApexVariationsForDeps = true
611 }
612 }
613 })
Jiyong Park25fc6a92018-11-18 18:02:45 +0900614}
615
Jiyong Parke4758ed2020-11-18 01:34:22 +0900616////////////////////////////////////////////////////////////////////////////////////////////////////
617//Below are routines for extra safety checks.
618//
619// BuildDepsInfoLists is to flatten the dependency graph for an apexBundle into a text file
620// (actually two in slightly different formats). The files are mostly for debugging, for example to
621// see why a certain module is included in an APEX via which dependency path.
622//
623// CheckMinSdkVersion is to make sure that all modules in an apexBundle satisfy the min_sdk_version
624// requirement of the apexBundle.
Artur Satayev872a1442020-04-27 17:08:37 +0100625
626// A dependency info for a single ApexModule, either direct or transitive.
627type ApexModuleDepInfo struct {
628 // Name of the dependency
629 To string
630 // List of dependencies To belongs to. Includes APEX itself, if a direct dependency.
631 From []string
632 // Whether the dependency belongs to the final compiled APEX.
633 IsExternal bool
Artur Satayev480e25b2020-04-27 18:53:18 +0100634 // min_sdk_version of the ApexModule
635 MinSdkVersion string
Artur Satayev872a1442020-04-27 17:08:37 +0100636}
637
638// A map of a dependency name to its ApexModuleDepInfo
639type DepNameToDepInfoMap map[string]ApexModuleDepInfo
640
641type ApexBundleDepsInfo struct {
Cole Faust4e9f5922024-11-13 16:09:23 -0800642 flatListPath Path
643 fullListPath Path
Artur Satayev872a1442020-04-27 17:08:37 +0100644}
645
Artur Satayev849f8442020-04-28 14:57:42 +0100646type ApexBundleDepsInfoIntf interface {
647 Updatable() bool
Artur Satayeva8bd1132020-04-27 18:07:06 +0100648 FlatListPath() Path
Artur Satayev872a1442020-04-27 17:08:37 +0100649 FullListPath() Path
650}
651
Artur Satayeva8bd1132020-04-27 18:07:06 +0100652func (d *ApexBundleDepsInfo) FlatListPath() Path {
653 return d.flatListPath
654}
655
Artur Satayev872a1442020-04-27 17:08:37 +0100656func (d *ApexBundleDepsInfo) FullListPath() Path {
657 return d.fullListPath
658}
659
Artur Satayeva8bd1132020-04-27 18:07:06 +0100660// Generate two module out files:
661// 1. FullList with transitive deps and their parents in the dep graph
662// 2. FlatList with a flat list of transitive deps
Artur Satayev533b98c2021-03-11 18:03:42 +0000663// In both cases transitive deps of external deps are not included. Neither are deps that are only
664// available to APEXes; they are developed with updatability in mind and don't need manual approval.
Artur Satayev480e25b2020-04-27 18:53:18 +0100665func (d *ApexBundleDepsInfo) BuildDepsInfoLists(ctx ModuleContext, minSdkVersion string, depInfos DepNameToDepInfoMap) {
Artur Satayeva8bd1132020-04-27 18:07:06 +0100666 var fullContent strings.Builder
667 var flatContent strings.Builder
668
Colin Crosscf371cc2020-11-13 11:48:42 -0800669 fmt.Fprintf(&fullContent, "%s(minSdkVersion:%s):\n", ctx.ModuleName(), minSdkVersion)
Cole Faust18994c72023-02-28 16:02:16 -0800670 for _, key := range FirstUniqueStrings(SortedKeys(depInfos)) {
Artur Satayev872a1442020-04-27 17:08:37 +0100671 info := depInfos[key]
Artur Satayev480e25b2020-04-27 18:53:18 +0100672 toName := fmt.Sprintf("%s(minSdkVersion:%s)", info.To, info.MinSdkVersion)
Artur Satayev872a1442020-04-27 17:08:37 +0100673 if info.IsExternal {
674 toName = toName + " (external)"
675 }
Colin Crosscf371cc2020-11-13 11:48:42 -0800676 fmt.Fprintf(&fullContent, " %s <- %s\n", toName, strings.Join(SortedUniqueStrings(info.From), ", "))
677 fmt.Fprintf(&flatContent, "%s\n", toName)
Artur Satayev872a1442020-04-27 17:08:37 +0100678 }
679
Cole Faust4e9f5922024-11-13 16:09:23 -0800680 fullListPath := PathForModuleOut(ctx, "depsinfo", "fulllist.txt")
681 WriteFileRule(ctx, fullListPath, fullContent.String())
682 d.fullListPath = fullListPath
Artur Satayeva8bd1132020-04-27 18:07:06 +0100683
Cole Faust4e9f5922024-11-13 16:09:23 -0800684 flatListPath := PathForModuleOut(ctx, "depsinfo", "flatlist.txt")
685 WriteFileRule(ctx, flatListPath, flatContent.String())
686 d.flatListPath = flatListPath
Mathew Inwood29bb2fd2021-02-18 11:36:40 +0000687
Cole Faust4e9f5922024-11-13 16:09:23 -0800688 ctx.Phony(fmt.Sprintf("%s-depsinfo", ctx.ModuleName()), fullListPath, flatListPath)
Artur Satayev872a1442020-04-27 17:08:37 +0100689}
Jooyung Han749dc692020-04-15 11:03:39 +0900690
Jooyung Han749dc692020-04-15 11:03:39 +0900691// Function called while walking an APEX's payload dependencies.
692//
693// Return true if the `to` module should be visited, false otherwise.
Colin Cross9cf55a52024-12-05 14:26:03 -0800694type PayloadDepsCallback func(ctx BaseModuleContext, from Module, to ApexModule, externalDep bool) bool
Colin Cross8bf14fc2024-09-25 16:41:31 -0700695type WalkPayloadDepsFunc func(ctx BaseModuleContext, do PayloadDepsCallback)
Jooyung Han749dc692020-04-15 11:03:39 +0900696
satayevb3fd4112021-12-02 13:59:35 +0000697// ModuleWithMinSdkVersionCheck represents a module that implements min_sdk_version checks
698type ModuleWithMinSdkVersionCheck interface {
Jooyung Han749dc692020-04-15 11:03:39 +0900699 Module
Spandan Das8c9ae7e2023-03-03 21:20:36 +0000700 MinSdkVersion(ctx EarlyModuleContext) ApiLevel
satayevb3fd4112021-12-02 13:59:35 +0000701 CheckMinSdkVersion(ctx ModuleContext)
Jooyung Han749dc692020-04-15 11:03:39 +0900702}
703
Jiyong Parke4758ed2020-11-18 01:34:22 +0900704// CheckMinSdkVersion checks if every dependency of an updatable module sets min_sdk_version
705// accordingly
satayevb3fd4112021-12-02 13:59:35 +0000706func CheckMinSdkVersion(ctx ModuleContext, minSdkVersion ApiLevel, walk WalkPayloadDepsFunc) {
Jooyung Han749dc692020-04-15 11:03:39 +0900707 // do not enforce min_sdk_version for host
708 if ctx.Host() {
709 return
710 }
711
712 // do not enforce for coverage build
713 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled() {
714 return
715 }
716
Jooyung Haned124c32021-01-26 11:43:46 +0900717 // do not enforce deps.min_sdk_version if APEX/APK doesn't set min_sdk_version
718 if minSdkVersion.IsNone() {
Jooyung Han749dc692020-04-15 11:03:39 +0900719 return
720 }
721
Colin Cross9cf55a52024-12-05 14:26:03 -0800722 walk(ctx, func(ctx BaseModuleContext, from Module, to ApexModule, externalDep bool) bool {
Jooyung Han749dc692020-04-15 11:03:39 +0900723 if externalDep {
Jiyong Parke4758ed2020-11-18 01:34:22 +0900724 // external deps are outside the payload boundary, which is "stable"
725 // interface. We don't have to check min_sdk_version for external
726 // dependencies.
Jooyung Han749dc692020-04-15 11:03:39 +0900727 return false
728 }
Colin Crossf7bbd2f2024-12-05 13:57:10 -0800729 if !IsDepInSameApex(ctx, from, to) {
Jooyung Han749dc692020-04-15 11:03:39 +0900730 return false
731 }
satayev758968a2021-12-06 11:42:40 +0000732 if m, ok := to.(ModuleWithMinSdkVersionCheck); ok {
733 // This dependency performs its own min_sdk_version check, just make sure it sets min_sdk_version
734 // to trigger the check.
735 if !m.MinSdkVersion(ctx).Specified() {
736 ctx.OtherModuleErrorf(m, "must set min_sdk_version")
737 }
738 return false
739 }
Jooyung Han749dc692020-04-15 11:03:39 +0900740 if err := to.ShouldSupportSdkVersion(ctx, minSdkVersion); err != nil {
741 toName := ctx.OtherModuleName(to)
Jooyung Han2c65d2c2022-06-24 14:56:43 +0900742 ctx.OtherModuleErrorf(to, "should support min_sdk_version(%v) for %q: %v."+
743 "\n\nDependency path: %s\n\n"+
744 "Consider adding 'min_sdk_version: %q' to %q",
745 minSdkVersion, ctx.ModuleName(), err.Error(),
746 ctx.GetPathString(false),
747 minSdkVersion, toName)
748 return false
Jooyung Han749dc692020-04-15 11:03:39 +0900749 }
750 return true
751 })
752}
Spandan Dasf57a9662023-04-12 19:05:49 +0000753
Colin Cross1cea5302024-12-03 16:40:08 -0800754type MinSdkVersionFromValueContext interface {
755 Config() Config
756 DeviceConfig() DeviceConfig
757 ModuleErrorContext
758}
759
Sam Delmerico0e0d96e2023-08-18 22:43:28 +0000760// Construct ApiLevel object from min_sdk_version string value
Colin Cross1cea5302024-12-03 16:40:08 -0800761func MinSdkVersionFromValue(ctx MinSdkVersionFromValueContext, value string) ApiLevel {
Sam Delmerico0e0d96e2023-08-18 22:43:28 +0000762 if value == "" {
763 return NoneApiLevel
764 }
765 apiLevel, err := ApiLevelFromUser(ctx, value)
766 if err != nil {
767 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
768 return NoneApiLevel
769 }
770 return apiLevel
771}
772
Spandan Dasda739a32023-12-13 00:06:32 +0000773var ApexExportsInfoProvider = blueprint.NewProvider[ApexExportsInfo]()
774
775// ApexExportsInfo contains information about the artifacts provided by apexes to dexpreopt and hiddenapi
776type ApexExportsInfo struct {
777 // Canonical name of this APEX. Used to determine the path to the activated APEX on
778 // device (/apex/<apex_name>)
779 ApexName string
780
781 // Path to the image profile file on host (or empty, if profile is not generated).
782 ProfilePathOnHost Path
Spandan Das5be63332023-12-13 00:06:32 +0000783
784 // Map from the apex library name (without prebuilt_ prefix) to the dex file path on host
785 LibraryNameToDexJarPathOnHost map[string]Path
Spandan Dasda739a32023-12-13 00:06:32 +0000786}
Spandan Das3490dfd2024-03-11 21:37:25 +0000787
788var PrebuiltInfoProvider = blueprint.NewProvider[PrebuiltInfo]()
789
790// contents of prebuilt_info.json
791type PrebuiltInfo struct {
792 // Name of the apex, without the prebuilt_ prefix
793 Name string
794
795 Is_prebuilt bool
796
797 // This is relative to root of the workspace.
798 // In case of mainline modules, this file contains the build_id that was used
799 // to generate the mainline module prebuilt.
800 Prebuilt_info_file_path string `json:",omitempty"`
801}
Colin Crossbdd344b2025-01-14 16:01:03 -0800802
803// FragmentInApexTag is embedded into a dependency tag to allow apex modules to annotate
804// their fragments in a way that allows the java bootclasspath modules to traverse from
805// the apex to the fragment.
806type FragmentInApexTag struct{}
807
808func (FragmentInApexTag) isFragmentInApexTag() {}
809
810type isFragmentInApexTagIntf interface {
811 isFragmentInApexTag()
812}
813
814// IsFragmentInApexTag returns true if the dependency tag embeds FragmentInApexTag,
815// signifying that it is a dependency from an apex module to its fragment.
816func IsFragmentInApexTag(tag blueprint.DependencyTag) bool {
817 _, ok := tag.(isFragmentInApexTagIntf)
818 return ok
819}