blob: ca00ac97627ab58764a503553d17ca1fae6ec879 [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//
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.
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 (
Justin Yun6977e8a2020-10-29 18:24:11 +090020 "fmt"
21 "reflect"
Inseob Kime498dd92020-08-04 09:24:04 +090022 "strings"
23
24 "android/soong/android"
25)
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
51func (ctx *moduleContext) ProductSpecific() bool {
Justin Yun7f99ec72021-04-12 13:19:28 +090052 return ctx.ModuleContext.ProductSpecific() || ctx.mod.productSpecificModuleContext()
Inseob Kime498dd92020-08-04 09:24:04 +090053}
54
55func (ctx *moduleContext) SocSpecific() bool {
Justin Yun7f99ec72021-04-12 13:19:28 +090056 return ctx.ModuleContext.SocSpecific() || ctx.mod.socSpecificModuleContext()
Justin Yunebcf0c52021-01-08 18:00:19 +090057}
58
59func (ctx *moduleContext) DeviceSpecific() bool {
Justin Yun7f99ec72021-04-12 13:19:28 +090060 return ctx.ModuleContext.DeviceSpecific() || ctx.mod.deviceSpecificModuleContext()
Inseob Kime498dd92020-08-04 09:24:04 +090061}
62
63func (ctx *moduleContextImpl) inProduct() bool {
Ivan Lozanof9e21722020-12-02 09:00:51 -050064 return ctx.mod.InProduct()
Inseob Kime498dd92020-08-04 09:24:04 +090065}
66
67func (ctx *moduleContextImpl) inVendor() bool {
Ivan Lozano3968d8f2020-12-14 11:27:52 -050068 return ctx.mod.InVendor()
Inseob Kime498dd92020-08-04 09:24:04 +090069}
70
71func (ctx *moduleContextImpl) inRamdisk() bool {
72 return ctx.mod.InRamdisk()
73}
74
Yifan Hong60e0cfb2020-10-21 15:17:56 -070075func (ctx *moduleContextImpl) inVendorRamdisk() bool {
76 return ctx.mod.InVendorRamdisk()
77}
78
Inseob Kime498dd92020-08-04 09:24:04 +090079func (ctx *moduleContextImpl) inRecovery() bool {
80 return ctx.mod.InRecovery()
81}
82
Justin Yun7f99ec72021-04-12 13:19:28 +090083func (c *Module) productSpecificModuleContext() bool {
84 // Additionally check if this module is inProduct() that means it is a "product" variant of a
85 // module. As well as product specific modules, product variants must be installed to /product.
86 return c.InProduct()
87}
88
89func (c *Module) socSpecificModuleContext() bool {
90 // Additionally check if this module is inVendor() that means it is a "vendor" variant of a
91 // module. As well as SoC specific modules, vendor variants must be installed to /vendor
92 // unless they have "odm_available: true".
93 return c.HasVendorVariant() && c.InVendor() && !c.VendorVariantToOdm()
94}
95
96func (c *Module) deviceSpecificModuleContext() bool {
97 // Some vendor variants want to be installed to /odm by setting "odm_available: true".
98 return c.InVendor() && c.VendorVariantToOdm()
99}
100
Justin Yun63e9ec72020-10-29 16:49:43 +0900101// Returns true when this module is configured to have core and vendor variants.
Inseob Kime498dd92020-08-04 09:24:04 +0900102func (c *Module) HasVendorVariant() bool {
Justin Yunebcf0c52021-01-08 18:00:19 +0900103 return Bool(c.VendorProperties.Vendor_available) || Bool(c.VendorProperties.Odm_available)
104}
105
106// Returns true when this module creates a vendor variant and wants to install the vendor variant
107// to the odm partition.
108func (c *Module) VendorVariantToOdm() bool {
109 return Bool(c.VendorProperties.Odm_available)
Inseob Kime498dd92020-08-04 09:24:04 +0900110}
111
Justin Yun63e9ec72020-10-29 16:49:43 +0900112// Returns true when this module is configured to have core and product variants.
113func (c *Module) HasProductVariant() bool {
Justin Yunc0d8c492021-01-07 17:45:31 +0900114 return Bool(c.VendorProperties.Product_available)
Justin Yun63e9ec72020-10-29 16:49:43 +0900115}
116
117// Returns true when this module is configured to have core and either product or vendor variants.
118func (c *Module) HasNonSystemVariants() bool {
Justin Yun6977e8a2020-10-29 18:24:11 +0900119 return c.HasVendorVariant() || c.HasProductVariant()
Justin Yun63e9ec72020-10-29 16:49:43 +0900120}
121
Inseob Kime498dd92020-08-04 09:24:04 +0900122// Returns true if the module is "product" variant. Usually these modules are installed in /product
Ivan Lozanof9e21722020-12-02 09:00:51 -0500123func (c *Module) InProduct() bool {
Inseob Kime498dd92020-08-04 09:24:04 +0900124 return c.Properties.ImageVariationPrefix == ProductVariationPrefix
125}
126
127// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500128func (c *Module) InVendor() bool {
Inseob Kime498dd92020-08-04 09:24:04 +0900129 return c.Properties.ImageVariationPrefix == VendorVariationPrefix
130}
131
132func (c *Module) InRamdisk() bool {
133 return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk()
134}
135
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700136func (c *Module) InVendorRamdisk() bool {
137 return c.ModuleBase.InVendorRamdisk() || c.ModuleBase.InstallInVendorRamdisk()
138}
139
Inseob Kime498dd92020-08-04 09:24:04 +0900140func (c *Module) InRecovery() bool {
141 return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
142}
143
144func (c *Module) OnlyInRamdisk() bool {
145 return c.ModuleBase.InstallInRamdisk()
146}
147
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700148func (c *Module) OnlyInVendorRamdisk() bool {
149 return c.ModuleBase.InstallInVendorRamdisk()
150}
151
Inseob Kime498dd92020-08-04 09:24:04 +0900152func (c *Module) OnlyInRecovery() bool {
153 return c.ModuleBase.InstallInRecovery()
154}
155
Justin Yun6977e8a2020-10-29 18:24:11 +0900156func visitPropsAndCompareVendorAndProductProps(v reflect.Value) bool {
157 if v.Kind() != reflect.Struct {
158 return true
159 }
160 for i := 0; i < v.NumField(); i++ {
161 prop := v.Field(i)
162 if prop.Kind() == reflect.Struct && v.Type().Field(i).Name == "Target" {
163 vendor_prop := prop.FieldByName("Vendor")
164 product_prop := prop.FieldByName("Product")
165 if vendor_prop.Kind() != reflect.Struct && product_prop.Kind() != reflect.Struct {
166 // Neither Target.Vendor nor Target.Product is defined
167 continue
168 }
169 if vendor_prop.Kind() != reflect.Struct || product_prop.Kind() != reflect.Struct ||
170 !reflect.DeepEqual(vendor_prop.Interface(), product_prop.Interface()) {
171 // If only one of either Target.Vendor or Target.Product is
172 // defined or they have different values, it fails the build
173 // since VNDK must have the same properties for both vendor
174 // and product variants.
175 return false
176 }
177 } else if !visitPropsAndCompareVendorAndProductProps(prop) {
178 // Visit the substructures to find Target.Vendor and Target.Product
179 return false
180 }
181 }
182 return true
183}
184
185// In the case of VNDK, vendor and product variants must have the same properties.
186// VNDK installs only one file and shares it for both vendor and product modules on
187// runtime. We may not define different versions of a VNDK lib for each partition.
188// This function is used only for the VNDK modules that is available to both vendor
189// and product partitions.
190func (c *Module) compareVendorAndProductProps() bool {
Justin Yunc0d8c492021-01-07 17:45:31 +0900191 if !c.IsVndk() && !Bool(c.VendorProperties.Product_available) {
Justin Yun6977e8a2020-10-29 18:24:11 +0900192 panic(fmt.Errorf("This is only for product available VNDK libs. %q is not a VNDK library or not product available", c.Name()))
193 }
194 for _, properties := range c.GetProperties() {
195 if !visitPropsAndCompareVendorAndProductProps(reflect.ValueOf(properties).Elem()) {
196 return false
197 }
198 }
199 return true
200}
201
Inseob Kime498dd92020-08-04 09:24:04 +0900202func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
203 // Validation check
204 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
205 productSpecific := mctx.ProductSpecific()
206
Justin Yunc0d8c492021-01-07 17:45:31 +0900207 if Bool(m.VendorProperties.Vendor_available) {
Justin Yun63e9ec72020-10-29 16:49:43 +0900208 if vendorSpecific {
209 mctx.PropertyErrorf("vendor_available",
Justin Yunebcf0c52021-01-08 18:00:19 +0900210 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific: true`")
211 }
212 if Bool(m.VendorProperties.Odm_available) {
213 mctx.PropertyErrorf("vendor_available",
214 "doesn't make sense at the same time as `odm_available: true`")
215 }
216 }
217
218 if Bool(m.VendorProperties.Odm_available) {
219 if vendorSpecific {
220 mctx.PropertyErrorf("odm_available",
221 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific: true`")
Justin Yun63e9ec72020-10-29 16:49:43 +0900222 }
Justin Yun63e9ec72020-10-29 16:49:43 +0900223 }
224
Justin Yunc0d8c492021-01-07 17:45:31 +0900225 if Bool(m.VendorProperties.Product_available) {
Justin Yun63e9ec72020-10-29 16:49:43 +0900226 if productSpecific {
227 mctx.PropertyErrorf("product_available",
228 "doesn't make sense at the same time as `product_specific: true`")
229 }
230 if vendorSpecific {
231 mctx.PropertyErrorf("product_available",
232 "cannot provide product variant from a vendor module. Please use `product_specific: true` with `vendor_available: true`")
233 }
Inseob Kime498dd92020-08-04 09:24:04 +0900234 }
235
236 if vndkdep := m.vndkdep; vndkdep != nil {
237 if vndkdep.isVndk() {
238 if vendorSpecific || productSpecific {
239 if !vndkdep.isVndkExt() {
240 mctx.PropertyErrorf("vndk",
241 "must set `extends: \"...\"` to vndk extension")
Justin Yunc0d8c492021-01-07 17:45:31 +0900242 } else if Bool(m.VendorProperties.Vendor_available) {
Inseob Kime498dd92020-08-04 09:24:04 +0900243 mctx.PropertyErrorf("vendor_available",
244 "must not set at the same time as `vndk: {extends: \"...\"}`")
Justin Yunc0d8c492021-01-07 17:45:31 +0900245 } else if Bool(m.VendorProperties.Product_available) {
Justin Yun63e9ec72020-10-29 16:49:43 +0900246 mctx.PropertyErrorf("product_available",
247 "must not set at the same time as `vndk: {extends: \"...\"}`")
Inseob Kime498dd92020-08-04 09:24:04 +0900248 }
249 } else {
250 if vndkdep.isVndkExt() {
251 mctx.PropertyErrorf("vndk",
252 "must set `vendor: true` or `product_specific: true` to set `extends: %q`",
253 m.getVndkExtendsModuleName())
254 }
Justin Yunc0d8c492021-01-07 17:45:31 +0900255 if !Bool(m.VendorProperties.Vendor_available) {
Inseob Kime498dd92020-08-04 09:24:04 +0900256 mctx.PropertyErrorf("vndk",
Justin Yunc0d8c492021-01-07 17:45:31 +0900257 "vendor_available must be set to true when `vndk: {enabled: true}`")
Inseob Kime498dd92020-08-04 09:24:04 +0900258 }
Justin Yunc0d8c492021-01-07 17:45:31 +0900259 if Bool(m.VendorProperties.Product_available) {
Justin Yunfd9e8042020-12-23 18:23:14 +0900260 // If a VNDK module creates both product and vendor variants, they
261 // must have the same properties since they share a single VNDK
262 // library on runtime.
Justin Yun6977e8a2020-10-29 18:24:11 +0900263 if !m.compareVendorAndProductProps() {
264 mctx.ModuleErrorf("product properties must have the same values with the vendor properties for VNDK modules")
265 }
266 }
Inseob Kime498dd92020-08-04 09:24:04 +0900267 }
268 } else {
269 if vndkdep.isVndkSp() {
270 mctx.PropertyErrorf("vndk",
271 "must set `enabled: true` to set `support_system_process: true`")
272 }
273 if vndkdep.isVndkExt() {
274 mctx.PropertyErrorf("vndk",
275 "must set `enabled: true` to set `extends: %q`",
276 m.getVndkExtendsModuleName())
277 }
278 }
279 }
280
281 var coreVariantNeeded bool = false
282 var ramdiskVariantNeeded bool = false
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700283 var vendorRamdiskVariantNeeded bool = false
Inseob Kime498dd92020-08-04 09:24:04 +0900284 var recoveryVariantNeeded bool = false
285
286 var vendorVariants []string
287 var productVariants []string
288
289 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
290 boardVndkVersion := mctx.DeviceConfig().VndkVersion()
291 productVndkVersion := mctx.DeviceConfig().ProductVndkVersion()
Jose Galmes6f843bc2020-12-11 13:36:29 -0800292 recoverySnapshotVersion := mctx.DeviceConfig().RecoverySnapshotVersion()
293 usingRecoverySnapshot := recoverySnapshotVersion != "current" &&
294 recoverySnapshotVersion != ""
Inseob Kime498dd92020-08-04 09:24:04 +0900295 if boardVndkVersion == "current" {
296 boardVndkVersion = platformVndkVersion
297 }
298 if productVndkVersion == "current" {
299 productVndkVersion = platformVndkVersion
300 }
301
Colin Crossb5f6fa62021-01-06 17:05:04 -0800302 _, isLLNDKLibrary := m.linker.(*llndkStubDecorator)
303 _, isLLNDKHeaders := m.linker.(*llndkHeadersDecorator)
304 lib := moduleLibraryInterface(m)
305 hasLLNDKStubs := lib != nil && lib.hasLLNDKStubs()
306
307 if isLLNDKLibrary || isLLNDKHeaders || hasLLNDKStubs {
308 // This is an LLNDK library. The implementation of the library will be on /system,
309 // and vendor and product variants will be created with LLNDK stubs.
310 // The LLNDK libraries need vendor variants even if there is no VNDK.
311 // The obsolete llndk_library and llndk_headers modules also need the vendor variants
312 // so the cc_library LLNDK stubs can depend on them.
313 if hasLLNDKStubs {
314 coreVariantNeeded = true
315 }
316 if platformVndkVersion != "" {
317 vendorVariants = append(vendorVariants, platformVndkVersion)
318 productVariants = append(productVariants, platformVndkVersion)
319 }
320 if boardVndkVersion != "" {
321 vendorVariants = append(vendorVariants, boardVndkVersion)
322 }
323 if productVndkVersion != "" {
324 productVariants = append(productVariants, productVndkVersion)
325 }
326 } else if boardVndkVersion == "" {
Inseob Kime498dd92020-08-04 09:24:04 +0900327 // If the device isn't compiling against the VNDK, we always
328 // use the core mode.
329 coreVariantNeeded = true
Inseob Kime498dd92020-08-04 09:24:04 +0900330 } else if m.isSnapshotPrebuilt() {
331 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
332 // PRODUCT_EXTRA_VNDK_VERSIONS.
Colin Crossa8890802021-01-22 14:06:33 -0800333 if snapshot, ok := m.linker.(snapshotInterface); ok {
Jose Galmes6f843bc2020-12-11 13:36:29 -0800334 if m.InstallInRecovery() {
335 recoveryVariantNeeded = true
336 } else {
337 vendorVariants = append(vendorVariants, snapshot.version())
338 }
Inseob Kime498dd92020-08-04 09:24:04 +0900339 } else {
340 mctx.ModuleErrorf("version is unknown for snapshot prebuilt")
341 }
Ivan Lozanof9e21722020-12-02 09:00:51 -0500342 } else if m.HasNonSystemVariants() && !m.IsVndkExt() {
Justin Yun63e9ec72020-10-29 16:49:43 +0900343 // This will be available to /system unless it is product_specific
344 // which will be handled later.
Inseob Kime498dd92020-08-04 09:24:04 +0900345 coreVariantNeeded = true
346
347 // We assume that modules under proprietary paths are compatible for
348 // BOARD_VNDK_VERSION. The other modules are regarded as AOSP, or
349 // PLATFORM_VNDK_VERSION.
Justin Yun63e9ec72020-10-29 16:49:43 +0900350 if m.HasVendorVariant() {
351 if isVendorProprietaryModule(mctx) {
352 vendorVariants = append(vendorVariants, boardVndkVersion)
353 } else {
354 vendorVariants = append(vendorVariants, platformVndkVersion)
355 }
Inseob Kime498dd92020-08-04 09:24:04 +0900356 }
357
Justin Yun6977e8a2020-10-29 18:24:11 +0900358 // product_available modules are available to /product.
359 if m.HasProductVariant() {
360 productVariants = append(productVariants, platformVndkVersion)
361 // VNDK is always PLATFORM_VNDK_VERSION
362 if !m.IsVndk() {
363 productVariants = append(productVariants, productVndkVersion)
364 }
Inseob Kime498dd92020-08-04 09:24:04 +0900365 }
366 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
367 // This will be available in /vendor (or /odm) only
368
369 // kernel_headers is a special module type whose exported headers
370 // are coming from DeviceKernelHeaders() which is always vendor
371 // dependent. They'll always have both vendor variants.
372 // For other modules, we assume that modules under proprietary
373 // paths are compatible for BOARD_VNDK_VERSION. The other modules
374 // are regarded as AOSP, which is PLATFORM_VNDK_VERSION.
375 if _, ok := m.linker.(*kernelHeadersDecorator); ok {
376 vendorVariants = append(vendorVariants,
377 platformVndkVersion,
378 boardVndkVersion,
379 )
Bill Peckham945441c2020-08-31 16:07:58 -0700380 } else if isVendorProprietaryModule(mctx) {
Inseob Kime498dd92020-08-04 09:24:04 +0900381 vendorVariants = append(vendorVariants, boardVndkVersion)
382 } else {
383 vendorVariants = append(vendorVariants, platformVndkVersion)
384 }
385 } else {
386 // This is either in /system (or similar: /data), or is a
387 // modules built with the NDK. Modules built with the NDK
388 // will be restricted using the existing link type checks.
389 coreVariantNeeded = true
390 }
391
392 if boardVndkVersion != "" && productVndkVersion != "" {
393 if coreVariantNeeded && productSpecific && String(m.Properties.Sdk_version) == "" {
394 // The module has "product_specific: true" that does not create core variant.
395 coreVariantNeeded = false
396 productVariants = append(productVariants, productVndkVersion)
397 }
398 } else {
399 // Unless PRODUCT_PRODUCT_VNDK_VERSION is set, product partition has no
400 // restriction to use system libs.
401 // No product variants defined in this case.
402 productVariants = []string{}
403 }
404
405 if Bool(m.Properties.Ramdisk_available) {
406 ramdiskVariantNeeded = true
407 }
408
409 if m.ModuleBase.InstallInRamdisk() {
410 ramdiskVariantNeeded = true
411 coreVariantNeeded = false
412 }
413
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700414 if Bool(m.Properties.Vendor_ramdisk_available) {
415 vendorRamdiskVariantNeeded = true
416 }
417
418 if m.ModuleBase.InstallInVendorRamdisk() {
419 vendorRamdiskVariantNeeded = true
420 coreVariantNeeded = false
421 }
422
Inseob Kime498dd92020-08-04 09:24:04 +0900423 if Bool(m.Properties.Recovery_available) {
424 recoveryVariantNeeded = true
425 }
426
427 if m.ModuleBase.InstallInRecovery() {
428 recoveryVariantNeeded = true
429 coreVariantNeeded = false
430 }
431
Jose Galmes6f843bc2020-12-11 13:36:29 -0800432 // If using a snapshot, the recovery variant under AOSP directories is not needed,
433 // except for kernel headers, which needs all variants.
434 if _, ok := m.linker.(*kernelHeadersDecorator); !ok &&
435 !m.isSnapshotPrebuilt() &&
436 usingRecoverySnapshot &&
437 !isRecoveryProprietaryModule(mctx) {
438 recoveryVariantNeeded = false
439 }
440
Inseob Kime498dd92020-08-04 09:24:04 +0900441 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
442 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, VendorVariationPrefix+variant)
443 }
444
445 for _, variant := range android.FirstUniqueStrings(productVariants) {
446 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, ProductVariationPrefix+variant)
447 }
448
449 m.Properties.RamdiskVariantNeeded = ramdiskVariantNeeded
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700450 m.Properties.VendorRamdiskVariantNeeded = vendorRamdiskVariantNeeded
Inseob Kime498dd92020-08-04 09:24:04 +0900451 m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
452 m.Properties.CoreVariantNeeded = coreVariantNeeded
Jose Galmes6f843bc2020-12-11 13:36:29 -0800453
454 // Disable the module if no variants are needed.
455 if !ramdiskVariantNeeded &&
456 !recoveryVariantNeeded &&
457 !coreVariantNeeded &&
458 len(m.Properties.ExtraVariants) == 0 {
459 m.Disable()
460 }
Inseob Kime498dd92020-08-04 09:24:04 +0900461}
462
463func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
464 return c.Properties.CoreVariantNeeded
465}
466
467func (c *Module) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
468 return c.Properties.RamdiskVariantNeeded
469}
470
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700471func (c *Module) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
472 return c.Properties.VendorRamdiskVariantNeeded
473}
474
Inseob Kime498dd92020-08-04 09:24:04 +0900475func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
476 return c.Properties.RecoveryVariantNeeded
477}
478
479func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
480 return c.Properties.ExtraVariants
481}
482
Justin Yun63e9ec72020-10-29 16:49:43 +0900483func squashVendorSrcs(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.Vendor.Srcs...)
487
488 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
489 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
490
491 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
492 lib.baseCompiler.Properties.Target.Vendor.Exclude_generated_sources...)
493 }
494}
495
496func squashProductSrcs(m *Module) {
497 if lib, ok := m.compiler.(*libraryDecorator); ok {
498 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
499 lib.baseCompiler.Properties.Target.Product.Srcs...)
500
501 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
502 lib.baseCompiler.Properties.Target.Product.Exclude_srcs...)
503
504 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
505 lib.baseCompiler.Properties.Target.Product.Exclude_generated_sources...)
506 }
507}
508
509func squashRecoverySrcs(m *Module) {
510 if lib, ok := m.compiler.(*libraryDecorator); ok {
511 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
512 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
513
514 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
515 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
516
517 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
518 lib.baseCompiler.Properties.Target.Recovery.Exclude_generated_sources...)
519 }
520}
521
522func squashVendorRamdiskSrcs(m *Module) {
523 if lib, ok := m.compiler.(*libraryDecorator); ok {
524 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, lib.baseCompiler.Properties.Target.Vendor_ramdisk.Exclude_srcs...)
525 }
526}
527
Inseob Kime498dd92020-08-04 09:24:04 +0900528func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
529 m := module.(*Module)
Yifan Hong6da33c22020-10-27 15:01:21 -0700530 if variant == android.RamdiskVariation {
Inseob Kime498dd92020-08-04 09:24:04 +0900531 m.MakeAsPlatform()
Yifan Hong6da33c22020-10-27 15:01:21 -0700532 } else if variant == android.VendorRamdiskVariation {
533 m.MakeAsPlatform()
534 squashVendorRamdiskSrcs(m)
Inseob Kime498dd92020-08-04 09:24:04 +0900535 } else if variant == android.RecoveryVariation {
536 m.MakeAsPlatform()
537 squashRecoverySrcs(m)
538 } else if strings.HasPrefix(variant, VendorVariationPrefix) {
539 m.Properties.ImageVariationPrefix = VendorVariationPrefix
540 m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
541 squashVendorSrcs(m)
542
543 // Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION.
544 // Hide other vendor variants to avoid collision.
545 vndkVersion := ctx.DeviceConfig().VndkVersion()
546 if vndkVersion != "current" && vndkVersion != "" && vndkVersion != m.Properties.VndkVersion {
547 m.Properties.HideFromMake = true
Colin Crossa9c8c9f2020-12-16 10:20:23 -0800548 m.HideFromMake()
Inseob Kime498dd92020-08-04 09:24:04 +0900549 }
550 } else if strings.HasPrefix(variant, ProductVariationPrefix) {
551 m.Properties.ImageVariationPrefix = ProductVariationPrefix
552 m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix)
Justin Yun6977e8a2020-10-29 18:24:11 +0900553 squashProductSrcs(m)
Inseob Kime498dd92020-08-04 09:24:04 +0900554 }
555}