blob: ede0965407046f9dd2517224287bf08e319ac3a2 [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 Han0c4e0162020-02-26 22:45:42 +090018 "fmt"
Colin Crosscefa94bd2019-06-03 15:07:03 -070019 "sort"
Jooyung Han0c4e0162020-02-26 22:45:42 +090020 "strconv"
Artur Satayev334b5172020-04-27 17:08:37 +010021 "strings"
Jiyong Park0ddfcd12018-12-11 01:35:25 +090022 "sync"
Paul Duffin3766cb72020-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
Jooyung Han23b0adf2020-03-12 18:37:20 +090027const (
28 SdkVersion_Android10 = 29
29)
30
Peter Collingbournedc4f9862020-02-12 17:13:25 -080031type ApexInfo struct {
32 // Name of the apex variant that this module is mutated into
33 ApexName string
34
Jooyung Han0c4e0162020-02-26 22:45:42 +090035 MinSdkVersion int
Peter Collingbournedc4f9862020-02-12 17:13:25 -080036}
37
Paul Duffin03e7d0c2020-03-30 15:33:32 +010038// Extracted from ApexModule to make it easier to define custom subsets of the
39// ApexModule interface and improve code navigation within the IDE.
40type DepIsInSameApex interface {
41 // DepIsInSameApex tests if the other module 'dep' is installed to the same
42 // APEX as this module
43 DepIsInSameApex(ctx BaseModuleContext, dep Module) bool
44}
45
Jiyong Park9d452992018-10-03 00:38:19 +090046// ApexModule is the interface that a module type is expected to implement if
47// the module has to be built differently depending on whether the module
48// is destined for an apex or not (installed to one of the regular partitions).
49//
50// Native shared libraries are one such module type; when it is built for an
51// APEX, it should depend only on stable interfaces such as NDK, stable AIDL,
52// or C APIs from other APEXs.
53//
54// A module implementing this interface will be mutated into multiple
Jiyong Park0ddfcd12018-12-11 01:35:25 +090055// variations by apex.apexMutator if it is directly or indirectly included
Jiyong Park9d452992018-10-03 00:38:19 +090056// in one or more APEXs. Specifically, if a module is included in apex.foo and
57// apex.bar then three apex variants are created: platform, apex.foo and
58// apex.bar. The platform variant is for the regular partitions
59// (e.g., /system or /vendor, etc.) while the other two are for the APEXs,
60// respectively.
61type ApexModule interface {
62 Module
Paul Duffin03e7d0c2020-03-30 15:33:32 +010063 DepIsInSameApex
64
Jiyong Park9d452992018-10-03 00:38:19 +090065 apexModuleBase() *ApexModuleBase
66
Peter Collingbournedc4f9862020-02-12 17:13:25 -080067 // Marks that this module should be built for the specified APEXes.
Jiyong Park0ddfcd12018-12-11 01:35:25 +090068 // Call this before apex.apexMutator is run.
Peter Collingbournedc4f9862020-02-12 17:13:25 -080069 BuildForApexes(apexes []ApexInfo)
Jiyong Parkf760cae2020-02-12 07:53:12 +090070
Peter Collingbournedc4f9862020-02-12 17:13:25 -080071 // Returns the APEXes that this module will be built for
72 ApexVariations() []ApexInfo
Jiyong Park9d452992018-10-03 00:38:19 +090073
Jiyong Park9d452992018-10-03 00:38:19 +090074 // Returns the name of APEX that this module will be built for. Empty string
75 // is returned when 'IsForPlatform() == true'. Note that a module can be
Jiyong Park0ddfcd12018-12-11 01:35:25 +090076 // included in multiple APEXes, in which case, the module is mutated into
Jiyong Park9d452992018-10-03 00:38:19 +090077 // multiple modules each of which for an APEX. This method returns the
78 // name of the APEX that a variant module is for.
Jiyong Park0ddfcd12018-12-11 01:35:25 +090079 // Call this after apex.apexMutator is run.
Jiyong Park9d452992018-10-03 00:38:19 +090080 ApexName() string
81
Jiyong Park0ddfcd12018-12-11 01:35:25 +090082 // Tests whether this module will be built for the platform or not.
83 // This is a shortcut for ApexName() == ""
84 IsForPlatform() bool
85
86 // Tests if this module could have APEX variants. APEX variants are
Jiyong Park9d452992018-10-03 00:38:19 +090087 // created only for the modules that returns true here. This is useful
Jiyong Park0ddfcd12018-12-11 01:35:25 +090088 // for not creating APEX variants for certain types of shared libraries
89 // such as NDK stubs.
Jiyong Park9d452992018-10-03 00:38:19 +090090 CanHaveApexVariants() bool
91
92 // Tests if this module can be installed to APEX as a file. For example,
93 // this would return true for shared libs while return false for static
94 // libs.
95 IsInstallableToApex() bool
Jiyong Park0ddfcd12018-12-11 01:35:25 +090096
97 // Mutate this module into one or more variants each of which is built
Jiyong Parkf760cae2020-02-12 07:53:12 +090098 // for an APEX marked via BuildForApexes().
Colin Cross43b92e02019-11-18 15:28:57 -080099 CreateApexVariations(mctx BottomUpMutatorContext) []Module
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900100
Jiyong Park127b40b2019-09-30 16:04:35 +0900101 // Tests if this module is available for the specified APEX or ":platform"
102 AvailableFor(what string) bool
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900103
Jiyong Park6a9ddc32020-04-07 16:37:39 +0900104 // Return true if this module is not available to platform (i.e. apex_available
105 // property doesn't have "//apex_available:platform"), or shouldn't be available
106 // to platform, which is the case when this module depends on other module that
107 // isn't available to platform.
108 NotAvailableForPlatform() bool
109
110 // Mark that this module is not available to platform. Set by the
111 // check-platform-availability mutator in the apex package.
112 SetNotAvailableForPlatform()
113
Jooyung Han74066602020-03-20 04:29:24 +0900114 // Returns the highest version which is <= maxSdkVersion.
115 // For example, with maxSdkVersion is 10 and versionList is [9,11]
116 // it returns 9 as string
117 ChooseSdkVersion(versionList []string, maxSdkVersion int) (string, error)
Jiyong Parkf0d01b72020-04-13 16:19:48 +0900118
119 // List of APEXes that this module tests. The module has access to
120 // the private part of the listed APEXes even when it is not included in the
121 // APEXes.
122 TestFor() []string
Jiyong Park9d452992018-10-03 00:38:19 +0900123}
124
125type ApexProperties struct {
Martin Stjernholm06ca82d2020-01-17 13:02:56 +0000126 // Availability of this module in APEXes. Only the listed APEXes can contain
127 // this module. If the module has stubs then other APEXes and the platform may
128 // access it through them (subject to visibility).
129 //
Jiyong Park127b40b2019-09-30 16:04:35 +0900130 // "//apex_available:anyapex" is a pseudo APEX name that matches to any APEX.
131 // "//apex_available:platform" refers to non-APEX partitions like "system.img".
Jiyong Park9a1e14e2020-02-13 02:30:45 +0900132 // Default is ["//apex_available:platform"].
Jiyong Park127b40b2019-09-30 16:04:35 +0900133 Apex_available []string
134
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800135 Info ApexInfo `blueprint:"mutated"`
Jiyong Park6a9ddc32020-04-07 16:37:39 +0900136
137 NotAvailableForPlatform bool `blueprint:"mutated"`
Jiyong Park9d452992018-10-03 00:38:19 +0900138}
139
Paul Duffin3766cb72020-04-07 15:25:44 +0100140// Marker interface that identifies dependencies that are excluded from APEX
141// contents.
142type ExcludeFromApexContentsTag interface {
143 blueprint.DependencyTag
144
145 // Method that differentiates this interface from others.
146 ExcludeFromApexContents()
147}
148
Jiyong Park9d452992018-10-03 00:38:19 +0900149// Provides default implementation for the ApexModule interface. APEX-aware
150// modules are expected to include this struct and call InitApexModule().
151type ApexModuleBase struct {
152 ApexProperties ApexProperties
153
154 canHaveApexVariants bool
Colin Crosscefa94bd2019-06-03 15:07:03 -0700155
156 apexVariationsLock sync.Mutex // protects apexVariations during parallel apexDepsMutator
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800157 apexVariations []ApexInfo
Jiyong Park9d452992018-10-03 00:38:19 +0900158}
159
160func (m *ApexModuleBase) apexModuleBase() *ApexModuleBase {
161 return m
162}
163
Paul Duffin3a6c0952020-03-04 14:22:45 +0000164func (m *ApexModuleBase) ApexAvailable() []string {
165 return m.ApexProperties.Apex_available
166}
167
Jiyong Parkf0d01b72020-04-13 16:19:48 +0900168func (m *ApexModuleBase) TestFor() []string {
169 // To be implemented by concrete types inheriting ApexModuleBase
170 return nil
171}
172
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800173func (m *ApexModuleBase) BuildForApexes(apexes []ApexInfo) {
Colin Crosscefa94bd2019-06-03 15:07:03 -0700174 m.apexVariationsLock.Lock()
175 defer m.apexVariationsLock.Unlock()
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800176nextApex:
177 for _, apex := range apexes {
178 for _, v := range m.apexVariations {
179 if v.ApexName == apex.ApexName {
180 continue nextApex
181 }
Jiyong Parkf760cae2020-02-12 07:53:12 +0900182 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800183 m.apexVariations = append(m.apexVariations, apex)
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900184 }
185}
186
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800187func (m *ApexModuleBase) ApexVariations() []ApexInfo {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900188 return m.apexVariations
189}
190
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900191func (m *ApexModuleBase) ApexName() string {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800192 return m.ApexProperties.Info.ApexName
Jiyong Park9d452992018-10-03 00:38:19 +0900193}
194
195func (m *ApexModuleBase) IsForPlatform() bool {
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800196 return m.ApexProperties.Info.ApexName == ""
Jiyong Park9d452992018-10-03 00:38:19 +0900197}
198
199func (m *ApexModuleBase) CanHaveApexVariants() bool {
200 return m.canHaveApexVariants
201}
202
203func (m *ApexModuleBase) IsInstallableToApex() bool {
204 // should be overriden if needed
205 return false
206}
207
Jiyong Park127b40b2019-09-30 16:04:35 +0900208const (
Jiyong Parkb02bb402019-12-03 00:43:57 +0900209 AvailableToPlatform = "//apex_available:platform"
Paul Duffin404db3f2020-03-06 12:30:13 +0000210 AvailableToAnyApex = "//apex_available:anyapex"
Jiyong Park127b40b2019-09-30 16:04:35 +0900211)
212
Jiyong Parka90ca002019-10-07 15:47:24 +0900213func CheckAvailableForApex(what string, apex_available []string) bool {
214 if len(apex_available) == 0 {
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000215 // apex_available defaults to ["//apex_available:platform"],
216 // which means 'available to the platform but no apexes'.
217 return what == AvailableToPlatform
Jiyong Park127b40b2019-09-30 16:04:35 +0900218 }
Jiyong Parka90ca002019-10-07 15:47:24 +0900219 return InList(what, apex_available) ||
Paul Duffin404db3f2020-03-06 12:30:13 +0000220 (what != AvailableToPlatform && InList(AvailableToAnyApex, apex_available))
Jiyong Parka90ca002019-10-07 15:47:24 +0900221}
222
223func (m *ApexModuleBase) AvailableFor(what string) bool {
224 return CheckAvailableForApex(what, m.ApexProperties.Apex_available)
Jiyong Park127b40b2019-09-30 16:04:35 +0900225}
226
Jiyong Park6a9ddc32020-04-07 16:37:39 +0900227func (m *ApexModuleBase) NotAvailableForPlatform() bool {
228 return m.ApexProperties.NotAvailableForPlatform
229}
230
231func (m *ApexModuleBase) SetNotAvailableForPlatform() {
232 m.ApexProperties.NotAvailableForPlatform = true
233}
234
Jiyong Parka7bc8ad2019-10-15 15:20:07 +0900235func (m *ApexModuleBase) DepIsInSameApex(ctx BaseModuleContext, dep Module) bool {
236 // By default, if there is a dependency from A to B, we try to include both in the same APEX,
237 // unless B is explicitly from outside of the APEX (i.e. a stubs lib). Thus, returning true.
238 // This is overridden by some module types like apex.ApexBundle, cc.Module, java.Module, etc.
239 return true
240}
241
Jooyung Han74066602020-03-20 04:29:24 +0900242func (m *ApexModuleBase) ChooseSdkVersion(versionList []string, maxSdkVersion int) (string, error) {
Jooyung Han0c4e0162020-02-26 22:45:42 +0900243 for i := range versionList {
244 ver, _ := strconv.Atoi(versionList[len(versionList)-i-1])
Jooyung Han74066602020-03-20 04:29:24 +0900245 if ver <= maxSdkVersion {
Jooyung Han0c4e0162020-02-26 22:45:42 +0900246 return versionList[len(versionList)-i-1], nil
247 }
248 }
Jooyung Han74066602020-03-20 04:29:24 +0900249 return "", fmt.Errorf("not found a version(<=%d) in versionList: %v", maxSdkVersion, versionList)
Jooyung Han0c4e0162020-02-26 22:45:42 +0900250}
251
Jiyong Park127b40b2019-09-30 16:04:35 +0900252func (m *ApexModuleBase) checkApexAvailableProperty(mctx BaseModuleContext) {
253 for _, n := range m.ApexProperties.Apex_available {
Paul Duffin404db3f2020-03-06 12:30:13 +0000254 if n == AvailableToPlatform || n == AvailableToAnyApex {
Jiyong Park127b40b2019-09-30 16:04:35 +0900255 continue
256 }
Orion Hodson4b5438a2019-10-08 10:40:51 +0100257 if !mctx.OtherModuleExists(n) && !mctx.Config().AllowMissingDependencies() {
Jiyong Park127b40b2019-09-30 16:04:35 +0900258 mctx.PropertyErrorf("apex_available", "%q is not a valid module name", n)
259 }
260 }
261}
262
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800263type byApexName []ApexInfo
264
265func (a byApexName) Len() int { return len(a) }
266func (a byApexName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
267func (a byApexName) Less(i, j int) bool { return a[i].ApexName < a[j].ApexName }
268
Colin Cross43b92e02019-11-18 15:28:57 -0800269func (m *ApexModuleBase) CreateApexVariations(mctx BottomUpMutatorContext) []Module {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900270 if len(m.apexVariations) > 0 {
Jiyong Park127b40b2019-09-30 16:04:35 +0900271 m.checkApexAvailableProperty(mctx)
Jiyong Park0f80c182020-01-31 02:49:53 +0900272
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800273 sort.Sort(byApexName(m.apexVariations))
Jiyong Park127b40b2019-09-30 16:04:35 +0900274 variations := []string{}
Jiyong Park0f80c182020-01-31 02:49:53 +0900275 variations = append(variations, "") // Original variation for platform
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800276 for _, apex := range m.apexVariations {
277 variations = append(variations, apex.ApexName)
278 }
Logan Chien3aeedc92018-12-26 15:32:21 +0800279
Jiyong Park3ff16992019-12-27 14:11:47 +0900280 defaultVariation := ""
281 mctx.SetDefaultDependencyVariation(&defaultVariation)
Jiyong Park0f80c182020-01-31 02:49:53 +0900282
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900283 modules := mctx.CreateVariations(variations...)
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800284 for i, mod := range modules {
Jiyong Park0f80c182020-01-31 02:49:53 +0900285 platformVariation := i == 0
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800286 if platformVariation && !mctx.Host() && !mod.(ApexModule).AvailableFor(AvailableToPlatform) {
287 mod.SkipInstall()
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900288 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800289 if !platformVariation {
290 mod.(ApexModule).apexModuleBase().ApexProperties.Info = m.apexVariations[i-1]
291 }
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900292 }
293 return modules
294 }
295 return nil
296}
297
298var apexData OncePer
299var apexNamesMapMutex sync.Mutex
Colin Cross571cccf2019-02-04 11:22:08 -0800300var apexNamesKey = NewOnceKey("apexNames")
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900301
302// This structure maintains the global mapping in between modules and APEXes.
303// Examples:
Jiyong Park25fc6a92018-11-18 18:02:45 +0900304//
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900305// apexNamesMap()["foo"]["bar"] == true: module foo is directly depended on by APEX bar
306// apexNamesMap()["foo"]["bar"] == false: module foo is indirectly depended on by APEX bar
307// apexNamesMap()["foo"]["bar"] doesn't exist: foo is not built for APEX bar
308func apexNamesMap() map[string]map[string]bool {
Colin Cross571cccf2019-02-04 11:22:08 -0800309 return apexData.Once(apexNamesKey, func() interface{} {
Jiyong Park25fc6a92018-11-18 18:02:45 +0900310 return make(map[string]map[string]bool)
311 }).(map[string]map[string]bool)
312}
313
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900314// Update the map to mark that a module named moduleName is directly or indirectly
Jiyong Parkf760cae2020-02-12 07:53:12 +0900315// depended on by the specified APEXes. Directly depending means that a module
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900316// is explicitly listed in the build definition of the APEX via properties like
317// native_shared_libs, java_libs, etc.
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800318func UpdateApexDependency(apexes []ApexInfo, moduleName string, directDep bool) {
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900319 apexNamesMapMutex.Lock()
320 defer apexNamesMapMutex.Unlock()
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800321 for _, apex := range apexes {
Jiyong Parkf760cae2020-02-12 07:53:12 +0900322 apexesForModule, ok := apexNamesMap()[moduleName]
323 if !ok {
324 apexesForModule = make(map[string]bool)
325 apexNamesMap()[moduleName] = apexesForModule
326 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800327 apexesForModule[apex.ApexName] = apexesForModule[apex.ApexName] || directDep
Jiyong Park25fc6a92018-11-18 18:02:45 +0900328 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900329}
330
Jooyung Han671f1ce2019-12-17 12:47:13 +0900331// TODO(b/146393795): remove this when b/146393795 is fixed
332func ClearApexDependency() {
333 m := apexNamesMap()
334 for k := range m {
335 delete(m, k)
336 }
337}
338
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900339// Tests whether a module named moduleName is directly depended on by an APEX
340// named apexName.
341func DirectlyInApex(apexName string, moduleName string) bool {
342 apexNamesMapMutex.Lock()
343 defer apexNamesMapMutex.Unlock()
344 if apexNames, ok := apexNamesMap()[moduleName]; ok {
345 return apexNames[apexName]
Jiyong Park25fc6a92018-11-18 18:02:45 +0900346 }
347 return false
348}
349
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +0000350type hostContext interface {
351 Host() bool
352}
353
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900354// Tests whether a module named moduleName is directly depended on by any APEX.
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +0000355func DirectlyInAnyApex(ctx hostContext, moduleName string) bool {
356 if ctx.Host() {
357 // Host has no APEX.
358 return false
359 }
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900360 apexNamesMapMutex.Lock()
361 defer apexNamesMapMutex.Unlock()
362 if apexNames, ok := apexNamesMap()[moduleName]; ok {
363 for an := range apexNames {
364 if apexNames[an] {
Jiyong Park25fc6a92018-11-18 18:02:45 +0900365 return true
366 }
367 }
368 }
369 return false
370}
371
Jiyong Park0ddfcd12018-12-11 01:35:25 +0900372// Tests whether a module named module is depended on (including both
373// direct and indirect dependencies) by any APEX.
374func InAnyApex(moduleName string) bool {
375 apexNamesMapMutex.Lock()
376 defer apexNamesMapMutex.Unlock()
377 apexNames, ok := apexNamesMap()[moduleName]
378 return ok && len(apexNames) > 0
379}
380
381func GetApexesForModule(moduleName string) []string {
382 ret := []string{}
383 apexNamesMapMutex.Lock()
384 defer apexNamesMapMutex.Unlock()
385 if apexNames, ok := apexNamesMap()[moduleName]; ok {
386 for an := range apexNames {
387 ret = append(ret, an)
388 }
389 }
390 return ret
Jiyong Parkde866cb2018-12-07 23:08:36 +0900391}
392
Jiyong Park9d452992018-10-03 00:38:19 +0900393func InitApexModule(m ApexModule) {
394 base := m.apexModuleBase()
395 base.canHaveApexVariants = true
396
397 m.AddProperties(&base.ApexProperties)
398}
Artur Satayev334b5172020-04-27 17:08:37 +0100399
400// A dependency info for a single ApexModule, either direct or transitive.
401type ApexModuleDepInfo struct {
402 // Name of the dependency
403 To string
404 // List of dependencies To belongs to. Includes APEX itself, if a direct dependency.
405 From []string
406 // Whether the dependency belongs to the final compiled APEX.
407 IsExternal bool
Artur Satayev388d39b2020-04-27 18:53:18 +0100408 // min_sdk_version of the ApexModule
409 MinSdkVersion string
Artur Satayev334b5172020-04-27 17:08:37 +0100410}
411
412// A map of a dependency name to its ApexModuleDepInfo
413type DepNameToDepInfoMap map[string]ApexModuleDepInfo
414
415type ApexBundleDepsInfo struct {
Artur Satayev388d39b2020-04-27 18:53:18 +0100416 minSdkVersion string
417 flatListPath OutputPath
418 fullListPath OutputPath
Artur Satayev334b5172020-04-27 17:08:37 +0100419}
420
421type ApexDepsInfoIntf interface {
Artur Satayev388d39b2020-04-27 18:53:18 +0100422 MinSdkVersion() string
Artur Satayev5e7c32d2020-04-27 18:07:06 +0100423 FlatListPath() Path
Artur Satayev334b5172020-04-27 17:08:37 +0100424 FullListPath() Path
425}
426
Artur Satayev388d39b2020-04-27 18:53:18 +0100427func (d *ApexBundleDepsInfo) MinSdkVersion() string {
428 return d.minSdkVersion
429}
430
Artur Satayev5e7c32d2020-04-27 18:07:06 +0100431func (d *ApexBundleDepsInfo) FlatListPath() Path {
432 return d.flatListPath
433}
434
Artur Satayev334b5172020-04-27 17:08:37 +0100435func (d *ApexBundleDepsInfo) FullListPath() Path {
436 return d.fullListPath
437}
438
439var _ ApexDepsInfoIntf = (*ApexBundleDepsInfo)(nil)
440
Artur Satayev5e7c32d2020-04-27 18:07:06 +0100441// Generate two module out files:
442// 1. FullList with transitive deps and their parents in the dep graph
443// 2. FlatList with a flat list of transitive deps
Artur Satayev388d39b2020-04-27 18:53:18 +0100444func (d *ApexBundleDepsInfo) BuildDepsInfoLists(ctx ModuleContext, minSdkVersion string, depInfos DepNameToDepInfoMap) {
445 d.minSdkVersion = minSdkVersion
446
Artur Satayev5e7c32d2020-04-27 18:07:06 +0100447 var fullContent strings.Builder
448 var flatContent strings.Builder
449
Artur Satayev388d39b2020-04-27 18:53:18 +0100450 fmt.Fprintf(&flatContent, "%s(minSdkVersion:%s):\\n", ctx.ModuleName(), minSdkVersion)
Artur Satayev334b5172020-04-27 17:08:37 +0100451 for _, key := range FirstUniqueStrings(SortedStringKeys(depInfos)) {
452 info := depInfos[key]
Artur Satayev388d39b2020-04-27 18:53:18 +0100453 toName := fmt.Sprintf("%s(minSdkVersion:%s)", info.To, info.MinSdkVersion)
Artur Satayev334b5172020-04-27 17:08:37 +0100454 if info.IsExternal {
455 toName = toName + " (external)"
456 }
Artur Satayev5e7c32d2020-04-27 18:07:06 +0100457 fmt.Fprintf(&fullContent, "%s <- %s\\n", toName, strings.Join(SortedUniqueStrings(info.From), ", "))
458 fmt.Fprintf(&flatContent, " %s\\n", toName)
Artur Satayev334b5172020-04-27 17:08:37 +0100459 }
460
461 d.fullListPath = PathForModuleOut(ctx, "depsinfo", "fulllist.txt").OutputPath
462 ctx.Build(pctx, BuildParams{
463 Rule: WriteFile,
464 Description: "Full Dependency Info",
465 Output: d.fullListPath,
466 Args: map[string]string{
Artur Satayev5e7c32d2020-04-27 18:07:06 +0100467 "content": fullContent.String(),
468 },
469 })
470
471 d.flatListPath = PathForModuleOut(ctx, "depsinfo", "flatlist.txt").OutputPath
472 ctx.Build(pctx, BuildParams{
473 Rule: WriteFile,
474 Description: "Flat Dependency Info",
475 Output: d.flatListPath,
476 Args: map[string]string{
477 "content": flatContent.String(),
Artur Satayev334b5172020-04-27 17:08:37 +0100478 },
479 })
480}