2020-08-04 02:24:04 +02: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
|
|
|
|
//
|
2022-08-16 19:27:33 +02:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2020-08-04 02:24:04 +02:00
|
|
|
//
|
|
|
|
// 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 10:24:11 +01:00
|
|
|
"fmt"
|
|
|
|
"reflect"
|
2020-08-04 02:24:04 +02:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"android/soong/android"
|
2023-12-01 06:21:13 +01:00
|
|
|
|
|
|
|
"github.com/google/blueprint/proptools"
|
2020-08-04 02:24:04 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ android.ImageInterface = (*Module)(nil)
|
|
|
|
|
2020-12-14 17:27:52 +01:00
|
|
|
type ImageVariantType string
|
2020-08-03 17:41:38 +02:00
|
|
|
|
|
|
|
const (
|
2020-12-14 17:27:52 +01: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 17:41:38 +02:00
|
|
|
)
|
|
|
|
|
2020-08-04 02:24:04 +02:00
|
|
|
const (
|
2024-01-03 06:24:34 +01:00
|
|
|
// VendorVariation is the variant name used for /vendor code that does not
|
|
|
|
// compile against the VNDK.
|
|
|
|
VendorVariation = "vendor"
|
|
|
|
|
2020-08-04 02:24:04 +02:00
|
|
|
// VendorVariationPrefix is the variant prefix used for /vendor code that compiles
|
|
|
|
// against the VNDK.
|
|
|
|
VendorVariationPrefix = "vendor."
|
|
|
|
|
2024-01-03 06:24:34 +01:00
|
|
|
// ProductVariation is the variant name used for /product code that does not
|
|
|
|
// compile against the VNDK.
|
|
|
|
ProductVariation = "product"
|
|
|
|
|
2020-08-04 02:24:04 +02:00
|
|
|
// ProductVariationPrefix is the variant prefix used for /product code that compiles
|
|
|
|
// against the VNDK.
|
|
|
|
ProductVariationPrefix = "product."
|
|
|
|
)
|
|
|
|
|
|
|
|
func (ctx *moduleContextImpl) inProduct() bool {
|
2020-12-02 15:00:51 +01:00
|
|
|
return ctx.mod.InProduct()
|
2020-08-04 02:24:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *moduleContextImpl) inVendor() bool {
|
2020-12-14 17:27:52 +01:00
|
|
|
return ctx.mod.InVendor()
|
2020-08-04 02:24:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *moduleContextImpl) inRamdisk() bool {
|
|
|
|
return ctx.mod.InRamdisk()
|
|
|
|
}
|
|
|
|
|
2020-10-22 00:17:56 +02:00
|
|
|
func (ctx *moduleContextImpl) inVendorRamdisk() bool {
|
|
|
|
return ctx.mod.InVendorRamdisk()
|
|
|
|
}
|
|
|
|
|
2020-08-04 02:24:04 +02:00
|
|
|
func (ctx *moduleContextImpl) inRecovery() bool {
|
|
|
|
return ctx.mod.InRecovery()
|
|
|
|
}
|
|
|
|
|
2023-11-30 01:00:16 +01:00
|
|
|
func (c *Module) InstallInProduct() bool {
|
2021-04-12 06:19:28 +02: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 c.InProduct()
|
|
|
|
}
|
|
|
|
|
2023-11-30 01:00:16 +01:00
|
|
|
func (c *Module) InstallInVendor() bool {
|
2021-04-12 06:19:28 +02:00
|
|
|
// Additionally check if this module is inVendor() that means it is a "vendor" variant of a
|
|
|
|
// module. As well as SoC specific modules, vendor variants must be installed to /vendor
|
|
|
|
// unless they have "odm_available: true".
|
|
|
|
return c.HasVendorVariant() && c.InVendor() && !c.VendorVariantToOdm()
|
|
|
|
}
|
|
|
|
|
2023-11-30 01:00:16 +01:00
|
|
|
func (c *Module) InstallInOdm() bool {
|
2021-04-12 06:19:28 +02:00
|
|
|
// Some vendor variants want to be installed to /odm by setting "odm_available: true".
|
|
|
|
return c.InVendor() && c.VendorVariantToOdm()
|
|
|
|
}
|
|
|
|
|
2020-10-29 08:49:43 +01:00
|
|
|
// Returns true when this module is configured to have core and vendor variants.
|
2020-08-04 02:24:04 +02:00
|
|
|
func (c *Module) HasVendorVariant() bool {
|
2021-01-08 10:00:19 +01: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 02:24:04 +02:00
|
|
|
}
|
|
|
|
|
2020-10-29 08:49:43 +01:00
|
|
|
// Returns true when this module is configured to have core and product variants.
|
|
|
|
func (c *Module) HasProductVariant() bool {
|
2021-01-07 09:45:31 +01:00
|
|
|
return Bool(c.VendorProperties.Product_available)
|
2020-10-29 08:49:43 +01: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 10:24:11 +01:00
|
|
|
return c.HasVendorVariant() || c.HasProductVariant()
|
2020-10-29 08:49:43 +01:00
|
|
|
}
|
|
|
|
|
2020-08-04 02:24:04 +02:00
|
|
|
// Returns true if the module is "product" variant. Usually these modules are installed in /product
|
2020-12-02 15:00:51 +01:00
|
|
|
func (c *Module) InProduct() bool {
|
2024-01-03 06:24:34 +01:00
|
|
|
return c.Properties.ImageVariation == ProductVariation
|
2020-08-04 02:24:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
|
2020-12-14 17:27:52 +01:00
|
|
|
func (c *Module) InVendor() bool {
|
2024-01-03 06:24:34 +01:00
|
|
|
return c.Properties.ImageVariation == VendorVariation
|
2020-08-04 02:24:04 +02:00
|
|
|
}
|
|
|
|
|
2024-01-08 04:55:45 +01:00
|
|
|
// Returns true if the module is "vendor" or "product" variant. This replaces previous UseVndk usages
|
|
|
|
// which were misused to check if the module variant is vendor or product.
|
|
|
|
func (c *Module) InVendorOrProduct() bool {
|
|
|
|
return c.InVendor() || c.InProduct()
|
|
|
|
}
|
|
|
|
|
2020-08-04 02:24:04 +02:00
|
|
|
func (c *Module) InRamdisk() bool {
|
|
|
|
return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk()
|
|
|
|
}
|
|
|
|
|
2020-10-22 00:17:56 +02:00
|
|
|
func (c *Module) InVendorRamdisk() bool {
|
|
|
|
return c.ModuleBase.InVendorRamdisk() || c.ModuleBase.InstallInVendorRamdisk()
|
|
|
|
}
|
|
|
|
|
2020-08-04 02:24:04 +02: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 00:17:56 +02:00
|
|
|
func (c *Module) OnlyInVendorRamdisk() bool {
|
|
|
|
return c.ModuleBase.InstallInVendorRamdisk()
|
|
|
|
}
|
|
|
|
|
2020-08-04 02:24:04 +02:00
|
|
|
func (c *Module) OnlyInRecovery() bool {
|
|
|
|
return c.ModuleBase.InstallInRecovery()
|
|
|
|
}
|
|
|
|
|
2020-10-29 10:24:11 +01: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 09:45:31 +01:00
|
|
|
if !c.IsVndk() && !Bool(c.VendorProperties.Product_available) {
|
2020-10-29 10:24:11 +01: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
|
|
|
|
}
|
|
|
|
|
2021-03-30 18:19:36 +02:00
|
|
|
// ImageMutatableModule provides a common image mutation interface for LinkableInterface modules.
|
|
|
|
type ImageMutatableModule interface {
|
|
|
|
android.Module
|
|
|
|
LinkableInterface
|
2020-08-04 02:24:04 +02:00
|
|
|
|
2021-03-30 18:19:36 +02:00
|
|
|
// AndroidModuleBase returns the android.ModuleBase for this module
|
|
|
|
AndroidModuleBase() *android.ModuleBase
|
2021-01-08 10:00:19 +01:00
|
|
|
|
2021-03-30 18:19:36 +02:00
|
|
|
// VendorAvailable returns true if this module is available on the vendor image.
|
|
|
|
VendorAvailable() bool
|
2020-10-29 08:49:43 +01:00
|
|
|
|
2021-03-30 18:19:36 +02:00
|
|
|
// OdmAvailable returns true if this module is available on the odm image.
|
|
|
|
OdmAvailable() bool
|
|
|
|
|
|
|
|
// ProductAvailable returns true if this module is available on the product image.
|
|
|
|
ProductAvailable() bool
|
|
|
|
|
|
|
|
// RamdiskAvailable returns true if this module is available on the ramdisk image.
|
|
|
|
RamdiskAvailable() bool
|
|
|
|
|
|
|
|
// RecoveryAvailable returns true if this module is available on the recovery image.
|
|
|
|
RecoveryAvailable() bool
|
|
|
|
|
|
|
|
// VendorRamdiskAvailable returns true if this module is available on the vendor ramdisk image.
|
|
|
|
VendorRamdiskAvailable() bool
|
|
|
|
|
|
|
|
// IsSnapshotPrebuilt returns true if this module is a snapshot prebuilt.
|
|
|
|
IsSnapshotPrebuilt() bool
|
|
|
|
|
|
|
|
// SnapshotVersion returns the snapshot version for this module.
|
|
|
|
SnapshotVersion(mctx android.BaseModuleContext) string
|
|
|
|
|
|
|
|
// SdkVersion returns the SDK version for this module.
|
|
|
|
SdkVersion() string
|
|
|
|
|
|
|
|
// ExtraVariants returns the list of extra variants this module requires.
|
|
|
|
ExtraVariants() []string
|
|
|
|
|
|
|
|
// AppendExtraVariant returns an extra variant to the list of extra variants this module requires.
|
|
|
|
AppendExtraVariant(extraVariant string)
|
|
|
|
|
|
|
|
// SetRamdiskVariantNeeded sets whether the Ramdisk Variant is needed.
|
|
|
|
SetRamdiskVariantNeeded(b bool)
|
|
|
|
|
|
|
|
// SetVendorRamdiskVariantNeeded sets whether the Vendor Ramdisk Variant is needed.
|
|
|
|
SetVendorRamdiskVariantNeeded(b bool)
|
|
|
|
|
|
|
|
// SetRecoveryVariantNeeded sets whether the Recovery Variant is needed.
|
|
|
|
SetRecoveryVariantNeeded(b bool)
|
|
|
|
|
|
|
|
// SetCoreVariantNeeded sets whether the Core Variant is needed.
|
|
|
|
SetCoreVariantNeeded(b bool)
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ ImageMutatableModule = (*Module)(nil)
|
|
|
|
|
|
|
|
func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
|
|
|
|
m.CheckVndkProperties(mctx)
|
|
|
|
MutateImage(mctx, m)
|
|
|
|
}
|
|
|
|
|
|
|
|
// CheckVndkProperties checks whether the VNDK-related properties are set correctly.
|
|
|
|
// If properties are not set correctly, results in a module context property error.
|
|
|
|
func (m *Module) CheckVndkProperties(mctx android.BaseModuleContext) {
|
|
|
|
vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
|
|
|
|
productSpecific := mctx.ProductSpecific()
|
2020-08-04 02:24:04 +02: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 09:45:31 +01:00
|
|
|
} else if Bool(m.VendorProperties.Vendor_available) {
|
2020-08-04 02:24:04 +02:00
|
|
|
mctx.PropertyErrorf("vendor_available",
|
|
|
|
"must not set at the same time as `vndk: {extends: \"...\"}`")
|
2021-01-07 09:45:31 +01:00
|
|
|
} else if Bool(m.VendorProperties.Product_available) {
|
2020-10-29 08:49:43 +01:00
|
|
|
mctx.PropertyErrorf("product_available",
|
|
|
|
"must not set at the same time as `vndk: {extends: \"...\"}`")
|
2020-08-04 02:24:04 +02: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 09:45:31 +01:00
|
|
|
if !Bool(m.VendorProperties.Vendor_available) {
|
2020-08-04 02:24:04 +02:00
|
|
|
mctx.PropertyErrorf("vndk",
|
2021-01-07 09:45:31 +01:00
|
|
|
"vendor_available must be set to true when `vndk: {enabled: true}`")
|
2020-08-04 02:24:04 +02:00
|
|
|
}
|
2021-01-07 09:45:31 +01: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 10:23:14 +01: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 10:24:11 +01:00
|
|
|
if !m.compareVendorAndProductProps() {
|
|
|
|
mctx.ModuleErrorf("product properties must have the same values with the vendor properties for VNDK modules")
|
|
|
|
}
|
|
|
|
}
|
2020-08-04 02:24:04 +02: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())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-30 18:19:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Module) VendorAvailable() bool {
|
|
|
|
return Bool(m.VendorProperties.Vendor_available)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Module) OdmAvailable() bool {
|
|
|
|
return Bool(m.VendorProperties.Odm_available)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Module) ProductAvailable() bool {
|
|
|
|
return Bool(m.VendorProperties.Product_available)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Module) RamdiskAvailable() bool {
|
|
|
|
return Bool(m.Properties.Ramdisk_available)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Module) VendorRamdiskAvailable() bool {
|
|
|
|
return Bool(m.Properties.Vendor_ramdisk_available)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Module) AndroidModuleBase() *android.ModuleBase {
|
|
|
|
return &m.ModuleBase
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Module) RecoveryAvailable() bool {
|
|
|
|
return Bool(m.Properties.Recovery_available)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Module) ExtraVariants() []string {
|
2021-06-15 11:27:56 +02:00
|
|
|
return m.Properties.ExtraVersionedImageVariations
|
2021-03-30 18:19:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Module) AppendExtraVariant(extraVariant string) {
|
2021-06-15 11:27:56 +02:00
|
|
|
m.Properties.ExtraVersionedImageVariations = append(m.Properties.ExtraVersionedImageVariations, extraVariant)
|
2021-03-30 18:19:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Module) SetRamdiskVariantNeeded(b bool) {
|
|
|
|
m.Properties.RamdiskVariantNeeded = b
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Module) SetVendorRamdiskVariantNeeded(b bool) {
|
|
|
|
m.Properties.VendorRamdiskVariantNeeded = b
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Module) SetRecoveryVariantNeeded(b bool) {
|
|
|
|
m.Properties.RecoveryVariantNeeded = b
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Module) SetCoreVariantNeeded(b bool) {
|
|
|
|
m.Properties.CoreVariantNeeded = b
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Module) SnapshotVersion(mctx android.BaseModuleContext) string {
|
2021-05-26 21:33:11 +02:00
|
|
|
if snapshot, ok := m.linker.(SnapshotInterface); ok {
|
|
|
|
return snapshot.Version()
|
2021-03-30 18:19:36 +02:00
|
|
|
} else {
|
|
|
|
mctx.ModuleErrorf("version is unknown for snapshot prebuilt")
|
|
|
|
// Should we be panicking here instead?
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Module) KernelHeadersDecorator() bool {
|
|
|
|
if _, ok := m.linker.(*kernelHeadersDecorator); ok {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// MutateImage handles common image mutations for ImageMutatableModule interfaces.
|
|
|
|
func MutateImage(mctx android.BaseModuleContext, m ImageMutatableModule) {
|
|
|
|
// Validation check
|
|
|
|
vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
|
|
|
|
productSpecific := mctx.ProductSpecific()
|
|
|
|
|
|
|
|
if m.VendorAvailable() {
|
|
|
|
if vendorSpecific {
|
|
|
|
mctx.PropertyErrorf("vendor_available",
|
|
|
|
"doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific: true`")
|
|
|
|
}
|
|
|
|
if m.OdmAvailable() {
|
|
|
|
mctx.PropertyErrorf("vendor_available",
|
|
|
|
"doesn't make sense at the same time as `odm_available: true`")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if m.OdmAvailable() {
|
|
|
|
if vendorSpecific {
|
|
|
|
mctx.PropertyErrorf("odm_available",
|
|
|
|
"doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific: true`")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if m.ProductAvailable() {
|
|
|
|
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 02:24:04 +02:00
|
|
|
|
|
|
|
var coreVariantNeeded bool = false
|
|
|
|
var ramdiskVariantNeeded bool = false
|
2020-10-22 00:17:56 +02:00
|
|
|
var vendorRamdiskVariantNeeded bool = false
|
2020-08-04 02:24:04 +02:00
|
|
|
var recoveryVariantNeeded bool = false
|
|
|
|
|
|
|
|
var vendorVariants []string
|
|
|
|
var productVariants []string
|
|
|
|
|
2021-05-18 16:10:00 +02:00
|
|
|
needVndkVersionVendorVariantForLlndk := false
|
2024-04-04 10:33:42 +02:00
|
|
|
|
2021-04-27 02:19:41 +02:00
|
|
|
if m.NeedsLlndkVariants() {
|
2021-01-07 02:05:04 +01:00
|
|
|
// 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.
|
2021-04-27 02:19:41 +02:00
|
|
|
coreVariantNeeded = true
|
2024-03-18 08:01:19 +01:00
|
|
|
vendorVariants = append(vendorVariants, "")
|
|
|
|
productVariants = append(productVariants, "")
|
2021-05-18 16:10:00 +02:00
|
|
|
// Generate vendor variants for boardVndkVersion only if the VNDK snapshot does not
|
|
|
|
// provide the LLNDK stub libraries.
|
|
|
|
if needVndkVersionVendorVariantForLlndk {
|
2024-04-04 10:33:42 +02:00
|
|
|
vendorVariants = append(vendorVariants, "")
|
2021-01-07 02:05:04 +01:00
|
|
|
}
|
2021-04-27 22:06:04 +02:00
|
|
|
} else if m.NeedsVendorPublicLibraryVariants() {
|
|
|
|
// A vendor public library has the implementation on /vendor, with stub variants
|
|
|
|
// for system and product.
|
|
|
|
coreVariantNeeded = true
|
2024-04-04 10:33:42 +02:00
|
|
|
vendorVariants = append(vendorVariants, "")
|
2024-03-18 08:01:19 +01:00
|
|
|
productVariants = append(productVariants, "")
|
2021-03-30 18:19:36 +02:00
|
|
|
} else if m.IsSnapshotPrebuilt() {
|
2020-08-04 02:24:04 +02:00
|
|
|
// Make vendor variants only for the versions in BOARD_VNDK_VERSION and
|
|
|
|
// PRODUCT_EXTRA_VNDK_VERSIONS.
|
2021-03-30 18:19:36 +02:00
|
|
|
if m.InstallInRecovery() {
|
|
|
|
recoveryVariantNeeded = true
|
2020-08-04 02:24:04 +02:00
|
|
|
} else {
|
2021-03-30 18:19:36 +02:00
|
|
|
vendorVariants = append(vendorVariants, m.SnapshotVersion(mctx))
|
2020-08-04 02:24:04 +02:00
|
|
|
}
|
2020-12-02 15:00:51 +01:00
|
|
|
} else if m.HasNonSystemVariants() && !m.IsVndkExt() {
|
2020-10-29 08:49:43 +01:00
|
|
|
// This will be available to /system unless it is product_specific
|
|
|
|
// which will be handled later.
|
2020-08-04 02:24:04 +02: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 08:49:43 +01:00
|
|
|
if m.HasVendorVariant() {
|
2024-04-04 02:56:15 +02:00
|
|
|
vendorVariants = append(vendorVariants, "")
|
2020-08-04 02:24:04 +02:00
|
|
|
}
|
|
|
|
|
2020-10-29 10:24:11 +01:00
|
|
|
// product_available modules are available to /product.
|
|
|
|
if m.HasProductVariant() {
|
2024-03-18 08:01:19 +01:00
|
|
|
productVariants = append(productVariants, "")
|
2020-08-04 02:24:04 +02:00
|
|
|
}
|
2021-03-30 18:19:36 +02:00
|
|
|
} else if vendorSpecific && m.SdkVersion() == "" {
|
2020-08-04 02:24:04 +02:00
|
|
|
// This will be available in /vendor (or /odm) only
|
2024-04-04 10:33:42 +02:00
|
|
|
vendorVariants = append(vendorVariants, "")
|
2020-08-04 02:24:04 +02:00
|
|
|
} else {
|
|
|
|
// This is either in /system (or similar: /data), or is a
|
2022-07-21 12:04:37 +02:00
|
|
|
// module built with the NDK. Modules built with the NDK
|
2020-08-04 02:24:04 +02:00
|
|
|
// will be restricted using the existing link type checks.
|
|
|
|
coreVariantNeeded = true
|
|
|
|
}
|
|
|
|
|
2023-09-27 09:22:10 +02:00
|
|
|
if coreVariantNeeded && productSpecific && m.SdkVersion() == "" {
|
|
|
|
// The module has "product_specific: true" that does not create core variant.
|
|
|
|
coreVariantNeeded = false
|
2024-03-18 08:01:19 +01:00
|
|
|
productVariants = append(productVariants, "")
|
2020-08-04 02:24:04 +02:00
|
|
|
}
|
|
|
|
|
2021-03-30 18:19:36 +02:00
|
|
|
if m.RamdiskAvailable() {
|
2020-08-04 02:24:04 +02:00
|
|
|
ramdiskVariantNeeded = true
|
|
|
|
}
|
|
|
|
|
2021-03-30 18:19:36 +02:00
|
|
|
if m.AndroidModuleBase().InstallInRamdisk() {
|
2020-08-04 02:24:04 +02:00
|
|
|
ramdiskVariantNeeded = true
|
|
|
|
coreVariantNeeded = false
|
|
|
|
}
|
|
|
|
|
2021-03-30 18:19:36 +02:00
|
|
|
if m.VendorRamdiskAvailable() {
|
2020-10-22 00:17:56 +02:00
|
|
|
vendorRamdiskVariantNeeded = true
|
|
|
|
}
|
|
|
|
|
2021-03-30 18:19:36 +02:00
|
|
|
if m.AndroidModuleBase().InstallInVendorRamdisk() {
|
2020-10-22 00:17:56 +02:00
|
|
|
vendorRamdiskVariantNeeded = true
|
|
|
|
coreVariantNeeded = false
|
|
|
|
}
|
|
|
|
|
2021-03-30 18:19:36 +02:00
|
|
|
if m.RecoveryAvailable() {
|
2020-08-04 02:24:04 +02:00
|
|
|
recoveryVariantNeeded = true
|
|
|
|
}
|
|
|
|
|
2021-03-30 18:19:36 +02:00
|
|
|
if m.AndroidModuleBase().InstallInRecovery() {
|
2020-08-04 02:24:04 +02:00
|
|
|
recoveryVariantNeeded = true
|
|
|
|
coreVariantNeeded = false
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, variant := range android.FirstUniqueStrings(vendorVariants) {
|
2024-01-03 06:24:34 +01:00
|
|
|
if variant == "" {
|
|
|
|
m.AppendExtraVariant(VendorVariation)
|
|
|
|
} else {
|
|
|
|
m.AppendExtraVariant(VendorVariationPrefix + variant)
|
|
|
|
}
|
2020-08-04 02:24:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, variant := range android.FirstUniqueStrings(productVariants) {
|
2024-01-03 06:24:34 +01:00
|
|
|
if variant == "" {
|
|
|
|
m.AppendExtraVariant(ProductVariation)
|
|
|
|
} else {
|
|
|
|
m.AppendExtraVariant(ProductVariationPrefix + variant)
|
|
|
|
}
|
2020-08-04 02:24:04 +02:00
|
|
|
}
|
|
|
|
|
2021-03-30 18:19:36 +02:00
|
|
|
m.SetRamdiskVariantNeeded(ramdiskVariantNeeded)
|
|
|
|
m.SetVendorRamdiskVariantNeeded(vendorRamdiskVariantNeeded)
|
|
|
|
m.SetRecoveryVariantNeeded(recoveryVariantNeeded)
|
|
|
|
m.SetCoreVariantNeeded(coreVariantNeeded)
|
2020-12-11 22:36:29 +01:00
|
|
|
|
|
|
|
// Disable the module if no variants are needed.
|
|
|
|
if !ramdiskVariantNeeded &&
|
|
|
|
!recoveryVariantNeeded &&
|
|
|
|
!coreVariantNeeded &&
|
2021-03-30 18:19:36 +02:00
|
|
|
len(m.ExtraVariants()) == 0 {
|
2020-12-11 22:36:29 +01:00
|
|
|
m.Disable()
|
|
|
|
}
|
2020-08-04 02:24:04 +02: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 00:17:56 +02:00
|
|
|
func (c *Module) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
|
|
|
|
return c.Properties.VendorRamdiskVariantNeeded
|
|
|
|
}
|
|
|
|
|
2021-04-08 14:13:22 +02:00
|
|
|
func (c *Module) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-08-04 02:24:04 +02:00
|
|
|
func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
|
|
|
|
return c.Properties.RecoveryVariantNeeded
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
|
2021-06-15 11:27:56 +02:00
|
|
|
return c.Properties.ExtraVersionedImageVariations
|
2020-08-04 02:24:04 +02:00
|
|
|
}
|
|
|
|
|
2020-10-29 08:49:43 +01: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...)
|
2023-12-01 06:21:13 +01:00
|
|
|
|
|
|
|
if lib.Properties.Target.Vendor.No_stubs {
|
|
|
|
proptools.Clear(&lib.Properties.Stubs)
|
|
|
|
}
|
2020-10-29 08:49:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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...)
|
2023-12-01 06:21:13 +01:00
|
|
|
|
|
|
|
if lib.Properties.Target.Product.No_stubs {
|
|
|
|
proptools.Clear(&lib.Properties.Stubs)
|
|
|
|
}
|
2020-10-29 08:49:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-28 02:06:46 +02:00
|
|
|
func squashRamdiskSrcs(m *Module) {
|
|
|
|
if lib, ok := m.compiler.(*libraryDecorator); ok {
|
|
|
|
lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, lib.baseCompiler.Properties.Target.Ramdisk.Exclude_srcs...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-04 02:24:04 +02:00
|
|
|
func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
|
|
|
|
m := module.(*Module)
|
2020-10-27 23:01:21 +01:00
|
|
|
if variant == android.RamdiskVariation {
|
2020-08-04 02:24:04 +02:00
|
|
|
m.MakeAsPlatform()
|
2023-07-28 02:06:46 +02:00
|
|
|
squashRamdiskSrcs(m)
|
2020-10-27 23:01:21 +01:00
|
|
|
} else if variant == android.VendorRamdiskVariation {
|
|
|
|
m.MakeAsPlatform()
|
|
|
|
squashVendorRamdiskSrcs(m)
|
2020-08-04 02:24:04 +02:00
|
|
|
} else if variant == android.RecoveryVariation {
|
|
|
|
m.MakeAsPlatform()
|
|
|
|
squashRecoverySrcs(m)
|
2024-01-03 06:24:34 +01:00
|
|
|
} else if strings.HasPrefix(variant, VendorVariation) {
|
|
|
|
m.Properties.ImageVariation = VendorVariation
|
|
|
|
|
|
|
|
if strings.HasPrefix(variant, VendorVariationPrefix) {
|
|
|
|
m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
|
|
|
|
}
|
2020-08-04 02:24:04 +02:00
|
|
|
squashVendorSrcs(m)
|
2024-01-03 06:24:34 +01:00
|
|
|
} else if strings.HasPrefix(variant, ProductVariation) {
|
|
|
|
m.Properties.ImageVariation = ProductVariation
|
|
|
|
if strings.HasPrefix(variant, ProductVariationPrefix) {
|
|
|
|
m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix)
|
|
|
|
}
|
2020-10-29 10:24:11 +01:00
|
|
|
squashProductSrcs(m)
|
2020-08-04 02:24:04 +02:00
|
|
|
}
|
2021-04-27 22:06:04 +02:00
|
|
|
|
|
|
|
if c.NeedsVendorPublicLibraryVariants() &&
|
|
|
|
(variant == android.CoreVariation || strings.HasPrefix(variant, ProductVariationPrefix)) {
|
|
|
|
c.VendorProperties.IsVendorPublicLibrary = true
|
|
|
|
}
|
2020-08-04 02:24:04 +02:00
|
|
|
}
|