blob: 68d0ce8a2b0a604fb32727a4c7fc80e7cede28ca [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
Jiyong Parke4758ed2020-11-18 01:34:22 +0900158// DepIsInSameApex 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. Note: this was
160// extracted from ApexModule to make it easier to define custom subsets of the ApexModule interface
161// and improve code navigation within the IDE.
Paul Duffin923e8a52020-03-30 15:33:32 +0100162type DepIsInSameApex interface {
Colin Crossf7bbd2f2024-12-05 13:57:10 -0800163 // OutgoingDepIsInSameApex tests if the module depended on via 'tag' is considered as part of
164 // 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 +0900165 // shared lib dependency to a stub library returns false.
Paul Duffin4c3e8e22021-03-18 15:41:29 +0000166 //
167 // This method must not be called directly without first ignoring dependencies whose tags
168 // implement ExcludeFromApexContentsTag. Calls from within the func passed to WalkPayloadDeps()
169 // are fine as WalkPayloadDeps() will ignore those dependencies automatically. Otherwise, use
170 // IsDepInSameApex instead.
Colin Crossf7bbd2f2024-12-05 13:57:10 -0800171 OutgoingDepIsInSameApex(tag blueprint.DependencyTag) bool
172
173 // IncomingDepIsInSameApex tests if this module depended on via 'tag' is considered as part of
174 // the same APEX as the depending module module. For example, a static lib dependency usually
175 // returns true here, while a shared lib dependency to a stub library returns false.
176 //
177 // This method must not be called directly without first ignoring dependencies whose tags
178 // implement ExcludeFromApexContentsTag. Calls from within the func passed to WalkPayloadDeps()
179 // are fine as WalkPayloadDeps() will ignore those dependencies automatically. Otherwise, use
180 // IsDepInSameApex instead.
181 IncomingDepIsInSameApex(tag blueprint.DependencyTag) bool
Paul Duffin923e8a52020-03-30 15:33:32 +0100182}
183
Paul Duffin4c3e8e22021-03-18 15:41:29 +0000184func IsDepInSameApex(ctx BaseModuleContext, module, dep Module) bool {
185 depTag := ctx.OtherModuleDependencyTag(dep)
186 if _, ok := depTag.(ExcludeFromApexContentsTag); ok {
187 // The tag defines a dependency that never requires the child module to be part of the same
188 // apex as the parent.
189 return false
190 }
Colin Crossf7bbd2f2024-12-05 13:57:10 -0800191
192 if m, ok := module.(DepIsInSameApex); ok && !m.OutgoingDepIsInSameApex(depTag) {
193 return false
194 }
195 if d, ok := dep.(DepIsInSameApex); ok && !d.IncomingDepIsInSameApex(depTag) {
196 return false
197 }
198 return true
Paul Duffin4c3e8e22021-03-18 15:41:29 +0000199}
200
Jiyong Parke4758ed2020-11-18 01:34:22 +0900201// ApexModule is the interface that a module type is expected to implement if the module has to be
202// built differently depending on whether the module is destined for an APEX or not (i.e., installed
203// to one of the regular partitions).
Jiyong Park9d452992018-10-03 00:38:19 +0900204//
Jiyong Parke4758ed2020-11-18 01:34:22 +0900205// Native shared libraries are one such module type; when it is built for an APEX, it should depend
206// only on stable interfaces such as NDK, stable AIDL, or C APIs from other APEXes.
Jiyong Park9d452992018-10-03 00:38:19 +0900207//
Jiyong Parke4758ed2020-11-18 01:34:22 +0900208// A module implementing this interface will be mutated into multiple variations by apex.apexMutator
209// if it is directly or indirectly included in one or more APEXes. Specifically, if a module is
210// included in apex.foo and apex.bar then three apex variants are created: platform, apex.foo and
211// apex.bar. The platform variant is for the regular partitions (e.g., /system or /vendor, etc.)
212// while the other two are for the APEXs, respectively. The latter two variations can be merged (see
213// mergedName) when the two APEXes have the same min_sdk_version requirement.
Jiyong Park9d452992018-10-03 00:38:19 +0900214type ApexModule interface {
215 Module
Paul Duffin923e8a52020-03-30 15:33:32 +0100216 DepIsInSameApex
217
Jiyong Park9d452992018-10-03 00:38:19 +0900218 apexModuleBase() *ApexModuleBase
219
Jiyong Parke4758ed2020-11-18 01:34:22 +0900220 // Marks that this module should be built for the specified APEX. Call this BEFORE
221 // apex.apexMutator is run.
Jooyung Han698dd9f2020-07-22 15:17:19 +0900222 BuildForApex(apex ApexInfo)
Jiyong Parkf760cae2020-02-12 07:53:12 +0900223
Jiyong Parke4758ed2020-11-18 01:34:22 +0900224 // Returns true if this module is present in any APEX either directly or indirectly. Call
225 // this after apex.apexMutator is run.
Colin Cross56a83212020-09-15 18:30:11 -0700226 InAnyApex() bool
Jiyong Park9d452992018-10-03 00:38:19 +0900227
Colin Cross0c19b692024-11-06 13:50:21 -0800228 // NotInPlatform returns true if the module is not available to the platform due to
229 // apex_available being set and not containing "//apex_available:platform".
Jiyong Parkf7c3bbe2020-12-09 21:18:56 +0900230 NotInPlatform() bool
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900231
Jiyong Parke4758ed2020-11-18 01:34:22 +0900232 // Tests if this module could have APEX variants. Even when a module type implements
233 // ApexModule interface, APEX variants are created only for the module instances that return
234 // true here. This is useful for not creating APEX variants for certain types of shared
235 // libraries such as NDK stubs.
Jiyong Park9d452992018-10-03 00:38:19 +0900236 CanHaveApexVariants() bool
237
Jiyong Parke4758ed2020-11-18 01:34:22 +0900238 // Tests if this module can be installed to APEX as a file. For example, this would return
239 // true for shared libs while return false for static libs because static libs are not
240 // installable module (but it can still be mutated for APEX)
Jiyong Park9d452992018-10-03 00:38:19 +0900241 IsInstallableToApex() bool
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900242
Jiyong Parke4758ed2020-11-18 01:34:22 +0900243 // Tests if this module is available for the specified APEX or ":platform". This is from the
244 // apex_available property of the module.
Jiyong Park127b40b2019-09-30 16:04:35 +0900245 AvailableFor(what string) bool
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900246
Yu Liub73c3a62024-12-10 00:58:06 +0000247 // Returns the apexes that are available for this module, valid values include
248 // "//apex_available:platform", "//apex_available:anyapex" and specific apexes.
249 // There are some differences between this one and the ApexAvailable on
250 // ApexModuleBase for cc, java library and sdkLibraryXml.
251 ApexAvailableFor() []string
252
Paul Duffinb5769c12021-05-12 16:16:51 +0100253 // AlwaysRequiresPlatformApexVariant allows the implementing module to determine whether an
254 // APEX mutator should always be created for it.
255 //
256 // Returns false by default.
257 AlwaysRequiresPlatformApexVariant() bool
258
Jiyong Parke4758ed2020-11-18 01:34:22 +0900259 // Returns true if this module is not available to platform (i.e. apex_available property
260 // doesn't have "//apex_available:platform"), or shouldn't be available to platform, which
261 // is the case when this module depends on other module that isn't available to platform.
Jiyong Park89e850a2020-04-07 16:37:39 +0900262 NotAvailableForPlatform() bool
263
Jiyong Parke4758ed2020-11-18 01:34:22 +0900264 // Marks that this module is not available to platform. Set by the
Jiyong Park89e850a2020-04-07 16:37:39 +0900265 // check-platform-availability mutator in the apex package.
266 SetNotAvailableForPlatform()
267
Jiyong Parke4758ed2020-11-18 01:34:22 +0900268 // Returns nil (success) if this module should support the given sdk version. Returns an
269 // error if not. No default implementation is provided for this method. A module type
270 // implementing this interface should provide an implementation. A module supports an sdk
271 // 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 -0700272 ShouldSupportSdkVersion(ctx BaseModuleContext, sdkVersion ApiLevel) error
Colin Crossaede88c2020-08-11 12:17:01 -0700273
Jiyong Parke4758ed2020-11-18 01:34:22 +0900274 // Returns true if this module needs a unique variation per apex, effectively disabling the
275 // deduping. This is turned on when, for example if use_apex_name_macro is set so that each
276 // apex variant should be built with different macro definitions.
Colin Crossaede88c2020-08-11 12:17:01 -0700277 UniqueApexVariations() bool
Jiyong Park9d452992018-10-03 00:38:19 +0900278}
279
Jiyong Parke4758ed2020-11-18 01:34:22 +0900280// Properties that are common to all module types implementing ApexModule interface.
Jiyong Park9d452992018-10-03 00:38:19 +0900281type ApexProperties struct {
Jiyong Parke4758ed2020-11-18 01:34:22 +0900282 // Availability of this module in APEXes. Only the listed APEXes can contain this module. If
283 // the module has stubs then other APEXes and the platform may access it through them
284 // (subject to visibility).
Martin Stjernholm06ca82d2020-01-17 13:02:56 +0000285 //
Jiyong Park127b40b2019-09-30 16:04:35 +0900286 // "//apex_available:anyapex" is a pseudo APEX name that matches to any APEX.
287 // "//apex_available:platform" refers to non-APEX partitions like "system.img".
Jooyung Han9a419e22024-08-16 17:14:21 +0900288 // 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 +0900289 // Default is ["//apex_available:platform"].
Jiyong Park127b40b2019-09-30 16:04:35 +0900290 Apex_available []string
291
Jiyong Parke4758ed2020-11-18 01:34:22 +0900292 // See ApexModule.NotAvailableForPlatform()
Jiyong Park89e850a2020-04-07 16:37:39 +0900293 NotAvailableForPlatform bool `blueprint:"mutated"`
Colin Crossaede88c2020-08-11 12:17:01 -0700294
Jiyong Parke4758ed2020-11-18 01:34:22 +0900295 // See ApexModule.UniqueApexVariants()
Colin Crossaede88c2020-08-11 12:17:01 -0700296 UniqueApexVariationsForDeps bool `blueprint:"mutated"`
Jiyong Park9d452992018-10-03 00:38:19 +0900297}
298
Jiyong Parke4758ed2020-11-18 01:34:22 +0900299// Marker interface that identifies dependencies that are excluded from APEX contents.
Paul Duffin573989d2021-03-17 13:25:29 +0000300//
Paul Duffin4c3e8e22021-03-18 15:41:29 +0000301// At the moment the sdk.sdkRequirementsMutator relies on the fact that the existing tags which
302// implement this interface do not define dependencies onto members of an sdk_snapshot. If that
303// changes then sdk.sdkRequirementsMutator will need fixing.
Paul Duffindddd5462020-04-07 15:25:44 +0100304type ExcludeFromApexContentsTag interface {
305 blueprint.DependencyTag
306
307 // Method that differentiates this interface from others.
308 ExcludeFromApexContents()
309}
310
Cindy Zhou18417cb2020-12-10 07:12:38 -0800311// Interface that identifies dependencies to skip Apex dependency check
312type SkipApexAllowedDependenciesCheck interface {
313 // Returns true to skip the Apex dependency check, which limits the allowed dependency in build.
314 SkipApexAllowedDependenciesCheck() bool
315}
316
Jiyong Parke4758ed2020-11-18 01:34:22 +0900317// ApexModuleBase provides the default implementation for the ApexModule interface. APEX-aware
Jiyong Park9d452992018-10-03 00:38:19 +0900318// modules are expected to include this struct and call InitApexModule().
319type ApexModuleBase struct {
Jihoon Kang46d66de2024-05-22 22:42:39 +0000320 ApexProperties ApexProperties
321 apexPropertiesLock sync.Mutex // protects ApexProperties during parallel apexDirectlyInAnyMutator
Jiyong Park9d452992018-10-03 00:38:19 +0900322
323 canHaveApexVariants bool
Colin Crosscefa94bd2019-06-03 15:07:03 -0700324
Jiyong Parke4758ed2020-11-18 01:34:22 +0900325 apexInfos []ApexInfo
Paul Duffin949abc02020-12-08 10:34:30 +0000326 apexInfosLock sync.Mutex // protects apexInfos during parallel apexInfoMutator
Jiyong Park9d452992018-10-03 00:38:19 +0900327}
328
Colin Cross1cea5302024-12-03 16:40:08 -0800329func (m *ApexModuleBase) ApexTransitionMutatorSplit(ctx BaseModuleContext) []ApexInfo {
330 return []ApexInfo{{}}
331}
332
333func (m *ApexModuleBase) ApexTransitionMutatorOutgoing(ctx OutgoingTransitionContext, info ApexInfo) ApexInfo {
334 if !ctx.Module().(DepIsInSameApex).OutgoingDepIsInSameApex(ctx.DepTag()) {
335 return ApexInfo{}
336 }
337 return info
338}
339
340func (m *ApexModuleBase) ApexTransitionMutatorIncoming(ctx IncomingTransitionContext, info ApexInfo) ApexInfo {
341 module := ctx.Module().(ApexModule)
342 if !module.CanHaveApexVariants() {
343 return ApexInfo{}
344 }
345
346 if !ctx.Module().(DepIsInSameApex).IncomingDepIsInSameApex(ctx.DepTag()) {
347 return ApexInfo{}
348 }
349
350 if info.ApexVariationName == "" {
351 return ApexInfo{}
352 }
353
354 if !ctx.Module().(ApexModule).UniqueApexVariations() && !m.ApexProperties.UniqueApexVariationsForDeps && !info.ForPrebuiltApex {
355 return info.Minimize()
356 }
357 return info
358}
359
360func (m *ApexModuleBase) ApexTransitionMutatorMutate(ctx BottomUpMutatorContext, info ApexInfo) {
361 SetProvider(ctx, ApexInfoProvider, info)
362
363 module := ctx.Module().(ApexModule)
364 base := module.apexModuleBase()
365
366 platformVariation := info.ApexVariationName == ""
367 if !platformVariation {
368 // Do some validity checks.
369 // TODO(jiyong): is this the right place?
370 base.checkApexAvailableProperty(ctx)
371
372 SetProvider(ctx, ApexAvailableInfoProvider, ApexAvailableInfo{
373 ApexAvailableFor: module.ApexAvailableFor(),
374 })
375 }
376 if platformVariation && !ctx.Host() && !module.AvailableFor(AvailableToPlatform) && module.NotAvailableForPlatform() {
377 // Do not install the module for platform, but still allow it to output
378 // uninstallable AndroidMk entries in certain cases when they have side
379 // effects. TODO(jiyong): move this routine to somewhere else
380 module.MakeUninstallable()
381 }
382}
383
Jiyong Parke4758ed2020-11-18 01:34:22 +0900384// Initializes ApexModuleBase struct. Not calling this (even when inheriting from ApexModuleBase)
385// prevents the module from being mutated for apexBundle.
386func InitApexModule(m ApexModule) {
387 base := m.apexModuleBase()
388 base.canHaveApexVariants = true
389
390 m.AddProperties(&base.ApexProperties)
391}
392
393// Implements ApexModule
Jiyong Park9d452992018-10-03 00:38:19 +0900394func (m *ApexModuleBase) apexModuleBase() *ApexModuleBase {
395 return m
396}
397
Spandan Das8e6386e2023-04-11 19:08:18 +0000398var (
399 availableToPlatformList = []string{AvailableToPlatform}
400)
401
Jiyong Parke4758ed2020-11-18 01:34:22 +0900402// Implements ApexModule
Paul Duffinbefa4b92020-03-04 14:22:45 +0000403func (m *ApexModuleBase) ApexAvailable() []string {
Spandan Das8e6386e2023-04-11 19:08:18 +0000404 aa := m.ApexProperties.Apex_available
405 if len(aa) > 0 {
406 return aa
407 }
408 // Default is availability to platform
409 return CopyOf(availableToPlatformList)
Paul Duffinbefa4b92020-03-04 14:22:45 +0000410}
411
Yu Liub73c3a62024-12-10 00:58:06 +0000412func (m *ApexModuleBase) ApexAvailableFor() []string {
413 return m.ApexAvailable()
414}
415
Jiyong Parke4758ed2020-11-18 01:34:22 +0900416// Implements ApexModule
Jooyung Han698dd9f2020-07-22 15:17:19 +0900417func (m *ApexModuleBase) BuildForApex(apex ApexInfo) {
Jiyong Parke4758ed2020-11-18 01:34:22 +0900418 m.apexInfosLock.Lock()
419 defer m.apexInfosLock.Unlock()
Colin Crossf6978172024-11-19 11:29:46 -0800420 if slices.ContainsFunc(m.apexInfos, func(existing ApexInfo) bool {
421 return existing.ApexVariationName == apex.ApexVariationName
422 }) {
423 return
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900424 }
Jiyong Parke4758ed2020-11-18 01:34:22 +0900425 m.apexInfos = append(m.apexInfos, apex)
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900426}
427
Jiyong Parke4758ed2020-11-18 01:34:22 +0900428// Implements ApexModule
Colin Cross56a83212020-09-15 18:30:11 -0700429func (m *ApexModuleBase) InAnyApex() bool {
Colin Cross2dcbca62024-11-20 14:55:14 -0800430 for _, apex_name := range m.ApexProperties.Apex_available {
431 if apex_name != AvailableToPlatform {
432 return true
433 }
434 }
435 return false
Jiyong Park9d452992018-10-03 00:38:19 +0900436}
437
Jiyong Parke4758ed2020-11-18 01:34:22 +0900438// Implements ApexModule
Jiyong Parkf7c3bbe2020-12-09 21:18:56 +0900439func (m *ApexModuleBase) NotInPlatform() bool {
Colin Cross0c19b692024-11-06 13:50:21 -0800440 return !m.AvailableFor(AvailableToPlatform)
Jiyong Parke4758ed2020-11-18 01:34:22 +0900441}
442
443// Implements ApexModule
Jiyong Park9d452992018-10-03 00:38:19 +0900444func (m *ApexModuleBase) CanHaveApexVariants() bool {
445 return m.canHaveApexVariants
446}
447
Jiyong Parke4758ed2020-11-18 01:34:22 +0900448// Implements ApexModule
Jiyong Park9d452992018-10-03 00:38:19 +0900449func (m *ApexModuleBase) IsInstallableToApex() bool {
Jiyong Parke4758ed2020-11-18 01:34:22 +0900450 // If needed, this will bel overridden by concrete types inheriting
451 // ApexModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900452 return false
453}
454
Jiyong Parke4758ed2020-11-18 01:34:22 +0900455// Implements ApexModule
456func (m *ApexModuleBase) UniqueApexVariations() bool {
457 // If needed, this will bel overridden by concrete types inheriting
458 // ApexModuleBase
459 return false
460}
461
462// Implements ApexModule
Colin Crossf7bbd2f2024-12-05 13:57:10 -0800463func (m *ApexModuleBase) OutgoingDepIsInSameApex(tag blueprint.DependencyTag) bool {
464 // By default, if there is a dependency from A to B, we try to include both in the same
465 // APEX, unless B is explicitly from outside of the APEX (i.e. a stubs lib). Thus, returning
466 // true. This is overridden by some module types like apex.ApexBundle, cc.Module,
467 // java.Module, etc.
468 return true
469}
470
471func (m *ApexModuleBase) IncomingDepIsInSameApex(tag blueprint.DependencyTag) bool {
Jiyong Parke4758ed2020-11-18 01:34:22 +0900472 // By default, if there is a dependency from A to B, we try to include both in the same
473 // APEX, unless B is explicitly from outside of the APEX (i.e. a stubs lib). Thus, returning
474 // true. This is overridden by some module types like apex.ApexBundle, cc.Module,
475 // java.Module, etc.
476 return true
477}
478
Jiyong Park127b40b2019-09-30 16:04:35 +0900479const (
Jiyong Parkb02bb402019-12-03 00:43:57 +0900480 AvailableToPlatform = "//apex_available:platform"
Paul Duffin7d74e7b2020-03-06 12:30:13 +0000481 AvailableToAnyApex = "//apex_available:anyapex"
Jiyong Park127b40b2019-09-30 16:04:35 +0900482)
483
Jiyong Parke4758ed2020-11-18 01:34:22 +0900484// CheckAvailableForApex provides the default algorithm for checking the apex availability. When the
485// availability is empty, it defaults to ["//apex_available:platform"] which means "available to the
486// platform but not available to any APEX". When the list is not empty, `what` is matched against
487// the list. If there is any matching element in the list, thus function returns true. The special
488// availability "//apex_available:anyapex" matches with anything except for
489// "//apex_available:platform".
Jiyong Parka90ca002019-10-07 15:47:24 +0900490func CheckAvailableForApex(what string, apex_available []string) bool {
491 if len(apex_available) == 0 {
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000492 return what == AvailableToPlatform
Jiyong Park127b40b2019-09-30 16:04:35 +0900493 }
Jooyung Han9a419e22024-08-16 17:14:21 +0900494
495 // TODO b/248601389
496 if what == "com.google.mainline.primary.libs" || what == "com.google.mainline.go.primary.libs" {
497 return true
498 }
499
500 for _, apex_name := range apex_available {
501 // exact match.
502 if apex_name == what {
503 return true
504 }
505 // //apex_available:anyapex matches with any apex name, but not //apex_available:platform
506 if apex_name == AvailableToAnyApex && what != AvailableToPlatform {
507 return true
508 }
509 // prefix match.
510 if strings.HasSuffix(apex_name, ".*") && strings.HasPrefix(what, strings.TrimSuffix(apex_name, "*")) {
511 return true
512 }
William Escandea345bba2024-12-12 14:00:01 -0800513 // TODO b/383863941: Remove once legacy name is no longer used
514 if (apex_name == "com.android.btservices" && what == "com.android.bt") || (apex_name == "com.android.bt" && what == "com.android.btservices") {
515 return true
516 }
Jooyung Han9a419e22024-08-16 17:14:21 +0900517 }
518 return false
Jiyong Parka90ca002019-10-07 15:47:24 +0900519}
520
Jiyong Parke4758ed2020-11-18 01:34:22 +0900521// Implements ApexModule
Jiyong Parka90ca002019-10-07 15:47:24 +0900522func (m *ApexModuleBase) AvailableFor(what string) bool {
Yu Liub73c3a62024-12-10 00:58:06 +0000523 return CheckAvailableForApex(what, m.ApexAvailableFor())
Jiyong Park127b40b2019-09-30 16:04:35 +0900524}
525
Jiyong Parke4758ed2020-11-18 01:34:22 +0900526// Implements ApexModule
Paul Duffinb5769c12021-05-12 16:16:51 +0100527func (m *ApexModuleBase) AlwaysRequiresPlatformApexVariant() bool {
528 return false
529}
530
531// Implements ApexModule
Jiyong Park89e850a2020-04-07 16:37:39 +0900532func (m *ApexModuleBase) NotAvailableForPlatform() bool {
533 return m.ApexProperties.NotAvailableForPlatform
534}
535
Jiyong Parke4758ed2020-11-18 01:34:22 +0900536// Implements ApexModule
Jiyong Park89e850a2020-04-07 16:37:39 +0900537func (m *ApexModuleBase) SetNotAvailableForPlatform() {
538 m.ApexProperties.NotAvailableForPlatform = true
539}
540
Jiyong Parke4758ed2020-11-18 01:34:22 +0900541// This function makes sure that the apex_available property is valid
Jiyong Park127b40b2019-09-30 16:04:35 +0900542func (m *ApexModuleBase) checkApexAvailableProperty(mctx BaseModuleContext) {
543 for _, n := range m.ApexProperties.Apex_available {
Jooyung Han40b79172024-08-16 16:00:33 +0900544 if n == AvailableToPlatform || n == AvailableToAnyApex {
Jiyong Park127b40b2019-09-30 16:04:35 +0900545 continue
546 }
Jooyung Han9a419e22024-08-16 17:14:21 +0900547 // Prefix pattern should end with .* and has at least two components.
548 if strings.Contains(n, "*") {
549 if !strings.HasSuffix(n, ".*") {
550 mctx.PropertyErrorf("apex_available", "Wildcard should end with .* like com.foo.*")
551 }
552 if strings.Count(n, ".") < 2 {
553 mctx.PropertyErrorf("apex_available", "Wildcard requires two or more components like com.foo.*")
554 }
555 if strings.Count(n, "*") != 1 {
556 mctx.PropertyErrorf("apex_available", "Wildcard is not allowed in the middle.")
557 }
558 continue
559 }
Orion Hodson4b5438a2019-10-08 10:40:51 +0100560 if !mctx.OtherModuleExists(n) && !mctx.Config().AllowMissingDependencies() {
Jiyong Park127b40b2019-09-30 16:04:35 +0900561 mctx.PropertyErrorf("apex_available", "%q is not a valid module name", n)
562 }
563 }
564}
565
Martin Stjernholm4e6c2692021-03-25 01:25:06 +0000566// AvailableToSameApexes returns true if the two modules are apex_available to
567// exactly the same set of APEXes (and platform), i.e. if their apex_available
568// properties have the same elements.
569func AvailableToSameApexes(mod1, mod2 ApexModule) bool {
Spandan Das8a8714c2023-04-25 18:03:54 +0000570 mod1ApexAvail := SortedUniqueStrings(mod1.apexModuleBase().ApexProperties.Apex_available)
571 mod2ApexAvail := SortedUniqueStrings(mod2.apexModuleBase().ApexProperties.Apex_available)
Martin Stjernholm4e6c2692021-03-25 01:25:06 +0000572 if len(mod1ApexAvail) != len(mod2ApexAvail) {
573 return false
574 }
575 for i, v := range mod1ApexAvail {
576 if v != mod2ApexAvail[i] {
577 return false
578 }
579 }
580 return true
581}
582
Jiyong Parke4758ed2020-11-18 01:34:22 +0900583// UpdateUniqueApexVariationsForDeps sets UniqueApexVariationsForDeps if any dependencies that are
584// in the same APEX have unique APEX variations so that the module can link against the right
585// variant.
Colin Cross56a83212020-09-15 18:30:11 -0700586func UpdateUniqueApexVariationsForDeps(mctx BottomUpMutatorContext, am ApexModule) {
Jiyong Parke4758ed2020-11-18 01:34:22 +0900587 // If any of the dependencies requires unique apex variations, so does this module.
Colin Cross56a83212020-09-15 18:30:11 -0700588 mctx.VisitDirectDeps(func(dep Module) {
589 if depApexModule, ok := dep.(ApexModule); ok {
Colin Cross1cea5302024-12-03 16:40:08 -0800590 if IsDepInSameApex(mctx, am, depApexModule) &&
Colin Cross56a83212020-09-15 18:30:11 -0700591 (depApexModule.UniqueApexVariations() ||
592 depApexModule.apexModuleBase().ApexProperties.UniqueApexVariationsForDeps) {
593 am.apexModuleBase().ApexProperties.UniqueApexVariationsForDeps = true
594 }
595 }
596 })
Jiyong Park25fc6a92018-11-18 18:02:45 +0900597}
598
Jiyong Parke4758ed2020-11-18 01:34:22 +0900599////////////////////////////////////////////////////////////////////////////////////////////////////
600//Below are routines for extra safety checks.
601//
602// BuildDepsInfoLists is to flatten the dependency graph for an apexBundle into a text file
603// (actually two in slightly different formats). The files are mostly for debugging, for example to
604// see why a certain module is included in an APEX via which dependency path.
605//
606// CheckMinSdkVersion is to make sure that all modules in an apexBundle satisfy the min_sdk_version
607// requirement of the apexBundle.
Artur Satayev872a1442020-04-27 17:08:37 +0100608
609// A dependency info for a single ApexModule, either direct or transitive.
610type ApexModuleDepInfo struct {
611 // Name of the dependency
612 To string
613 // List of dependencies To belongs to. Includes APEX itself, if a direct dependency.
614 From []string
615 // Whether the dependency belongs to the final compiled APEX.
616 IsExternal bool
Artur Satayev480e25b2020-04-27 18:53:18 +0100617 // min_sdk_version of the ApexModule
618 MinSdkVersion string
Artur Satayev872a1442020-04-27 17:08:37 +0100619}
620
621// A map of a dependency name to its ApexModuleDepInfo
622type DepNameToDepInfoMap map[string]ApexModuleDepInfo
623
624type ApexBundleDepsInfo struct {
Cole Faust4e9f5922024-11-13 16:09:23 -0800625 flatListPath Path
626 fullListPath Path
Artur Satayev872a1442020-04-27 17:08:37 +0100627}
628
Artur Satayev849f8442020-04-28 14:57:42 +0100629type ApexBundleDepsInfoIntf interface {
630 Updatable() bool
Artur Satayeva8bd1132020-04-27 18:07:06 +0100631 FlatListPath() Path
Artur Satayev872a1442020-04-27 17:08:37 +0100632 FullListPath() Path
633}
634
Artur Satayeva8bd1132020-04-27 18:07:06 +0100635func (d *ApexBundleDepsInfo) FlatListPath() Path {
636 return d.flatListPath
637}
638
Artur Satayev872a1442020-04-27 17:08:37 +0100639func (d *ApexBundleDepsInfo) FullListPath() Path {
640 return d.fullListPath
641}
642
Artur Satayeva8bd1132020-04-27 18:07:06 +0100643// Generate two module out files:
644// 1. FullList with transitive deps and their parents in the dep graph
645// 2. FlatList with a flat list of transitive deps
Artur Satayev533b98c2021-03-11 18:03:42 +0000646// In both cases transitive deps of external deps are not included. Neither are deps that are only
647// available to APEXes; they are developed with updatability in mind and don't need manual approval.
Artur Satayev480e25b2020-04-27 18:53:18 +0100648func (d *ApexBundleDepsInfo) BuildDepsInfoLists(ctx ModuleContext, minSdkVersion string, depInfos DepNameToDepInfoMap) {
Artur Satayeva8bd1132020-04-27 18:07:06 +0100649 var fullContent strings.Builder
650 var flatContent strings.Builder
651
Colin Crosscf371cc2020-11-13 11:48:42 -0800652 fmt.Fprintf(&fullContent, "%s(minSdkVersion:%s):\n", ctx.ModuleName(), minSdkVersion)
Cole Faust18994c72023-02-28 16:02:16 -0800653 for _, key := range FirstUniqueStrings(SortedKeys(depInfos)) {
Artur Satayev872a1442020-04-27 17:08:37 +0100654 info := depInfos[key]
Artur Satayev480e25b2020-04-27 18:53:18 +0100655 toName := fmt.Sprintf("%s(minSdkVersion:%s)", info.To, info.MinSdkVersion)
Artur Satayev872a1442020-04-27 17:08:37 +0100656 if info.IsExternal {
657 toName = toName + " (external)"
658 }
Colin Crosscf371cc2020-11-13 11:48:42 -0800659 fmt.Fprintf(&fullContent, " %s <- %s\n", toName, strings.Join(SortedUniqueStrings(info.From), ", "))
660 fmt.Fprintf(&flatContent, "%s\n", toName)
Artur Satayev872a1442020-04-27 17:08:37 +0100661 }
662
Cole Faust4e9f5922024-11-13 16:09:23 -0800663 fullListPath := PathForModuleOut(ctx, "depsinfo", "fulllist.txt")
664 WriteFileRule(ctx, fullListPath, fullContent.String())
665 d.fullListPath = fullListPath
Artur Satayeva8bd1132020-04-27 18:07:06 +0100666
Cole Faust4e9f5922024-11-13 16:09:23 -0800667 flatListPath := PathForModuleOut(ctx, "depsinfo", "flatlist.txt")
668 WriteFileRule(ctx, flatListPath, flatContent.String())
669 d.flatListPath = flatListPath
Mathew Inwood29bb2fd2021-02-18 11:36:40 +0000670
Cole Faust4e9f5922024-11-13 16:09:23 -0800671 ctx.Phony(fmt.Sprintf("%s-depsinfo", ctx.ModuleName()), fullListPath, flatListPath)
Artur Satayev872a1442020-04-27 17:08:37 +0100672}
Jooyung Han749dc692020-04-15 11:03:39 +0900673
Jooyung Han749dc692020-04-15 11:03:39 +0900674// Function called while walking an APEX's payload dependencies.
675//
676// Return true if the `to` module should be visited, false otherwise.
Colin Cross9cf55a52024-12-05 14:26:03 -0800677type PayloadDepsCallback func(ctx BaseModuleContext, from Module, to ApexModule, externalDep bool) bool
Colin Cross8bf14fc2024-09-25 16:41:31 -0700678type WalkPayloadDepsFunc func(ctx BaseModuleContext, do PayloadDepsCallback)
Jooyung Han749dc692020-04-15 11:03:39 +0900679
satayevb3fd4112021-12-02 13:59:35 +0000680// ModuleWithMinSdkVersionCheck represents a module that implements min_sdk_version checks
681type ModuleWithMinSdkVersionCheck interface {
Jooyung Han749dc692020-04-15 11:03:39 +0900682 Module
Spandan Das8c9ae7e2023-03-03 21:20:36 +0000683 MinSdkVersion(ctx EarlyModuleContext) ApiLevel
satayevb3fd4112021-12-02 13:59:35 +0000684 CheckMinSdkVersion(ctx ModuleContext)
Jooyung Han749dc692020-04-15 11:03:39 +0900685}
686
Jiyong Parke4758ed2020-11-18 01:34:22 +0900687// CheckMinSdkVersion checks if every dependency of an updatable module sets min_sdk_version
688// accordingly
satayevb3fd4112021-12-02 13:59:35 +0000689func CheckMinSdkVersion(ctx ModuleContext, minSdkVersion ApiLevel, walk WalkPayloadDepsFunc) {
Jooyung Han749dc692020-04-15 11:03:39 +0900690 // do not enforce min_sdk_version for host
691 if ctx.Host() {
692 return
693 }
694
695 // do not enforce for coverage build
696 if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT") || ctx.DeviceConfig().NativeCoverageEnabled() || ctx.DeviceConfig().ClangCoverageEnabled() {
697 return
698 }
699
Jooyung Haned124c32021-01-26 11:43:46 +0900700 // do not enforce deps.min_sdk_version if APEX/APK doesn't set min_sdk_version
701 if minSdkVersion.IsNone() {
Jooyung Han749dc692020-04-15 11:03:39 +0900702 return
703 }
704
Colin Cross9cf55a52024-12-05 14:26:03 -0800705 walk(ctx, func(ctx BaseModuleContext, from Module, to ApexModule, externalDep bool) bool {
Jooyung Han749dc692020-04-15 11:03:39 +0900706 if externalDep {
Jiyong Parke4758ed2020-11-18 01:34:22 +0900707 // external deps are outside the payload boundary, which is "stable"
708 // interface. We don't have to check min_sdk_version for external
709 // dependencies.
Jooyung Han749dc692020-04-15 11:03:39 +0900710 return false
711 }
Colin Crossf7bbd2f2024-12-05 13:57:10 -0800712 if !IsDepInSameApex(ctx, from, to) {
Jooyung Han749dc692020-04-15 11:03:39 +0900713 return false
714 }
satayev758968a2021-12-06 11:42:40 +0000715 if m, ok := to.(ModuleWithMinSdkVersionCheck); ok {
716 // This dependency performs its own min_sdk_version check, just make sure it sets min_sdk_version
717 // to trigger the check.
718 if !m.MinSdkVersion(ctx).Specified() {
719 ctx.OtherModuleErrorf(m, "must set min_sdk_version")
720 }
721 return false
722 }
Jooyung Han749dc692020-04-15 11:03:39 +0900723 if err := to.ShouldSupportSdkVersion(ctx, minSdkVersion); err != nil {
724 toName := ctx.OtherModuleName(to)
Jooyung Han2c65d2c2022-06-24 14:56:43 +0900725 ctx.OtherModuleErrorf(to, "should support min_sdk_version(%v) for %q: %v."+
726 "\n\nDependency path: %s\n\n"+
727 "Consider adding 'min_sdk_version: %q' to %q",
728 minSdkVersion, ctx.ModuleName(), err.Error(),
729 ctx.GetPathString(false),
730 minSdkVersion, toName)
731 return false
Jooyung Han749dc692020-04-15 11:03:39 +0900732 }
733 return true
734 })
735}
Spandan Dasf57a9662023-04-12 19:05:49 +0000736
Colin Cross1cea5302024-12-03 16:40:08 -0800737type MinSdkVersionFromValueContext interface {
738 Config() Config
739 DeviceConfig() DeviceConfig
740 ModuleErrorContext
741}
742
Sam Delmerico0e0d96e2023-08-18 22:43:28 +0000743// Construct ApiLevel object from min_sdk_version string value
Colin Cross1cea5302024-12-03 16:40:08 -0800744func MinSdkVersionFromValue(ctx MinSdkVersionFromValueContext, value string) ApiLevel {
Sam Delmerico0e0d96e2023-08-18 22:43:28 +0000745 if value == "" {
746 return NoneApiLevel
747 }
748 apiLevel, err := ApiLevelFromUser(ctx, value)
749 if err != nil {
750 ctx.PropertyErrorf("min_sdk_version", "%s", err.Error())
751 return NoneApiLevel
752 }
753 return apiLevel
754}
755
Spandan Dasda739a32023-12-13 00:06:32 +0000756var ApexExportsInfoProvider = blueprint.NewProvider[ApexExportsInfo]()
757
758// ApexExportsInfo contains information about the artifacts provided by apexes to dexpreopt and hiddenapi
759type ApexExportsInfo struct {
760 // Canonical name of this APEX. Used to determine the path to the activated APEX on
761 // device (/apex/<apex_name>)
762 ApexName string
763
764 // Path to the image profile file on host (or empty, if profile is not generated).
765 ProfilePathOnHost Path
Spandan Das5be63332023-12-13 00:06:32 +0000766
767 // Map from the apex library name (without prebuilt_ prefix) to the dex file path on host
768 LibraryNameToDexJarPathOnHost map[string]Path
Spandan Dasda739a32023-12-13 00:06:32 +0000769}
Spandan Das3490dfd2024-03-11 21:37:25 +0000770
771var PrebuiltInfoProvider = blueprint.NewProvider[PrebuiltInfo]()
772
773// contents of prebuilt_info.json
774type PrebuiltInfo struct {
775 // Name of the apex, without the prebuilt_ prefix
776 Name string
777
778 Is_prebuilt bool
779
780 // This is relative to root of the workspace.
781 // In case of mainline modules, this file contains the build_id that was used
782 // to generate the mainline module prebuilt.
783 Prebuilt_info_file_path string `json:",omitempty"`
784}
Colin Crossbdd344b2025-01-14 16:01:03 -0800785
786// FragmentInApexTag is embedded into a dependency tag to allow apex modules to annotate
787// their fragments in a way that allows the java bootclasspath modules to traverse from
788// the apex to the fragment.
789type FragmentInApexTag struct{}
790
791func (FragmentInApexTag) isFragmentInApexTag() {}
792
793type isFragmentInApexTagIntf interface {
794 isFragmentInApexTag()
795}
796
797// IsFragmentInApexTag returns true if the dependency tag embeds FragmentInApexTag,
798// signifying that it is a dependency from an apex module to its fragment.
799func IsFragmentInApexTag(tag blueprint.DependencyTag) bool {
800 _, ok := tag.(isFragmentInApexTagIntf)
801 return ok
802}