blob: b55e1f41723b2b9bb99a1f1f5184c70fcb2e82f3 [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 {
Justin Yun63e9ec72020-10-29 16:49:43 +090070 //TODO(b/150902910): Replace HasNonSystemVariants() with HasProductVariant()
Inseob Kime498dd92020-08-04 09:24:04 +090071 return ctx.ModuleContext.ProductSpecific() ||
Ivan Lozanof9e21722020-12-02 09:00:51 -050072 (ctx.mod.HasNonSystemVariants() && ctx.mod.InProduct())
Inseob Kime498dd92020-08-04 09:24:04 +090073}
74
75func (ctx *moduleContext) SocSpecific() bool {
76 return ctx.ModuleContext.SocSpecific() ||
Justin Yun543f60b2020-10-18 10:54:31 +090077 (ctx.mod.HasVendorVariant() && ctx.mod.inVendor())
Inseob Kime498dd92020-08-04 09:24:04 +090078}
79
80func (ctx *moduleContextImpl) inProduct() bool {
Ivan Lozanof9e21722020-12-02 09:00:51 -050081 return ctx.mod.InProduct()
Inseob Kime498dd92020-08-04 09:24:04 +090082}
83
84func (ctx *moduleContextImpl) inVendor() bool {
85 return ctx.mod.inVendor()
86}
87
88func (ctx *moduleContextImpl) inRamdisk() bool {
89 return ctx.mod.InRamdisk()
90}
91
Yifan Hong60e0cfb2020-10-21 15:17:56 -070092func (ctx *moduleContextImpl) inVendorRamdisk() bool {
93 return ctx.mod.InVendorRamdisk()
94}
95
Inseob Kime498dd92020-08-04 09:24:04 +090096func (ctx *moduleContextImpl) inRecovery() bool {
97 return ctx.mod.InRecovery()
98}
99
Justin Yun63e9ec72020-10-29 16:49:43 +0900100// Returns true when this module is configured to have core and vendor variants.
Inseob Kime498dd92020-08-04 09:24:04 +0900101func (c *Module) HasVendorVariant() bool {
Justin Yun6977e8a2020-10-29 18:24:11 +0900102 // In case of a VNDK, 'vendor_available: false' still creates a vendor variant.
Inseob Kime498dd92020-08-04 09:24:04 +0900103 return c.IsVndk() || Bool(c.VendorProperties.Vendor_available)
104}
105
Justin Yun63e9ec72020-10-29 16:49:43 +0900106// Returns true when this module is configured to have core and product variants.
107func (c *Module) HasProductVariant() bool {
Justin Yun6977e8a2020-10-29 18:24:11 +0900108 if c.VendorProperties.Product_available == nil {
109 // Without 'product_available', product variant will not be created even for VNDKs.
110 return false
111 }
112 // However, 'product_available: false' in a VNDK still creates a product variant.
Justin Yun63e9ec72020-10-29 16:49:43 +0900113 return c.IsVndk() || Bool(c.VendorProperties.Product_available)
114}
115
116// Returns true when this module is configured to have core and either product or vendor variants.
117func (c *Module) HasNonSystemVariants() bool {
Justin Yun6977e8a2020-10-29 18:24:11 +0900118 return c.HasVendorVariant() || c.HasProductVariant()
Justin Yun63e9ec72020-10-29 16:49:43 +0900119}
120
Inseob Kime498dd92020-08-04 09:24:04 +0900121// Returns true if the module is "product" variant. Usually these modules are installed in /product
Ivan Lozanof9e21722020-12-02 09:00:51 -0500122func (c *Module) InProduct() bool {
Inseob Kime498dd92020-08-04 09:24:04 +0900123 return c.Properties.ImageVariationPrefix == ProductVariationPrefix
124}
125
126// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
127func (c *Module) inVendor() bool {
128 return c.Properties.ImageVariationPrefix == VendorVariationPrefix
129}
130
131func (c *Module) InRamdisk() bool {
132 return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk()
133}
134
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700135func (c *Module) InVendorRamdisk() bool {
136 return c.ModuleBase.InVendorRamdisk() || c.ModuleBase.InstallInVendorRamdisk()
137}
138
Inseob Kime498dd92020-08-04 09:24:04 +0900139func (c *Module) InRecovery() bool {
140 return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
141}
142
143func (c *Module) OnlyInRamdisk() bool {
144 return c.ModuleBase.InstallInRamdisk()
145}
146
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700147func (c *Module) OnlyInVendorRamdisk() bool {
148 return c.ModuleBase.InstallInVendorRamdisk()
149}
150
Inseob Kime498dd92020-08-04 09:24:04 +0900151func (c *Module) OnlyInRecovery() bool {
152 return c.ModuleBase.InstallInRecovery()
153}
154
Justin Yun6977e8a2020-10-29 18:24:11 +0900155func visitPropsAndCompareVendorAndProductProps(v reflect.Value) bool {
156 if v.Kind() != reflect.Struct {
157 return true
158 }
159 for i := 0; i < v.NumField(); i++ {
160 prop := v.Field(i)
161 if prop.Kind() == reflect.Struct && v.Type().Field(i).Name == "Target" {
162 vendor_prop := prop.FieldByName("Vendor")
163 product_prop := prop.FieldByName("Product")
164 if vendor_prop.Kind() != reflect.Struct && product_prop.Kind() != reflect.Struct {
165 // Neither Target.Vendor nor Target.Product is defined
166 continue
167 }
168 if vendor_prop.Kind() != reflect.Struct || product_prop.Kind() != reflect.Struct ||
169 !reflect.DeepEqual(vendor_prop.Interface(), product_prop.Interface()) {
170 // If only one of either Target.Vendor or Target.Product is
171 // defined or they have different values, it fails the build
172 // since VNDK must have the same properties for both vendor
173 // and product variants.
174 return false
175 }
176 } else if !visitPropsAndCompareVendorAndProductProps(prop) {
177 // Visit the substructures to find Target.Vendor and Target.Product
178 return false
179 }
180 }
181 return true
182}
183
184// In the case of VNDK, vendor and product variants must have the same properties.
185// VNDK installs only one file and shares it for both vendor and product modules on
186// runtime. We may not define different versions of a VNDK lib for each partition.
187// This function is used only for the VNDK modules that is available to both vendor
188// and product partitions.
189func (c *Module) compareVendorAndProductProps() bool {
190 if !c.IsVndk() && c.VendorProperties.Product_available != nil {
191 panic(fmt.Errorf("This is only for product available VNDK libs. %q is not a VNDK library or not product available", c.Name()))
192 }
193 for _, properties := range c.GetProperties() {
194 if !visitPropsAndCompareVendorAndProductProps(reflect.ValueOf(properties).Elem()) {
195 return false
196 }
197 }
198 return true
199}
200
Inseob Kime498dd92020-08-04 09:24:04 +0900201func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
202 // Validation check
203 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
204 productSpecific := mctx.ProductSpecific()
205
Justin Yun63e9ec72020-10-29 16:49:43 +0900206 if m.VendorProperties.Vendor_available != nil {
207 if vendorSpecific {
208 mctx.PropertyErrorf("vendor_available",
209 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
210 }
Justin Yun63e9ec72020-10-29 16:49:43 +0900211 }
212
213 if m.VendorProperties.Product_available != nil {
214 if productSpecific {
215 mctx.PropertyErrorf("product_available",
216 "doesn't make sense at the same time as `product_specific: true`")
217 }
218 if vendorSpecific {
219 mctx.PropertyErrorf("product_available",
220 "cannot provide product variant from a vendor module. Please use `product_specific: true` with `vendor_available: true`")
221 }
Inseob Kime498dd92020-08-04 09:24:04 +0900222 }
223
224 if vndkdep := m.vndkdep; vndkdep != nil {
225 if vndkdep.isVndk() {
226 if vendorSpecific || productSpecific {
227 if !vndkdep.isVndkExt() {
228 mctx.PropertyErrorf("vndk",
229 "must set `extends: \"...\"` to vndk extension")
230 } else if m.VendorProperties.Vendor_available != nil {
231 mctx.PropertyErrorf("vendor_available",
232 "must not set at the same time as `vndk: {extends: \"...\"}`")
Justin Yun63e9ec72020-10-29 16:49:43 +0900233 } else if m.VendorProperties.Product_available != nil {
234 mctx.PropertyErrorf("product_available",
235 "must not set at the same time as `vndk: {extends: \"...\"}`")
Inseob Kime498dd92020-08-04 09:24:04 +0900236 }
237 } else {
238 if vndkdep.isVndkExt() {
239 mctx.PropertyErrorf("vndk",
240 "must set `vendor: true` or `product_specific: true` to set `extends: %q`",
241 m.getVndkExtendsModuleName())
242 }
243 if m.VendorProperties.Vendor_available == nil {
244 mctx.PropertyErrorf("vndk",
245 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
246 }
Justin Yun6977e8a2020-10-29 18:24:11 +0900247 if m.VendorProperties.Product_available != nil {
248 // If product_available is defined for a VNDK, make sure vendor_available and
249 // product_available has the same value since `false` for these properties
250 // means the module is VNDK-private.
251 if Bool(m.VendorProperties.Vendor_available) != Bool(m.VendorProperties.Product_available) {
252 mctx.PropertyErrorf("product_available", "may not have different value than `vendor_available` for a VNDK")
253 }
254 // Also, both variants must have the same properties since they share a single VNDK library on runtime.
255 if !m.compareVendorAndProductProps() {
256 mctx.ModuleErrorf("product properties must have the same values with the vendor properties for VNDK modules")
257 }
258 }
Inseob Kime498dd92020-08-04 09:24:04 +0900259 }
260 } else {
261 if vndkdep.isVndkSp() {
262 mctx.PropertyErrorf("vndk",
263 "must set `enabled: true` to set `support_system_process: true`")
264 }
265 if vndkdep.isVndkExt() {
266 mctx.PropertyErrorf("vndk",
267 "must set `enabled: true` to set `extends: %q`",
268 m.getVndkExtendsModuleName())
269 }
270 }
271 }
272
273 var coreVariantNeeded bool = false
274 var ramdiskVariantNeeded bool = false
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700275 var vendorRamdiskVariantNeeded bool = false
Inseob Kime498dd92020-08-04 09:24:04 +0900276 var recoveryVariantNeeded bool = false
277
278 var vendorVariants []string
279 var productVariants []string
280
281 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
282 boardVndkVersion := mctx.DeviceConfig().VndkVersion()
283 productVndkVersion := mctx.DeviceConfig().ProductVndkVersion()
284 if boardVndkVersion == "current" {
285 boardVndkVersion = platformVndkVersion
286 }
287 if productVndkVersion == "current" {
288 productVndkVersion = platformVndkVersion
289 }
290
291 if boardVndkVersion == "" {
292 // If the device isn't compiling against the VNDK, we always
293 // use the core mode.
294 coreVariantNeeded = true
295 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
296 // LL-NDK stubs only exist in the vendor and product variants,
297 // since the real libraries will be used in the core variant.
298 vendorVariants = append(vendorVariants,
299 platformVndkVersion,
300 boardVndkVersion,
301 )
302 productVariants = append(productVariants,
303 platformVndkVersion,
304 productVndkVersion,
305 )
306 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
307 // ... and LL-NDK headers as well
308 vendorVariants = append(vendorVariants,
309 platformVndkVersion,
310 boardVndkVersion,
311 )
312 productVariants = append(productVariants,
313 platformVndkVersion,
314 productVndkVersion,
315 )
316 } else if m.isSnapshotPrebuilt() {
317 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
318 // PRODUCT_EXTRA_VNDK_VERSIONS.
319 if snapshot, ok := m.linker.(interface {
320 version() string
321 }); ok {
322 vendorVariants = append(vendorVariants, snapshot.version())
323 } else {
324 mctx.ModuleErrorf("version is unknown for snapshot prebuilt")
325 }
Ivan Lozanof9e21722020-12-02 09:00:51 -0500326 } else if m.HasNonSystemVariants() && !m.IsVndkExt() {
Justin Yun63e9ec72020-10-29 16:49:43 +0900327 // This will be available to /system unless it is product_specific
328 // which will be handled later.
Inseob Kime498dd92020-08-04 09:24:04 +0900329 coreVariantNeeded = true
330
331 // We assume that modules under proprietary paths are compatible for
332 // BOARD_VNDK_VERSION. The other modules are regarded as AOSP, or
333 // PLATFORM_VNDK_VERSION.
Justin Yun63e9ec72020-10-29 16:49:43 +0900334 if m.HasVendorVariant() {
335 if isVendorProprietaryModule(mctx) {
336 vendorVariants = append(vendorVariants, boardVndkVersion)
337 } else {
338 vendorVariants = append(vendorVariants, platformVndkVersion)
339 }
Inseob Kime498dd92020-08-04 09:24:04 +0900340 }
341
Justin Yun6977e8a2020-10-29 18:24:11 +0900342 // product_available modules are available to /product.
343 if m.HasProductVariant() {
344 productVariants = append(productVariants, platformVndkVersion)
345 // VNDK is always PLATFORM_VNDK_VERSION
346 if !m.IsVndk() {
347 productVariants = append(productVariants, productVndkVersion)
348 }
Inseob Kime498dd92020-08-04 09:24:04 +0900349 }
350 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
351 // This will be available in /vendor (or /odm) only
352
353 // kernel_headers is a special module type whose exported headers
354 // are coming from DeviceKernelHeaders() which is always vendor
355 // dependent. They'll always have both vendor variants.
356 // For other modules, we assume that modules under proprietary
357 // paths are compatible for BOARD_VNDK_VERSION. The other modules
358 // are regarded as AOSP, which is PLATFORM_VNDK_VERSION.
359 if _, ok := m.linker.(*kernelHeadersDecorator); ok {
360 vendorVariants = append(vendorVariants,
361 platformVndkVersion,
362 boardVndkVersion,
363 )
Bill Peckham945441c2020-08-31 16:07:58 -0700364 } else if isVendorProprietaryModule(mctx) {
Inseob Kime498dd92020-08-04 09:24:04 +0900365 vendorVariants = append(vendorVariants, boardVndkVersion)
366 } else {
367 vendorVariants = append(vendorVariants, platformVndkVersion)
368 }
Colin Cross127bb8b2020-12-16 16:46:01 -0800369 } else if lib := moduleLibraryInterface(m); lib != nil && lib.hasLLNDKStubs() {
370 // This is an LLNDK library. The implementation of the library will be on /system,
371 // and vendor and product variants will be created with LLNDK stubs.
372 coreVariantNeeded = true
373 vendorVariants = append(vendorVariants,
374 platformVndkVersion,
375 boardVndkVersion,
376 )
377 productVariants = append(productVariants,
378 platformVndkVersion,
379 productVndkVersion,
380 )
Inseob Kime498dd92020-08-04 09:24:04 +0900381 } else {
382 // This is either in /system (or similar: /data), or is a
383 // modules built with the NDK. Modules built with the NDK
384 // will be restricted using the existing link type checks.
385 coreVariantNeeded = true
386 }
387
388 if boardVndkVersion != "" && productVndkVersion != "" {
389 if coreVariantNeeded && productSpecific && String(m.Properties.Sdk_version) == "" {
390 // The module has "product_specific: true" that does not create core variant.
391 coreVariantNeeded = false
392 productVariants = append(productVariants, productVndkVersion)
393 }
394 } else {
395 // Unless PRODUCT_PRODUCT_VNDK_VERSION is set, product partition has no
396 // restriction to use system libs.
397 // No product variants defined in this case.
398 productVariants = []string{}
399 }
400
401 if Bool(m.Properties.Ramdisk_available) {
402 ramdiskVariantNeeded = true
403 }
404
405 if m.ModuleBase.InstallInRamdisk() {
406 ramdiskVariantNeeded = true
407 coreVariantNeeded = false
408 }
409
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700410 if Bool(m.Properties.Vendor_ramdisk_available) {
411 vendorRamdiskVariantNeeded = true
412 }
413
414 if m.ModuleBase.InstallInVendorRamdisk() {
415 vendorRamdiskVariantNeeded = true
416 coreVariantNeeded = false
417 }
418
Inseob Kime498dd92020-08-04 09:24:04 +0900419 if Bool(m.Properties.Recovery_available) {
420 recoveryVariantNeeded = true
421 }
422
423 if m.ModuleBase.InstallInRecovery() {
424 recoveryVariantNeeded = true
425 coreVariantNeeded = false
426 }
427
428 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
429 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, VendorVariationPrefix+variant)
430 }
431
432 for _, variant := range android.FirstUniqueStrings(productVariants) {
433 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, ProductVariationPrefix+variant)
434 }
435
436 m.Properties.RamdiskVariantNeeded = ramdiskVariantNeeded
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700437 m.Properties.VendorRamdiskVariantNeeded = vendorRamdiskVariantNeeded
Inseob Kime498dd92020-08-04 09:24:04 +0900438 m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
439 m.Properties.CoreVariantNeeded = coreVariantNeeded
440}
441
442func (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 Kime498dd92020-08-04 09:24:04 +0900454func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
455 return c.Properties.RecoveryVariantNeeded
456}
457
458func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
459 return c.Properties.ExtraVariants
460}
461
Justin Yun63e9ec72020-10-29 16:49:43 +0900462func squashVendorSrcs(m *Module) {
463 if lib, ok := m.compiler.(*libraryDecorator); ok {
464 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
465 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
466
467 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
468 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
469
470 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
471 lib.baseCompiler.Properties.Target.Vendor.Exclude_generated_sources...)
472 }
473}
474
475func squashProductSrcs(m *Module) {
476 if lib, ok := m.compiler.(*libraryDecorator); ok {
477 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
478 lib.baseCompiler.Properties.Target.Product.Srcs...)
479
480 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
481 lib.baseCompiler.Properties.Target.Product.Exclude_srcs...)
482
483 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
484 lib.baseCompiler.Properties.Target.Product.Exclude_generated_sources...)
485 }
486}
487
488func squashRecoverySrcs(m *Module) {
489 if lib, ok := m.compiler.(*libraryDecorator); ok {
490 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
491 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
492
493 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
494 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
495
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 {
503 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, lib.baseCompiler.Properties.Target.Vendor_ramdisk.Exclude_srcs...)
504 }
505}
506
Inseob Kime498dd92020-08-04 09:24:04 +0900507func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
508 m := module.(*Module)
Yifan Hong6da33c22020-10-27 15:01:21 -0700509 if variant == android.RamdiskVariation {
Inseob Kime498dd92020-08-04 09:24:04 +0900510 m.MakeAsPlatform()
Yifan Hong6da33c22020-10-27 15:01:21 -0700511 } else if variant == android.VendorRamdiskVariation {
512 m.MakeAsPlatform()
513 squashVendorRamdiskSrcs(m)
Inseob Kime498dd92020-08-04 09:24:04 +0900514 } else if variant == android.RecoveryVariation {
515 m.MakeAsPlatform()
516 squashRecoverySrcs(m)
517 } else if strings.HasPrefix(variant, VendorVariationPrefix) {
518 m.Properties.ImageVariationPrefix = VendorVariationPrefix
519 m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
520 squashVendorSrcs(m)
521
522 // Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION.
523 // Hide other vendor variants to avoid collision.
524 vndkVersion := ctx.DeviceConfig().VndkVersion()
525 if vndkVersion != "current" && vndkVersion != "" && vndkVersion != m.Properties.VndkVersion {
526 m.Properties.HideFromMake = true
Colin Crossa9c8c9f2020-12-16 10:20:23 -0800527 m.HideFromMake()
Inseob Kime498dd92020-08-04 09:24:04 +0900528 }
529 } else if strings.HasPrefix(variant, ProductVariationPrefix) {
530 m.Properties.ImageVariationPrefix = ProductVariationPrefix
531 m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix)
Justin Yun6977e8a2020-10-29 18:24:11 +0900532 squashProductSrcs(m)
Inseob Kime498dd92020-08-04 09:24:04 +0900533 }
534}