rust: Use new common image mutator interface.

Refactor rust to use and implement the new common image mutator
interface to handle future image mutations.

Bug: 184042776
Test: m nothing
Change-Id: If6a85e2b8c6a1969d62264eaea6c6b53cae9c039
This commit is contained in:
Ivan Lozano 2021-03-22 14:29:47 -04:00
parent 3a7d000d12
commit 699e218324
2 changed files with 75 additions and 39 deletions

View File

@ -23,6 +23,68 @@ import (
var _ android.ImageInterface = (*Module)(nil)
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 {
return false
}
func (mod *Module) RamdiskAvailable() bool {
return false
}
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 {
return false
}
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) {
if b {
panic("Setting ramdisk variant needed for Rust module is unsupported: " + mod.BaseModuleName())
}
}
func (mod *Module) SetVendorRamdiskVariantNeeded(b bool) {
mod.Properties.VendorRamdiskVariantNeeded = b
}
func (mod *Module) SetRecoveryVariantNeeded(b bool) {
if b {
panic("Setting recovery variant needed for Rust module is unsupported: " + mod.BaseModuleName())
}
}
func (mod *Module) SetCoreVariantNeeded(b bool) {
mod.Properties.CoreVariantNeeded = b
}
func (mod *Module) SnapshotVersion(mctx android.BaseModuleContext) string {
panic("Rust modules do not support snapshotting: " + mod.BaseModuleName())
}
func (mod *Module) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
return mod.Properties.VendorRamdiskVariantNeeded
}
@ -43,6 +105,11 @@ func (mod *Module) ExtraImageVariations(android.BaseModuleContext) []string {
return mod.Properties.ExtraVariants
}
func (mod *Module) IsSnapshotPrebuilt() bool {
// Rust does not support prebuilts in its snapshots
return false
}
func (ctx *moduleContext) ProductSpecific() bool {
return false
}
@ -84,7 +151,7 @@ func (mod *Module) HasNonSystemVariants() bool {
return mod.HasVendorVariant() || mod.HasProductVariant()
}
func (c *Module) InProduct() bool {
func (mod *Module) InProduct() bool {
return false
}
@ -107,9 +174,6 @@ func (mod *Module) SetImageVariation(ctx android.BaseModuleContext, variant stri
}
func (mod *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
// Rust does not support installing to the product image yet.
if Bool(mod.VendorProperties.Product_available) {
mctx.PropertyErrorf("product_available",
@ -122,59 +186,31 @@ func (mod *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
"Rust modules do not yet support double loading")
}
coreVariantNeeded := true
vendorRamdiskVariantNeeded := false
var vendorVariants []string
if mod.HasVendorVariant() {
prop := "vendor_available"
if Bool(mod.VendorProperties.Odm_available) {
prop = "odm_available"
}
if vendorSpecific {
mctx.PropertyErrorf(prop,
"doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific: true`")
}
if lib, ok := mod.compiler.(libraryInterface); ok {
if lib, ok := mod.compiler.(libraryInterface); ok && lib.buildShared() {
// Explicitly disallow rust_ffi variants which produce shared libraries from setting vendor_available.
// Vendor variants do not produce an error for dylibs, rlibs with dylib-std linkage are disabled in the respective library
// mutators until support is added.
//
// We can't check shared() here because image mutator is called before the library mutator, so we need to
// check buildShared()
if lib.buildShared() {
mctx.PropertyErrorf(prop, "cannot be set for rust_ffi or rust_ffi_shared modules.")
} else {
vendorVariants = append(vendorVariants, platformVndkVersion)
}
mctx.PropertyErrorf("vendor_available", "cannot be set for rust_ffi or rust_ffi_shared modules.")
}
}
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.")
} else {
vendorRamdiskVariantNeeded = true
}
}
vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
if vendorSpecific {
if lib, ok := mod.compiler.(libraryInterface); !ok || (ok && (lib.buildShared() || lib.buildDylib() || lib.buildRlib())) {
mctx.ModuleErrorf("Rust vendor specific modules are currently only supported for rust_ffi_static modules.")
} else {
coreVariantNeeded = false
vendorVariants = append(vendorVariants, platformVndkVersion)
}
}
mod.Properties.CoreVariantNeeded = coreVariantNeeded
mod.Properties.VendorRamdiskVariantNeeded = vendorRamdiskVariantNeeded
for _, variant := range android.FirstUniqueStrings(vendorVariants) {
mod.Properties.ExtraVariants = append(mod.Properties.ExtraVariants, cc.VendorVariationPrefix+variant)
}
cc.MutateImage(mctx, mod)
}

View File

@ -150,7 +150,7 @@ func GatherRequiredDepsForTest() string {
host_supported: true,
vendor_available: true,
vendor_ramdisk_available: true,
native_coverage: false,
native_coverage: false,
sysroot: true,
apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
min_sdk_version: "29",
@ -163,7 +163,7 @@ func GatherRequiredDepsForTest() string {
host_supported: true,
vendor_available: true,
vendor_ramdisk_available: true,
native_coverage: false,
native_coverage: false,
sysroot: true,
apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
min_sdk_version: "29",