blob: f89194fb2c7b5b7b5cba7cfb04e89b7156f08212 [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
Colin Crossb5f6fa62021-01-06 17:05:04 -0800267 _, isLLNDKLibrary := m.linker.(*llndkStubDecorator)
268 _, isLLNDKHeaders := m.linker.(*llndkHeadersDecorator)
269 lib := moduleLibraryInterface(m)
270 hasLLNDKStubs := lib != nil && lib.hasLLNDKStubs()
271
272 if isLLNDKLibrary || isLLNDKHeaders || hasLLNDKStubs {
273 // This is an LLNDK library. The implementation of the library will be on /system,
274 // and vendor and product variants will be created with LLNDK stubs.
275 // The LLNDK libraries need vendor variants even if there is no VNDK.
276 // The obsolete llndk_library and llndk_headers modules also need the vendor variants
277 // so the cc_library LLNDK stubs can depend on them.
278 if hasLLNDKStubs {
279 coreVariantNeeded = true
280 }
281 if platformVndkVersion != "" {
282 vendorVariants = append(vendorVariants, platformVndkVersion)
283 productVariants = append(productVariants, platformVndkVersion)
284 }
285 if boardVndkVersion != "" {
286 vendorVariants = append(vendorVariants, boardVndkVersion)
287 }
288 if productVndkVersion != "" {
289 productVariants = append(productVariants, productVndkVersion)
290 }
291 } else if boardVndkVersion == "" {
Inseob Kime498dd92020-08-04 09:24:04 +0900292 // If the device isn't compiling against the VNDK, we always
293 // use the core mode.
294 coreVariantNeeded = true
Inseob Kime498dd92020-08-04 09:24:04 +0900295 } else if m.isSnapshotPrebuilt() {
296 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
297 // PRODUCT_EXTRA_VNDK_VERSIONS.
298 if snapshot, ok := m.linker.(interface {
299 version() string
300 }); ok {
Jose Galmes6f843bc2020-12-11 13:36:29 -0800301 if m.InstallInRecovery() {
302 recoveryVariantNeeded = true
303 } else {
304 vendorVariants = append(vendorVariants, snapshot.version())
305 }
Inseob Kime498dd92020-08-04 09:24:04 +0900306 } else {
307 mctx.ModuleErrorf("version is unknown for snapshot prebuilt")
308 }
Ivan Lozanof9e21722020-12-02 09:00:51 -0500309 } else if m.HasNonSystemVariants() && !m.IsVndkExt() {
Justin Yun63e9ec72020-10-29 16:49:43 +0900310 // This will be available to /system unless it is product_specific
311 // which will be handled later.
Inseob Kime498dd92020-08-04 09:24:04 +0900312 coreVariantNeeded = true
313
314 // We assume that modules under proprietary paths are compatible for
315 // BOARD_VNDK_VERSION. The other modules are regarded as AOSP, or
316 // PLATFORM_VNDK_VERSION.
Justin Yun63e9ec72020-10-29 16:49:43 +0900317 if m.HasVendorVariant() {
318 if isVendorProprietaryModule(mctx) {
319 vendorVariants = append(vendorVariants, boardVndkVersion)
320 } else {
321 vendorVariants = append(vendorVariants, platformVndkVersion)
322 }
Inseob Kime498dd92020-08-04 09:24:04 +0900323 }
324
Justin Yun6977e8a2020-10-29 18:24:11 +0900325 // product_available modules are available to /product.
326 if m.HasProductVariant() {
327 productVariants = append(productVariants, platformVndkVersion)
328 // VNDK is always PLATFORM_VNDK_VERSION
329 if !m.IsVndk() {
330 productVariants = append(productVariants, productVndkVersion)
331 }
Inseob Kime498dd92020-08-04 09:24:04 +0900332 }
333 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
334 // This will be available in /vendor (or /odm) only
335
336 // kernel_headers is a special module type whose exported headers
337 // are coming from DeviceKernelHeaders() which is always vendor
338 // dependent. They'll always have both vendor variants.
339 // For other modules, we assume that modules under proprietary
340 // paths are compatible for BOARD_VNDK_VERSION. The other modules
341 // are regarded as AOSP, which is PLATFORM_VNDK_VERSION.
342 if _, ok := m.linker.(*kernelHeadersDecorator); ok {
343 vendorVariants = append(vendorVariants,
344 platformVndkVersion,
345 boardVndkVersion,
346 )
Bill Peckham945441c2020-08-31 16:07:58 -0700347 } else if isVendorProprietaryModule(mctx) {
Inseob Kime498dd92020-08-04 09:24:04 +0900348 vendorVariants = append(vendorVariants, boardVndkVersion)
349 } else {
350 vendorVariants = append(vendorVariants, platformVndkVersion)
351 }
352 } else {
353 // This is either in /system (or similar: /data), or is a
354 // modules built with the NDK. Modules built with the NDK
355 // will be restricted using the existing link type checks.
356 coreVariantNeeded = true
357 }
358
359 if boardVndkVersion != "" && productVndkVersion != "" {
360 if coreVariantNeeded && productSpecific && String(m.Properties.Sdk_version) == "" {
361 // The module has "product_specific: true" that does not create core variant.
362 coreVariantNeeded = false
363 productVariants = append(productVariants, productVndkVersion)
364 }
365 } else {
366 // Unless PRODUCT_PRODUCT_VNDK_VERSION is set, product partition has no
367 // restriction to use system libs.
368 // No product variants defined in this case.
369 productVariants = []string{}
370 }
371
372 if Bool(m.Properties.Ramdisk_available) {
373 ramdiskVariantNeeded = true
374 }
375
376 if m.ModuleBase.InstallInRamdisk() {
377 ramdiskVariantNeeded = true
378 coreVariantNeeded = false
379 }
380
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700381 if Bool(m.Properties.Vendor_ramdisk_available) {
382 vendorRamdiskVariantNeeded = true
383 }
384
385 if m.ModuleBase.InstallInVendorRamdisk() {
386 vendorRamdiskVariantNeeded = true
387 coreVariantNeeded = false
388 }
389
Inseob Kime498dd92020-08-04 09:24:04 +0900390 if Bool(m.Properties.Recovery_available) {
391 recoveryVariantNeeded = true
392 }
393
394 if m.ModuleBase.InstallInRecovery() {
395 recoveryVariantNeeded = true
396 coreVariantNeeded = false
397 }
398
Jose Galmes6f843bc2020-12-11 13:36:29 -0800399 // If using a snapshot, the recovery variant under AOSP directories is not needed,
400 // except for kernel headers, which needs all variants.
401 if _, ok := m.linker.(*kernelHeadersDecorator); !ok &&
402 !m.isSnapshotPrebuilt() &&
403 usingRecoverySnapshot &&
404 !isRecoveryProprietaryModule(mctx) {
405 recoveryVariantNeeded = false
406 }
407
Inseob Kime498dd92020-08-04 09:24:04 +0900408 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
409 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, VendorVariationPrefix+variant)
410 }
411
412 for _, variant := range android.FirstUniqueStrings(productVariants) {
413 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, ProductVariationPrefix+variant)
414 }
415
416 m.Properties.RamdiskVariantNeeded = ramdiskVariantNeeded
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700417 m.Properties.VendorRamdiskVariantNeeded = vendorRamdiskVariantNeeded
Inseob Kime498dd92020-08-04 09:24:04 +0900418 m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
419 m.Properties.CoreVariantNeeded = coreVariantNeeded
Jose Galmes6f843bc2020-12-11 13:36:29 -0800420
421 // Disable the module if no variants are needed.
422 if !ramdiskVariantNeeded &&
423 !recoveryVariantNeeded &&
424 !coreVariantNeeded &&
425 len(m.Properties.ExtraVariants) == 0 {
426 m.Disable()
427 }
Inseob Kime498dd92020-08-04 09:24:04 +0900428}
429
430func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
431 return c.Properties.CoreVariantNeeded
432}
433
434func (c *Module) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
435 return c.Properties.RamdiskVariantNeeded
436}
437
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700438func (c *Module) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
439 return c.Properties.VendorRamdiskVariantNeeded
440}
441
Inseob Kime498dd92020-08-04 09:24:04 +0900442func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
443 return c.Properties.RecoveryVariantNeeded
444}
445
446func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
447 return c.Properties.ExtraVariants
448}
449
Justin Yun63e9ec72020-10-29 16:49:43 +0900450func squashVendorSrcs(m *Module) {
451 if lib, ok := m.compiler.(*libraryDecorator); ok {
452 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
453 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
454
455 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
456 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
457
458 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
459 lib.baseCompiler.Properties.Target.Vendor.Exclude_generated_sources...)
460 }
461}
462
463func squashProductSrcs(m *Module) {
464 if lib, ok := m.compiler.(*libraryDecorator); ok {
465 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
466 lib.baseCompiler.Properties.Target.Product.Srcs...)
467
468 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
469 lib.baseCompiler.Properties.Target.Product.Exclude_srcs...)
470
471 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
472 lib.baseCompiler.Properties.Target.Product.Exclude_generated_sources...)
473 }
474}
475
476func squashRecoverySrcs(m *Module) {
477 if lib, ok := m.compiler.(*libraryDecorator); ok {
478 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
479 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
480
481 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
482 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
483
484 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
485 lib.baseCompiler.Properties.Target.Recovery.Exclude_generated_sources...)
486 }
487}
488
489func squashVendorRamdiskSrcs(m *Module) {
490 if lib, ok := m.compiler.(*libraryDecorator); ok {
491 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, lib.baseCompiler.Properties.Target.Vendor_ramdisk.Exclude_srcs...)
492 }
493}
494
Inseob Kime498dd92020-08-04 09:24:04 +0900495func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
496 m := module.(*Module)
Yifan Hong6da33c22020-10-27 15:01:21 -0700497 if variant == android.RamdiskVariation {
Inseob Kime498dd92020-08-04 09:24:04 +0900498 m.MakeAsPlatform()
Yifan Hong6da33c22020-10-27 15:01:21 -0700499 } else if variant == android.VendorRamdiskVariation {
500 m.MakeAsPlatform()
501 squashVendorRamdiskSrcs(m)
Inseob Kime498dd92020-08-04 09:24:04 +0900502 } else if variant == android.RecoveryVariation {
503 m.MakeAsPlatform()
504 squashRecoverySrcs(m)
505 } else if strings.HasPrefix(variant, VendorVariationPrefix) {
506 m.Properties.ImageVariationPrefix = VendorVariationPrefix
507 m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
508 squashVendorSrcs(m)
509
510 // Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION.
511 // Hide other vendor variants to avoid collision.
512 vndkVersion := ctx.DeviceConfig().VndkVersion()
513 if vndkVersion != "current" && vndkVersion != "" && vndkVersion != m.Properties.VndkVersion {
514 m.Properties.HideFromMake = true
Colin Crossa9c8c9f2020-12-16 10:20:23 -0800515 m.HideFromMake()
Inseob Kime498dd92020-08-04 09:24:04 +0900516 }
517 } else if strings.HasPrefix(variant, ProductVariationPrefix) {
518 m.Properties.ImageVariationPrefix = ProductVariationPrefix
519 m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix)
Justin Yun6977e8a2020-10-29 18:24:11 +0900520 squashProductSrcs(m)
Inseob Kime498dd92020-08-04 09:24:04 +0900521 }
522}