blob: 9766af3df35e7a95d2f440bc0749314fea568c84 [file] [log] [blame]
Inseob Kime498dd92020-08-04 09:24:04 +09001// Copyright 2020 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
Colin Crossd079e0b2022-08-16 10:27:33 -07007// http://www.apache.org/licenses/LICENSE-2.0
Inseob Kime498dd92020-08-04 09:24:04 +09008//
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.
14package cc
15
16// This file contains image variant related things, including image mutator functions, utility
17// functions to determine where a module is installed, etc.
18
19import (
20 "strings"
21
22 "android/soong/android"
Jooyung Han85707de2023-12-01 14:21:13 +090023
24 "github.com/google/blueprint/proptools"
Inseob Kime498dd92020-08-04 09:24:04 +090025)
26
27var _ android.ImageInterface = (*Module)(nil)
28
Ivan Lozano3968d8f2020-12-14 11:27:52 -050029type ImageVariantType string
Inseob Kim74d25562020-08-04 00:41:38 +090030
31const (
Ivan Lozano3968d8f2020-12-14 11:27:52 -050032 coreImageVariant ImageVariantType = "core"
33 vendorImageVariant ImageVariantType = "vendor"
34 productImageVariant ImageVariantType = "product"
35 ramdiskImageVariant ImageVariantType = "ramdisk"
36 vendorRamdiskImageVariant ImageVariantType = "vendor_ramdisk"
37 recoveryImageVariant ImageVariantType = "recovery"
38 hostImageVariant ImageVariantType = "host"
Inseob Kim74d25562020-08-04 00:41:38 +090039)
40
Inseob Kime498dd92020-08-04 09:24:04 +090041const (
42 // VendorVariationPrefix is the variant prefix used for /vendor code that compiles
43 // against the VNDK.
44 VendorVariationPrefix = "vendor."
45
46 // ProductVariationPrefix is the variant prefix used for /product code that compiles
47 // against the VNDK.
48 ProductVariationPrefix = "product."
49)
50
Inseob Kime498dd92020-08-04 09:24:04 +090051func (ctx *moduleContextImpl) inProduct() bool {
Ivan Lozanof9e21722020-12-02 09:00:51 -050052 return ctx.mod.InProduct()
Inseob Kime498dd92020-08-04 09:24:04 +090053}
54
55func (ctx *moduleContextImpl) inVendor() bool {
Ivan Lozano3968d8f2020-12-14 11:27:52 -050056 return ctx.mod.InVendor()
Inseob Kime498dd92020-08-04 09:24:04 +090057}
58
59func (ctx *moduleContextImpl) inRamdisk() bool {
60 return ctx.mod.InRamdisk()
61}
62
Yifan Hong60e0cfb2020-10-21 15:17:56 -070063func (ctx *moduleContextImpl) inVendorRamdisk() bool {
64 return ctx.mod.InVendorRamdisk()
65}
66
Inseob Kime498dd92020-08-04 09:24:04 +090067func (ctx *moduleContextImpl) inRecovery() bool {
68 return ctx.mod.InRecovery()
69}
70
Colin Crossea30d852023-11-29 16:00:16 -080071func (c *Module) InstallInProduct() bool {
Justin Yun7f99ec72021-04-12 13:19:28 +090072 // Additionally check if this module is inProduct() that means it is a "product" variant of a
73 // module. As well as product specific modules, product variants must be installed to /product.
74 return c.InProduct()
75}
76
Colin Crossea30d852023-11-29 16:00:16 -080077func (c *Module) InstallInVendor() bool {
Justin Yun7f99ec72021-04-12 13:19:28 +090078 // Additionally check if this module is inVendor() that means it is a "vendor" variant of a
79 // module. As well as SoC specific modules, vendor variants must be installed to /vendor
80 // unless they have "odm_available: true".
81 return c.HasVendorVariant() && c.InVendor() && !c.VendorVariantToOdm()
82}
83
Colin Crossea30d852023-11-29 16:00:16 -080084func (c *Module) InstallInOdm() bool {
Justin Yun7f99ec72021-04-12 13:19:28 +090085 // Some vendor variants want to be installed to /odm by setting "odm_available: true".
86 return c.InVendor() && c.VendorVariantToOdm()
87}
88
Justin Yun63e9ec72020-10-29 16:49:43 +090089// Returns true when this module is configured to have core and vendor variants.
Inseob Kime498dd92020-08-04 09:24:04 +090090func (c *Module) HasVendorVariant() bool {
Justin Yunebcf0c52021-01-08 18:00:19 +090091 return Bool(c.VendorProperties.Vendor_available) || Bool(c.VendorProperties.Odm_available)
92}
93
94// Returns true when this module creates a vendor variant and wants to install the vendor variant
95// to the odm partition.
96func (c *Module) VendorVariantToOdm() bool {
97 return Bool(c.VendorProperties.Odm_available)
Inseob Kime498dd92020-08-04 09:24:04 +090098}
99
Justin Yun63e9ec72020-10-29 16:49:43 +0900100// Returns true when this module is configured to have core and product variants.
101func (c *Module) HasProductVariant() bool {
Justin Yunc0d8c492021-01-07 17:45:31 +0900102 return Bool(c.VendorProperties.Product_available)
Justin Yun63e9ec72020-10-29 16:49:43 +0900103}
104
105// Returns true when this module is configured to have core and either product or vendor variants.
106func (c *Module) HasNonSystemVariants() bool {
Justin Yun6977e8a2020-10-29 18:24:11 +0900107 return c.HasVendorVariant() || c.HasProductVariant()
Justin Yun63e9ec72020-10-29 16:49:43 +0900108}
109
Inseob Kime498dd92020-08-04 09:24:04 +0900110// Returns true if the module is "product" variant. Usually these modules are installed in /product
Ivan Lozanof9e21722020-12-02 09:00:51 -0500111func (c *Module) InProduct() bool {
Jihoon Kang47e91842024-06-19 00:51:16 +0000112 return c.Properties.ImageVariation == android.ProductVariation
Inseob Kime498dd92020-08-04 09:24:04 +0900113}
114
115// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500116func (c *Module) InVendor() bool {
Jihoon Kang47e91842024-06-19 00:51:16 +0000117 return c.Properties.ImageVariation == android.VendorVariation
Inseob Kime498dd92020-08-04 09:24:04 +0900118}
119
Kiyoung Kimaa394802024-01-08 12:55:45 +0900120// Returns true if the module is "vendor" or "product" variant. This replaces previous UseVndk usages
121// which were misused to check if the module variant is vendor or product.
122func (c *Module) InVendorOrProduct() bool {
123 return c.InVendor() || c.InProduct()
124}
125
Inseob Kime498dd92020-08-04 09:24:04 +0900126func (c *Module) InRamdisk() bool {
127 return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk()
128}
129
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700130func (c *Module) InVendorRamdisk() bool {
131 return c.ModuleBase.InVendorRamdisk() || c.ModuleBase.InstallInVendorRamdisk()
132}
133
Inseob Kime498dd92020-08-04 09:24:04 +0900134func (c *Module) InRecovery() bool {
135 return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
136}
137
138func (c *Module) OnlyInRamdisk() bool {
139 return c.ModuleBase.InstallInRamdisk()
140}
141
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700142func (c *Module) OnlyInVendorRamdisk() bool {
143 return c.ModuleBase.InstallInVendorRamdisk()
144}
145
Inseob Kime498dd92020-08-04 09:24:04 +0900146func (c *Module) OnlyInRecovery() bool {
147 return c.ModuleBase.InstallInRecovery()
148}
149
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400150// ImageMutatableModule provides a common image mutation interface for LinkableInterface modules.
151type ImageMutatableModule interface {
152 android.Module
153 LinkableInterface
154
155 // AndroidModuleBase returns the android.ModuleBase for this module
156 AndroidModuleBase() *android.ModuleBase
157
158 // VendorAvailable returns true if this module is available on the vendor image.
159 VendorAvailable() bool
160
161 // OdmAvailable returns true if this module is available on the odm image.
162 OdmAvailable() bool
163
164 // ProductAvailable returns true if this module is available on the product image.
165 ProductAvailable() bool
166
167 // RamdiskAvailable returns true if this module is available on the ramdisk image.
168 RamdiskAvailable() bool
169
170 // RecoveryAvailable returns true if this module is available on the recovery image.
171 RecoveryAvailable() bool
172
173 // VendorRamdiskAvailable returns true if this module is available on the vendor ramdisk image.
174 VendorRamdiskAvailable() bool
175
176 // IsSnapshotPrebuilt returns true if this module is a snapshot prebuilt.
177 IsSnapshotPrebuilt() bool
178
179 // SnapshotVersion returns the snapshot version for this module.
Cole Faustfa6e0fd2024-10-15 15:22:57 -0700180 SnapshotVersion(mctx android.ImageInterfaceContext) string
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400181
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400182 // ExtraVariants returns the list of extra variants this module requires.
183 ExtraVariants() []string
184
185 // AppendExtraVariant returns an extra variant to the list of extra variants this module requires.
186 AppendExtraVariant(extraVariant string)
187
188 // SetRamdiskVariantNeeded sets whether the Ramdisk Variant is needed.
189 SetRamdiskVariantNeeded(b bool)
190
191 // SetVendorRamdiskVariantNeeded sets whether the Vendor Ramdisk Variant is needed.
192 SetVendorRamdiskVariantNeeded(b bool)
193
194 // SetRecoveryVariantNeeded sets whether the Recovery Variant is needed.
195 SetRecoveryVariantNeeded(b bool)
196
197 // SetCoreVariantNeeded sets whether the Core Variant is needed.
198 SetCoreVariantNeeded(b bool)
Jihoon Kang47e91842024-06-19 00:51:16 +0000199
200 // SetProductVariantNeeded sets whether the Product Variant is needed.
201 SetProductVariantNeeded(b bool)
202
203 // SetVendorVariantNeeded sets whether the Vendor Variant is needed.
204 SetVendorVariantNeeded(b bool)
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400205}
206
207var _ ImageMutatableModule = (*Module)(nil)
208
Cole Faustfa6e0fd2024-10-15 15:22:57 -0700209func (m *Module) ImageMutatorBegin(mctx android.ImageInterfaceContext) {
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400210 MutateImage(mctx, m)
211}
212
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400213func (m *Module) VendorAvailable() bool {
214 return Bool(m.VendorProperties.Vendor_available)
215}
216
217func (m *Module) OdmAvailable() bool {
218 return Bool(m.VendorProperties.Odm_available)
219}
220
221func (m *Module) ProductAvailable() bool {
222 return Bool(m.VendorProperties.Product_available)
223}
224
225func (m *Module) RamdiskAvailable() bool {
226 return Bool(m.Properties.Ramdisk_available)
227}
228
229func (m *Module) VendorRamdiskAvailable() bool {
230 return Bool(m.Properties.Vendor_ramdisk_available)
231}
232
233func (m *Module) AndroidModuleBase() *android.ModuleBase {
234 return &m.ModuleBase
235}
236
237func (m *Module) RecoveryAvailable() bool {
238 return Bool(m.Properties.Recovery_available)
239}
240
241func (m *Module) ExtraVariants() []string {
Lukacs T. Berki2f5c3402021-06-15 11:27:56 +0200242 return m.Properties.ExtraVersionedImageVariations
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400243}
244
245func (m *Module) AppendExtraVariant(extraVariant string) {
Lukacs T. Berki2f5c3402021-06-15 11:27:56 +0200246 m.Properties.ExtraVersionedImageVariations = append(m.Properties.ExtraVersionedImageVariations, extraVariant)
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400247}
248
249func (m *Module) SetRamdiskVariantNeeded(b bool) {
250 m.Properties.RamdiskVariantNeeded = b
251}
252
253func (m *Module) SetVendorRamdiskVariantNeeded(b bool) {
254 m.Properties.VendorRamdiskVariantNeeded = b
255}
256
257func (m *Module) SetRecoveryVariantNeeded(b bool) {
258 m.Properties.RecoveryVariantNeeded = b
259}
260
261func (m *Module) SetCoreVariantNeeded(b bool) {
262 m.Properties.CoreVariantNeeded = b
263}
264
Jihoon Kang47e91842024-06-19 00:51:16 +0000265func (m *Module) SetProductVariantNeeded(b bool) {
266 m.Properties.ProductVariantNeeded = b
267}
268
269func (m *Module) SetVendorVariantNeeded(b bool) {
270 m.Properties.VendorVariantNeeded = b
271}
272
Cole Faustfa6e0fd2024-10-15 15:22:57 -0700273func (m *Module) SnapshotVersion(mctx android.ImageInterfaceContext) string {
Ivan Lozanod1dec542021-05-26 15:33:11 -0400274 if snapshot, ok := m.linker.(SnapshotInterface); ok {
275 return snapshot.Version()
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400276 } else {
277 mctx.ModuleErrorf("version is unknown for snapshot prebuilt")
278 // Should we be panicking here instead?
279 return ""
280 }
281}
282
283func (m *Module) KernelHeadersDecorator() bool {
284 if _, ok := m.linker.(*kernelHeadersDecorator); ok {
285 return true
286 }
287 return false
288}
289
290// MutateImage handles common image mutations for ImageMutatableModule interfaces.
Cole Faustfa6e0fd2024-10-15 15:22:57 -0700291func MutateImage(mctx android.ImageInterfaceContext, m ImageMutatableModule) {
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400292 // Validation check
293 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
294 productSpecific := mctx.ProductSpecific()
295
296 if m.VendorAvailable() {
297 if vendorSpecific {
298 mctx.PropertyErrorf("vendor_available",
299 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific: true`")
300 }
301 if m.OdmAvailable() {
302 mctx.PropertyErrorf("vendor_available",
303 "doesn't make sense at the same time as `odm_available: true`")
304 }
305 }
306
307 if m.OdmAvailable() {
308 if vendorSpecific {
309 mctx.PropertyErrorf("odm_available",
310 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific: true`")
311 }
312 }
313
314 if m.ProductAvailable() {
315 if productSpecific {
316 mctx.PropertyErrorf("product_available",
317 "doesn't make sense at the same time as `product_specific: true`")
318 }
319 if vendorSpecific {
320 mctx.PropertyErrorf("product_available",
321 "cannot provide product variant from a vendor module. Please use `product_specific: true` with `vendor_available: true`")
322 }
323 }
Inseob Kime498dd92020-08-04 09:24:04 +0900324
Jihoon Kang47e91842024-06-19 00:51:16 +0000325 var vendorVariantNeeded bool = false
326 var productVariantNeeded bool = false
Inseob Kime498dd92020-08-04 09:24:04 +0900327 var coreVariantNeeded bool = false
328 var ramdiskVariantNeeded bool = false
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700329 var vendorRamdiskVariantNeeded bool = false
Inseob Kime498dd92020-08-04 09:24:04 +0900330 var recoveryVariantNeeded bool = false
331
Colin Cross203b4212021-04-26 17:19:41 -0700332 if m.NeedsLlndkVariants() {
Colin Crossb5f6fa62021-01-06 17:05:04 -0800333 // This is an LLNDK library. The implementation of the library will be on /system,
334 // and vendor and product variants will be created with LLNDK stubs.
335 // The LLNDK libraries need vendor variants even if there is no VNDK.
Colin Cross203b4212021-04-26 17:19:41 -0700336 coreVariantNeeded = true
Jihoon Kang47e91842024-06-19 00:51:16 +0000337 vendorVariantNeeded = true
338 productVariantNeeded = true
339
Colin Cross5271fea2021-04-27 13:06:04 -0700340 } else if m.NeedsVendorPublicLibraryVariants() {
341 // A vendor public library has the implementation on /vendor, with stub variants
342 // for system and product.
343 coreVariantNeeded = true
Jihoon Kang47e91842024-06-19 00:51:16 +0000344 vendorVariantNeeded = true
345 productVariantNeeded = true
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400346 } else if m.IsSnapshotPrebuilt() {
Inseob Kime498dd92020-08-04 09:24:04 +0900347 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
348 // PRODUCT_EXTRA_VNDK_VERSIONS.
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400349 if m.InstallInRecovery() {
350 recoveryVariantNeeded = true
Inseob Kime498dd92020-08-04 09:24:04 +0900351 } else {
Jihoon Kang47e91842024-06-19 00:51:16 +0000352 m.AppendExtraVariant(VendorVariationPrefix + m.SnapshotVersion(mctx))
Inseob Kime498dd92020-08-04 09:24:04 +0900353 }
Kiyoung Kim9f26fcf2024-05-27 17:25:52 +0900354 } else if m.HasNonSystemVariants() {
Justin Yun63e9ec72020-10-29 16:49:43 +0900355 // This will be available to /system unless it is product_specific
356 // which will be handled later.
Inseob Kime498dd92020-08-04 09:24:04 +0900357 coreVariantNeeded = true
358
359 // We assume that modules under proprietary paths are compatible for
360 // BOARD_VNDK_VERSION. The other modules are regarded as AOSP, or
361 // PLATFORM_VNDK_VERSION.
Justin Yun63e9ec72020-10-29 16:49:43 +0900362 if m.HasVendorVariant() {
Jihoon Kang47e91842024-06-19 00:51:16 +0000363 vendorVariantNeeded = true
Inseob Kime498dd92020-08-04 09:24:04 +0900364 }
365
Justin Yun6977e8a2020-10-29 18:24:11 +0900366 // product_available modules are available to /product.
367 if m.HasProductVariant() {
Jihoon Kang47e91842024-06-19 00:51:16 +0000368 productVariantNeeded = true
Inseob Kime498dd92020-08-04 09:24:04 +0900369 }
Inseob Kim69c65102024-11-12 16:59:20 +0900370 } else if vendorSpecific {
Inseob Kime498dd92020-08-04 09:24:04 +0900371 // This will be available in /vendor (or /odm) only
Jihoon Kang47e91842024-06-19 00:51:16 +0000372 vendorVariantNeeded = true
Inseob Kime498dd92020-08-04 09:24:04 +0900373 } else {
374 // This is either in /system (or similar: /data), or is a
jiajia tangcd1c27b2022-07-21 18:04:37 +0800375 // module built with the NDK. Modules built with the NDK
Inseob Kime498dd92020-08-04 09:24:04 +0900376 // will be restricted using the existing link type checks.
377 coreVariantNeeded = true
378 }
379
Inseob Kim69c65102024-11-12 16:59:20 +0900380 if coreVariantNeeded && productSpecific {
Justin Yunaf1fde42023-09-27 16:22:10 +0900381 // The module has "product_specific: true" that does not create core variant.
382 coreVariantNeeded = false
Jihoon Kang47e91842024-06-19 00:51:16 +0000383 productVariantNeeded = true
Inseob Kime498dd92020-08-04 09:24:04 +0900384 }
385
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400386 if m.RamdiskAvailable() {
Inseob Kime498dd92020-08-04 09:24:04 +0900387 ramdiskVariantNeeded = true
388 }
389
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400390 if m.AndroidModuleBase().InstallInRamdisk() {
Inseob Kime498dd92020-08-04 09:24:04 +0900391 ramdiskVariantNeeded = true
392 coreVariantNeeded = false
393 }
394
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400395 if m.VendorRamdiskAvailable() {
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700396 vendorRamdiskVariantNeeded = true
397 }
398
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400399 if m.AndroidModuleBase().InstallInVendorRamdisk() {
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700400 vendorRamdiskVariantNeeded = true
401 coreVariantNeeded = false
402 }
403
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400404 if m.RecoveryAvailable() {
Inseob Kime498dd92020-08-04 09:24:04 +0900405 recoveryVariantNeeded = true
406 }
407
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400408 if m.AndroidModuleBase().InstallInRecovery() {
Inseob Kime498dd92020-08-04 09:24:04 +0900409 recoveryVariantNeeded = true
410 coreVariantNeeded = false
411 }
412
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400413 m.SetRamdiskVariantNeeded(ramdiskVariantNeeded)
414 m.SetVendorRamdiskVariantNeeded(vendorRamdiskVariantNeeded)
415 m.SetRecoveryVariantNeeded(recoveryVariantNeeded)
416 m.SetCoreVariantNeeded(coreVariantNeeded)
Jihoon Kang47e91842024-06-19 00:51:16 +0000417 m.SetProductVariantNeeded(productVariantNeeded)
418 m.SetVendorVariantNeeded(vendorVariantNeeded)
Jose Galmes6f843bc2020-12-11 13:36:29 -0800419
420 // Disable the module if no variants are needed.
421 if !ramdiskVariantNeeded &&
422 !recoveryVariantNeeded &&
423 !coreVariantNeeded &&
Jihoon Kang47e91842024-06-19 00:51:16 +0000424 !productVariantNeeded &&
425 !vendorVariantNeeded &&
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400426 len(m.ExtraVariants()) == 0 {
Jose Galmes6f843bc2020-12-11 13:36:29 -0800427 m.Disable()
428 }
Inseob Kime498dd92020-08-04 09:24:04 +0900429}
430
Cole Faustfa6e0fd2024-10-15 15:22:57 -0700431func (c *Module) VendorVariantNeeded(ctx android.ImageInterfaceContext) bool {
Jihoon Kang47e91842024-06-19 00:51:16 +0000432 return c.Properties.VendorVariantNeeded
433}
434
Cole Faustfa6e0fd2024-10-15 15:22:57 -0700435func (c *Module) ProductVariantNeeded(ctx android.ImageInterfaceContext) bool {
Jihoon Kang47e91842024-06-19 00:51:16 +0000436 return c.Properties.ProductVariantNeeded
437}
438
Cole Faustfa6e0fd2024-10-15 15:22:57 -0700439func (c *Module) CoreVariantNeeded(ctx android.ImageInterfaceContext) bool {
Inseob Kime498dd92020-08-04 09:24:04 +0900440 return c.Properties.CoreVariantNeeded
441}
442
Cole Faustfa6e0fd2024-10-15 15:22:57 -0700443func (c *Module) RamdiskVariantNeeded(ctx android.ImageInterfaceContext) bool {
Inseob Kime498dd92020-08-04 09:24:04 +0900444 return c.Properties.RamdiskVariantNeeded
445}
446
Cole Faustfa6e0fd2024-10-15 15:22:57 -0700447func (c *Module) VendorRamdiskVariantNeeded(ctx android.ImageInterfaceContext) bool {
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700448 return c.Properties.VendorRamdiskVariantNeeded
449}
450
Cole Faustfa6e0fd2024-10-15 15:22:57 -0700451func (c *Module) DebugRamdiskVariantNeeded(ctx android.ImageInterfaceContext) bool {
Inseob Kim08758f02021-04-08 21:13:22 +0900452 return false
453}
454
Cole Faustfa6e0fd2024-10-15 15:22:57 -0700455func (c *Module) RecoveryVariantNeeded(ctx android.ImageInterfaceContext) bool {
Inseob Kime498dd92020-08-04 09:24:04 +0900456 return c.Properties.RecoveryVariantNeeded
457}
458
Cole Faustfa6e0fd2024-10-15 15:22:57 -0700459func (c *Module) ExtraImageVariations(ctx android.ImageInterfaceContext) []string {
Lukacs T. Berki2f5c3402021-06-15 11:27:56 +0200460 return c.Properties.ExtraVersionedImageVariations
Inseob Kime498dd92020-08-04 09:24:04 +0900461}
462
Justin Yun63e9ec72020-10-29 16:49:43 +0900463func squashVendorSrcs(m *Module) {
464 if lib, ok := m.compiler.(*libraryDecorator); ok {
Cole Faust96a692b2024-08-08 14:47:51 -0700465 lib.baseCompiler.Properties.Srcs.AppendSimpleValue(lib.baseCompiler.Properties.Target.Vendor.Srcs)
466 lib.baseCompiler.Properties.Exclude_srcs.AppendSimpleValue(lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs)
Justin Yun63e9ec72020-10-29 16:49:43 +0900467
468 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
469 lib.baseCompiler.Properties.Target.Vendor.Exclude_generated_sources...)
Jooyung Han85707de2023-12-01 14:21:13 +0900470
471 if lib.Properties.Target.Vendor.No_stubs {
472 proptools.Clear(&lib.Properties.Stubs)
473 }
Justin Yun63e9ec72020-10-29 16:49:43 +0900474 }
475}
476
477func squashProductSrcs(m *Module) {
478 if lib, ok := m.compiler.(*libraryDecorator); ok {
Cole Faust96a692b2024-08-08 14:47:51 -0700479 lib.baseCompiler.Properties.Srcs.AppendSimpleValue(lib.baseCompiler.Properties.Target.Product.Srcs)
480 lib.baseCompiler.Properties.Exclude_srcs.AppendSimpleValue(lib.baseCompiler.Properties.Target.Product.Exclude_srcs)
Justin Yun63e9ec72020-10-29 16:49:43 +0900481
482 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
483 lib.baseCompiler.Properties.Target.Product.Exclude_generated_sources...)
Jooyung Han85707de2023-12-01 14:21:13 +0900484
485 if lib.Properties.Target.Product.No_stubs {
486 proptools.Clear(&lib.Properties.Stubs)
487 }
Justin Yun63e9ec72020-10-29 16:49:43 +0900488 }
489}
490
491func squashRecoverySrcs(m *Module) {
492 if lib, ok := m.compiler.(*libraryDecorator); ok {
Cole Faust96a692b2024-08-08 14:47:51 -0700493 lib.baseCompiler.Properties.Srcs.AppendSimpleValue(lib.baseCompiler.Properties.Target.Recovery.Srcs)
494 lib.baseCompiler.Properties.Exclude_srcs.AppendSimpleValue(lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs)
Justin Yun63e9ec72020-10-29 16:49:43 +0900495
496 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
497 lib.baseCompiler.Properties.Target.Recovery.Exclude_generated_sources...)
498 }
499}
500
501func squashVendorRamdiskSrcs(m *Module) {
502 if lib, ok := m.compiler.(*libraryDecorator); ok {
Cole Faust96a692b2024-08-08 14:47:51 -0700503 lib.baseCompiler.Properties.Exclude_srcs.AppendSimpleValue(lib.baseCompiler.Properties.Target.Vendor_ramdisk.Exclude_srcs)
Justin Yun63e9ec72020-10-29 16:49:43 +0900504 }
505}
506
Christopher Ferrise0202c42023-07-27 17:06:46 -0700507func squashRamdiskSrcs(m *Module) {
508 if lib, ok := m.compiler.(*libraryDecorator); ok {
Cole Faust96a692b2024-08-08 14:47:51 -0700509 lib.baseCompiler.Properties.Exclude_srcs.AppendSimpleValue(lib.baseCompiler.Properties.Target.Ramdisk.Exclude_srcs)
Christopher Ferrise0202c42023-07-27 17:06:46 -0700510 }
511}
512
Cole Faustfa6e0fd2024-10-15 15:22:57 -0700513func (c *Module) SetImageVariation(ctx android.ImageInterfaceContext, variant string) {
Yifan Hong6da33c22020-10-27 15:01:21 -0700514 if variant == android.RamdiskVariation {
Jihoon Kang7583e832024-06-13 21:25:45 +0000515 c.MakeAsPlatform()
516 squashRamdiskSrcs(c)
Yifan Hong6da33c22020-10-27 15:01:21 -0700517 } else if variant == android.VendorRamdiskVariation {
Jihoon Kang7583e832024-06-13 21:25:45 +0000518 c.MakeAsPlatform()
519 squashVendorRamdiskSrcs(c)
Inseob Kime498dd92020-08-04 09:24:04 +0900520 } else if variant == android.RecoveryVariation {
Jihoon Kang7583e832024-06-13 21:25:45 +0000521 c.MakeAsPlatform()
522 squashRecoverySrcs(c)
Jihoon Kang47e91842024-06-19 00:51:16 +0000523 } else if strings.HasPrefix(variant, android.VendorVariation) {
524 c.Properties.ImageVariation = android.VendorVariation
Kiyoung Kimb5fdb2e2024-01-03 14:24:34 +0900525
526 if strings.HasPrefix(variant, VendorVariationPrefix) {
Jihoon Kang7583e832024-06-13 21:25:45 +0000527 c.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
Kiyoung Kimb5fdb2e2024-01-03 14:24:34 +0900528 }
Jihoon Kang7583e832024-06-13 21:25:45 +0000529 squashVendorSrcs(c)
Jihoon Kang47e91842024-06-19 00:51:16 +0000530 } else if strings.HasPrefix(variant, android.ProductVariation) {
531 c.Properties.ImageVariation = android.ProductVariation
Kiyoung Kimb5fdb2e2024-01-03 14:24:34 +0900532 if strings.HasPrefix(variant, ProductVariationPrefix) {
Jihoon Kang7583e832024-06-13 21:25:45 +0000533 c.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix)
Kiyoung Kimb5fdb2e2024-01-03 14:24:34 +0900534 }
Jihoon Kang7583e832024-06-13 21:25:45 +0000535 squashProductSrcs(c)
Inseob Kime498dd92020-08-04 09:24:04 +0900536 }
Colin Cross5271fea2021-04-27 13:06:04 -0700537
538 if c.NeedsVendorPublicLibraryVariants() &&
539 (variant == android.CoreVariation || strings.HasPrefix(variant, ProductVariationPrefix)) {
540 c.VendorProperties.IsVendorPublicLibrary = true
541 }
Inseob Kime498dd92020-08-04 09:24:04 +0900542}