blob: 11ba55c84d13eca924d245d995cc0352f46cc160 [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
Inseob Kim74d25562020-08-04 00:41:38 +090029type imageVariantType string
30
31const (
Yifan Hong60e0cfb2020-10-21 15:17:56 -070032 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
41func (c *Module) getImageVariantType() imageVariantType {
42 if c.Host() {
43 return hostImageVariant
44 } else if c.inVendor() {
45 return vendorImageVariant
Ivan Lozanof9e21722020-12-02 09:00:51 -050046 } else if c.InProduct() {
Inseob Kim74d25562020-08-04 00:41:38 +090047 return productImageVariant
48 } else if c.InRamdisk() {
49 return ramdiskImageVariant
Yifan Hong60e0cfb2020-10-21 15:17:56 -070050 } else if c.InVendorRamdisk() {
51 return vendorRamdiskImageVariant
Inseob Kim74d25562020-08-04 00:41:38 +090052 } else if c.InRecovery() {
53 return recoveryImageVariant
54 } else {
55 return coreImageVariant
56 }
57}
58
Inseob Kime498dd92020-08-04 09:24:04 +090059const (
60 // VendorVariationPrefix is the variant prefix used for /vendor code that compiles
61 // against the VNDK.
62 VendorVariationPrefix = "vendor."
63
64 // ProductVariationPrefix is the variant prefix used for /product code that compiles
65 // against the VNDK.
66 ProductVariationPrefix = "product."
67)
68
69func (ctx *moduleContext) ProductSpecific() bool {
70 return ctx.ModuleContext.ProductSpecific() ||
Justin Yun8a2600c2020-12-07 12:44:03 +090071 (ctx.mod.HasProductVariant() && ctx.mod.InProduct())
Inseob Kime498dd92020-08-04 09:24:04 +090072}
73
74func (ctx *moduleContext) SocSpecific() bool {
75 return ctx.ModuleContext.SocSpecific() ||
Justin Yun543f60b2020-10-18 10:54:31 +090076 (ctx.mod.HasVendorVariant() && ctx.mod.inVendor())
Inseob Kime498dd92020-08-04 09:24:04 +090077}
78
79func (ctx *moduleContextImpl) inProduct() bool {
Ivan Lozanof9e21722020-12-02 09:00:51 -050080 return ctx.mod.InProduct()
Inseob Kime498dd92020-08-04 09:24:04 +090081}
82
83func (ctx *moduleContextImpl) inVendor() bool {
84 return ctx.mod.inVendor()
85}
86
87func (ctx *moduleContextImpl) inRamdisk() bool {
88 return ctx.mod.InRamdisk()
89}
90
Yifan Hong60e0cfb2020-10-21 15:17:56 -070091func (ctx *moduleContextImpl) inVendorRamdisk() bool {
92 return ctx.mod.InVendorRamdisk()
93}
94
Inseob Kime498dd92020-08-04 09:24:04 +090095func (ctx *moduleContextImpl) inRecovery() bool {
96 return ctx.mod.InRecovery()
97}
98
Justin Yun63e9ec72020-10-29 16:49:43 +090099// Returns true when this module is configured to have core and vendor variants.
Inseob Kime498dd92020-08-04 09:24:04 +0900100func (c *Module) HasVendorVariant() bool {
Justin Yun6977e8a2020-10-29 18:24:11 +0900101 // In case of a VNDK, 'vendor_available: false' still creates a vendor variant.
Inseob Kime498dd92020-08-04 09:24:04 +0900102 return c.IsVndk() || Bool(c.VendorProperties.Vendor_available)
103}
104
Justin Yun63e9ec72020-10-29 16:49:43 +0900105// Returns true when this module is configured to have core and product variants.
106func (c *Module) HasProductVariant() bool {
Justin Yun6977e8a2020-10-29 18:24:11 +0900107 if c.VendorProperties.Product_available == nil {
108 // Without 'product_available', product variant will not be created even for VNDKs.
109 return false
110 }
111 // However, 'product_available: false' in a VNDK still creates a product variant.
Justin Yun63e9ec72020-10-29 16:49:43 +0900112 return c.IsVndk() || Bool(c.VendorProperties.Product_available)
113}
114
115// Returns true when this module is configured to have core and either product or vendor variants.
116func (c *Module) HasNonSystemVariants() bool {
Justin Yun6977e8a2020-10-29 18:24:11 +0900117 return c.HasVendorVariant() || c.HasProductVariant()
Justin Yun63e9ec72020-10-29 16:49:43 +0900118}
119
Inseob Kime498dd92020-08-04 09:24:04 +0900120// Returns true if the module is "product" variant. Usually these modules are installed in /product
Ivan Lozanof9e21722020-12-02 09:00:51 -0500121func (c *Module) InProduct() bool {
Inseob Kime498dd92020-08-04 09:24:04 +0900122 return c.Properties.ImageVariationPrefix == ProductVariationPrefix
123}
124
125// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
126func (c *Module) inVendor() bool {
127 return c.Properties.ImageVariationPrefix == VendorVariationPrefix
128}
129
130func (c *Module) InRamdisk() bool {
131 return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk()
132}
133
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700134func (c *Module) InVendorRamdisk() bool {
135 return c.ModuleBase.InVendorRamdisk() || c.ModuleBase.InstallInVendorRamdisk()
136}
137
Inseob Kime498dd92020-08-04 09:24:04 +0900138func (c *Module) InRecovery() bool {
139 return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
140}
141
142func (c *Module) OnlyInRamdisk() bool {
143 return c.ModuleBase.InstallInRamdisk()
144}
145
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700146func (c *Module) OnlyInVendorRamdisk() bool {
147 return c.ModuleBase.InstallInVendorRamdisk()
148}
149
Inseob Kime498dd92020-08-04 09:24:04 +0900150func (c *Module) OnlyInRecovery() bool {
151 return c.ModuleBase.InstallInRecovery()
152}
153
Justin Yun6977e8a2020-10-29 18:24:11 +0900154func visitPropsAndCompareVendorAndProductProps(v reflect.Value) bool {
155 if v.Kind() != reflect.Struct {
156 return true
157 }
158 for i := 0; i < v.NumField(); i++ {
159 prop := v.Field(i)
160 if prop.Kind() == reflect.Struct && v.Type().Field(i).Name == "Target" {
161 vendor_prop := prop.FieldByName("Vendor")
162 product_prop := prop.FieldByName("Product")
163 if vendor_prop.Kind() != reflect.Struct && product_prop.Kind() != reflect.Struct {
164 // Neither Target.Vendor nor Target.Product is defined
165 continue
166 }
167 if vendor_prop.Kind() != reflect.Struct || product_prop.Kind() != reflect.Struct ||
168 !reflect.DeepEqual(vendor_prop.Interface(), product_prop.Interface()) {
169 // If only one of either Target.Vendor or Target.Product is
170 // defined or they have different values, it fails the build
171 // since VNDK must have the same properties for both vendor
172 // and product variants.
173 return false
174 }
175 } else if !visitPropsAndCompareVendorAndProductProps(prop) {
176 // Visit the substructures to find Target.Vendor and Target.Product
177 return false
178 }
179 }
180 return true
181}
182
183// In the case of VNDK, vendor and product variants must have the same properties.
184// VNDK installs only one file and shares it for both vendor and product modules on
185// runtime. We may not define different versions of a VNDK lib for each partition.
186// This function is used only for the VNDK modules that is available to both vendor
187// and product partitions.
188func (c *Module) compareVendorAndProductProps() bool {
189 if !c.IsVndk() && c.VendorProperties.Product_available != nil {
190 panic(fmt.Errorf("This is only for product available VNDK libs. %q is not a VNDK library or not product available", c.Name()))
191 }
192 for _, properties := range c.GetProperties() {
193 if !visitPropsAndCompareVendorAndProductProps(reflect.ValueOf(properties).Elem()) {
194 return false
195 }
196 }
197 return true
198}
199
Inseob Kime498dd92020-08-04 09:24:04 +0900200func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
201 // Validation check
202 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
203 productSpecific := mctx.ProductSpecific()
204
Justin Yun63e9ec72020-10-29 16:49:43 +0900205 if m.VendorProperties.Vendor_available != nil {
206 if vendorSpecific {
207 mctx.PropertyErrorf("vendor_available",
208 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
209 }
Justin Yun63e9ec72020-10-29 16:49:43 +0900210 }
211
212 if m.VendorProperties.Product_available != nil {
213 if productSpecific {
214 mctx.PropertyErrorf("product_available",
215 "doesn't make sense at the same time as `product_specific: true`")
216 }
217 if vendorSpecific {
218 mctx.PropertyErrorf("product_available",
219 "cannot provide product variant from a vendor module. Please use `product_specific: true` with `vendor_available: true`")
220 }
Inseob Kime498dd92020-08-04 09:24:04 +0900221 }
222
223 if vndkdep := m.vndkdep; vndkdep != nil {
224 if vndkdep.isVndk() {
225 if vendorSpecific || productSpecific {
226 if !vndkdep.isVndkExt() {
227 mctx.PropertyErrorf("vndk",
228 "must set `extends: \"...\"` to vndk extension")
229 } else if m.VendorProperties.Vendor_available != nil {
230 mctx.PropertyErrorf("vendor_available",
231 "must not set at the same time as `vndk: {extends: \"...\"}`")
Justin Yun63e9ec72020-10-29 16:49:43 +0900232 } else if m.VendorProperties.Product_available != nil {
233 mctx.PropertyErrorf("product_available",
234 "must not set at the same time as `vndk: {extends: \"...\"}`")
Inseob Kime498dd92020-08-04 09:24:04 +0900235 }
236 } else {
237 if vndkdep.isVndkExt() {
238 mctx.PropertyErrorf("vndk",
239 "must set `vendor: true` or `product_specific: true` to set `extends: %q`",
240 m.getVndkExtendsModuleName())
241 }
242 if m.VendorProperties.Vendor_available == nil {
243 mctx.PropertyErrorf("vndk",
244 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
245 }
Justin Yun6977e8a2020-10-29 18:24:11 +0900246 if m.VendorProperties.Product_available != nil {
Justin Yunfd9e8042020-12-23 18:23:14 +0900247 // If a VNDK module creates both product and vendor variants, they
248 // must have the same properties since they share a single VNDK
249 // library on runtime.
Justin Yun6977e8a2020-10-29 18:24:11 +0900250 if !m.compareVendorAndProductProps() {
251 mctx.ModuleErrorf("product properties must have the same values with the vendor properties for VNDK modules")
252 }
253 }
Inseob Kime498dd92020-08-04 09:24:04 +0900254 }
255 } else {
256 if vndkdep.isVndkSp() {
257 mctx.PropertyErrorf("vndk",
258 "must set `enabled: true` to set `support_system_process: true`")
259 }
260 if vndkdep.isVndkExt() {
261 mctx.PropertyErrorf("vndk",
262 "must set `enabled: true` to set `extends: %q`",
263 m.getVndkExtendsModuleName())
264 }
265 }
266 }
267
268 var coreVariantNeeded bool = false
269 var ramdiskVariantNeeded bool = false
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700270 var vendorRamdiskVariantNeeded bool = false
Inseob Kime498dd92020-08-04 09:24:04 +0900271 var recoveryVariantNeeded bool = false
272
273 var vendorVariants []string
274 var productVariants []string
275
276 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
277 boardVndkVersion := mctx.DeviceConfig().VndkVersion()
278 productVndkVersion := mctx.DeviceConfig().ProductVndkVersion()
Jose Galmes6f843bc2020-12-11 13:36:29 -0800279 recoverySnapshotVersion := mctx.DeviceConfig().RecoverySnapshotVersion()
280 usingRecoverySnapshot := recoverySnapshotVersion != "current" &&
281 recoverySnapshotVersion != ""
Inseob Kime498dd92020-08-04 09:24:04 +0900282 if boardVndkVersion == "current" {
283 boardVndkVersion = platformVndkVersion
284 }
285 if productVndkVersion == "current" {
286 productVndkVersion = platformVndkVersion
287 }
288
289 if boardVndkVersion == "" {
290 // If the device isn't compiling against the VNDK, we always
291 // use the core mode.
292 coreVariantNeeded = true
293 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
294 // LL-NDK stubs only exist in the vendor and product variants,
295 // since the real libraries will be used in the core variant.
296 vendorVariants = append(vendorVariants,
297 platformVndkVersion,
298 boardVndkVersion,
299 )
300 productVariants = append(productVariants,
301 platformVndkVersion,
302 productVndkVersion,
303 )
304 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
305 // ... and LL-NDK headers as well
306 vendorVariants = append(vendorVariants,
307 platformVndkVersion,
308 boardVndkVersion,
309 )
310 productVariants = append(productVariants,
311 platformVndkVersion,
312 productVndkVersion,
313 )
314 } else if m.isSnapshotPrebuilt() {
315 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
316 // PRODUCT_EXTRA_VNDK_VERSIONS.
317 if snapshot, ok := m.linker.(interface {
318 version() string
319 }); ok {
Jose Galmes6f843bc2020-12-11 13:36:29 -0800320 if m.InstallInRecovery() {
321 recoveryVariantNeeded = true
322 } else {
323 vendorVariants = append(vendorVariants, snapshot.version())
324 }
Inseob Kime498dd92020-08-04 09:24:04 +0900325 } else {
326 mctx.ModuleErrorf("version is unknown for snapshot prebuilt")
327 }
Ivan Lozanof9e21722020-12-02 09:00:51 -0500328 } else if m.HasNonSystemVariants() && !m.IsVndkExt() {
Justin Yun63e9ec72020-10-29 16:49:43 +0900329 // This will be available to /system unless it is product_specific
330 // which will be handled later.
Inseob Kime498dd92020-08-04 09:24:04 +0900331 coreVariantNeeded = true
332
333 // We assume that modules under proprietary paths are compatible for
334 // BOARD_VNDK_VERSION. The other modules are regarded as AOSP, or
335 // PLATFORM_VNDK_VERSION.
Justin Yun63e9ec72020-10-29 16:49:43 +0900336 if m.HasVendorVariant() {
337 if isVendorProprietaryModule(mctx) {
338 vendorVariants = append(vendorVariants, boardVndkVersion)
339 } else {
340 vendorVariants = append(vendorVariants, platformVndkVersion)
341 }
Inseob Kime498dd92020-08-04 09:24:04 +0900342 }
343
Justin Yun6977e8a2020-10-29 18:24:11 +0900344 // product_available modules are available to /product.
345 if m.HasProductVariant() {
346 productVariants = append(productVariants, platformVndkVersion)
347 // VNDK is always PLATFORM_VNDK_VERSION
348 if !m.IsVndk() {
349 productVariants = append(productVariants, productVndkVersion)
350 }
Inseob Kime498dd92020-08-04 09:24:04 +0900351 }
352 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
353 // This will be available in /vendor (or /odm) only
354
355 // kernel_headers is a special module type whose exported headers
356 // are coming from DeviceKernelHeaders() which is always vendor
357 // dependent. They'll always have both vendor variants.
358 // For other modules, we assume that modules under proprietary
359 // paths are compatible for BOARD_VNDK_VERSION. The other modules
360 // are regarded as AOSP, which is PLATFORM_VNDK_VERSION.
361 if _, ok := m.linker.(*kernelHeadersDecorator); ok {
362 vendorVariants = append(vendorVariants,
363 platformVndkVersion,
364 boardVndkVersion,
365 )
Bill Peckham945441c2020-08-31 16:07:58 -0700366 } else if isVendorProprietaryModule(mctx) {
Inseob Kime498dd92020-08-04 09:24:04 +0900367 vendorVariants = append(vendorVariants, boardVndkVersion)
368 } else {
369 vendorVariants = append(vendorVariants, platformVndkVersion)
370 }
Colin Cross127bb8b2020-12-16 16:46:01 -0800371 } else if lib := moduleLibraryInterface(m); lib != nil && lib.hasLLNDKStubs() {
372 // This is an LLNDK library. The implementation of the library will be on /system,
373 // and vendor and product variants will be created with LLNDK stubs.
374 coreVariantNeeded = true
375 vendorVariants = append(vendorVariants,
376 platformVndkVersion,
377 boardVndkVersion,
378 )
379 productVariants = append(productVariants,
380 platformVndkVersion,
381 productVndkVersion,
382 )
Inseob Kime498dd92020-08-04 09:24:04 +0900383 } else {
384 // This is either in /system (or similar: /data), or is a
385 // modules built with the NDK. Modules built with the NDK
386 // will be restricted using the existing link type checks.
387 coreVariantNeeded = true
388 }
389
390 if boardVndkVersion != "" && productVndkVersion != "" {
391 if coreVariantNeeded && productSpecific && String(m.Properties.Sdk_version) == "" {
392 // The module has "product_specific: true" that does not create core variant.
393 coreVariantNeeded = false
394 productVariants = append(productVariants, productVndkVersion)
395 }
396 } else {
397 // Unless PRODUCT_PRODUCT_VNDK_VERSION is set, product partition has no
398 // restriction to use system libs.
399 // No product variants defined in this case.
400 productVariants = []string{}
401 }
402
403 if Bool(m.Properties.Ramdisk_available) {
404 ramdiskVariantNeeded = true
405 }
406
407 if m.ModuleBase.InstallInRamdisk() {
408 ramdiskVariantNeeded = true
409 coreVariantNeeded = false
410 }
411
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700412 if Bool(m.Properties.Vendor_ramdisk_available) {
413 vendorRamdiskVariantNeeded = true
414 }
415
416 if m.ModuleBase.InstallInVendorRamdisk() {
417 vendorRamdiskVariantNeeded = true
418 coreVariantNeeded = false
419 }
420
Inseob Kime498dd92020-08-04 09:24:04 +0900421 if Bool(m.Properties.Recovery_available) {
422 recoveryVariantNeeded = true
423 }
424
425 if m.ModuleBase.InstallInRecovery() {
426 recoveryVariantNeeded = true
427 coreVariantNeeded = false
428 }
429
Jose Galmes6f843bc2020-12-11 13:36:29 -0800430 // If using a snapshot, the recovery variant under AOSP directories is not needed,
431 // except for kernel headers, which needs all variants.
432 if _, ok := m.linker.(*kernelHeadersDecorator); !ok &&
433 !m.isSnapshotPrebuilt() &&
434 usingRecoverySnapshot &&
435 !isRecoveryProprietaryModule(mctx) {
436 recoveryVariantNeeded = false
437 }
438
Inseob Kime498dd92020-08-04 09:24:04 +0900439 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
440 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, VendorVariationPrefix+variant)
441 }
442
443 for _, variant := range android.FirstUniqueStrings(productVariants) {
444 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, ProductVariationPrefix+variant)
445 }
446
447 m.Properties.RamdiskVariantNeeded = ramdiskVariantNeeded
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700448 m.Properties.VendorRamdiskVariantNeeded = vendorRamdiskVariantNeeded
Inseob Kime498dd92020-08-04 09:24:04 +0900449 m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
450 m.Properties.CoreVariantNeeded = coreVariantNeeded
Jose Galmes6f843bc2020-12-11 13:36:29 -0800451
452 // Disable the module if no variants are needed.
453 if !ramdiskVariantNeeded &&
454 !recoveryVariantNeeded &&
455 !coreVariantNeeded &&
456 len(m.Properties.ExtraVariants) == 0 {
457 m.Disable()
458 }
Inseob Kime498dd92020-08-04 09:24:04 +0900459}
460
461func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
462 return c.Properties.CoreVariantNeeded
463}
464
465func (c *Module) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
466 return c.Properties.RamdiskVariantNeeded
467}
468
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700469func (c *Module) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
470 return c.Properties.VendorRamdiskVariantNeeded
471}
472
Inseob Kime498dd92020-08-04 09:24:04 +0900473func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
474 return c.Properties.RecoveryVariantNeeded
475}
476
477func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
478 return c.Properties.ExtraVariants
479}
480
Justin Yun63e9ec72020-10-29 16:49:43 +0900481func squashVendorSrcs(m *Module) {
482 if lib, ok := m.compiler.(*libraryDecorator); ok {
483 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
484 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
485
486 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
487 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
488
489 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
490 lib.baseCompiler.Properties.Target.Vendor.Exclude_generated_sources...)
491 }
492}
493
494func squashProductSrcs(m *Module) {
495 if lib, ok := m.compiler.(*libraryDecorator); ok {
496 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
497 lib.baseCompiler.Properties.Target.Product.Srcs...)
498
499 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
500 lib.baseCompiler.Properties.Target.Product.Exclude_srcs...)
501
502 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
503 lib.baseCompiler.Properties.Target.Product.Exclude_generated_sources...)
504 }
505}
506
507func squashRecoverySrcs(m *Module) {
508 if lib, ok := m.compiler.(*libraryDecorator); ok {
509 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
510 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
511
512 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
513 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
514
515 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
516 lib.baseCompiler.Properties.Target.Recovery.Exclude_generated_sources...)
517 }
518}
519
520func squashVendorRamdiskSrcs(m *Module) {
521 if lib, ok := m.compiler.(*libraryDecorator); ok {
522 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, lib.baseCompiler.Properties.Target.Vendor_ramdisk.Exclude_srcs...)
523 }
524}
525
Inseob Kime498dd92020-08-04 09:24:04 +0900526func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
527 m := module.(*Module)
Yifan Hong6da33c22020-10-27 15:01:21 -0700528 if variant == android.RamdiskVariation {
Inseob Kime498dd92020-08-04 09:24:04 +0900529 m.MakeAsPlatform()
Yifan Hong6da33c22020-10-27 15:01:21 -0700530 } else if variant == android.VendorRamdiskVariation {
531 m.MakeAsPlatform()
532 squashVendorRamdiskSrcs(m)
Inseob Kime498dd92020-08-04 09:24:04 +0900533 } else if variant == android.RecoveryVariation {
534 m.MakeAsPlatform()
535 squashRecoverySrcs(m)
536 } else if strings.HasPrefix(variant, VendorVariationPrefix) {
537 m.Properties.ImageVariationPrefix = VendorVariationPrefix
538 m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
539 squashVendorSrcs(m)
540
541 // Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION.
542 // Hide other vendor variants to avoid collision.
543 vndkVersion := ctx.DeviceConfig().VndkVersion()
544 if vndkVersion != "current" && vndkVersion != "" && vndkVersion != m.Properties.VndkVersion {
545 m.Properties.HideFromMake = true
Colin Crossa9c8c9f2020-12-16 10:20:23 -0800546 m.HideFromMake()
Inseob Kime498dd92020-08-04 09:24:04 +0900547 }
548 } else if strings.HasPrefix(variant, ProductVariationPrefix) {
549 m.Properties.ImageVariationPrefix = ProductVariationPrefix
550 m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix)
Justin Yun6977e8a2020-10-29 18:24:11 +0900551 squashProductSrcs(m)
Inseob Kime498dd92020-08-04 09:24:04 +0900552 }
553}