blob: 13095fca565d3dc4325ca775e612ddfb7d3db208 [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
59 // module. As well as SoC specific modules, vendor variants must be installed to /vendor.
Ivan Lozano3968d8f2020-12-14 11:27:52 -050060 return ctx.ModuleContext.SocSpecific() || ctx.mod.InVendor()
Inseob Kime498dd92020-08-04 09:24:04 +090061}
62
63func (ctx *moduleContextImpl) inProduct() bool {
Ivan Lozanof9e21722020-12-02 09:00:51 -050064 return ctx.mod.InProduct()
Inseob Kime498dd92020-08-04 09:24:04 +090065}
66
67func (ctx *moduleContextImpl) inVendor() bool {
Ivan Lozano3968d8f2020-12-14 11:27:52 -050068 return ctx.mod.InVendor()
Inseob Kime498dd92020-08-04 09:24:04 +090069}
70
71func (ctx *moduleContextImpl) inRamdisk() bool {
72 return ctx.mod.InRamdisk()
73}
74
Yifan Hong60e0cfb2020-10-21 15:17:56 -070075func (ctx *moduleContextImpl) inVendorRamdisk() bool {
76 return ctx.mod.InVendorRamdisk()
77}
78
Inseob Kime498dd92020-08-04 09:24:04 +090079func (ctx *moduleContextImpl) inRecovery() bool {
80 return ctx.mod.InRecovery()
81}
82
Justin Yun63e9ec72020-10-29 16:49:43 +090083// Returns true when this module is configured to have core and vendor variants.
Inseob Kime498dd92020-08-04 09:24:04 +090084func (c *Module) HasVendorVariant() bool {
Justin Yunc0d8c492021-01-07 17:45:31 +090085 return Bool(c.VendorProperties.Vendor_available)
Inseob Kime498dd92020-08-04 09:24:04 +090086}
87
Justin Yun63e9ec72020-10-29 16:49:43 +090088// Returns true when this module is configured to have core and product variants.
89func (c *Module) HasProductVariant() bool {
Justin Yunc0d8c492021-01-07 17:45:31 +090090 return Bool(c.VendorProperties.Product_available)
Justin Yun63e9ec72020-10-29 16:49:43 +090091}
92
93// Returns true when this module is configured to have core and either product or vendor variants.
94func (c *Module) HasNonSystemVariants() bool {
Justin Yun6977e8a2020-10-29 18:24:11 +090095 return c.HasVendorVariant() || c.HasProductVariant()
Justin Yun63e9ec72020-10-29 16:49:43 +090096}
97
Inseob Kime498dd92020-08-04 09:24:04 +090098// Returns true if the module is "product" variant. Usually these modules are installed in /product
Ivan Lozanof9e21722020-12-02 09:00:51 -050099func (c *Module) InProduct() bool {
Inseob Kime498dd92020-08-04 09:24:04 +0900100 return c.Properties.ImageVariationPrefix == ProductVariationPrefix
101}
102
103// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500104func (c *Module) InVendor() bool {
Inseob Kime498dd92020-08-04 09:24:04 +0900105 return c.Properties.ImageVariationPrefix == VendorVariationPrefix
106}
107
108func (c *Module) InRamdisk() bool {
109 return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk()
110}
111
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700112func (c *Module) InVendorRamdisk() bool {
113 return c.ModuleBase.InVendorRamdisk() || c.ModuleBase.InstallInVendorRamdisk()
114}
115
Inseob Kime498dd92020-08-04 09:24:04 +0900116func (c *Module) InRecovery() bool {
117 return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
118}
119
120func (c *Module) OnlyInRamdisk() bool {
121 return c.ModuleBase.InstallInRamdisk()
122}
123
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700124func (c *Module) OnlyInVendorRamdisk() bool {
125 return c.ModuleBase.InstallInVendorRamdisk()
126}
127
Inseob Kime498dd92020-08-04 09:24:04 +0900128func (c *Module) OnlyInRecovery() bool {
129 return c.ModuleBase.InstallInRecovery()
130}
131
Justin Yun6977e8a2020-10-29 18:24:11 +0900132func visitPropsAndCompareVendorAndProductProps(v reflect.Value) bool {
133 if v.Kind() != reflect.Struct {
134 return true
135 }
136 for i := 0; i < v.NumField(); i++ {
137 prop := v.Field(i)
138 if prop.Kind() == reflect.Struct && v.Type().Field(i).Name == "Target" {
139 vendor_prop := prop.FieldByName("Vendor")
140 product_prop := prop.FieldByName("Product")
141 if vendor_prop.Kind() != reflect.Struct && product_prop.Kind() != reflect.Struct {
142 // Neither Target.Vendor nor Target.Product is defined
143 continue
144 }
145 if vendor_prop.Kind() != reflect.Struct || product_prop.Kind() != reflect.Struct ||
146 !reflect.DeepEqual(vendor_prop.Interface(), product_prop.Interface()) {
147 // If only one of either Target.Vendor or Target.Product is
148 // defined or they have different values, it fails the build
149 // since VNDK must have the same properties for both vendor
150 // and product variants.
151 return false
152 }
153 } else if !visitPropsAndCompareVendorAndProductProps(prop) {
154 // Visit the substructures to find Target.Vendor and Target.Product
155 return false
156 }
157 }
158 return true
159}
160
161// In the case of VNDK, vendor and product variants must have the same properties.
162// VNDK installs only one file and shares it for both vendor and product modules on
163// runtime. We may not define different versions of a VNDK lib for each partition.
164// This function is used only for the VNDK modules that is available to both vendor
165// and product partitions.
166func (c *Module) compareVendorAndProductProps() bool {
Justin Yunc0d8c492021-01-07 17:45:31 +0900167 if !c.IsVndk() && !Bool(c.VendorProperties.Product_available) {
Justin Yun6977e8a2020-10-29 18:24:11 +0900168 panic(fmt.Errorf("This is only for product available VNDK libs. %q is not a VNDK library or not product available", c.Name()))
169 }
170 for _, properties := range c.GetProperties() {
171 if !visitPropsAndCompareVendorAndProductProps(reflect.ValueOf(properties).Elem()) {
172 return false
173 }
174 }
175 return true
176}
177
Inseob Kime498dd92020-08-04 09:24:04 +0900178func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
179 // Validation check
180 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
181 productSpecific := mctx.ProductSpecific()
182
Justin Yunc0d8c492021-01-07 17:45:31 +0900183 if Bool(m.VendorProperties.Vendor_available) {
Justin Yun63e9ec72020-10-29 16:49:43 +0900184 if vendorSpecific {
185 mctx.PropertyErrorf("vendor_available",
186 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
187 }
Justin Yun63e9ec72020-10-29 16:49:43 +0900188 }
189
Justin Yunc0d8c492021-01-07 17:45:31 +0900190 if Bool(m.VendorProperties.Product_available) {
Justin Yun63e9ec72020-10-29 16:49:43 +0900191 if productSpecific {
192 mctx.PropertyErrorf("product_available",
193 "doesn't make sense at the same time as `product_specific: true`")
194 }
195 if vendorSpecific {
196 mctx.PropertyErrorf("product_available",
197 "cannot provide product variant from a vendor module. Please use `product_specific: true` with `vendor_available: true`")
198 }
Inseob Kime498dd92020-08-04 09:24:04 +0900199 }
200
201 if vndkdep := m.vndkdep; vndkdep != nil {
202 if vndkdep.isVndk() {
203 if vendorSpecific || productSpecific {
204 if !vndkdep.isVndkExt() {
205 mctx.PropertyErrorf("vndk",
206 "must set `extends: \"...\"` to vndk extension")
Justin Yunc0d8c492021-01-07 17:45:31 +0900207 } else if Bool(m.VendorProperties.Vendor_available) {
Inseob Kime498dd92020-08-04 09:24:04 +0900208 mctx.PropertyErrorf("vendor_available",
209 "must not set at the same time as `vndk: {extends: \"...\"}`")
Justin Yunc0d8c492021-01-07 17:45:31 +0900210 } else if Bool(m.VendorProperties.Product_available) {
Justin Yun63e9ec72020-10-29 16:49:43 +0900211 mctx.PropertyErrorf("product_available",
212 "must not set at the same time as `vndk: {extends: \"...\"}`")
Inseob Kime498dd92020-08-04 09:24:04 +0900213 }
214 } else {
215 if vndkdep.isVndkExt() {
216 mctx.PropertyErrorf("vndk",
217 "must set `vendor: true` or `product_specific: true` to set `extends: %q`",
218 m.getVndkExtendsModuleName())
219 }
Justin Yunc0d8c492021-01-07 17:45:31 +0900220 if !Bool(m.VendorProperties.Vendor_available) {
Inseob Kime498dd92020-08-04 09:24:04 +0900221 mctx.PropertyErrorf("vndk",
Justin Yunc0d8c492021-01-07 17:45:31 +0900222 "vendor_available must be set to true when `vndk: {enabled: true}`")
Inseob Kime498dd92020-08-04 09:24:04 +0900223 }
Justin Yunc0d8c492021-01-07 17:45:31 +0900224 if Bool(m.VendorProperties.Product_available) {
Justin Yunfd9e8042020-12-23 18:23:14 +0900225 // If a VNDK module creates both product and vendor variants, they
226 // must have the same properties since they share a single VNDK
227 // library on runtime.
Justin Yun6977e8a2020-10-29 18:24:11 +0900228 if !m.compareVendorAndProductProps() {
229 mctx.ModuleErrorf("product properties must have the same values with the vendor properties for VNDK modules")
230 }
231 }
Inseob Kime498dd92020-08-04 09:24:04 +0900232 }
233 } else {
234 if vndkdep.isVndkSp() {
235 mctx.PropertyErrorf("vndk",
236 "must set `enabled: true` to set `support_system_process: true`")
237 }
238 if vndkdep.isVndkExt() {
239 mctx.PropertyErrorf("vndk",
240 "must set `enabled: true` to set `extends: %q`",
241 m.getVndkExtendsModuleName())
242 }
243 }
244 }
245
246 var coreVariantNeeded bool = false
247 var ramdiskVariantNeeded bool = false
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700248 var vendorRamdiskVariantNeeded bool = false
Inseob Kime498dd92020-08-04 09:24:04 +0900249 var recoveryVariantNeeded bool = false
250
251 var vendorVariants []string
252 var productVariants []string
253
254 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
255 boardVndkVersion := mctx.DeviceConfig().VndkVersion()
256 productVndkVersion := mctx.DeviceConfig().ProductVndkVersion()
Jose Galmes6f843bc2020-12-11 13:36:29 -0800257 recoverySnapshotVersion := mctx.DeviceConfig().RecoverySnapshotVersion()
258 usingRecoverySnapshot := recoverySnapshotVersion != "current" &&
259 recoverySnapshotVersion != ""
Inseob Kime498dd92020-08-04 09:24:04 +0900260 if boardVndkVersion == "current" {
261 boardVndkVersion = platformVndkVersion
262 }
263 if productVndkVersion == "current" {
264 productVndkVersion = platformVndkVersion
265 }
266
267 if boardVndkVersion == "" {
268 // If the device isn't compiling against the VNDK, we always
269 // use the core mode.
270 coreVariantNeeded = true
271 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
272 // LL-NDK stubs only exist in the vendor and product variants,
273 // since the real libraries will be used in the core variant.
274 vendorVariants = append(vendorVariants,
275 platformVndkVersion,
276 boardVndkVersion,
277 )
278 productVariants = append(productVariants,
279 platformVndkVersion,
280 productVndkVersion,
281 )
282 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
283 // ... and LL-NDK headers as well
284 vendorVariants = append(vendorVariants,
285 platformVndkVersion,
286 boardVndkVersion,
287 )
288 productVariants = append(productVariants,
289 platformVndkVersion,
290 productVndkVersion,
291 )
292 } else if m.isSnapshotPrebuilt() {
293 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
294 // PRODUCT_EXTRA_VNDK_VERSIONS.
295 if snapshot, ok := m.linker.(interface {
296 version() string
297 }); ok {
Jose Galmes6f843bc2020-12-11 13:36:29 -0800298 if m.InstallInRecovery() {
299 recoveryVariantNeeded = true
300 } else {
301 vendorVariants = append(vendorVariants, snapshot.version())
302 }
Inseob Kime498dd92020-08-04 09:24:04 +0900303 } else {
304 mctx.ModuleErrorf("version is unknown for snapshot prebuilt")
305 }
Ivan Lozanof9e21722020-12-02 09:00:51 -0500306 } else if m.HasNonSystemVariants() && !m.IsVndkExt() {
Justin Yun63e9ec72020-10-29 16:49:43 +0900307 // This will be available to /system unless it is product_specific
308 // which will be handled later.
Inseob Kime498dd92020-08-04 09:24:04 +0900309 coreVariantNeeded = true
310
311 // We assume that modules under proprietary paths are compatible for
312 // BOARD_VNDK_VERSION. The other modules are regarded as AOSP, or
313 // PLATFORM_VNDK_VERSION.
Justin Yun63e9ec72020-10-29 16:49:43 +0900314 if m.HasVendorVariant() {
315 if isVendorProprietaryModule(mctx) {
316 vendorVariants = append(vendorVariants, boardVndkVersion)
317 } else {
318 vendorVariants = append(vendorVariants, platformVndkVersion)
319 }
Inseob Kime498dd92020-08-04 09:24:04 +0900320 }
321
Justin Yun6977e8a2020-10-29 18:24:11 +0900322 // product_available modules are available to /product.
323 if m.HasProductVariant() {
324 productVariants = append(productVariants, platformVndkVersion)
325 // VNDK is always PLATFORM_VNDK_VERSION
326 if !m.IsVndk() {
327 productVariants = append(productVariants, productVndkVersion)
328 }
Inseob Kime498dd92020-08-04 09:24:04 +0900329 }
330 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
331 // This will be available in /vendor (or /odm) only
332
333 // kernel_headers is a special module type whose exported headers
334 // are coming from DeviceKernelHeaders() which is always vendor
335 // dependent. They'll always have both vendor variants.
336 // For other modules, we assume that modules under proprietary
337 // paths are compatible for BOARD_VNDK_VERSION. The other modules
338 // are regarded as AOSP, which is PLATFORM_VNDK_VERSION.
339 if _, ok := m.linker.(*kernelHeadersDecorator); ok {
340 vendorVariants = append(vendorVariants,
341 platformVndkVersion,
342 boardVndkVersion,
343 )
Bill Peckham945441c2020-08-31 16:07:58 -0700344 } else if isVendorProprietaryModule(mctx) {
Inseob Kime498dd92020-08-04 09:24:04 +0900345 vendorVariants = append(vendorVariants, boardVndkVersion)
346 } else {
347 vendorVariants = append(vendorVariants, platformVndkVersion)
348 }
Colin Cross127bb8b2020-12-16 16:46:01 -0800349 } else if lib := moduleLibraryInterface(m); lib != nil && lib.hasLLNDKStubs() {
350 // This is an LLNDK library. The implementation of the library will be on /system,
351 // and vendor and product variants will be created with LLNDK stubs.
352 coreVariantNeeded = true
353 vendorVariants = append(vendorVariants,
354 platformVndkVersion,
355 boardVndkVersion,
356 )
357 productVariants = append(productVariants,
358 platformVndkVersion,
359 productVndkVersion,
360 )
Inseob Kime498dd92020-08-04 09:24:04 +0900361 } else {
362 // This is either in /system (or similar: /data), or is a
363 // modules built with the NDK. Modules built with the NDK
364 // will be restricted using the existing link type checks.
365 coreVariantNeeded = true
366 }
367
368 if boardVndkVersion != "" && productVndkVersion != "" {
369 if coreVariantNeeded && productSpecific && String(m.Properties.Sdk_version) == "" {
370 // The module has "product_specific: true" that does not create core variant.
371 coreVariantNeeded = false
372 productVariants = append(productVariants, productVndkVersion)
373 }
374 } else {
375 // Unless PRODUCT_PRODUCT_VNDK_VERSION is set, product partition has no
376 // restriction to use system libs.
377 // No product variants defined in this case.
378 productVariants = []string{}
379 }
380
381 if Bool(m.Properties.Ramdisk_available) {
382 ramdiskVariantNeeded = true
383 }
384
385 if m.ModuleBase.InstallInRamdisk() {
386 ramdiskVariantNeeded = true
387 coreVariantNeeded = false
388 }
389
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700390 if Bool(m.Properties.Vendor_ramdisk_available) {
391 vendorRamdiskVariantNeeded = true
392 }
393
394 if m.ModuleBase.InstallInVendorRamdisk() {
395 vendorRamdiskVariantNeeded = true
396 coreVariantNeeded = false
397 }
398
Inseob Kime498dd92020-08-04 09:24:04 +0900399 if Bool(m.Properties.Recovery_available) {
400 recoveryVariantNeeded = true
401 }
402
403 if m.ModuleBase.InstallInRecovery() {
404 recoveryVariantNeeded = true
405 coreVariantNeeded = false
406 }
407
Jose Galmes6f843bc2020-12-11 13:36:29 -0800408 // If using a snapshot, the recovery variant under AOSP directories is not needed,
409 // except for kernel headers, which needs all variants.
410 if _, ok := m.linker.(*kernelHeadersDecorator); !ok &&
411 !m.isSnapshotPrebuilt() &&
412 usingRecoverySnapshot &&
413 !isRecoveryProprietaryModule(mctx) {
414 recoveryVariantNeeded = false
415 }
416
Inseob Kime498dd92020-08-04 09:24:04 +0900417 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
418 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, VendorVariationPrefix+variant)
419 }
420
421 for _, variant := range android.FirstUniqueStrings(productVariants) {
422 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, ProductVariationPrefix+variant)
423 }
424
425 m.Properties.RamdiskVariantNeeded = ramdiskVariantNeeded
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700426 m.Properties.VendorRamdiskVariantNeeded = vendorRamdiskVariantNeeded
Inseob Kime498dd92020-08-04 09:24:04 +0900427 m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
428 m.Properties.CoreVariantNeeded = coreVariantNeeded
Jose Galmes6f843bc2020-12-11 13:36:29 -0800429
430 // Disable the module if no variants are needed.
431 if !ramdiskVariantNeeded &&
432 !recoveryVariantNeeded &&
433 !coreVariantNeeded &&
434 len(m.Properties.ExtraVariants) == 0 {
435 m.Disable()
436 }
Inseob Kime498dd92020-08-04 09:24:04 +0900437}
438
439func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
440 return c.Properties.CoreVariantNeeded
441}
442
443func (c *Module) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
444 return c.Properties.RamdiskVariantNeeded
445}
446
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700447func (c *Module) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
448 return c.Properties.VendorRamdiskVariantNeeded
449}
450
Inseob Kime498dd92020-08-04 09:24:04 +0900451func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
452 return c.Properties.RecoveryVariantNeeded
453}
454
455func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
456 return c.Properties.ExtraVariants
457}
458
Justin Yun63e9ec72020-10-29 16:49:43 +0900459func squashVendorSrcs(m *Module) {
460 if lib, ok := m.compiler.(*libraryDecorator); ok {
461 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
462 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
463
464 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
465 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
466
467 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
468 lib.baseCompiler.Properties.Target.Vendor.Exclude_generated_sources...)
469 }
470}
471
472func squashProductSrcs(m *Module) {
473 if lib, ok := m.compiler.(*libraryDecorator); ok {
474 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
475 lib.baseCompiler.Properties.Target.Product.Srcs...)
476
477 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
478 lib.baseCompiler.Properties.Target.Product.Exclude_srcs...)
479
480 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
481 lib.baseCompiler.Properties.Target.Product.Exclude_generated_sources...)
482 }
483}
484
485func squashRecoverySrcs(m *Module) {
486 if lib, ok := m.compiler.(*libraryDecorator); ok {
487 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
488 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
489
490 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
491 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
492
493 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
494 lib.baseCompiler.Properties.Target.Recovery.Exclude_generated_sources...)
495 }
496}
497
498func squashVendorRamdiskSrcs(m *Module) {
499 if lib, ok := m.compiler.(*libraryDecorator); ok {
500 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, lib.baseCompiler.Properties.Target.Vendor_ramdisk.Exclude_srcs...)
501 }
502}
503
Inseob Kime498dd92020-08-04 09:24:04 +0900504func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
505 m := module.(*Module)
Yifan Hong6da33c22020-10-27 15:01:21 -0700506 if variant == android.RamdiskVariation {
Inseob Kime498dd92020-08-04 09:24:04 +0900507 m.MakeAsPlatform()
Yifan Hong6da33c22020-10-27 15:01:21 -0700508 } else if variant == android.VendorRamdiskVariation {
509 m.MakeAsPlatform()
510 squashVendorRamdiskSrcs(m)
Inseob Kime498dd92020-08-04 09:24:04 +0900511 } else if variant == android.RecoveryVariation {
512 m.MakeAsPlatform()
513 squashRecoverySrcs(m)
514 } else if strings.HasPrefix(variant, VendorVariationPrefix) {
515 m.Properties.ImageVariationPrefix = VendorVariationPrefix
516 m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
517 squashVendorSrcs(m)
518
519 // Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION.
520 // Hide other vendor variants to avoid collision.
521 vndkVersion := ctx.DeviceConfig().VndkVersion()
522 if vndkVersion != "current" && vndkVersion != "" && vndkVersion != m.Properties.VndkVersion {
523 m.Properties.HideFromMake = true
Colin Crossa9c8c9f2020-12-16 10:20:23 -0800524 m.HideFromMake()
Inseob Kime498dd92020-08-04 09:24:04 +0900525 }
526 } else if strings.HasPrefix(variant, ProductVariationPrefix) {
527 m.Properties.ImageVariationPrefix = ProductVariationPrefix
528 m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix)
Justin Yun6977e8a2020-10-29 18:24:11 +0900529 squashProductSrcs(m)
Inseob Kime498dd92020-08-04 09:24:04 +0900530 }
531}