blob: 91fa2c71812f5bd7dc4485bf08b1b546c1ead857 [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
Yu Liudf0b8392025-02-12 18:27:03 +0000285 // Returns the min sdk version that the module supports, .
286 MinSdkVersionSupported(ctx BaseModuleContext) ApiLevel
Colin Crossaede88c2020-08-11 12:17:01 -0700287
Jiyong Parke4758ed2020-11-18 01:34:22 +0900288 // Returns true if this module needs a unique variation per apex, effectively disabling the
289 // deduping. This is turned on when, for example if use_apex_name_macro is set so that each
290 // apex variant should be built with different macro definitions.
Colin Crossaede88c2020-08-11 12:17:01 -0700291 UniqueApexVariations() bool
Yu Liuf1806032025-02-07 00:23:34 +0000292
293 GetDepInSameApexChecker() DepInSameApexChecker
Jiyong Park9d452992018-10-03 00:38:19 +0900294}
295
Jiyong Parke4758ed2020-11-18 01:34:22 +0900296// Properties that are common to all module types implementing ApexModule interface.
Jiyong Park9d452992018-10-03 00:38:19 +0900297type ApexProperties struct {
Jiyong Parke4758ed2020-11-18 01:34:22 +0900298 // Availability of this module in APEXes. Only the listed APEXes can contain this module. If
299 // the module has stubs then other APEXes and the platform may access it through them
300 // (subject to visibility).
Martin Stjernholm06ca82d2020-01-17 13:02:56 +0000301 //
Jiyong Park127b40b2019-09-30 16:04:35 +0900302 // "//apex_available:anyapex" is a pseudo APEX name that matches to any APEX.
303 // "//apex_available:platform" refers to non-APEX partitions like "system.img".
Jooyung Han9a419e22024-08-16 17:14:21 +0900304 // 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 +0900305 // Default is ["//apex_available:platform"].
Jiyong Park127b40b2019-09-30 16:04:35 +0900306 Apex_available []string
307
Jiyong Parke4758ed2020-11-18 01:34:22 +0900308 // See ApexModule.NotAvailableForPlatform()
Jiyong Park89e850a2020-04-07 16:37:39 +0900309 NotAvailableForPlatform bool `blueprint:"mutated"`
Colin Crossaede88c2020-08-11 12:17:01 -0700310
Jiyong Parke4758ed2020-11-18 01:34:22 +0900311 // See ApexModule.UniqueApexVariants()
Colin Crossaede88c2020-08-11 12:17:01 -0700312 UniqueApexVariationsForDeps bool `blueprint:"mutated"`
Jiyong Park9d452992018-10-03 00:38:19 +0900313}
314
Jiyong Parke4758ed2020-11-18 01:34:22 +0900315// Marker interface that identifies dependencies that are excluded from APEX contents.
Paul Duffin573989d2021-03-17 13:25:29 +0000316//
Paul Duffin4c3e8e22021-03-18 15:41:29 +0000317// At the moment the sdk.sdkRequirementsMutator relies on the fact that the existing tags which
318// implement this interface do not define dependencies onto members of an sdk_snapshot. If that
319// changes then sdk.sdkRequirementsMutator will need fixing.
Paul Duffindddd5462020-04-07 15:25:44 +0100320type ExcludeFromApexContentsTag interface {
321 blueprint.DependencyTag
322
323 // Method that differentiates this interface from others.
324 ExcludeFromApexContents()
325}
326
Cindy Zhou18417cb2020-12-10 07:12:38 -0800327// Interface that identifies dependencies to skip Apex dependency check
328type SkipApexAllowedDependenciesCheck interface {
329 // Returns true to skip the Apex dependency check, which limits the allowed dependency in build.
330 SkipApexAllowedDependenciesCheck() bool
331}
332
Jiyong Parke4758ed2020-11-18 01:34:22 +0900333// ApexModuleBase provides the default implementation for the ApexModule interface. APEX-aware
Jiyong Park9d452992018-10-03 00:38:19 +0900334// modules are expected to include this struct and call InitApexModule().
335type ApexModuleBase struct {
Jihoon Kang46d66de2024-05-22 22:42:39 +0000336 ApexProperties ApexProperties
337 apexPropertiesLock sync.Mutex // protects ApexProperties during parallel apexDirectlyInAnyMutator
Jiyong Park9d452992018-10-03 00:38:19 +0900338
339 canHaveApexVariants bool
Colin Crosscefa94bd2019-06-03 15:07:03 -0700340
Jiyong Parke4758ed2020-11-18 01:34:22 +0900341 apexInfos []ApexInfo
Paul Duffin949abc02020-12-08 10:34:30 +0000342 apexInfosLock sync.Mutex // protects apexInfos during parallel apexInfoMutator
Jiyong Park9d452992018-10-03 00:38:19 +0900343}
344
Colin Cross1cea5302024-12-03 16:40:08 -0800345func (m *ApexModuleBase) ApexTransitionMutatorSplit(ctx BaseModuleContext) []ApexInfo {
346 return []ApexInfo{{}}
347}
348
349func (m *ApexModuleBase) ApexTransitionMutatorOutgoing(ctx OutgoingTransitionContext, info ApexInfo) ApexInfo {
Yu Liuf1806032025-02-07 00:23:34 +0000350 if !ctx.Module().(ApexModule).GetDepInSameApexChecker().OutgoingDepIsInSameApex(ctx.DepTag()) {
Colin Cross1cea5302024-12-03 16:40:08 -0800351 return ApexInfo{}
352 }
353 return info
354}
355
356func (m *ApexModuleBase) ApexTransitionMutatorIncoming(ctx IncomingTransitionContext, info ApexInfo) ApexInfo {
357 module := ctx.Module().(ApexModule)
358 if !module.CanHaveApexVariants() {
359 return ApexInfo{}
360 }
361
Yu Liuf1806032025-02-07 00:23:34 +0000362 if !ctx.Module().(ApexModule).GetDepInSameApexChecker().IncomingDepIsInSameApex(ctx.DepTag()) {
Colin Cross1cea5302024-12-03 16:40:08 -0800363 return ApexInfo{}
364 }
365
366 if info.ApexVariationName == "" {
367 return ApexInfo{}
368 }
369
370 if !ctx.Module().(ApexModule).UniqueApexVariations() && !m.ApexProperties.UniqueApexVariationsForDeps && !info.ForPrebuiltApex {
371 return info.Minimize()
372 }
373 return info
374}
375
376func (m *ApexModuleBase) ApexTransitionMutatorMutate(ctx BottomUpMutatorContext, info ApexInfo) {
377 SetProvider(ctx, ApexInfoProvider, info)
378
379 module := ctx.Module().(ApexModule)
380 base := module.apexModuleBase()
381
382 platformVariation := info.ApexVariationName == ""
383 if !platformVariation {
384 // Do some validity checks.
385 // TODO(jiyong): is this the right place?
386 base.checkApexAvailableProperty(ctx)
387
388 SetProvider(ctx, ApexAvailableInfoProvider, ApexAvailableInfo{
389 ApexAvailableFor: module.ApexAvailableFor(),
390 })
391 }
392 if platformVariation && !ctx.Host() && !module.AvailableFor(AvailableToPlatform) && module.NotAvailableForPlatform() {
393 // Do not install the module for platform, but still allow it to output
394 // uninstallable AndroidMk entries in certain cases when they have side
395 // effects. TODO(jiyong): move this routine to somewhere else
396 module.MakeUninstallable()
397 }
398}
399
Jiyong Parke4758ed2020-11-18 01:34:22 +0900400// Initializes ApexModuleBase struct. Not calling this (even when inheriting from ApexModuleBase)
401// prevents the module from being mutated for apexBundle.
402func InitApexModule(m ApexModule) {
403 base := m.apexModuleBase()
404 base.canHaveApexVariants = true
405
406 m.AddProperties(&base.ApexProperties)
407}
408
409// Implements ApexModule
Jiyong Park9d452992018-10-03 00:38:19 +0900410func (m *ApexModuleBase) apexModuleBase() *ApexModuleBase {
411 return m
412}
413
Spandan Das8e6386e2023-04-11 19:08:18 +0000414var (
415 availableToPlatformList = []string{AvailableToPlatform}
416)
417
Jiyong Parke4758ed2020-11-18 01:34:22 +0900418// Implements ApexModule
Paul Duffinbefa4b92020-03-04 14:22:45 +0000419func (m *ApexModuleBase) ApexAvailable() []string {
Spandan Das8e6386e2023-04-11 19:08:18 +0000420 aa := m.ApexProperties.Apex_available
421 if len(aa) > 0 {
422 return aa
423 }
424 // Default is availability to platform
425 return CopyOf(availableToPlatformList)
Paul Duffinbefa4b92020-03-04 14:22:45 +0000426}
427
Yu Liub73c3a62024-12-10 00:58:06 +0000428func (m *ApexModuleBase) ApexAvailableFor() []string {
429 return m.ApexAvailable()
430}
431
Jiyong Parke4758ed2020-11-18 01:34:22 +0900432// Implements ApexModule
Jooyung Han698dd9f2020-07-22 15:17:19 +0900433func (m *ApexModuleBase) BuildForApex(apex ApexInfo) {
Jiyong Parke4758ed2020-11-18 01:34:22 +0900434 m.apexInfosLock.Lock()
435 defer m.apexInfosLock.Unlock()
Colin Crossf6978172024-11-19 11:29:46 -0800436 if slices.ContainsFunc(m.apexInfos, func(existing ApexInfo) bool {
437 return existing.ApexVariationName == apex.ApexVariationName
438 }) {
439 return
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900440 }
Jiyong Parke4758ed2020-11-18 01:34:22 +0900441 m.apexInfos = append(m.apexInfos, apex)
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900442}
443
Jiyong Parke4758ed2020-11-18 01:34:22 +0900444// Implements ApexModule
Colin Cross56a83212020-09-15 18:30:11 -0700445func (m *ApexModuleBase) InAnyApex() bool {
Colin Cross2dcbca62024-11-20 14:55:14 -0800446 for _, apex_name := range m.ApexProperties.Apex_available {
447 if apex_name != AvailableToPlatform {
448 return true
449 }
450 }
451 return false
Jiyong Park9d452992018-10-03 00:38:19 +0900452}
453
Jiyong Parke4758ed2020-11-18 01:34:22 +0900454// Implements ApexModule
Jiyong Parkf7c3bbe2020-12-09 21:18:56 +0900455func (m *ApexModuleBase) NotInPlatform() bool {
Colin Cross0c19b692024-11-06 13:50:21 -0800456 return !m.AvailableFor(AvailableToPlatform)
Jiyong Parke4758ed2020-11-18 01:34:22 +0900457}
458
459// Implements ApexModule
Jiyong Park9d452992018-10-03 00:38:19 +0900460func (m *ApexModuleBase) CanHaveApexVariants() bool {
461 return m.canHaveApexVariants
462}
463
Jiyong Parke4758ed2020-11-18 01:34:22 +0900464// Implements ApexModule
Jiyong Park9d452992018-10-03 00:38:19 +0900465func (m *ApexModuleBase) IsInstallableToApex() bool {
Jiyong Parke4758ed2020-11-18 01:34:22 +0900466 // If needed, this will bel overridden by concrete types inheriting
467 // ApexModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900468 return false
469}
470
Jiyong Parke4758ed2020-11-18 01:34:22 +0900471// Implements ApexModule
472func (m *ApexModuleBase) UniqueApexVariations() bool {
473 // If needed, this will bel overridden by concrete types inheriting
474 // ApexModuleBase
475 return false
476}
477
478// Implements ApexModule
Yu Liuf1806032025-02-07 00:23:34 +0000479func (m *ApexModuleBase) GetDepInSameApexChecker() DepInSameApexChecker {
480 return BaseDepInSameApexChecker{}
481}
482
483type BaseDepInSameApexChecker struct{}
484
485func (m BaseDepInSameApexChecker) OutgoingDepIsInSameApex(tag blueprint.DependencyTag) bool {
Colin Crossf7bbd2f2024-12-05 13:57:10 -0800486 return true
487}
488
Yu Liuf1806032025-02-07 00:23:34 +0000489func (m BaseDepInSameApexChecker) IncomingDepIsInSameApex(tag blueprint.DependencyTag) bool {
Jiyong Parke4758ed2020-11-18 01:34:22 +0900490 return true
491}
492
Jiyong Park127b40b2019-09-30 16:04:35 +0900493const (
Jiyong Parkb02bb402019-12-03 00:43:57 +0900494 AvailableToPlatform = "//apex_available:platform"
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000495 AvailableToAnyApex = "//apex_available:anyapex"
Jiyong Park127b40b2019-09-30 16:04:35 +0900496)
497
Jiyong Parke4758ed2020-11-18 01:34:22 +0900498// CheckAvailableForApex provides the default algorithm for checking the apex availability. When the
499// availability is empty, it defaults to ["//apex_available:platform"] which means "available to the
500// platform but not available to any APEX". When the list is not empty, `what` is matched against
501// the list. If there is any matching element in the list, thus function returns true. The special
502// availability "//apex_available:anyapex" matches with anything except for
503// "//apex_available:platform".
Jiyong Parka90ca002019-10-07 15:47:24 +0900504func CheckAvailableForApex(what string, apex_available []string) bool {
505 if len(apex_available) == 0 {
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000506 return what == AvailableToPlatform
Jiyong Park127b40b2019-09-30 16:04:35 +0900507 }
Jooyung Han9a419e22024-08-16 17:14:21 +0900508
509 // TODO b/248601389
510 if what == "com.google.mainline.primary.libs" || what == "com.google.mainline.go.primary.libs" {
511 return true
512 }
513
514 for _, apex_name := range apex_available {
515 // exact match.
516 if apex_name == what {
517 return true
518 }
519 // //apex_available:anyapex matches with any apex name, but not //apex_available:platform
520 if apex_name == AvailableToAnyApex && what != AvailableToPlatform {
521 return true
522 }
523 // prefix match.
524 if strings.HasSuffix(apex_name, ".*") && strings.HasPrefix(what, strings.TrimSuffix(apex_name, "*")) {
525 return true
526 }
William Escandea345bba2024-12-12 14:00:01 -0800527 // TODO b/383863941: Remove once legacy name is no longer used
528 if (apex_name == "com.android.btservices" && what == "com.android.bt") || (apex_name == "com.android.bt" && what == "com.android.btservices") {
529 return true
530 }
Jooyung Han9a419e22024-08-16 17:14:21 +0900531 }
532 return false
Jiyong Parka90ca002019-10-07 15:47:24 +0900533}
534
Jiyong Parke4758ed2020-11-18 01:34:22 +0900535// Implements ApexModule
Jiyong Parka90ca002019-10-07 15:47:24 +0900536func (m *ApexModuleBase) AvailableFor(what string) bool {
Yu Liub73c3a62024-12-10 00:58:06 +0000537 return CheckAvailableForApex(what, m.ApexAvailableFor())
Jiyong Park127b40b2019-09-30 16:04:35 +0900538}
539
Jiyong Parke4758ed2020-11-18 01:34:22 +0900540// Implements ApexModule
Paul Duffinb5769c12021-05-12 16:16:51 +0100541func (m *ApexModuleBase) AlwaysRequiresPlatformApexVariant() bool {
542 return false
543}
544
545// Implements ApexModule
Jiyong Park89e850a2020-04-07 16:37:39 +0900546func (m *ApexModuleBase) NotAvailableForPlatform() bool {
547 return m.ApexProperties.NotAvailableForPlatform
548}
549
Jiyong Parke4758ed2020-11-18 01:34:22 +0900550// Implements ApexModule
Jiyong Park89e850a2020-04-07 16:37:39 +0900551func (m *ApexModuleBase) SetNotAvailableForPlatform() {
552 m.ApexProperties.NotAvailableForPlatform = true
553}
554
Jiyong Parke4758ed2020-11-18 01:34:22 +0900555// This function makes sure that the apex_available property is valid
Jiyong Park127b40b2019-09-30 16:04:35 +0900556func (m *ApexModuleBase) checkApexAvailableProperty(mctx BaseModuleContext) {
557 for _, n := range m.ApexProperties.Apex_available {
Jooyung Han40b79172024-08-16 16:00:33 +0900558 if n == AvailableToPlatform || n == AvailableToAnyApex {
Jiyong Park127b40b2019-09-30 16:04:35 +0900559 continue
560 }
Jooyung Han9a419e22024-08-16 17:14:21 +0900561 // Prefix pattern should end with .* and has at least two components.
562 if strings.Contains(n, "*") {
563 if !strings.HasSuffix(n, ".*") {
564 mctx.PropertyErrorf("apex_available", "Wildcard should end with .* like com.foo.*")
565 }
566 if strings.Count(n, ".") < 2 {
567 mctx.PropertyErrorf("apex_available", "Wildcard requires two or more components like com.foo.*")
568 }
569 if strings.Count(n, "*") != 1 {
570 mctx.PropertyErrorf("apex_available", "Wildcard is not allowed in the middle.")
571 }
572 continue
573 }
Orion Hodson4b5438a2019-10-08 10:40:51 +0100574 if !mctx.OtherModuleExists(n) && !mctx.Config().AllowMissingDependencies() {
Jiyong Park127b40b2019-09-30 16:04:35 +0900575 mctx.PropertyErrorf("apex_available", "%q is not a valid module name", n)
576 }
577 }
578}
579
Martin Stjernholm4e6c2692021-03-25 01:25:06 +0000580// AvailableToSameApexes returns true if the two modules are apex_available to
581// exactly the same set of APEXes (and platform), i.e. if their apex_available
582// properties have the same elements.
583func AvailableToSameApexes(mod1, mod2 ApexModule) bool {
Spandan Das8a8714c2023-04-25 18:03:54 +0000584 mod1ApexAvail := SortedUniqueStrings(mod1.apexModuleBase().ApexProperties.Apex_available)
585 mod2ApexAvail := SortedUniqueStrings(mod2.apexModuleBase().ApexProperties.Apex_available)
Martin Stjernholm4e6c2692021-03-25 01:25:06 +0000586 if len(mod1ApexAvail) != len(mod2ApexAvail) {
587 return false
588 }
589 for i, v := range mod1ApexAvail {
590 if v != mod2ApexAvail[i] {
591 return false
592 }
593 }
594 return true
595}
596
Jiyong Parke4758ed2020-11-18 01:34:22 +0900597// UpdateUniqueApexVariationsForDeps sets UniqueApexVariationsForDeps if any dependencies that are
598// in the same APEX have unique APEX variations so that the module can link against the right
599// variant.
Colin Cross56a83212020-09-15 18:30:11 -0700600func UpdateUniqueApexVariationsForDeps(mctx BottomUpMutatorContext, am ApexModule) {
Jiyong Parke4758ed2020-11-18 01:34:22 +0900601 // If any of the dependencies requires unique apex variations, so does this module.
Colin Cross56a83212020-09-15 18:30:11 -0700602 mctx.VisitDirectDeps(func(dep Module) {
603 if depApexModule, ok := dep.(ApexModule); ok {
Colin Cross1cea5302024-12-03 16:40:08 -0800604 if IsDepInSameApex(mctx, am, depApexModule) &&
Colin Cross56a83212020-09-15 18:30:11 -0700605 (depApexModule.UniqueApexVariations() ||
606 depApexModule.apexModuleBase().ApexProperties.UniqueApexVariationsForDeps) {
607 am.apexModuleBase().ApexProperties.UniqueApexVariationsForDeps = true
608 }
609 }
610 })
Jiyong Park25fc6a92018-11-18 18:02:45 +0900611}
612
Jiyong Parke4758ed2020-11-18 01:34:22 +0900613////////////////////////////////////////////////////////////////////////////////////////////////////
614//Below are routines for extra safety checks.
615//
616// BuildDepsInfoLists is to flatten the dependency graph for an apexBundle into a text file
617// (actually two in slightly different formats). The files are mostly for debugging, for example to
618// see why a certain module is included in an APEX via which dependency path.
619//
620// CheckMinSdkVersion is to make sure that all modules in an apexBundle satisfy the min_sdk_version
621// requirement of the apexBundle.
Artur Satayev872a1442020-04-27 17:08:37 +0100622
623// A dependency info for a single ApexModule, either direct or transitive.
624type ApexModuleDepInfo struct {
625 // Name of the dependency
626 To string
627 // List of dependencies To belongs to. Includes APEX itself, if a direct dependency.
628 From []string
629 // Whether the dependency belongs to the final compiled APEX.
630 IsExternal bool
Artur Satayev480e25b2020-04-27 18:53:18 +0100631 // min_sdk_version of the ApexModule
632 MinSdkVersion string
Artur Satayev872a1442020-04-27 17:08:37 +0100633}
634
635// A map of a dependency name to its ApexModuleDepInfo
636type DepNameToDepInfoMap map[string]ApexModuleDepInfo
637
638type ApexBundleDepsInfo struct {
Cole Faust4e9f5922024-11-13 16:09:23 -0800639 flatListPath Path
640 fullListPath Path
Artur Satayev872a1442020-04-27 17:08:37 +0100641}
642
Artur Satayev849f8442020-04-28 14:57:42 +0100643type ApexBundleDepsInfoIntf interface {
644 Updatable() bool
Artur Satayeva8bd1132020-04-27 18:07:06 +0100645 FlatListPath() Path
Artur Satayev872a1442020-04-27 17:08:37 +0100646 FullListPath() Path
647}
648
Artur Satayeva8bd1132020-04-27 18:07:06 +0100649func (d *ApexBundleDepsInfo) FlatListPath() Path {
650 return d.flatListPath
651}
652
Artur Satayev872a1442020-04-27 17:08:37 +0100653func (d *ApexBundleDepsInfo) FullListPath() Path {
654 return d.fullListPath
655}
656
Artur Satayeva8bd1132020-04-27 18:07:06 +0100657// Generate two module out files:
658// 1. FullList with transitive deps and their parents in the dep graph
659// 2. FlatList with a flat list of transitive deps
Artur Satayev533b98c2021-03-11 18:03:42 +0000660// In both cases transitive deps of external deps are not included. Neither are deps that are only
661// available to APEXes; they are developed with updatability in mind and don't need manual approval.
Artur Satayev480e25b2020-04-27 18:53:18 +0100662func (d *ApexBundleDepsInfo) BuildDepsInfoLists(ctx ModuleContext, minSdkVersion string, depInfos DepNameToDepInfoMap) {
Artur Satayeva8bd1132020-04-27 18:07:06 +0100663 var fullContent strings.Builder
664 var flatContent strings.Builder
665
Colin Crosscf371cc2020-11-13 11:48:42 -0800666 fmt.Fprintf(&fullContent, "%s(minSdkVersion:%s):\n", ctx.ModuleName(), minSdkVersion)
Cole Faust18994c72023-02-28 16:02:16 -0800667 for _, key := range FirstUniqueStrings(SortedKeys(depInfos)) {
Artur Satayev872a1442020-04-27 17:08:37 +0100668 info := depInfos[key]
Artur Satayev480e25b2020-04-27 18:53:18 +0100669 toName := fmt.Sprintf("%s(minSdkVersion:%s)", info.To, info.MinSdkVersion)
Artur Satayev872a1442020-04-27 17:08:37 +0100670 if info.IsExternal {
671 toName = toName + " (external)"
672 }
Colin Crosscf371cc2020-11-13 11:48:42 -0800673 fmt.Fprintf(&fullContent, " %s <- %s\n", toName, strings.Join(SortedUniqueStrings(info.From), ", "))
674 fmt.Fprintf(&flatContent, "%s\n", toName)
Artur Satayev872a1442020-04-27 17:08:37 +0100675 }
676
Cole Faust4e9f5922024-11-13 16:09:23 -0800677 fullListPath := PathForModuleOut(ctx, "depsinfo", "fulllist.txt")
678 WriteFileRule(ctx, fullListPath, fullContent.String())
679 d.fullListPath = fullListPath
Artur Satayeva8bd1132020-04-27 18:07:06 +0100680
Cole Faust4e9f5922024-11-13 16:09:23 -0800681 flatListPath := PathForModuleOut(ctx, "depsinfo", "flatlist.txt")
682 WriteFileRule(ctx, flatListPath, flatContent.String())
683 d.flatListPath = flatListPath
Mathew Inwood29bb2fd2021-02-18 11:36:40 +0000684
Cole Faust4e9f5922024-11-13 16:09:23 -0800685 ctx.Phony(fmt.Sprintf("%s-depsinfo", ctx.ModuleName()), fullListPath, flatListPath)
Artur Satayev872a1442020-04-27 17:08:37 +0100686}
Jooyung Han749dc692020-04-15 11:03:39 +0900687
Jooyung Han749dc692020-04-15 11:03:39 +0900688// Function called while walking an APEX's payload dependencies.
689//
690// Return true if the `to` module should be visited, false otherwise.
Colin Cross9cf55a52024-12-05 14:26:03 -0800691type PayloadDepsCallback func(ctx BaseModuleContext, from Module, to ApexModule, externalDep bool) bool
Colin Cross8bf14fc2024-09-25 16:41:31 -0700692type WalkPayloadDepsFunc func(ctx BaseModuleContext, do PayloadDepsCallback)
Jooyung Han749dc692020-04-15 11:03:39 +0900693
satayevb3fd4112021-12-02 13:59:35 +0000694// ModuleWithMinSdkVersionCheck represents a module that implements min_sdk_version checks
695type ModuleWithMinSdkVersionCheck interface {
Jooyung Han749dc692020-04-15 11:03:39 +0900696 Module
Spandan Das8c9ae7e2023-03-03 21:20:36 +0000697 MinSdkVersion(ctx EarlyModuleContext) ApiLevel
satayevb3fd4112021-12-02 13:59:35 +0000698 CheckMinSdkVersion(ctx ModuleContext)
Jooyung Han749dc692020-04-15 11:03:39 +0900699}
700
Jiyong Parke4758ed2020-11-18 01:34:22 +0900701// CheckMinSdkVersion checks if every dependency of an updatable module sets min_sdk_version
702// accordingly
satayevb3fd4112021-12-02 13:59:35 +0000703func CheckMinSdkVersion(ctx ModuleContext, minSdkVersion ApiLevel, walk WalkPayloadDepsFunc) {
Jooyung Han749dc692020-04-15 11:03:39 +0900704 // do not enforce min_sdk_version for host
705 if ctx.Host() {
706 return
707 }
708
709 // do not enforce for coverage build
710 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled() {
711 return
712 }
713
Jooyung Haned124c32021-01-26 11:43:46 +0900714 // do not enforce deps.min_sdk_version if APEX/APK doesn't set min_sdk_version
715 if minSdkVersion.IsNone() {
Jooyung Han749dc692020-04-15 11:03:39 +0900716 return
717 }
718
Colin Cross9cf55a52024-12-05 14:26:03 -0800719 walk(ctx, func(ctx BaseModuleContext, from Module, to ApexModule, externalDep bool) bool {
Jooyung Han749dc692020-04-15 11:03:39 +0900720 if externalDep {
Jiyong Parke4758ed2020-11-18 01:34:22 +0900721 // external deps are outside the payload boundary, which is "stable"
722 // interface. We don't have to check min_sdk_version for external
723 // dependencies.
Jooyung Han749dc692020-04-15 11:03:39 +0900724 return false
725 }
Colin Crossf7bbd2f2024-12-05 13:57:10 -0800726 if !IsDepInSameApex(ctx, from, to) {
Jooyung Han749dc692020-04-15 11:03:39 +0900727 return false
728 }
Yu Liudf0b8392025-02-12 18:27:03 +0000729 if info, ok := OtherModuleProvider(ctx, to, CommonModuleInfoKey); ok && info.ModuleWithMinSdkVersionCheck {
730 if info.MinSdkVersion.ApiLevel == nil || !info.MinSdkVersion.ApiLevel.Specified() {
731 // This dependency performs its own min_sdk_version check, just make sure it sets min_sdk_version
732 // to trigger the check.
733 ctx.OtherModuleErrorf(to, "must set min_sdk_version")
satayev758968a2021-12-06 11:42:40 +0000734 }
735 return false
736 }
Yu Liudf0b8392025-02-12 18:27:03 +0000737 if err := ShouldSupportSdkVersion(ctx, to, minSdkVersion); err != nil {
Jooyung Han2c65d2c2022-06-24 14:56:43 +0900738 ctx.OtherModuleErrorf(to, "should support min_sdk_version(%v) for %q: %v."+
739 "\n\nDependency path: %s\n\n"+
740 "Consider adding 'min_sdk_version: %q' to %q",
741 minSdkVersion, ctx.ModuleName(), err.Error(),
742 ctx.GetPathString(false),
Yu Liudf0b8392025-02-12 18:27:03 +0000743 minSdkVersion, ctx.OtherModuleName(to))
Jooyung Han2c65d2c2022-06-24 14:56:43 +0900744 return false
Jooyung Han749dc692020-04-15 11:03:39 +0900745 }
746 return true
747 })
748}
Spandan Dasf57a9662023-04-12 19:05:49 +0000749
Colin Cross1cea5302024-12-03 16:40:08 -0800750type MinSdkVersionFromValueContext interface {
751 Config() Config
752 DeviceConfig() DeviceConfig
753 ModuleErrorContext
754}
755
Yu Liudf0b8392025-02-12 18:27:03 +0000756// Returns nil (success) if this module should support the given sdk version. Returns an
757// error if not. No default implementation is provided for this method. A module type
758// implementing this interface should provide an implementation. A module supports an sdk
759// version when the module's min_sdk_version is equal to or less than the given sdk version.
760func ShouldSupportSdkVersion(ctx BaseModuleContext, module Module, sdkVersion ApiLevel) error {
761 info, ok := OtherModuleProvider(ctx, module, CommonModuleInfoKey)
762 if !ok || info.MinSdkVersionSupported.IsNone() {
763 return fmt.Errorf("min_sdk_version is not specified")
764 }
765 minVer := info.MinSdkVersionSupported
766
767 if minVer.GreaterThan(sdkVersion) {
768 return fmt.Errorf("newer SDK(%v)", minVer)
769 }
770
771 return nil
772}
773
Sam Delmerico0e0d96e2023-08-18 22:43:28 +0000774// Construct ApiLevel object from min_sdk_version string value
Colin Cross1cea5302024-12-03 16:40:08 -0800775func MinSdkVersionFromValue(ctx MinSdkVersionFromValueContext, value string) ApiLevel {
Sam Delmerico0e0d96e2023-08-18 22:43:28 +0000776 if value == "" {
777 return NoneApiLevel
778 }
779 apiLevel, err := ApiLevelFromUser(ctx, value)
780 if err != nil {
781 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
782 return NoneApiLevel
783 }
784 return apiLevel
785}
786
Spandan Dasda739a32023-12-13 00:06:32 +0000787var ApexExportsInfoProvider = blueprint.NewProvider[ApexExportsInfo]()
788
789// ApexExportsInfo contains information about the artifacts provided by apexes to dexpreopt and hiddenapi
790type ApexExportsInfo struct {
791 // Canonical name of this APEX. Used to determine the path to the activated APEX on
792 // device (/apex/<apex_name>)
793 ApexName string
794
795 // Path to the image profile file on host (or empty, if profile is not generated).
796 ProfilePathOnHost Path
Spandan Das5be63332023-12-13 00:06:32 +0000797
798 // Map from the apex library name (without prebuilt_ prefix) to the dex file path on host
799 LibraryNameToDexJarPathOnHost map[string]Path
Spandan Dasda739a32023-12-13 00:06:32 +0000800}
Spandan Das3490dfd2024-03-11 21:37:25 +0000801
802var PrebuiltInfoProvider = blueprint.NewProvider[PrebuiltInfo]()
803
804// contents of prebuilt_info.json
805type PrebuiltInfo struct {
806 // Name of the apex, without the prebuilt_ prefix
807 Name string
808
809 Is_prebuilt bool
810
811 // This is relative to root of the workspace.
812 // In case of mainline modules, this file contains the build_id that was used
813 // to generate the mainline module prebuilt.
814 Prebuilt_info_file_path string `json:",omitempty"`
815}
Colin Crossbdd344b2025-01-14 16:01:03 -0800816
817// FragmentInApexTag is embedded into a dependency tag to allow apex modules to annotate
818// their fragments in a way that allows the java bootclasspath modules to traverse from
819// the apex to the fragment.
820type FragmentInApexTag struct{}
821
822func (FragmentInApexTag) isFragmentInApexTag() {}
823
824type isFragmentInApexTagIntf interface {
825 isFragmentInApexTag()
826}
827
828// IsFragmentInApexTag returns true if the dependency tag embeds FragmentInApexTag,
829// signifying that it is a dependency from an apex module to its fragment.
830func IsFragmentInApexTag(tag blueprint.DependencyTag) bool {
831 _, ok := tag.(isFragmentInApexTagIntf)
832 return ok
833}