blob: 86c7e60a7a6486394ef34a61630015fc34d3e36c [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 Yunc0d8c492021-01-07 17:45:31 +090070 // Additionally check if this module is inProduct() that means it is a "product" variant of a
71 // module. As well as product specific modules, product variants must be installed to /product.
72 return ctx.ModuleContext.ProductSpecific() || ctx.mod.InProduct()
Inseob Kime498dd92020-08-04 09:24:04 +090073}
74
75func (ctx *moduleContext) SocSpecific() bool {
Justin Yunc0d8c492021-01-07 17:45:31 +090076 // Additionally check if this module is inVendor() that means it is a "vendor" variant of a
77 // module. As well as SoC specific modules, vendor variants must be installed to /vendor.
78 return ctx.ModuleContext.SocSpecific() || ctx.mod.inVendor()
Inseob Kime498dd92020-08-04 09:24:04 +090079}
80
81func (ctx *moduleContextImpl) inProduct() bool {
Ivan Lozanof9e21722020-12-02 09:00:51 -050082 return ctx.mod.InProduct()
Inseob Kime498dd92020-08-04 09:24:04 +090083}
84
85func (ctx *moduleContextImpl) inVendor() bool {
86 return ctx.mod.inVendor()
87}
88
89func (ctx *moduleContextImpl) inRamdisk() bool {
90 return ctx.mod.InRamdisk()
91}
92
Yifan Hong60e0cfb2020-10-21 15:17:56 -070093func (ctx *moduleContextImpl) inVendorRamdisk() bool {
94 return ctx.mod.InVendorRamdisk()
95}
96
Inseob Kime498dd92020-08-04 09:24:04 +090097func (ctx *moduleContextImpl) inRecovery() bool {
98 return ctx.mod.InRecovery()
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 Yunc0d8c492021-01-07 17:45:31 +0900103 return Bool(c.VendorProperties.Vendor_available)
Inseob Kime498dd92020-08-04 09:24:04 +0900104}
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 Yunc0d8c492021-01-07 17:45:31 +0900108 return Bool(c.VendorProperties.Product_available)
Justin Yun63e9ec72020-10-29 16:49:43 +0900109}
110
111// Returns true when this module is configured to have core and either product or vendor variants.
112func (c *Module) HasNonSystemVariants() bool {
Justin Yun6977e8a2020-10-29 18:24:11 +0900113 return c.HasVendorVariant() || c.HasProductVariant()
Justin Yun63e9ec72020-10-29 16:49:43 +0900114}
115
Inseob Kime498dd92020-08-04 09:24:04 +0900116// Returns true if the module is "product" variant. Usually these modules are installed in /product
Ivan Lozanof9e21722020-12-02 09:00:51 -0500117func (c *Module) InProduct() bool {
Inseob Kime498dd92020-08-04 09:24:04 +0900118 return c.Properties.ImageVariationPrefix == ProductVariationPrefix
119}
120
121// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
122func (c *Module) inVendor() bool {
123 return c.Properties.ImageVariationPrefix == VendorVariationPrefix
124}
125
126func (c *Module) InRamdisk() bool {
127 return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk()
128}
129
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700130func (c *Module) InVendorRamdisk() bool {
131 return c.ModuleBase.InVendorRamdisk() || c.ModuleBase.InstallInVendorRamdisk()
132}
133
Inseob Kime498dd92020-08-04 09:24:04 +0900134func (c *Module) InRecovery() bool {
135 return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
136}
137
138func (c *Module) OnlyInRamdisk() bool {
139 return c.ModuleBase.InstallInRamdisk()
140}
141
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700142func (c *Module) OnlyInVendorRamdisk() bool {
143 return c.ModuleBase.InstallInVendorRamdisk()
144}
145
Inseob Kime498dd92020-08-04 09:24:04 +0900146func (c *Module) OnlyInRecovery() bool {
147 return c.ModuleBase.InstallInRecovery()
148}
149
Justin Yun6977e8a2020-10-29 18:24:11 +0900150func visitPropsAndCompareVendorAndProductProps(v reflect.Value) bool {
151 if v.Kind() != reflect.Struct {
152 return true
153 }
154 for i := 0; i < v.NumField(); i++ {
155 prop := v.Field(i)
156 if prop.Kind() == reflect.Struct && v.Type().Field(i).Name == "Target" {
157 vendor_prop := prop.FieldByName("Vendor")
158 product_prop := prop.FieldByName("Product")
159 if vendor_prop.Kind() != reflect.Struct && product_prop.Kind() != reflect.Struct {
160 // Neither Target.Vendor nor Target.Product is defined
161 continue
162 }
163 if vendor_prop.Kind() != reflect.Struct || product_prop.Kind() != reflect.Struct ||
164 !reflect.DeepEqual(vendor_prop.Interface(), product_prop.Interface()) {
165 // If only one of either Target.Vendor or Target.Product is
166 // defined or they have different values, it fails the build
167 // since VNDK must have the same properties for both vendor
168 // and product variants.
169 return false
170 }
171 } else if !visitPropsAndCompareVendorAndProductProps(prop) {
172 // Visit the substructures to find Target.Vendor and Target.Product
173 return false
174 }
175 }
176 return true
177}
178
179// In the case of VNDK, vendor and product variants must have the same properties.
180// VNDK installs only one file and shares it for both vendor and product modules on
181// runtime. We may not define different versions of a VNDK lib for each partition.
182// This function is used only for the VNDK modules that is available to both vendor
183// and product partitions.
184func (c *Module) compareVendorAndProductProps() bool {
Justin Yunc0d8c492021-01-07 17:45:31 +0900185 if !c.IsVndk() && !Bool(c.VendorProperties.Product_available) {
Justin Yun6977e8a2020-10-29 18:24:11 +0900186 panic(fmt.Errorf("This is only for product available VNDK libs. %q is not a VNDK library or not product available", c.Name()))
187 }
188 for _, properties := range c.GetProperties() {
189 if !visitPropsAndCompareVendorAndProductProps(reflect.ValueOf(properties).Elem()) {
190 return false
191 }
192 }
193 return true
194}
195
Inseob Kime498dd92020-08-04 09:24:04 +0900196func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
197 // Validation check
198 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
199 productSpecific := mctx.ProductSpecific()
200
Justin Yunc0d8c492021-01-07 17:45:31 +0900201 if Bool(m.VendorProperties.Vendor_available) {
Justin Yun63e9ec72020-10-29 16:49:43 +0900202 if vendorSpecific {
203 mctx.PropertyErrorf("vendor_available",
204 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
205 }
Justin Yun63e9ec72020-10-29 16:49:43 +0900206 }
207
Justin Yunc0d8c492021-01-07 17:45:31 +0900208 if Bool(m.VendorProperties.Product_available) {
Justin Yun63e9ec72020-10-29 16:49:43 +0900209 if productSpecific {
210 mctx.PropertyErrorf("product_available",
211 "doesn't make sense at the same time as `product_specific: true`")
212 }
213 if vendorSpecific {
214 mctx.PropertyErrorf("product_available",
215 "cannot provide product variant from a vendor module. Please use `product_specific: true` with `vendor_available: true`")
216 }
Inseob Kime498dd92020-08-04 09:24:04 +0900217 }
218
219 if vndkdep := m.vndkdep; vndkdep != nil {
220 if vndkdep.isVndk() {
221 if vendorSpecific || productSpecific {
222 if !vndkdep.isVndkExt() {
223 mctx.PropertyErrorf("vndk",
224 "must set `extends: \"...\"` to vndk extension")
Justin Yunc0d8c492021-01-07 17:45:31 +0900225 } else if Bool(m.VendorProperties.Vendor_available) {
Inseob Kime498dd92020-08-04 09:24:04 +0900226 mctx.PropertyErrorf("vendor_available",
227 "must not set at the same time as `vndk: {extends: \"...\"}`")
Justin Yunc0d8c492021-01-07 17:45:31 +0900228 } else if Bool(m.VendorProperties.Product_available) {
Justin Yun63e9ec72020-10-29 16:49:43 +0900229 mctx.PropertyErrorf("product_available",
230 "must not set at the same time as `vndk: {extends: \"...\"}`")
Inseob Kime498dd92020-08-04 09:24:04 +0900231 }
232 } else {
233 if vndkdep.isVndkExt() {
234 mctx.PropertyErrorf("vndk",
235 "must set `vendor: true` or `product_specific: true` to set `extends: %q`",
236 m.getVndkExtendsModuleName())
237 }
Justin Yunc0d8c492021-01-07 17:45:31 +0900238 if !Bool(m.VendorProperties.Vendor_available) {
Inseob Kime498dd92020-08-04 09:24:04 +0900239 mctx.PropertyErrorf("vndk",
Justin Yunc0d8c492021-01-07 17:45:31 +0900240 "vendor_available must be set to true when `vndk: {enabled: true}`")
Inseob Kime498dd92020-08-04 09:24:04 +0900241 }
Justin Yunc0d8c492021-01-07 17:45:31 +0900242 if Bool(m.VendorProperties.Product_available) {
Justin Yunfd9e8042020-12-23 18:23:14 +0900243 // If a VNDK module creates both product and vendor variants, they
244 // must have the same properties since they share a single VNDK
245 // library on runtime.
Justin Yun6977e8a2020-10-29 18:24:11 +0900246 if !m.compareVendorAndProductProps() {
247 mctx.ModuleErrorf("product properties must have the same values with the vendor properties for VNDK modules")
248 }
249 }
Inseob Kime498dd92020-08-04 09:24:04 +0900250 }
251 } else {
252 if vndkdep.isVndkSp() {
253 mctx.PropertyErrorf("vndk",
254 "must set `enabled: true` to set `support_system_process: true`")
255 }
256 if vndkdep.isVndkExt() {
257 mctx.PropertyErrorf("vndk",
258 "must set `enabled: true` to set `extends: %q`",
259 m.getVndkExtendsModuleName())
260 }
261 }
262 }
263
264 var coreVariantNeeded bool = false
265 var ramdiskVariantNeeded bool = false
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700266 var vendorRamdiskVariantNeeded bool = false
Inseob Kime498dd92020-08-04 09:24:04 +0900267 var recoveryVariantNeeded bool = false
268
269 var vendorVariants []string
270 var productVariants []string
271
272 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
273 boardVndkVersion := mctx.DeviceConfig().VndkVersion()
274 productVndkVersion := mctx.DeviceConfig().ProductVndkVersion()
Jose Galmes6f843bc2020-12-11 13:36:29 -0800275 recoverySnapshotVersion := mctx.DeviceConfig().RecoverySnapshotVersion()
276 usingRecoverySnapshot := recoverySnapshotVersion != "current" &&
277 recoverySnapshotVersion != ""
Inseob Kime498dd92020-08-04 09:24:04 +0900278 if boardVndkVersion == "current" {
279 boardVndkVersion = platformVndkVersion
280 }
281 if productVndkVersion == "current" {
282 productVndkVersion = platformVndkVersion
283 }
284
Colin Crossb5f6fa62021-01-06 17:05:04 -0800285 _, isLLNDKLibrary := m.linker.(*llndkStubDecorator)
286 _, isLLNDKHeaders := m.linker.(*llndkHeadersDecorator)
287 lib := moduleLibraryInterface(m)
288 hasLLNDKStubs := lib != nil && lib.hasLLNDKStubs()
289
290 if isLLNDKLibrary || isLLNDKHeaders || hasLLNDKStubs {
291 // This is an LLNDK library. The implementation of the library will be on /system,
292 // and vendor and product variants will be created with LLNDK stubs.
293 // The LLNDK libraries need vendor variants even if there is no VNDK.
294 // The obsolete llndk_library and llndk_headers modules also need the vendor variants
295 // so the cc_library LLNDK stubs can depend on them.
296 if hasLLNDKStubs {
297 coreVariantNeeded = true
298 }
299 if platformVndkVersion != "" {
300 vendorVariants = append(vendorVariants, platformVndkVersion)
301 productVariants = append(productVariants, platformVndkVersion)
302 }
303 if boardVndkVersion != "" {
304 vendorVariants = append(vendorVariants, boardVndkVersion)
305 }
306 if productVndkVersion != "" {
307 productVariants = append(productVariants, productVndkVersion)
308 }
309 } else if boardVndkVersion == "" {
Inseob Kime498dd92020-08-04 09:24:04 +0900310 // If the device isn't compiling against the VNDK, we always
311 // use the core mode.
312 coreVariantNeeded = true
Inseob Kime498dd92020-08-04 09:24:04 +0900313 } else if m.isSnapshotPrebuilt() {
314 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
315 // PRODUCT_EXTRA_VNDK_VERSIONS.
316 if snapshot, ok := m.linker.(interface {
317 version() string
318 }); ok {
Jose Galmes6f843bc2020-12-11 13:36:29 -0800319 if m.InstallInRecovery() {
320 recoveryVariantNeeded = true
321 } else {
322 vendorVariants = append(vendorVariants, snapshot.version())
323 }
Inseob Kime498dd92020-08-04 09:24:04 +0900324 } else {
325 mctx.ModuleErrorf("version is unknown for snapshot prebuilt")
326 }
Ivan Lozanof9e21722020-12-02 09:00:51 -0500327 } else if m.HasNonSystemVariants() && !m.IsVndkExt() {
Justin Yun63e9ec72020-10-29 16:49:43 +0900328 // This will be available to /system unless it is product_specific
329 // which will be handled later.
Inseob Kime498dd92020-08-04 09:24:04 +0900330 coreVariantNeeded = true
331
332 // We assume that modules under proprietary paths are compatible for
333 // BOARD_VNDK_VERSION. The other modules are regarded as AOSP, or
334 // PLATFORM_VNDK_VERSION.
Justin Yun63e9ec72020-10-29 16:49:43 +0900335 if m.HasVendorVariant() {
336 if isVendorProprietaryModule(mctx) {
337 vendorVariants = append(vendorVariants, boardVndkVersion)
338 } else {
339 vendorVariants = append(vendorVariants, platformVndkVersion)
340 }
Inseob Kime498dd92020-08-04 09:24:04 +0900341 }
342
Justin Yun6977e8a2020-10-29 18:24:11 +0900343 // product_available modules are available to /product.
344 if m.HasProductVariant() {
345 productVariants = append(productVariants, platformVndkVersion)
346 // VNDK is always PLATFORM_VNDK_VERSION
347 if !m.IsVndk() {
348 productVariants = append(productVariants, productVndkVersion)
349 }
Inseob Kime498dd92020-08-04 09:24:04 +0900350 }
351 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
352 // This will be available in /vendor (or /odm) only
353
354 // kernel_headers is a special module type whose exported headers
355 // are coming from DeviceKernelHeaders() which is always vendor
356 // dependent. They'll always have both vendor variants.
357 // For other modules, we assume that modules under proprietary
358 // paths are compatible for BOARD_VNDK_VERSION. The other modules
359 // are regarded as AOSP, which is PLATFORM_VNDK_VERSION.
360 if _, ok := m.linker.(*kernelHeadersDecorator); ok {
361 vendorVariants = append(vendorVariants,
362 platformVndkVersion,
363 boardVndkVersion,
364 )
Bill Peckham945441c2020-08-31 16:07:58 -0700365 } else if isVendorProprietaryModule(mctx) {
Inseob Kime498dd92020-08-04 09:24:04 +0900366 vendorVariants = append(vendorVariants, boardVndkVersion)
367 } else {
368 vendorVariants = append(vendorVariants, platformVndkVersion)
369 }
370 } else {
371 // This is either in /system (or similar: /data), or is a
372 // modules built with the NDK. Modules built with the NDK
373 // will be restricted using the existing link type checks.
374 coreVariantNeeded = true
375 }
376
377 if boardVndkVersion != "" && productVndkVersion != "" {
378 if coreVariantNeeded && productSpecific && String(m.Properties.Sdk_version) == "" {
379 // The module has "product_specific: true" that does not create core variant.
380 coreVariantNeeded = false
381 productVariants = append(productVariants, productVndkVersion)
382 }
383 } else {
384 // Unless PRODUCT_PRODUCT_VNDK_VERSION is set, product partition has no
385 // restriction to use system libs.
386 // No product variants defined in this case.
387 productVariants = []string{}
388 }
389
390 if Bool(m.Properties.Ramdisk_available) {
391 ramdiskVariantNeeded = true
392 }
393
394 if m.ModuleBase.InstallInRamdisk() {
395 ramdiskVariantNeeded = true
396 coreVariantNeeded = false
397 }
398
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700399 if Bool(m.Properties.Vendor_ramdisk_available) {
400 vendorRamdiskVariantNeeded = true
401 }
402
403 if m.ModuleBase.InstallInVendorRamdisk() {
404 vendorRamdiskVariantNeeded = true
405 coreVariantNeeded = false
406 }
407
Inseob Kime498dd92020-08-04 09:24:04 +0900408 if Bool(m.Properties.Recovery_available) {
409 recoveryVariantNeeded = true
410 }
411
412 if m.ModuleBase.InstallInRecovery() {
413 recoveryVariantNeeded = true
414 coreVariantNeeded = false
415 }
416
Jose Galmes6f843bc2020-12-11 13:36:29 -0800417 // If using a snapshot, the recovery variant under AOSP directories is not needed,
418 // except for kernel headers, which needs all variants.
419 if _, ok := m.linker.(*kernelHeadersDecorator); !ok &&
420 !m.isSnapshotPrebuilt() &&
421 usingRecoverySnapshot &&
422 !isRecoveryProprietaryModule(mctx) {
423 recoveryVariantNeeded = false
424 }
425
Inseob Kime498dd92020-08-04 09:24:04 +0900426 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
427 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, VendorVariationPrefix+variant)
428 }
429
430 for _, variant := range android.FirstUniqueStrings(productVariants) {
431 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, ProductVariationPrefix+variant)
432 }
433
434 m.Properties.RamdiskVariantNeeded = ramdiskVariantNeeded
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700435 m.Properties.VendorRamdiskVariantNeeded = vendorRamdiskVariantNeeded
Inseob Kime498dd92020-08-04 09:24:04 +0900436 m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
437 m.Properties.CoreVariantNeeded = coreVariantNeeded
Jose Galmes6f843bc2020-12-11 13:36:29 -0800438
439 // Disable the module if no variants are needed.
440 if !ramdiskVariantNeeded &&
441 !recoveryVariantNeeded &&
442 !coreVariantNeeded &&
443 len(m.Properties.ExtraVariants) == 0 {
444 m.Disable()
445 }
Inseob Kime498dd92020-08-04 09:24:04 +0900446}
447
448func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
449 return c.Properties.CoreVariantNeeded
450}
451
452func (c *Module) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
453 return c.Properties.RamdiskVariantNeeded
454}
455
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700456func (c *Module) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
457 return c.Properties.VendorRamdiskVariantNeeded
458}
459
Inseob Kime498dd92020-08-04 09:24:04 +0900460func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
461 return c.Properties.RecoveryVariantNeeded
462}
463
464func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
465 return c.Properties.ExtraVariants
466}
467
Justin Yun63e9ec72020-10-29 16:49:43 +0900468func squashVendorSrcs(m *Module) {
469 if lib, ok := m.compiler.(*libraryDecorator); ok {
470 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
471 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
472
473 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
474 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
475
476 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
477 lib.baseCompiler.Properties.Target.Vendor.Exclude_generated_sources...)
478 }
479}
480
481func squashProductSrcs(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.Product.Srcs...)
485
486 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
487 lib.baseCompiler.Properties.Target.Product.Exclude_srcs...)
488
489 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
490 lib.baseCompiler.Properties.Target.Product.Exclude_generated_sources...)
491 }
492}
493
494func squashRecoverySrcs(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.Recovery.Srcs...)
498
499 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
500 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
501
502 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
503 lib.baseCompiler.Properties.Target.Recovery.Exclude_generated_sources...)
504 }
505}
506
507func squashVendorRamdiskSrcs(m *Module) {
508 if lib, ok := m.compiler.(*libraryDecorator); ok {
509 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, lib.baseCompiler.Properties.Target.Vendor_ramdisk.Exclude_srcs...)
510 }
511}
512
Inseob Kime498dd92020-08-04 09:24:04 +0900513func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
514 m := module.(*Module)
Yifan Hong6da33c22020-10-27 15:01:21 -0700515 if variant == android.RamdiskVariation {
Inseob Kime498dd92020-08-04 09:24:04 +0900516 m.MakeAsPlatform()
Yifan Hong6da33c22020-10-27 15:01:21 -0700517 } else if variant == android.VendorRamdiskVariation {
518 m.MakeAsPlatform()
519 squashVendorRamdiskSrcs(m)
Inseob Kime498dd92020-08-04 09:24:04 +0900520 } else if variant == android.RecoveryVariation {
521 m.MakeAsPlatform()
522 squashRecoverySrcs(m)
523 } else if strings.HasPrefix(variant, VendorVariationPrefix) {
524 m.Properties.ImageVariationPrefix = VendorVariationPrefix
525 m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
526 squashVendorSrcs(m)
527
528 // Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION.
529 // Hide other vendor variants to avoid collision.
530 vndkVersion := ctx.DeviceConfig().VndkVersion()
531 if vndkVersion != "current" && vndkVersion != "" && vndkVersion != m.Properties.VndkVersion {
532 m.Properties.HideFromMake = true
Colin Crossa9c8c9f2020-12-16 10:20:23 -0800533 m.HideFromMake()
Inseob Kime498dd92020-08-04 09:24:04 +0900534 }
535 } else if strings.HasPrefix(variant, ProductVariationPrefix) {
536 m.Properties.ImageVariationPrefix = ProductVariationPrefix
537 m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix)
Justin Yun6977e8a2020-10-29 18:24:11 +0900538 squashProductSrcs(m)
Inseob Kime498dd92020-08-04 09:24:04 +0900539 }
540}