blob: 2e52ccc6326091aa4b4d7479c4e8ab3ccdf28015 [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.
180 SnapshotVersion(mctx android.BaseModuleContext) string
181
182 // SdkVersion returns the SDK version for this module.
183 SdkVersion() string
184
185 // ExtraVariants returns the list of extra variants this module requires.
186 ExtraVariants() []string
187
188 // AppendExtraVariant returns an extra variant to the list of extra variants this module requires.
189 AppendExtraVariant(extraVariant string)
190
191 // SetRamdiskVariantNeeded sets whether the Ramdisk Variant is needed.
192 SetRamdiskVariantNeeded(b bool)
193
194 // SetVendorRamdiskVariantNeeded sets whether the Vendor Ramdisk Variant is needed.
195 SetVendorRamdiskVariantNeeded(b bool)
196
197 // SetRecoveryVariantNeeded sets whether the Recovery Variant is needed.
198 SetRecoveryVariantNeeded(b bool)
199
200 // SetCoreVariantNeeded sets whether the Core Variant is needed.
201 SetCoreVariantNeeded(b bool)
Jihoon Kang47e91842024-06-19 00:51:16 +0000202
203 // SetProductVariantNeeded sets whether the Product Variant is needed.
204 SetProductVariantNeeded(b bool)
205
206 // SetVendorVariantNeeded sets whether the Vendor Variant is needed.
207 SetVendorVariantNeeded(b bool)
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400208}
209
210var _ ImageMutatableModule = (*Module)(nil)
211
Inseob Kime498dd92020-08-04 09:24:04 +0900212func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400213 MutateImage(mctx, m)
214}
215
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400216func (m *Module) VendorAvailable() bool {
217 return Bool(m.VendorProperties.Vendor_available)
218}
219
220func (m *Module) OdmAvailable() bool {
221 return Bool(m.VendorProperties.Odm_available)
222}
223
224func (m *Module) ProductAvailable() bool {
225 return Bool(m.VendorProperties.Product_available)
226}
227
228func (m *Module) RamdiskAvailable() bool {
229 return Bool(m.Properties.Ramdisk_available)
230}
231
232func (m *Module) VendorRamdiskAvailable() bool {
233 return Bool(m.Properties.Vendor_ramdisk_available)
234}
235
236func (m *Module) AndroidModuleBase() *android.ModuleBase {
237 return &m.ModuleBase
238}
239
240func (m *Module) RecoveryAvailable() bool {
241 return Bool(m.Properties.Recovery_available)
242}
243
244func (m *Module) ExtraVariants() []string {
Lukacs T. Berki2f5c3402021-06-15 11:27:56 +0200245 return m.Properties.ExtraVersionedImageVariations
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400246}
247
248func (m *Module) AppendExtraVariant(extraVariant string) {
Lukacs T. Berki2f5c3402021-06-15 11:27:56 +0200249 m.Properties.ExtraVersionedImageVariations = append(m.Properties.ExtraVersionedImageVariations, extraVariant)
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400250}
251
252func (m *Module) SetRamdiskVariantNeeded(b bool) {
253 m.Properties.RamdiskVariantNeeded = b
254}
255
256func (m *Module) SetVendorRamdiskVariantNeeded(b bool) {
257 m.Properties.VendorRamdiskVariantNeeded = b
258}
259
260func (m *Module) SetRecoveryVariantNeeded(b bool) {
261 m.Properties.RecoveryVariantNeeded = b
262}
263
264func (m *Module) SetCoreVariantNeeded(b bool) {
265 m.Properties.CoreVariantNeeded = b
266}
267
Jihoon Kang47e91842024-06-19 00:51:16 +0000268func (m *Module) SetProductVariantNeeded(b bool) {
269 m.Properties.ProductVariantNeeded = b
270}
271
272func (m *Module) SetVendorVariantNeeded(b bool) {
273 m.Properties.VendorVariantNeeded = b
274}
275
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400276func (m *Module) SnapshotVersion(mctx android.BaseModuleContext) string {
Ivan Lozanod1dec542021-05-26 15:33:11 -0400277 if snapshot, ok := m.linker.(SnapshotInterface); ok {
278 return snapshot.Version()
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400279 } else {
280 mctx.ModuleErrorf("version is unknown for snapshot prebuilt")
281 // Should we be panicking here instead?
282 return ""
283 }
284}
285
286func (m *Module) KernelHeadersDecorator() bool {
287 if _, ok := m.linker.(*kernelHeadersDecorator); ok {
288 return true
289 }
290 return false
291}
292
293// MutateImage handles common image mutations for ImageMutatableModule interfaces.
294func MutateImage(mctx android.BaseModuleContext, m ImageMutatableModule) {
295 // Validation check
296 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
297 productSpecific := mctx.ProductSpecific()
298
299 if m.VendorAvailable() {
300 if vendorSpecific {
301 mctx.PropertyErrorf("vendor_available",
302 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific: true`")
303 }
304 if m.OdmAvailable() {
305 mctx.PropertyErrorf("vendor_available",
306 "doesn't make sense at the same time as `odm_available: true`")
307 }
308 }
309
310 if m.OdmAvailable() {
311 if vendorSpecific {
312 mctx.PropertyErrorf("odm_available",
313 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific: true`")
314 }
315 }
316
317 if m.ProductAvailable() {
318 if productSpecific {
319 mctx.PropertyErrorf("product_available",
320 "doesn't make sense at the same time as `product_specific: true`")
321 }
322 if vendorSpecific {
323 mctx.PropertyErrorf("product_available",
324 "cannot provide product variant from a vendor module. Please use `product_specific: true` with `vendor_available: true`")
325 }
326 }
Inseob Kime498dd92020-08-04 09:24:04 +0900327
Jihoon Kang47e91842024-06-19 00:51:16 +0000328 var vendorVariantNeeded bool = false
329 var productVariantNeeded bool = false
Inseob Kime498dd92020-08-04 09:24:04 +0900330 var coreVariantNeeded bool = false
331 var ramdiskVariantNeeded bool = false
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700332 var vendorRamdiskVariantNeeded bool = false
Inseob Kime498dd92020-08-04 09:24:04 +0900333 var recoveryVariantNeeded bool = false
334
Colin Cross203b4212021-04-26 17:19:41 -0700335 if m.NeedsLlndkVariants() {
Colin Crossb5f6fa62021-01-06 17:05:04 -0800336 // This is an LLNDK library. The implementation of the library will be on /system,
337 // and vendor and product variants will be created with LLNDK stubs.
338 // The LLNDK libraries need vendor variants even if there is no VNDK.
Colin Cross203b4212021-04-26 17:19:41 -0700339 coreVariantNeeded = true
Jihoon Kang47e91842024-06-19 00:51:16 +0000340 vendorVariantNeeded = true
341 productVariantNeeded = true
342
Colin Cross5271fea2021-04-27 13:06:04 -0700343 } else if m.NeedsVendorPublicLibraryVariants() {
344 // A vendor public library has the implementation on /vendor, with stub variants
345 // for system and product.
346 coreVariantNeeded = true
Jihoon Kang47e91842024-06-19 00:51:16 +0000347 vendorVariantNeeded = true
348 productVariantNeeded = true
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400349 } else if m.IsSnapshotPrebuilt() {
Inseob Kime498dd92020-08-04 09:24:04 +0900350 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
351 // PRODUCT_EXTRA_VNDK_VERSIONS.
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400352 if m.InstallInRecovery() {
353 recoveryVariantNeeded = true
Inseob Kime498dd92020-08-04 09:24:04 +0900354 } else {
Jihoon Kang47e91842024-06-19 00:51:16 +0000355 m.AppendExtraVariant(VendorVariationPrefix + m.SnapshotVersion(mctx))
Inseob Kime498dd92020-08-04 09:24:04 +0900356 }
Kiyoung Kim9f26fcf2024-05-27 17:25:52 +0900357 } else if m.HasNonSystemVariants() {
Justin Yun63e9ec72020-10-29 16:49:43 +0900358 // This will be available to /system unless it is product_specific
359 // which will be handled later.
Inseob Kime498dd92020-08-04 09:24:04 +0900360 coreVariantNeeded = true
361
362 // We assume that modules under proprietary paths are compatible for
363 // BOARD_VNDK_VERSION. The other modules are regarded as AOSP, or
364 // PLATFORM_VNDK_VERSION.
Justin Yun63e9ec72020-10-29 16:49:43 +0900365 if m.HasVendorVariant() {
Jihoon Kang47e91842024-06-19 00:51:16 +0000366 vendorVariantNeeded = true
Inseob Kime498dd92020-08-04 09:24:04 +0900367 }
368
Justin Yun6977e8a2020-10-29 18:24:11 +0900369 // product_available modules are available to /product.
370 if m.HasProductVariant() {
Jihoon Kang47e91842024-06-19 00:51:16 +0000371 productVariantNeeded = true
Inseob Kime498dd92020-08-04 09:24:04 +0900372 }
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400373 } else if vendorSpecific && m.SdkVersion() == "" {
Inseob Kime498dd92020-08-04 09:24:04 +0900374 // This will be available in /vendor (or /odm) only
Jihoon Kang47e91842024-06-19 00:51:16 +0000375 vendorVariantNeeded = true
Inseob Kime498dd92020-08-04 09:24:04 +0900376 } else {
377 // This is either in /system (or similar: /data), or is a
jiajia tangcd1c27b2022-07-21 18:04:37 +0800378 // module built with the NDK. Modules built with the NDK
Inseob Kime498dd92020-08-04 09:24:04 +0900379 // will be restricted using the existing link type checks.
380 coreVariantNeeded = true
381 }
382
Justin Yunaf1fde42023-09-27 16:22:10 +0900383 if coreVariantNeeded && productSpecific && m.SdkVersion() == "" {
384 // The module has "product_specific: true" that does not create core variant.
385 coreVariantNeeded = false
Jihoon Kang47e91842024-06-19 00:51:16 +0000386 productVariantNeeded = true
Inseob Kime498dd92020-08-04 09:24:04 +0900387 }
388
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400389 if m.RamdiskAvailable() {
Inseob Kime498dd92020-08-04 09:24:04 +0900390 ramdiskVariantNeeded = true
391 }
392
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400393 if m.AndroidModuleBase().InstallInRamdisk() {
Inseob Kime498dd92020-08-04 09:24:04 +0900394 ramdiskVariantNeeded = true
395 coreVariantNeeded = false
396 }
397
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400398 if m.VendorRamdiskAvailable() {
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700399 vendorRamdiskVariantNeeded = true
400 }
401
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400402 if m.AndroidModuleBase().InstallInVendorRamdisk() {
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700403 vendorRamdiskVariantNeeded = true
404 coreVariantNeeded = false
405 }
406
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400407 if m.RecoveryAvailable() {
Inseob Kime498dd92020-08-04 09:24:04 +0900408 recoveryVariantNeeded = true
409 }
410
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400411 if m.AndroidModuleBase().InstallInRecovery() {
Inseob Kime498dd92020-08-04 09:24:04 +0900412 recoveryVariantNeeded = true
413 coreVariantNeeded = false
414 }
415
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400416 m.SetRamdiskVariantNeeded(ramdiskVariantNeeded)
417 m.SetVendorRamdiskVariantNeeded(vendorRamdiskVariantNeeded)
418 m.SetRecoveryVariantNeeded(recoveryVariantNeeded)
419 m.SetCoreVariantNeeded(coreVariantNeeded)
Jihoon Kang47e91842024-06-19 00:51:16 +0000420 m.SetProductVariantNeeded(productVariantNeeded)
421 m.SetVendorVariantNeeded(vendorVariantNeeded)
Jose Galmes6f843bc2020-12-11 13:36:29 -0800422
423 // Disable the module if no variants are needed.
424 if !ramdiskVariantNeeded &&
425 !recoveryVariantNeeded &&
426 !coreVariantNeeded &&
Jihoon Kang47e91842024-06-19 00:51:16 +0000427 !productVariantNeeded &&
428 !vendorVariantNeeded &&
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400429 len(m.ExtraVariants()) == 0 {
Jose Galmes6f843bc2020-12-11 13:36:29 -0800430 m.Disable()
431 }
Inseob Kime498dd92020-08-04 09:24:04 +0900432}
433
Jihoon Kang47e91842024-06-19 00:51:16 +0000434func (c *Module) VendorVariantNeeded(ctx android.BaseModuleContext) bool {
435 return c.Properties.VendorVariantNeeded
436}
437
438func (c *Module) ProductVariantNeeded(ctx android.BaseModuleContext) bool {
439 return c.Properties.ProductVariantNeeded
440}
441
Inseob Kime498dd92020-08-04 09:24:04 +0900442func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
443 return c.Properties.CoreVariantNeeded
444}
445
446func (c *Module) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
447 return c.Properties.RamdiskVariantNeeded
448}
449
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700450func (c *Module) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
451 return c.Properties.VendorRamdiskVariantNeeded
452}
453
Inseob Kim08758f02021-04-08 21:13:22 +0900454func (c *Module) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
455 return false
456}
457
Inseob Kime498dd92020-08-04 09:24:04 +0900458func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
459 return c.Properties.RecoveryVariantNeeded
460}
461
462func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
Lukacs T. Berki2f5c3402021-06-15 11:27:56 +0200463 return c.Properties.ExtraVersionedImageVariations
Inseob Kime498dd92020-08-04 09:24:04 +0900464}
465
Justin Yun63e9ec72020-10-29 16:49:43 +0900466func squashVendorSrcs(m *Module) {
467 if lib, ok := m.compiler.(*libraryDecorator); ok {
468 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
469 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
470
471 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
472 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
473
474 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
475 lib.baseCompiler.Properties.Target.Vendor.Exclude_generated_sources...)
Jooyung Han85707de2023-12-01 14:21:13 +0900476
477 if lib.Properties.Target.Vendor.No_stubs {
478 proptools.Clear(&lib.Properties.Stubs)
479 }
Justin Yun63e9ec72020-10-29 16:49:43 +0900480 }
481}
482
483func squashProductSrcs(m *Module) {
484 if lib, ok := m.compiler.(*libraryDecorator); ok {
485 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
486 lib.baseCompiler.Properties.Target.Product.Srcs...)
487
488 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
489 lib.baseCompiler.Properties.Target.Product.Exclude_srcs...)
490
491 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
492 lib.baseCompiler.Properties.Target.Product.Exclude_generated_sources...)
Jooyung Han85707de2023-12-01 14:21:13 +0900493
494 if lib.Properties.Target.Product.No_stubs {
495 proptools.Clear(&lib.Properties.Stubs)
496 }
Justin Yun63e9ec72020-10-29 16:49:43 +0900497 }
498}
499
500func squashRecoverySrcs(m *Module) {
501 if lib, ok := m.compiler.(*libraryDecorator); ok {
502 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
503 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
504
505 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
506 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
507
508 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
509 lib.baseCompiler.Properties.Target.Recovery.Exclude_generated_sources...)
510 }
511}
512
513func squashVendorRamdiskSrcs(m *Module) {
514 if lib, ok := m.compiler.(*libraryDecorator); ok {
515 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, lib.baseCompiler.Properties.Target.Vendor_ramdisk.Exclude_srcs...)
516 }
517}
518
Christopher Ferrise0202c42023-07-27 17:06:46 -0700519func squashRamdiskSrcs(m *Module) {
520 if lib, ok := m.compiler.(*libraryDecorator); ok {
521 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, lib.baseCompiler.Properties.Target.Ramdisk.Exclude_srcs...)
522 }
523}
524
Jihoon Kang7583e832024-06-13 21:25:45 +0000525func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string) {
Yifan Hong6da33c22020-10-27 15:01:21 -0700526 if variant == android.RamdiskVariation {
Jihoon Kang7583e832024-06-13 21:25:45 +0000527 c.MakeAsPlatform()
528 squashRamdiskSrcs(c)
Yifan Hong6da33c22020-10-27 15:01:21 -0700529 } else if variant == android.VendorRamdiskVariation {
Jihoon Kang7583e832024-06-13 21:25:45 +0000530 c.MakeAsPlatform()
531 squashVendorRamdiskSrcs(c)
Inseob Kime498dd92020-08-04 09:24:04 +0900532 } else if variant == android.RecoveryVariation {
Jihoon Kang7583e832024-06-13 21:25:45 +0000533 c.MakeAsPlatform()
534 squashRecoverySrcs(c)
Jihoon Kang47e91842024-06-19 00:51:16 +0000535 } else if strings.HasPrefix(variant, android.VendorVariation) {
536 c.Properties.ImageVariation = android.VendorVariation
Kiyoung Kimb5fdb2e2024-01-03 14:24:34 +0900537
538 if strings.HasPrefix(variant, VendorVariationPrefix) {
Jihoon Kang7583e832024-06-13 21:25:45 +0000539 c.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
Kiyoung Kimb5fdb2e2024-01-03 14:24:34 +0900540 }
Jihoon Kang7583e832024-06-13 21:25:45 +0000541 squashVendorSrcs(c)
Jihoon Kang47e91842024-06-19 00:51:16 +0000542 } else if strings.HasPrefix(variant, android.ProductVariation) {
543 c.Properties.ImageVariation = android.ProductVariation
Kiyoung Kimb5fdb2e2024-01-03 14:24:34 +0900544 if strings.HasPrefix(variant, ProductVariationPrefix) {
Jihoon Kang7583e832024-06-13 21:25:45 +0000545 c.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix)
Kiyoung Kimb5fdb2e2024-01-03 14:24:34 +0900546 }
Jihoon Kang7583e832024-06-13 21:25:45 +0000547 squashProductSrcs(c)
Inseob Kime498dd92020-08-04 09:24:04 +0900548 }
Colin Cross5271fea2021-04-27 13:06:04 -0700549
550 if c.NeedsVendorPublicLibraryVariants() &&
551 (variant == android.CoreVariation || strings.HasPrefix(variant, ProductVariationPrefix)) {
552 c.VendorProperties.IsVendorPublicLibrary = true
553 }
Inseob Kime498dd92020-08-04 09:24:04 +0900554}