2020-08-04 08:24:04 +08:00
|
|
|
// Copyright 2020 The Android Open Source Project
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
package cc
|
|
|
|
|
|
|
|
// This file contains image variant related things, including image mutator functions, utility
|
|
|
|
// functions to determine where a module is installed, etc.
|
|
|
|
|
|
|
|
import (
|
2020-10-29 17:24:11 +08:00
|
|
|
"fmt"
|
|
|
|
"reflect"
|
2020-08-04 08:24:04 +08:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"android/soong/android"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ android.ImageInterface = (*Module)(nil)
|
|
|
|
|
2020-12-15 00:27:52 +08:00
|
|
|
type ImageVariantType string
|
2020-08-03 23:41:38 +08:00
|
|
|
|
|
|
|
const (
|
2020-12-15 00:27:52 +08:00
|
|
|
coreImageVariant ImageVariantType = "core"
|
|
|
|
vendorImageVariant ImageVariantType = "vendor"
|
|
|
|
productImageVariant ImageVariantType = "product"
|
|
|
|
ramdiskImageVariant ImageVariantType = "ramdisk"
|
|
|
|
vendorRamdiskImageVariant ImageVariantType = "vendor_ramdisk"
|
|
|
|
recoveryImageVariant ImageVariantType = "recovery"
|
|
|
|
hostImageVariant ImageVariantType = "host"
|
2020-08-03 23:41:38 +08:00
|
|
|
)
|
|
|
|
|
2020-08-04 08:24:04 +08:00
|
|
|
const (
|
|
|
|
// VendorVariationPrefix is the variant prefix used for /vendor code that compiles
|
|
|
|
// against the VNDK.
|
|
|
|
VendorVariationPrefix = "vendor."
|
|
|
|
|
|
|
|
// ProductVariationPrefix is the variant prefix used for /product code that compiles
|
|
|
|
// against the VNDK.
|
|
|
|
ProductVariationPrefix = "product."
|
|
|
|
)
|
|
|
|
|
|
|
|
func (ctx *moduleContext) ProductSpecific() bool {
|
2021-01-07 16:45:31 +08:00
|
|
|
// Additionally check if this module is inProduct() that means it is a "product" variant of a
|
|
|
|
// module. As well as product specific modules, product variants must be installed to /product.
|
|
|
|
return ctx.ModuleContext.ProductSpecific() || ctx.mod.InProduct()
|
2020-08-04 08:24:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *moduleContext) SocSpecific() bool {
|
2021-01-07 16:45:31 +08:00
|
|
|
// Additionally check if this module is inVendor() that means it is a "vendor" variant of a
|
2021-01-08 17:00:19 +08:00
|
|
|
// module. As well as SoC specific modules, vendor variants must be installed to /vendor
|
|
|
|
// unless they have "odm_available: true".
|
|
|
|
return ctx.ModuleContext.SocSpecific() || (ctx.mod.InVendor() && !ctx.mod.VendorVariantToOdm())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *moduleContext) DeviceSpecific() bool {
|
|
|
|
// Some vendor variants want to be installed to /odm by setting "odm_available: true".
|
|
|
|
return ctx.ModuleContext.DeviceSpecific() || (ctx.mod.InVendor() && ctx.mod.VendorVariantToOdm())
|
2020-08-04 08:24:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *moduleContextImpl) inProduct() bool {
|
2020-12-02 22:00:51 +08:00
|
|
|
return ctx.mod.InProduct()
|
2020-08-04 08:24:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *moduleContextImpl) inVendor() bool {
|
2020-12-15 00:27:52 +08:00
|
|
|
return ctx.mod.InVendor()
|
2020-08-04 08:24:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *moduleContextImpl) inRamdisk() bool {
|
|
|
|
return ctx.mod.InRamdisk()
|
|
|
|
}
|
|
|
|
|
2020-10-22 06:17:56 +08:00
|
|
|
func (ctx *moduleContextImpl) inVendorRamdisk() bool {
|
|
|
|
return ctx.mod.InVendorRamdisk()
|
|
|
|
}
|
|
|
|
|
2020-08-04 08:24:04 +08:00
|
|
|
func (ctx *moduleContextImpl) inRecovery() bool {
|
|
|
|
return ctx.mod.InRecovery()
|
|
|
|
}
|
|
|
|
|
2020-10-29 15:49:43 +08:00
|
|
|
// Returns true when this module is configured to have core and vendor variants.
|
2020-08-04 08:24:04 +08:00
|
|
|
func (c *Module) HasVendorVariant() bool {
|
2021-01-08 17:00:19 +08:00
|
|
|
return Bool(c.VendorProperties.Vendor_available) || Bool(c.VendorProperties.Odm_available)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns true when this module creates a vendor variant and wants to install the vendor variant
|
|
|
|
// to the odm partition.
|
|
|
|
func (c *Module) VendorVariantToOdm() bool {
|
|
|
|
return Bool(c.VendorProperties.Odm_available)
|
2020-08-04 08:24:04 +08:00
|
|
|
}
|
|
|
|
|
2020-10-29 15:49:43 +08:00
|
|
|
// Returns true when this module is configured to have core and product variants.
|
|
|
|
func (c *Module) HasProductVariant() bool {
|
2021-01-07 16:45:31 +08:00
|
|
|
return Bool(c.VendorProperties.Product_available)
|
2020-10-29 15:49:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns true when this module is configured to have core and either product or vendor variants.
|
|
|
|
func (c *Module) HasNonSystemVariants() bool {
|
2020-10-29 17:24:11 +08:00
|
|
|
return c.HasVendorVariant() || c.HasProductVariant()
|
2020-10-29 15:49:43 +08:00
|
|
|
}
|
|
|
|
|
2020-08-04 08:24:04 +08:00
|
|
|
// Returns true if the module is "product" variant. Usually these modules are installed in /product
|
2020-12-02 22:00:51 +08:00
|
|
|
func (c *Module) InProduct() bool {
|
2020-08-04 08:24:04 +08:00
|
|
|
return c.Properties.ImageVariationPrefix == ProductVariationPrefix
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
|
2020-12-15 00:27:52 +08:00
|
|
|
func (c *Module) InVendor() bool {
|
2020-08-04 08:24:04 +08:00
|
|
|
return c.Properties.ImageVariationPrefix == VendorVariationPrefix
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Module) InRamdisk() bool {
|
|
|
|
return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk()
|
|
|
|
}
|
|
|
|
|
2020-10-22 06:17:56 +08:00
|
|
|
func (c *Module) InVendorRamdisk() bool {
|
|
|
|
return c.ModuleBase.InVendorRamdisk() || c.ModuleBase.InstallInVendorRamdisk()
|
|
|
|
}
|
|
|
|
|
2020-08-04 08:24:04 +08:00
|
|
|
func (c *Module) InRecovery() bool {
|
|
|
|
return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Module) OnlyInRamdisk() bool {
|
|
|
|
return c.ModuleBase.InstallInRamdisk()
|
|
|
|
}
|
|
|
|
|
2020-10-22 06:17:56 +08:00
|
|
|
func (c *Module) OnlyInVendorRamdisk() bool {
|
|
|
|
return c.ModuleBase.InstallInVendorRamdisk()
|
|
|
|
}
|
|
|
|
|
2020-08-04 08:24:04 +08:00
|
|
|
func (c *Module) OnlyInRecovery() bool {
|
|
|
|
return c.ModuleBase.InstallInRecovery()
|
|
|
|
}
|
|
|
|
|
2020-10-29 17:24:11 +08:00
|
|
|
func visitPropsAndCompareVendorAndProductProps(v reflect.Value) bool {
|
|
|
|
if v.Kind() != reflect.Struct {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
for i := 0; i < v.NumField(); i++ {
|
|
|
|
prop := v.Field(i)
|
|
|
|
if prop.Kind() == reflect.Struct && v.Type().Field(i).Name == "Target" {
|
|
|
|
vendor_prop := prop.FieldByName("Vendor")
|
|
|
|
product_prop := prop.FieldByName("Product")
|
|
|
|
if vendor_prop.Kind() != reflect.Struct && product_prop.Kind() != reflect.Struct {
|
|
|
|
// Neither Target.Vendor nor Target.Product is defined
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if vendor_prop.Kind() != reflect.Struct || product_prop.Kind() != reflect.Struct ||
|
|
|
|
!reflect.DeepEqual(vendor_prop.Interface(), product_prop.Interface()) {
|
|
|
|
// If only one of either Target.Vendor or Target.Product is
|
|
|
|
// defined or they have different values, it fails the build
|
|
|
|
// since VNDK must have the same properties for both vendor
|
|
|
|
// and product variants.
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
} else if !visitPropsAndCompareVendorAndProductProps(prop) {
|
|
|
|
// Visit the substructures to find Target.Vendor and Target.Product
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// In the case of VNDK, vendor and product variants must have the same properties.
|
|
|
|
// VNDK installs only one file and shares it for both vendor and product modules on
|
|
|
|
// runtime. We may not define different versions of a VNDK lib for each partition.
|
|
|
|
// This function is used only for the VNDK modules that is available to both vendor
|
|
|
|
// and product partitions.
|
|
|
|
func (c *Module) compareVendorAndProductProps() bool {
|
2021-01-07 16:45:31 +08:00
|
|
|
if !c.IsVndk() && !Bool(c.VendorProperties.Product_available) {
|
2020-10-29 17:24:11 +08:00
|
|
|
panic(fmt.Errorf("This is only for product available VNDK libs. %q is not a VNDK library or not product available", c.Name()))
|
|
|
|
}
|
|
|
|
for _, properties := range c.GetProperties() {
|
|
|
|
if !visitPropsAndCompareVendorAndProductProps(reflect.ValueOf(properties).Elem()) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2020-08-04 08:24:04 +08:00
|
|
|
func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
|
|
|
|
// Validation check
|
|
|
|
vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
|
|
|
|
productSpecific := mctx.ProductSpecific()
|
|
|
|
|
2021-01-07 16:45:31 +08:00
|
|
|
if Bool(m.VendorProperties.Vendor_available) {
|
2020-10-29 15:49:43 +08:00
|
|
|
if vendorSpecific {
|
|
|
|
mctx.PropertyErrorf("vendor_available",
|
2021-01-08 17:00:19 +08:00
|
|
|
"doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific: true`")
|
|
|
|
}
|
|
|
|
if Bool(m.VendorProperties.Odm_available) {
|
|
|
|
mctx.PropertyErrorf("vendor_available",
|
|
|
|
"doesn't make sense at the same time as `odm_available: true`")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if Bool(m.VendorProperties.Odm_available) {
|
|
|
|
if vendorSpecific {
|
|
|
|
mctx.PropertyErrorf("odm_available",
|
|
|
|
"doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific: true`")
|
2020-10-29 15:49:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-07 16:45:31 +08:00
|
|
|
if Bool(m.VendorProperties.Product_available) {
|
2020-10-29 15:49:43 +08:00
|
|
|
if productSpecific {
|
|
|
|
mctx.PropertyErrorf("product_available",
|
|
|
|
"doesn't make sense at the same time as `product_specific: true`")
|
|
|
|
}
|
|
|
|
if vendorSpecific {
|
|
|
|
mctx.PropertyErrorf("product_available",
|
|
|
|
"cannot provide product variant from a vendor module. Please use `product_specific: true` with `vendor_available: true`")
|
|
|
|
}
|
2020-08-04 08:24:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if vndkdep := m.vndkdep; vndkdep != nil {
|
|
|
|
if vndkdep.isVndk() {
|
|
|
|
if vendorSpecific || productSpecific {
|
|
|
|
if !vndkdep.isVndkExt() {
|
|
|
|
mctx.PropertyErrorf("vndk",
|
|
|
|
"must set `extends: \"...\"` to vndk extension")
|
2021-01-07 16:45:31 +08:00
|
|
|
} else if Bool(m.VendorProperties.Vendor_available) {
|
2020-08-04 08:24:04 +08:00
|
|
|
mctx.PropertyErrorf("vendor_available",
|
|
|
|
"must not set at the same time as `vndk: {extends: \"...\"}`")
|
2021-01-07 16:45:31 +08:00
|
|
|
} else if Bool(m.VendorProperties.Product_available) {
|
2020-10-29 15:49:43 +08:00
|
|
|
mctx.PropertyErrorf("product_available",
|
|
|
|
"must not set at the same time as `vndk: {extends: \"...\"}`")
|
2020-08-04 08:24:04 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if vndkdep.isVndkExt() {
|
|
|
|
mctx.PropertyErrorf("vndk",
|
|
|
|
"must set `vendor: true` or `product_specific: true` to set `extends: %q`",
|
|
|
|
m.getVndkExtendsModuleName())
|
|
|
|
}
|
2021-01-07 16:45:31 +08:00
|
|
|
if !Bool(m.VendorProperties.Vendor_available) {
|
2020-08-04 08:24:04 +08:00
|
|
|
mctx.PropertyErrorf("vndk",
|
2021-01-07 16:45:31 +08:00
|
|
|
"vendor_available must be set to true when `vndk: {enabled: true}`")
|
2020-08-04 08:24:04 +08:00
|
|
|
}
|
2021-01-07 16:45:31 +08:00
|
|
|
if Bool(m.VendorProperties.Product_available) {
|
Define vndk.private property for VNDK-private libraries
To define VNDK-private libraries, we used `vendor_available: false`.
Because of it, `vendor_available == nil` had different meaning from
`vendor_available: false` for the VNDK libraries.
To clarify this, we change the logic for defining VNDK-private
libraries which was:
cc_library {
name: "vndk_private",
vendor_available: false,
product_available: false,
vndk: {
enabled: true,
},
}
It must be replaced with
cc_library {
name: "vndk_private",
vendor_available: true,
product_available: true,
vndk: {
enabled: true,
private: true,
},
}
Bug: 175768895
Test: m nothing
Change-Id: I81769f57c2231e54b682a28e4b82631ab9f3d390
2020-12-23 17:23:14 +08:00
|
|
|
// If a VNDK module creates both product and vendor variants, they
|
|
|
|
// must have the same properties since they share a single VNDK
|
|
|
|
// library on runtime.
|
2020-10-29 17:24:11 +08:00
|
|
|
if !m.compareVendorAndProductProps() {
|
|
|
|
mctx.ModuleErrorf("product properties must have the same values with the vendor properties for VNDK modules")
|
|
|
|
}
|
|
|
|
}
|
2020-08-04 08:24:04 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if vndkdep.isVndkSp() {
|
|
|
|
mctx.PropertyErrorf("vndk",
|
|
|
|
"must set `enabled: true` to set `support_system_process: true`")
|
|
|
|
}
|
|
|
|
if vndkdep.isVndkExt() {
|
|
|
|
mctx.PropertyErrorf("vndk",
|
|
|
|
"must set `enabled: true` to set `extends: %q`",
|
|
|
|
m.getVndkExtendsModuleName())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var coreVariantNeeded bool = false
|
|
|
|
var ramdiskVariantNeeded bool = false
|
2020-10-22 06:17:56 +08:00
|
|
|
var vendorRamdiskVariantNeeded bool = false
|
2020-08-04 08:24:04 +08:00
|
|
|
var recoveryVariantNeeded bool = false
|
|
|
|
|
|
|
|
var vendorVariants []string
|
|
|
|
var productVariants []string
|
|
|
|
|
|
|
|
platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
|
|
|
|
boardVndkVersion := mctx.DeviceConfig().VndkVersion()
|
|
|
|
productVndkVersion := mctx.DeviceConfig().ProductVndkVersion()
|
2020-12-12 05:36:29 +08:00
|
|
|
recoverySnapshotVersion := mctx.DeviceConfig().RecoverySnapshotVersion()
|
|
|
|
usingRecoverySnapshot := recoverySnapshotVersion != "current" &&
|
|
|
|
recoverySnapshotVersion != ""
|
2020-08-04 08:24:04 +08:00
|
|
|
if boardVndkVersion == "current" {
|
|
|
|
boardVndkVersion = platformVndkVersion
|
|
|
|
}
|
|
|
|
if productVndkVersion == "current" {
|
|
|
|
productVndkVersion = platformVndkVersion
|
|
|
|
}
|
|
|
|
|
2021-01-07 09:05:04 +08:00
|
|
|
_, isLLNDKLibrary := m.linker.(*llndkStubDecorator)
|
|
|
|
_, isLLNDKHeaders := m.linker.(*llndkHeadersDecorator)
|
|
|
|
lib := moduleLibraryInterface(m)
|
|
|
|
hasLLNDKStubs := lib != nil && lib.hasLLNDKStubs()
|
|
|
|
|
|
|
|
if isLLNDKLibrary || isLLNDKHeaders || hasLLNDKStubs {
|
|
|
|
// This is an LLNDK library. The implementation of the library will be on /system,
|
|
|
|
// and vendor and product variants will be created with LLNDK stubs.
|
|
|
|
// The LLNDK libraries need vendor variants even if there is no VNDK.
|
|
|
|
// The obsolete llndk_library and llndk_headers modules also need the vendor variants
|
|
|
|
// so the cc_library LLNDK stubs can depend on them.
|
|
|
|
if hasLLNDKStubs {
|
|
|
|
coreVariantNeeded = true
|
|
|
|
}
|
|
|
|
if platformVndkVersion != "" {
|
|
|
|
vendorVariants = append(vendorVariants, platformVndkVersion)
|
|
|
|
productVariants = append(productVariants, platformVndkVersion)
|
|
|
|
}
|
|
|
|
if boardVndkVersion != "" {
|
|
|
|
vendorVariants = append(vendorVariants, boardVndkVersion)
|
|
|
|
}
|
|
|
|
if productVndkVersion != "" {
|
|
|
|
productVariants = append(productVariants, productVndkVersion)
|
|
|
|
}
|
|
|
|
} else if boardVndkVersion == "" {
|
2020-08-04 08:24:04 +08:00
|
|
|
// If the device isn't compiling against the VNDK, we always
|
|
|
|
// use the core mode.
|
|
|
|
coreVariantNeeded = true
|
|
|
|
} else if m.isSnapshotPrebuilt() {
|
|
|
|
// Make vendor variants only for the versions in BOARD_VNDK_VERSION and
|
|
|
|
// PRODUCT_EXTRA_VNDK_VERSIONS.
|
2021-01-23 06:06:33 +08:00
|
|
|
if snapshot, ok := m.linker.(snapshotInterface); ok {
|
2020-12-12 05:36:29 +08:00
|
|
|
if m.InstallInRecovery() {
|
|
|
|
recoveryVariantNeeded = true
|
|
|
|
} else {
|
|
|
|
vendorVariants = append(vendorVariants, snapshot.version())
|
|
|
|
}
|
2020-08-04 08:24:04 +08:00
|
|
|
} else {
|
|
|
|
mctx.ModuleErrorf("version is unknown for snapshot prebuilt")
|
|
|
|
}
|
2020-12-02 22:00:51 +08:00
|
|
|
} else if m.HasNonSystemVariants() && !m.IsVndkExt() {
|
2020-10-29 15:49:43 +08:00
|
|
|
// This will be available to /system unless it is product_specific
|
|
|
|
// which will be handled later.
|
2020-08-04 08:24:04 +08:00
|
|
|
coreVariantNeeded = true
|
|
|
|
|
|
|
|
// We assume that modules under proprietary paths are compatible for
|
|
|
|
// BOARD_VNDK_VERSION. The other modules are regarded as AOSP, or
|
|
|
|
// PLATFORM_VNDK_VERSION.
|
2020-10-29 15:49:43 +08:00
|
|
|
if m.HasVendorVariant() {
|
|
|
|
if isVendorProprietaryModule(mctx) {
|
|
|
|
vendorVariants = append(vendorVariants, boardVndkVersion)
|
|
|
|
} else {
|
|
|
|
vendorVariants = append(vendorVariants, platformVndkVersion)
|
|
|
|
}
|
2020-08-04 08:24:04 +08:00
|
|
|
}
|
|
|
|
|
2020-10-29 17:24:11 +08:00
|
|
|
// product_available modules are available to /product.
|
|
|
|
if m.HasProductVariant() {
|
|
|
|
productVariants = append(productVariants, platformVndkVersion)
|
|
|
|
// VNDK is always PLATFORM_VNDK_VERSION
|
|
|
|
if !m.IsVndk() {
|
|
|
|
productVariants = append(productVariants, productVndkVersion)
|
|
|
|
}
|
2020-08-04 08:24:04 +08:00
|
|
|
}
|
|
|
|
} else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
|
|
|
|
// This will be available in /vendor (or /odm) only
|
|
|
|
|
|
|
|
// kernel_headers is a special module type whose exported headers
|
|
|
|
// are coming from DeviceKernelHeaders() which is always vendor
|
|
|
|
// dependent. They'll always have both vendor variants.
|
|
|
|
// For other modules, we assume that modules under proprietary
|
|
|
|
// paths are compatible for BOARD_VNDK_VERSION. The other modules
|
|
|
|
// are regarded as AOSP, which is PLATFORM_VNDK_VERSION.
|
|
|
|
if _, ok := m.linker.(*kernelHeadersDecorator); ok {
|
|
|
|
vendorVariants = append(vendorVariants,
|
|
|
|
platformVndkVersion,
|
|
|
|
boardVndkVersion,
|
|
|
|
)
|
2020-09-01 07:07:58 +08:00
|
|
|
} else if isVendorProprietaryModule(mctx) {
|
2020-08-04 08:24:04 +08:00
|
|
|
vendorVariants = append(vendorVariants, boardVndkVersion)
|
|
|
|
} else {
|
|
|
|
vendorVariants = append(vendorVariants, platformVndkVersion)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// This is either in /system (or similar: /data), or is a
|
|
|
|
// modules built with the NDK. Modules built with the NDK
|
|
|
|
// will be restricted using the existing link type checks.
|
|
|
|
coreVariantNeeded = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if boardVndkVersion != "" && productVndkVersion != "" {
|
|
|
|
if coreVariantNeeded && productSpecific && String(m.Properties.Sdk_version) == "" {
|
|
|
|
// The module has "product_specific: true" that does not create core variant.
|
|
|
|
coreVariantNeeded = false
|
|
|
|
productVariants = append(productVariants, productVndkVersion)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Unless PRODUCT_PRODUCT_VNDK_VERSION is set, product partition has no
|
|
|
|
// restriction to use system libs.
|
|
|
|
// No product variants defined in this case.
|
|
|
|
productVariants = []string{}
|
|
|
|
}
|
|
|
|
|
|
|
|
if Bool(m.Properties.Ramdisk_available) {
|
|
|
|
ramdiskVariantNeeded = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if m.ModuleBase.InstallInRamdisk() {
|
|
|
|
ramdiskVariantNeeded = true
|
|
|
|
coreVariantNeeded = false
|
|
|
|
}
|
|
|
|
|
2020-10-22 06:17:56 +08:00
|
|
|
if Bool(m.Properties.Vendor_ramdisk_available) {
|
|
|
|
vendorRamdiskVariantNeeded = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if m.ModuleBase.InstallInVendorRamdisk() {
|
|
|
|
vendorRamdiskVariantNeeded = true
|
|
|
|
coreVariantNeeded = false
|
|
|
|
}
|
|
|
|
|
2020-08-04 08:24:04 +08:00
|
|
|
if Bool(m.Properties.Recovery_available) {
|
|
|
|
recoveryVariantNeeded = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if m.ModuleBase.InstallInRecovery() {
|
|
|
|
recoveryVariantNeeded = true
|
|
|
|
coreVariantNeeded = false
|
|
|
|
}
|
|
|
|
|
2020-12-12 05:36:29 +08:00
|
|
|
// If using a snapshot, the recovery variant under AOSP directories is not needed,
|
|
|
|
// except for kernel headers, which needs all variants.
|
|
|
|
if _, ok := m.linker.(*kernelHeadersDecorator); !ok &&
|
|
|
|
!m.isSnapshotPrebuilt() &&
|
|
|
|
usingRecoverySnapshot &&
|
|
|
|
!isRecoveryProprietaryModule(mctx) {
|
|
|
|
recoveryVariantNeeded = false
|
|
|
|
}
|
|
|
|
|
2020-08-04 08:24:04 +08:00
|
|
|
for _, variant := range android.FirstUniqueStrings(vendorVariants) {
|
|
|
|
m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, VendorVariationPrefix+variant)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, variant := range android.FirstUniqueStrings(productVariants) {
|
|
|
|
m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, ProductVariationPrefix+variant)
|
|
|
|
}
|
|
|
|
|
|
|
|
m.Properties.RamdiskVariantNeeded = ramdiskVariantNeeded
|
2020-10-22 06:17:56 +08:00
|
|
|
m.Properties.VendorRamdiskVariantNeeded = vendorRamdiskVariantNeeded
|
2020-08-04 08:24:04 +08:00
|
|
|
m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
|
|
|
|
m.Properties.CoreVariantNeeded = coreVariantNeeded
|
2020-12-12 05:36:29 +08:00
|
|
|
|
|
|
|
// Disable the module if no variants are needed.
|
|
|
|
if !ramdiskVariantNeeded &&
|
|
|
|
!recoveryVariantNeeded &&
|
|
|
|
!coreVariantNeeded &&
|
|
|
|
len(m.Properties.ExtraVariants) == 0 {
|
|
|
|
m.Disable()
|
|
|
|
}
|
2020-08-04 08:24:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
|
|
|
|
return c.Properties.CoreVariantNeeded
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Module) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
|
|
|
|
return c.Properties.RamdiskVariantNeeded
|
|
|
|
}
|
|
|
|
|
2020-10-22 06:17:56 +08:00
|
|
|
func (c *Module) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
|
|
|
|
return c.Properties.VendorRamdiskVariantNeeded
|
|
|
|
}
|
|
|
|
|
2020-08-04 08:24:04 +08:00
|
|
|
func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
|
|
|
|
return c.Properties.RecoveryVariantNeeded
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
|
|
|
|
return c.Properties.ExtraVariants
|
|
|
|
}
|
|
|
|
|
2020-10-29 15:49:43 +08:00
|
|
|
func squashVendorSrcs(m *Module) {
|
|
|
|
if lib, ok := m.compiler.(*libraryDecorator); ok {
|
|
|
|
lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
|
|
|
|
lib.baseCompiler.Properties.Target.Vendor.Srcs...)
|
|
|
|
|
|
|
|
lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
|
|
|
|
lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
|
|
|
|
|
|
|
|
lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
|
|
|
|
lib.baseCompiler.Properties.Target.Vendor.Exclude_generated_sources...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func squashProductSrcs(m *Module) {
|
|
|
|
if lib, ok := m.compiler.(*libraryDecorator); ok {
|
|
|
|
lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
|
|
|
|
lib.baseCompiler.Properties.Target.Product.Srcs...)
|
|
|
|
|
|
|
|
lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
|
|
|
|
lib.baseCompiler.Properties.Target.Product.Exclude_srcs...)
|
|
|
|
|
|
|
|
lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
|
|
|
|
lib.baseCompiler.Properties.Target.Product.Exclude_generated_sources...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func squashRecoverySrcs(m *Module) {
|
|
|
|
if lib, ok := m.compiler.(*libraryDecorator); ok {
|
|
|
|
lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
|
|
|
|
lib.baseCompiler.Properties.Target.Recovery.Srcs...)
|
|
|
|
|
|
|
|
lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
|
|
|
|
lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
|
|
|
|
|
|
|
|
lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
|
|
|
|
lib.baseCompiler.Properties.Target.Recovery.Exclude_generated_sources...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func squashVendorRamdiskSrcs(m *Module) {
|
|
|
|
if lib, ok := m.compiler.(*libraryDecorator); ok {
|
|
|
|
lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, lib.baseCompiler.Properties.Target.Vendor_ramdisk.Exclude_srcs...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-04 08:24:04 +08:00
|
|
|
func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
|
|
|
|
m := module.(*Module)
|
2020-10-28 06:01:21 +08:00
|
|
|
if variant == android.RamdiskVariation {
|
2020-08-04 08:24:04 +08:00
|
|
|
m.MakeAsPlatform()
|
2020-10-28 06:01:21 +08:00
|
|
|
} else if variant == android.VendorRamdiskVariation {
|
|
|
|
m.MakeAsPlatform()
|
|
|
|
squashVendorRamdiskSrcs(m)
|
2020-08-04 08:24:04 +08:00
|
|
|
} else if variant == android.RecoveryVariation {
|
|
|
|
m.MakeAsPlatform()
|
|
|
|
squashRecoverySrcs(m)
|
|
|
|
} else if strings.HasPrefix(variant, VendorVariationPrefix) {
|
|
|
|
m.Properties.ImageVariationPrefix = VendorVariationPrefix
|
|
|
|
m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
|
|
|
|
squashVendorSrcs(m)
|
|
|
|
|
|
|
|
// Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION.
|
|
|
|
// Hide other vendor variants to avoid collision.
|
|
|
|
vndkVersion := ctx.DeviceConfig().VndkVersion()
|
|
|
|
if vndkVersion != "current" && vndkVersion != "" && vndkVersion != m.Properties.VndkVersion {
|
|
|
|
m.Properties.HideFromMake = true
|
2020-12-17 02:20:23 +08:00
|
|
|
m.HideFromMake()
|
2020-08-04 08:24:04 +08:00
|
|
|
}
|
|
|
|
} else if strings.HasPrefix(variant, ProductVariationPrefix) {
|
|
|
|
m.Properties.ImageVariationPrefix = ProductVariationPrefix
|
|
|
|
m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix)
|
2020-10-29 17:24:11 +08:00
|
|
|
squashProductSrcs(m)
|
2020-08-04 08:24:04 +08:00
|
|
|
}
|
|
|
|
}
|