blob: 231da7e29ee7b5aa74b6d8079be97c38d2258dca [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 Yunc0d8c492021-01-07 17:45:31 +090052 // Additionally check if this module is inProduct() that means it is a "product" variant of a
53 // module. As well as product specific modules, product variants must be installed to /product.
54 return ctx.ModuleContext.ProductSpecific() || ctx.mod.InProduct()
Inseob Kime498dd92020-08-04 09:24:04 +090055}
56
57func (ctx *moduleContext) SocSpecific() bool {
Justin Yunc0d8c492021-01-07 17:45:31 +090058 // Additionally check if this module is inVendor() that means it is a "vendor" variant of a
Justin Yunebcf0c52021-01-08 18:00:19 +090059 // module. As well as SoC specific modules, vendor variants must be installed to /vendor
60 // unless they have "odm_available: true".
61 return ctx.ModuleContext.SocSpecific() || (ctx.mod.InVendor() && !ctx.mod.VendorVariantToOdm())
62}
63
64func (ctx *moduleContext) DeviceSpecific() bool {
65 // Some vendor variants want to be installed to /odm by setting "odm_available: true".
66 return ctx.ModuleContext.DeviceSpecific() || (ctx.mod.InVendor() && ctx.mod.VendorVariantToOdm())
Inseob Kime498dd92020-08-04 09:24:04 +090067}
68
69func (ctx *moduleContextImpl) inProduct() bool {
Ivan Lozanof9e21722020-12-02 09:00:51 -050070 return ctx.mod.InProduct()
Inseob Kime498dd92020-08-04 09:24:04 +090071}
72
73func (ctx *moduleContextImpl) inVendor() bool {
Ivan Lozano3968d8f2020-12-14 11:27:52 -050074 return ctx.mod.InVendor()
Inseob Kime498dd92020-08-04 09:24:04 +090075}
76
77func (ctx *moduleContextImpl) inRamdisk() bool {
78 return ctx.mod.InRamdisk()
79}
80
Yifan Hong60e0cfb2020-10-21 15:17:56 -070081func (ctx *moduleContextImpl) inVendorRamdisk() bool {
82 return ctx.mod.InVendorRamdisk()
83}
84
Inseob Kime498dd92020-08-04 09:24:04 +090085func (ctx *moduleContextImpl) inRecovery() bool {
86 return ctx.mod.InRecovery()
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 {
Inseob Kime498dd92020-08-04 09:24:04 +0900112 return c.Properties.ImageVariationPrefix == ProductVariationPrefix
113}
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 {
Inseob Kime498dd92020-08-04 09:24:04 +0900117 return c.Properties.ImageVariationPrefix == VendorVariationPrefix
118}
119
120func (c *Module) InRamdisk() bool {
121 return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk()
122}
123
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700124func (c *Module) InVendorRamdisk() bool {
125 return c.ModuleBase.InVendorRamdisk() || c.ModuleBase.InstallInVendorRamdisk()
126}
127
Inseob Kime498dd92020-08-04 09:24:04 +0900128func (c *Module) InRecovery() bool {
129 return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
130}
131
132func (c *Module) OnlyInRamdisk() bool {
133 return c.ModuleBase.InstallInRamdisk()
134}
135
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700136func (c *Module) OnlyInVendorRamdisk() bool {
137 return c.ModuleBase.InstallInVendorRamdisk()
138}
139
Inseob Kime498dd92020-08-04 09:24:04 +0900140func (c *Module) OnlyInRecovery() bool {
141 return c.ModuleBase.InstallInRecovery()
142}
143
Justin Yun6977e8a2020-10-29 18:24:11 +0900144func visitPropsAndCompareVendorAndProductProps(v reflect.Value) bool {
145 if v.Kind() != reflect.Struct {
146 return true
147 }
148 for i := 0; i < v.NumField(); i++ {
149 prop := v.Field(i)
150 if prop.Kind() == reflect.Struct && v.Type().Field(i).Name == "Target" {
151 vendor_prop := prop.FieldByName("Vendor")
152 product_prop := prop.FieldByName("Product")
153 if vendor_prop.Kind() != reflect.Struct && product_prop.Kind() != reflect.Struct {
154 // Neither Target.Vendor nor Target.Product is defined
155 continue
156 }
157 if vendor_prop.Kind() != reflect.Struct || product_prop.Kind() != reflect.Struct ||
158 !reflect.DeepEqual(vendor_prop.Interface(), product_prop.Interface()) {
159 // If only one of either Target.Vendor or Target.Product is
160 // defined or they have different values, it fails the build
161 // since VNDK must have the same properties for both vendor
162 // and product variants.
163 return false
164 }
165 } else if !visitPropsAndCompareVendorAndProductProps(prop) {
166 // Visit the substructures to find Target.Vendor and Target.Product
167 return false
168 }
169 }
170 return true
171}
172
173// In the case of VNDK, vendor and product variants must have the same properties.
174// VNDK installs only one file and shares it for both vendor and product modules on
175// runtime. We may not define different versions of a VNDK lib for each partition.
176// This function is used only for the VNDK modules that is available to both vendor
177// and product partitions.
178func (c *Module) compareVendorAndProductProps() bool {
Justin Yunc0d8c492021-01-07 17:45:31 +0900179 if !c.IsVndk() && !Bool(c.VendorProperties.Product_available) {
Justin Yun6977e8a2020-10-29 18:24:11 +0900180 panic(fmt.Errorf("This is only for product available VNDK libs. %q is not a VNDK library or not product available", c.Name()))
181 }
182 for _, properties := range c.GetProperties() {
183 if !visitPropsAndCompareVendorAndProductProps(reflect.ValueOf(properties).Elem()) {
184 return false
185 }
186 }
187 return true
188}
189
Inseob Kime498dd92020-08-04 09:24:04 +0900190func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
191 // Validation check
192 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
193 productSpecific := mctx.ProductSpecific()
194
Justin Yunc0d8c492021-01-07 17:45:31 +0900195 if Bool(m.VendorProperties.Vendor_available) {
Justin Yun63e9ec72020-10-29 16:49:43 +0900196 if vendorSpecific {
197 mctx.PropertyErrorf("vendor_available",
Justin Yunebcf0c52021-01-08 18:00:19 +0900198 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific: true`")
199 }
200 if Bool(m.VendorProperties.Odm_available) {
201 mctx.PropertyErrorf("vendor_available",
202 "doesn't make sense at the same time as `odm_available: true`")
203 }
204 }
205
206 if Bool(m.VendorProperties.Odm_available) {
207 if vendorSpecific {
208 mctx.PropertyErrorf("odm_available",
209 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific: true`")
Justin Yun63e9ec72020-10-29 16:49:43 +0900210 }
Justin Yun63e9ec72020-10-29 16:49:43 +0900211 }
212
Justin Yunc0d8c492021-01-07 17:45:31 +0900213 if Bool(m.VendorProperties.Product_available) {
Justin Yun63e9ec72020-10-29 16:49:43 +0900214 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")
Justin Yunc0d8c492021-01-07 17:45:31 +0900230 } else if Bool(m.VendorProperties.Vendor_available) {
Inseob Kime498dd92020-08-04 09:24:04 +0900231 mctx.PropertyErrorf("vendor_available",
232 "must not set at the same time as `vndk: {extends: \"...\"}`")
Justin Yunc0d8c492021-01-07 17:45:31 +0900233 } else if Bool(m.VendorProperties.Product_available) {
Justin Yun63e9ec72020-10-29 16:49:43 +0900234 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 }
Justin Yunc0d8c492021-01-07 17:45:31 +0900243 if !Bool(m.VendorProperties.Vendor_available) {
Inseob Kime498dd92020-08-04 09:24:04 +0900244 mctx.PropertyErrorf("vndk",
Justin Yunc0d8c492021-01-07 17:45:31 +0900245 "vendor_available must be set to true when `vndk: {enabled: true}`")
Inseob Kime498dd92020-08-04 09:24:04 +0900246 }
Justin Yunc0d8c492021-01-07 17:45:31 +0900247 if Bool(m.VendorProperties.Product_available) {
Justin Yunfd9e8042020-12-23 18:23:14 +0900248 // If a VNDK module creates both product and vendor variants, they
249 // must have the same properties since they share a single VNDK
250 // library on runtime.
Justin Yun6977e8a2020-10-29 18:24:11 +0900251 if !m.compareVendorAndProductProps() {
252 mctx.ModuleErrorf("product properties must have the same values with the vendor properties for VNDK modules")
253 }
254 }
Inseob Kime498dd92020-08-04 09:24:04 +0900255 }
256 } else {
257 if vndkdep.isVndkSp() {
258 mctx.PropertyErrorf("vndk",
259 "must set `enabled: true` to set `support_system_process: true`")
260 }
261 if vndkdep.isVndkExt() {
262 mctx.PropertyErrorf("vndk",
263 "must set `enabled: true` to set `extends: %q`",
264 m.getVndkExtendsModuleName())
265 }
266 }
267 }
268
269 var coreVariantNeeded bool = false
270 var ramdiskVariantNeeded bool = false
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700271 var vendorRamdiskVariantNeeded bool = false
Inseob Kime498dd92020-08-04 09:24:04 +0900272 var recoveryVariantNeeded bool = false
273
274 var vendorVariants []string
275 var productVariants []string
276
277 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
278 boardVndkVersion := mctx.DeviceConfig().VndkVersion()
279 productVndkVersion := mctx.DeviceConfig().ProductVndkVersion()
Jose Galmes6f843bc2020-12-11 13:36:29 -0800280 recoverySnapshotVersion := mctx.DeviceConfig().RecoverySnapshotVersion()
281 usingRecoverySnapshot := recoverySnapshotVersion != "current" &&
282 recoverySnapshotVersion != ""
Inseob Kime498dd92020-08-04 09:24:04 +0900283 if boardVndkVersion == "current" {
284 boardVndkVersion = platformVndkVersion
285 }
286 if productVndkVersion == "current" {
287 productVndkVersion = platformVndkVersion
288 }
289
Colin Crossb5f6fa62021-01-06 17:05:04 -0800290 _, isLLNDKLibrary := m.linker.(*llndkStubDecorator)
291 _, isLLNDKHeaders := m.linker.(*llndkHeadersDecorator)
292 lib := moduleLibraryInterface(m)
293 hasLLNDKStubs := lib != nil && lib.hasLLNDKStubs()
294
295 if isLLNDKLibrary || isLLNDKHeaders || hasLLNDKStubs {
296 // This is an LLNDK library. The implementation of the library will be on /system,
297 // and vendor and product variants will be created with LLNDK stubs.
298 // The LLNDK libraries need vendor variants even if there is no VNDK.
299 // The obsolete llndk_library and llndk_headers modules also need the vendor variants
300 // so the cc_library LLNDK stubs can depend on them.
301 if hasLLNDKStubs {
302 coreVariantNeeded = true
303 }
304 if platformVndkVersion != "" {
305 vendorVariants = append(vendorVariants, platformVndkVersion)
306 productVariants = append(productVariants, platformVndkVersion)
307 }
308 if boardVndkVersion != "" {
309 vendorVariants = append(vendorVariants, boardVndkVersion)
310 }
311 if productVndkVersion != "" {
312 productVariants = append(productVariants, productVndkVersion)
313 }
314 } else if boardVndkVersion == "" {
Inseob Kime498dd92020-08-04 09:24:04 +0900315 // If the device isn't compiling against the VNDK, we always
316 // use the core mode.
317 coreVariantNeeded = true
Inseob Kime498dd92020-08-04 09:24:04 +0900318 } else if m.isSnapshotPrebuilt() {
319 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
320 // PRODUCT_EXTRA_VNDK_VERSIONS.
321 if snapshot, ok := m.linker.(interface {
322 version() string
323 }); ok {
Jose Galmes6f843bc2020-12-11 13:36:29 -0800324 if m.InstallInRecovery() {
325 recoveryVariantNeeded = true
326 } else {
327 vendorVariants = append(vendorVariants, snapshot.version())
328 }
Inseob Kime498dd92020-08-04 09:24:04 +0900329 } else {
330 mctx.ModuleErrorf("version is unknown for snapshot prebuilt")
331 }
Ivan Lozanof9e21722020-12-02 09:00:51 -0500332 } else if m.HasNonSystemVariants() && !m.IsVndkExt() {
Justin Yun63e9ec72020-10-29 16:49:43 +0900333 // This will be available to /system unless it is product_specific
334 // which will be handled later.
Inseob Kime498dd92020-08-04 09:24:04 +0900335 coreVariantNeeded = true
336
337 // We assume that modules under proprietary paths are compatible for
338 // BOARD_VNDK_VERSION. The other modules are regarded as AOSP, or
339 // PLATFORM_VNDK_VERSION.
Justin Yun63e9ec72020-10-29 16:49:43 +0900340 if m.HasVendorVariant() {
341 if isVendorProprietaryModule(mctx) {
342 vendorVariants = append(vendorVariants, boardVndkVersion)
343 } else {
344 vendorVariants = append(vendorVariants, platformVndkVersion)
345 }
Inseob Kime498dd92020-08-04 09:24:04 +0900346 }
347
Justin Yun6977e8a2020-10-29 18:24:11 +0900348 // product_available modules are available to /product.
349 if m.HasProductVariant() {
350 productVariants = append(productVariants, platformVndkVersion)
351 // VNDK is always PLATFORM_VNDK_VERSION
352 if !m.IsVndk() {
353 productVariants = append(productVariants, productVndkVersion)
354 }
Inseob Kime498dd92020-08-04 09:24:04 +0900355 }
356 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
357 // This will be available in /vendor (or /odm) only
358
359 // kernel_headers is a special module type whose exported headers
360 // are coming from DeviceKernelHeaders() which is always vendor
361 // dependent. They'll always have both vendor variants.
362 // For other modules, we assume that modules under proprietary
363 // paths are compatible for BOARD_VNDK_VERSION. The other modules
364 // are regarded as AOSP, which is PLATFORM_VNDK_VERSION.
365 if _, ok := m.linker.(*kernelHeadersDecorator); ok {
366 vendorVariants = append(vendorVariants,
367 platformVndkVersion,
368 boardVndkVersion,
369 )
Bill Peckham945441c2020-08-31 16:07:58 -0700370 } else if isVendorProprietaryModule(mctx) {
Inseob Kime498dd92020-08-04 09:24:04 +0900371 vendorVariants = append(vendorVariants, boardVndkVersion)
372 } else {
373 vendorVariants = append(vendorVariants, platformVndkVersion)
374 }
375 } else {
376 // This is either in /system (or similar: /data), or is a
377 // modules built with the NDK. Modules built with the NDK
378 // will be restricted using the existing link type checks.
379 coreVariantNeeded = true
380 }
381
382 if boardVndkVersion != "" && productVndkVersion != "" {
383 if coreVariantNeeded && productSpecific && String(m.Properties.Sdk_version) == "" {
384 // The module has "product_specific: true" that does not create core variant.
385 coreVariantNeeded = false
386 productVariants = append(productVariants, productVndkVersion)
387 }
388 } else {
389 // Unless PRODUCT_PRODUCT_VNDK_VERSION is set, product partition has no
390 // restriction to use system libs.
391 // No product variants defined in this case.
392 productVariants = []string{}
393 }
394
395 if Bool(m.Properties.Ramdisk_available) {
396 ramdiskVariantNeeded = true
397 }
398
399 if m.ModuleBase.InstallInRamdisk() {
400 ramdiskVariantNeeded = true
401 coreVariantNeeded = false
402 }
403
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700404 if Bool(m.Properties.Vendor_ramdisk_available) {
405 vendorRamdiskVariantNeeded = true
406 }
407
408 if m.ModuleBase.InstallInVendorRamdisk() {
409 vendorRamdiskVariantNeeded = true
410 coreVariantNeeded = false
411 }
412
Inseob Kime498dd92020-08-04 09:24:04 +0900413 if Bool(m.Properties.Recovery_available) {
414 recoveryVariantNeeded = true
415 }
416
417 if m.ModuleBase.InstallInRecovery() {
418 recoveryVariantNeeded = true
419 coreVariantNeeded = false
420 }
421
Jose Galmes6f843bc2020-12-11 13:36:29 -0800422 // If using a snapshot, the recovery variant under AOSP directories is not needed,
423 // except for kernel headers, which needs all variants.
424 if _, ok := m.linker.(*kernelHeadersDecorator); !ok &&
425 !m.isSnapshotPrebuilt() &&
426 usingRecoverySnapshot &&
427 !isRecoveryProprietaryModule(mctx) {
428 recoveryVariantNeeded = false
429 }
430
Inseob Kime498dd92020-08-04 09:24:04 +0900431 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
432 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, VendorVariationPrefix+variant)
433 }
434
435 for _, variant := range android.FirstUniqueStrings(productVariants) {
436 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, ProductVariationPrefix+variant)
437 }
438
439 m.Properties.RamdiskVariantNeeded = ramdiskVariantNeeded
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700440 m.Properties.VendorRamdiskVariantNeeded = vendorRamdiskVariantNeeded
Inseob Kime498dd92020-08-04 09:24:04 +0900441 m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
442 m.Properties.CoreVariantNeeded = coreVariantNeeded
Jose Galmes6f843bc2020-12-11 13:36:29 -0800443
444 // Disable the module if no variants are needed.
445 if !ramdiskVariantNeeded &&
446 !recoveryVariantNeeded &&
447 !coreVariantNeeded &&
448 len(m.Properties.ExtraVariants) == 0 {
449 m.Disable()
450 }
Inseob Kime498dd92020-08-04 09:24:04 +0900451}
452
453func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
454 return c.Properties.CoreVariantNeeded
455}
456
457func (c *Module) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
458 return c.Properties.RamdiskVariantNeeded
459}
460
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700461func (c *Module) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
462 return c.Properties.VendorRamdiskVariantNeeded
463}
464
Inseob Kime498dd92020-08-04 09:24:04 +0900465func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
466 return c.Properties.RecoveryVariantNeeded
467}
468
469func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
470 return c.Properties.ExtraVariants
471}
472
Justin Yun63e9ec72020-10-29 16:49:43 +0900473func squashVendorSrcs(m *Module) {
474 if lib, ok := m.compiler.(*libraryDecorator); ok {
475 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
476 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
477
478 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
479 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
480
481 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
482 lib.baseCompiler.Properties.Target.Vendor.Exclude_generated_sources...)
483 }
484}
485
486func squashProductSrcs(m *Module) {
487 if lib, ok := m.compiler.(*libraryDecorator); ok {
488 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
489 lib.baseCompiler.Properties.Target.Product.Srcs...)
490
491 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
492 lib.baseCompiler.Properties.Target.Product.Exclude_srcs...)
493
494 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
495 lib.baseCompiler.Properties.Target.Product.Exclude_generated_sources...)
496 }
497}
498
499func squashRecoverySrcs(m *Module) {
500 if lib, ok := m.compiler.(*libraryDecorator); ok {
501 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
502 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
503
504 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
505 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
506
507 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
508 lib.baseCompiler.Properties.Target.Recovery.Exclude_generated_sources...)
509 }
510}
511
512func squashVendorRamdiskSrcs(m *Module) {
513 if lib, ok := m.compiler.(*libraryDecorator); ok {
514 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, lib.baseCompiler.Properties.Target.Vendor_ramdisk.Exclude_srcs...)
515 }
516}
517
Inseob Kime498dd92020-08-04 09:24:04 +0900518func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
519 m := module.(*Module)
Yifan Hong6da33c22020-10-27 15:01:21 -0700520 if variant == android.RamdiskVariation {
Inseob Kime498dd92020-08-04 09:24:04 +0900521 m.MakeAsPlatform()
Yifan Hong6da33c22020-10-27 15:01:21 -0700522 } else if variant == android.VendorRamdiskVariation {
523 m.MakeAsPlatform()
524 squashVendorRamdiskSrcs(m)
Inseob Kime498dd92020-08-04 09:24:04 +0900525 } else if variant == android.RecoveryVariation {
526 m.MakeAsPlatform()
527 squashRecoverySrcs(m)
528 } else if strings.HasPrefix(variant, VendorVariationPrefix) {
529 m.Properties.ImageVariationPrefix = VendorVariationPrefix
530 m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
531 squashVendorSrcs(m)
532
533 // Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION.
534 // Hide other vendor variants to avoid collision.
535 vndkVersion := ctx.DeviceConfig().VndkVersion()
536 if vndkVersion != "current" && vndkVersion != "" && vndkVersion != m.Properties.VndkVersion {
537 m.Properties.HideFromMake = true
Colin Crossa9c8c9f2020-12-16 10:20:23 -0800538 m.HideFromMake()
Inseob Kime498dd92020-08-04 09:24:04 +0900539 }
540 } else if strings.HasPrefix(variant, ProductVariationPrefix) {
541 m.Properties.ImageVariationPrefix = ProductVariationPrefix
542 m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix)
Justin Yun6977e8a2020-10-29 18:24:11 +0900543 squashProductSrcs(m)
Inseob Kime498dd92020-08-04 09:24:04 +0900544 }
545}