2020-12-02 15:15:16 +01: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 rust
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/cc"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ android.ImageInterface = (*Module)(nil)
|
|
|
|
|
2021-03-22 19:29:47 +01:00
|
|
|
var _ cc.ImageMutatableModule = (*Module)(nil)
|
|
|
|
|
|
|
|
func (mod *Module) VendorAvailable() bool {
|
|
|
|
return Bool(mod.VendorProperties.Vendor_available)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mod *Module) OdmAvailable() bool {
|
|
|
|
return Bool(mod.VendorProperties.Odm_available)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mod *Module) ProductAvailable() bool {
|
2021-05-27 19:01:36 +02:00
|
|
|
return Bool(mod.VendorProperties.Product_available)
|
2021-03-22 19:29:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (mod *Module) RamdiskAvailable() bool {
|
2021-07-13 23:12:37 +02:00
|
|
|
return Bool(mod.Properties.Ramdisk_available)
|
2021-03-22 19:29:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (mod *Module) VendorRamdiskAvailable() bool {
|
|
|
|
return Bool(mod.Properties.Vendor_ramdisk_available)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mod *Module) AndroidModuleBase() *android.ModuleBase {
|
|
|
|
return &mod.ModuleBase
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mod *Module) RecoveryAvailable() bool {
|
2021-02-11 21:31:46 +01:00
|
|
|
return Bool(mod.Properties.Recovery_available)
|
2021-03-22 19:29:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (mod *Module) ExtraVariants() []string {
|
|
|
|
return mod.Properties.ExtraVariants
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mod *Module) AppendExtraVariant(extraVariant string) {
|
|
|
|
mod.Properties.ExtraVariants = append(mod.Properties.ExtraVariants, extraVariant)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mod *Module) SetRamdiskVariantNeeded(b bool) {
|
2021-07-13 23:12:37 +02:00
|
|
|
mod.Properties.RamdiskVariantNeeded = b
|
2021-03-22 19:29:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (mod *Module) SetVendorRamdiskVariantNeeded(b bool) {
|
|
|
|
mod.Properties.VendorRamdiskVariantNeeded = b
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mod *Module) SetRecoveryVariantNeeded(b bool) {
|
2021-02-11 21:31:46 +01:00
|
|
|
mod.Properties.RecoveryVariantNeeded = b
|
2021-03-22 19:29:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (mod *Module) SetCoreVariantNeeded(b bool) {
|
|
|
|
mod.Properties.CoreVariantNeeded = b
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mod *Module) SnapshotVersion(mctx android.BaseModuleContext) string {
|
2021-06-01 21:09:53 +02:00
|
|
|
if snapshot, ok := mod.compiler.(cc.SnapshotInterface); ok {
|
|
|
|
return snapshot.Version()
|
|
|
|
} else {
|
|
|
|
mctx.ModuleErrorf("version is unknown for snapshot prebuilt")
|
|
|
|
return ""
|
|
|
|
}
|
2021-03-22 19:29:47 +01:00
|
|
|
}
|
|
|
|
|
2020-12-02 15:15:16 +01:00
|
|
|
func (mod *Module) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
|
2021-02-05 16:57:43 +01:00
|
|
|
return mod.Properties.VendorRamdiskVariantNeeded
|
2020-12-02 15:15:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (mod *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
|
|
|
|
return mod.Properties.CoreVariantNeeded
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mod *Module) RamdiskVariantNeeded(android.BaseModuleContext) bool {
|
2021-07-13 23:12:37 +02:00
|
|
|
return mod.Properties.RamdiskVariantNeeded
|
2020-12-02 15:15:16 +01:00
|
|
|
}
|
|
|
|
|
2021-04-08 14:13:22 +02:00
|
|
|
func (mod *Module) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-12-02 15:15:16 +01:00
|
|
|
func (mod *Module) RecoveryVariantNeeded(android.BaseModuleContext) bool {
|
2021-02-11 21:31:46 +01:00
|
|
|
return mod.Properties.RecoveryVariantNeeded
|
2020-12-02 15:15:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (mod *Module) ExtraImageVariations(android.BaseModuleContext) []string {
|
|
|
|
return mod.Properties.ExtraVariants
|
|
|
|
}
|
|
|
|
|
2021-03-22 19:29:47 +01:00
|
|
|
func (mod *Module) IsSnapshotPrebuilt() bool {
|
2021-06-01 21:09:53 +02:00
|
|
|
if p, ok := mod.compiler.(cc.SnapshotInterface); ok {
|
|
|
|
return p.IsSnapshotPrebuilt()
|
|
|
|
}
|
2021-03-22 19:29:47 +01:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2023-11-30 01:00:16 +01:00
|
|
|
func (mod *Module) InstallInVendor() bool {
|
2021-04-02 18:41:32 +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".
|
2023-11-30 01:00:16 +01:00
|
|
|
return mod.InVendor() && !mod.VendorVariantToOdm()
|
2021-04-02 18:41:32 +02:00
|
|
|
}
|
|
|
|
|
2023-11-30 01:00:16 +01:00
|
|
|
func (mod *Module) InstallInOdm() bool {
|
2021-04-02 18:41:32 +02:00
|
|
|
// Some vendor variants want to be installed to /odm by setting "odm_available: true".
|
2023-11-30 01:00:16 +01:00
|
|
|
return mod.InVendor() && mod.VendorVariantToOdm()
|
2023-01-25 01:36:02 +01:00
|
|
|
}
|
|
|
|
|
2021-04-02 18:41:32 +02:00
|
|
|
// 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-12-02 15:15:16 +01:00
|
|
|
func (ctx *moduleContext) ProductSpecific() bool {
|
2021-08-19 22:10:05 +02:00
|
|
|
return ctx.ModuleContext.ProductSpecific() || ctx.RustModule().productSpecificModuleContext()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Module) productSpecificModuleContext() bool {
|
|
|
|
// 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()
|
2020-12-02 15:15:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (mod *Module) InRecovery() bool {
|
2021-02-11 21:31:46 +01:00
|
|
|
return mod.ModuleBase.InRecovery() || mod.ModuleBase.InstallInRecovery()
|
2020-12-02 15:15:16 +01:00
|
|
|
}
|
|
|
|
|
2022-02-07 07:06:23 +01:00
|
|
|
func (mod *Module) InRamdisk() bool {
|
|
|
|
return mod.ModuleBase.InRamdisk() || mod.ModuleBase.InstallInRamdisk()
|
|
|
|
}
|
|
|
|
|
2021-02-05 16:57:43 +01:00
|
|
|
func (mod *Module) InVendorRamdisk() bool {
|
|
|
|
return mod.ModuleBase.InVendorRamdisk() || mod.ModuleBase.InstallInVendorRamdisk()
|
|
|
|
}
|
|
|
|
|
2020-12-02 15:15:16 +01:00
|
|
|
func (mod *Module) OnlyInRamdisk() bool {
|
2023-01-25 01:36:02 +01:00
|
|
|
return mod.ModuleBase.InstallInRamdisk()
|
2020-12-02 15:15:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (mod *Module) OnlyInRecovery() bool {
|
2023-01-25 01:36:02 +01:00
|
|
|
return mod.ModuleBase.InstallInRecovery()
|
2020-12-02 15:15:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (mod *Module) OnlyInVendorRamdisk() bool {
|
2023-01-25 01:36:02 +01:00
|
|
|
return mod.ModuleBase.InstallInVendorRamdisk()
|
2021-05-27 19:01:36 +02:00
|
|
|
}
|
|
|
|
|
2020-12-02 15:15:16 +01:00
|
|
|
// Returns true when this module is configured to have core and vendor variants.
|
|
|
|
func (mod *Module) HasVendorVariant() bool {
|
2021-01-08 10:00:19 +01:00
|
|
|
return Bool(mod.VendorProperties.Vendor_available) || Bool(mod.VendorProperties.Odm_available)
|
2020-12-02 15:15:16 +01:00
|
|
|
}
|
|
|
|
|
2021-02-03 11:24:13 +01:00
|
|
|
// Always returns false because rust modules do not support product variant.
|
|
|
|
func (mod *Module) HasProductVariant() bool {
|
|
|
|
return Bool(mod.VendorProperties.Product_available)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mod *Module) HasNonSystemVariants() bool {
|
|
|
|
return mod.HasVendorVariant() || mod.HasProductVariant()
|
|
|
|
}
|
|
|
|
|
2021-03-22 19:29:47 +01:00
|
|
|
func (mod *Module) InProduct() bool {
|
2024-01-03 06:24:34 +01:00
|
|
|
return mod.Properties.ImageVariation == cc.ProductVariation
|
2020-12-02 15:15:16 +01:00
|
|
|
}
|
|
|
|
|
2021-04-02 18:41:32 +02:00
|
|
|
// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
|
|
|
|
func (mod *Module) InVendor() bool {
|
2024-01-03 06:24:34 +01:00
|
|
|
return mod.Properties.ImageVariation == cc.VendorVariation
|
2021-04-02 18:41:32 +02:00
|
|
|
}
|
|
|
|
|
2024-01-08 04:55:45 +01:00
|
|
|
// Returns true if the module is "vendor" or "product" variant.
|
|
|
|
func (mod *Module) InVendorOrProduct() bool {
|
|
|
|
return mod.InVendor() || mod.InProduct()
|
|
|
|
}
|
|
|
|
|
2024-06-13 23:25:45 +02:00
|
|
|
func (mod *Module) SetImageVariation(ctx android.BaseModuleContext, variant string) {
|
2021-02-05 16:57:43 +01:00
|
|
|
if variant == android.VendorRamdiskVariation {
|
2024-06-13 23:25:45 +02:00
|
|
|
mod.MakeAsPlatform()
|
2021-02-11 21:31:46 +01:00
|
|
|
} else if variant == android.RecoveryVariation {
|
2024-06-13 23:25:45 +02:00
|
|
|
mod.MakeAsPlatform()
|
2024-01-03 06:24:34 +01:00
|
|
|
} else if strings.HasPrefix(variant, cc.VendorVariation) {
|
2024-06-13 23:25:45 +02:00
|
|
|
mod.Properties.ImageVariation = cc.VendorVariation
|
2024-01-03 06:24:34 +01:00
|
|
|
if strings.HasPrefix(variant, cc.VendorVariationPrefix) {
|
2024-06-13 23:25:45 +02:00
|
|
|
mod.Properties.VndkVersion = strings.TrimPrefix(variant, cc.VendorVariationPrefix)
|
2024-01-03 06:24:34 +01:00
|
|
|
}
|
|
|
|
} else if strings.HasPrefix(variant, cc.ProductVariation) {
|
2024-06-13 23:25:45 +02:00
|
|
|
mod.Properties.ImageVariation = cc.ProductVariation
|
2024-01-03 06:24:34 +01:00
|
|
|
if strings.HasPrefix(variant, cc.ProductVariationPrefix) {
|
2024-06-13 23:25:45 +02:00
|
|
|
mod.Properties.VndkVersion = strings.TrimPrefix(variant, cc.ProductVariationPrefix)
|
2024-01-03 06:24:34 +01:00
|
|
|
}
|
2020-12-02 15:15:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mod *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
|
2023-01-25 01:36:02 +01:00
|
|
|
if Bool(mod.VendorProperties.Double_loadable) {
|
2020-12-02 15:15:16 +01:00
|
|
|
mctx.PropertyErrorf("double_loadable",
|
|
|
|
"Rust modules do not yet support double loading")
|
|
|
|
}
|
2021-02-05 16:57:43 +01:00
|
|
|
if Bool(mod.Properties.Vendor_ramdisk_available) {
|
|
|
|
if lib, ok := mod.compiler.(libraryInterface); !ok || (ok && lib.buildShared()) {
|
|
|
|
mctx.PropertyErrorf("vendor_ramdisk_available", "cannot be set for rust_ffi or rust_ffi_shared modules.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-02 18:41:32 +02:00
|
|
|
cc.MutateImage(mctx, mod)
|
|
|
|
|
|
|
|
if !mod.Properties.CoreVariantNeeded || mod.HasNonSystemVariants() {
|
|
|
|
|
|
|
|
if _, ok := mod.compiler.(*prebuiltLibraryDecorator); ok {
|
|
|
|
// Rust does not support prebuilt libraries on non-System images.
|
|
|
|
mctx.ModuleErrorf("Rust prebuilt modules not supported for non-system images.")
|
2020-12-02 15:15:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|