Support Rust in Product

Bug: 178565008
Bug: 165791368
Test: Build and link a Rust library into a product binary
Change-Id: I9c5aa5f3a1f323af9aa2aee804635045f1b91bd4
This commit is contained in:
Matthew Maurer 2021-05-27 10:01:36 -07:00
parent 460ee9429e
commit 52af5b052b
4 changed files with 18 additions and 9 deletions

View file

@ -25,7 +25,7 @@ import (
var ( var (
nativeBridgeSuffix = ".native_bridge" nativeBridgeSuffix = ".native_bridge"
productSuffix = ".product" ProductSuffix = ".product"
VendorSuffix = ".vendor" VendorSuffix = ".vendor"
ramdiskSuffix = ".ramdisk" ramdiskSuffix = ".ramdisk"
VendorRamdiskSuffix = ".vendor_ramdisk" VendorRamdiskSuffix = ".vendor_ramdisk"

View file

@ -1632,7 +1632,7 @@ func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string
return "" return ""
} }
vndkVersion = ctx.DeviceConfig().ProductVndkVersion() vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
nameSuffix = productSuffix nameSuffix = ProductSuffix
} else { } else {
vndkVersion = ctx.DeviceConfig().VndkVersion() vndkVersion = ctx.DeviceConfig().VndkVersion()
nameSuffix = VendorSuffix nameSuffix = VendorSuffix

View file

@ -34,7 +34,7 @@ func (mod *Module) OdmAvailable() bool {
} }
func (mod *Module) ProductAvailable() bool { func (mod *Module) ProductAvailable() bool {
return false return Bool(mod.VendorProperties.Product_available)
} }
func (mod *Module) RamdiskAvailable() bool { func (mod *Module) RamdiskAvailable() bool {
@ -163,6 +163,11 @@ func (mod *Module) OnlyInVendorRamdisk() bool {
return false return false
} }
func (mod *Module) OnlyInProduct() bool {
//TODO(b/165791368)
return false
}
// Returns true when this module is configured to have core and vendor variants. // Returns true when this module is configured to have core and vendor variants.
func (mod *Module) HasVendorVariant() bool { func (mod *Module) HasVendorVariant() bool {
return Bool(mod.VendorProperties.Vendor_available) || Bool(mod.VendorProperties.Odm_available) return Bool(mod.VendorProperties.Vendor_available) || Bool(mod.VendorProperties.Odm_available)
@ -178,7 +183,7 @@ func (mod *Module) HasNonSystemVariants() bool {
} }
func (mod *Module) InProduct() bool { func (mod *Module) InProduct() bool {
return false return mod.Properties.ImageVariationPrefix == cc.ProductVariationPrefix
} }
// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor // Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
@ -203,6 +208,9 @@ func (mod *Module) SetImageVariation(ctx android.BaseModuleContext, variant stri
m.Properties.HideFromMake = true m.Properties.HideFromMake = true
m.HideFromMake() m.HideFromMake()
} }
} else if strings.HasPrefix(variant, cc.ProductVariationPrefix) {
m.Properties.ImageVariationPrefix = cc.ProductVariationPrefix
m.Properties.VndkVersion = strings.TrimPrefix(variant, cc.ProductVariationPrefix)
} }
} }
@ -210,10 +218,7 @@ func (mod *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
// Rust does not support installing to the product image yet. // Rust does not support installing to the product image yet.
vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific() vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
if Bool(mod.VendorProperties.Product_available) { if mctx.ProductSpecific() {
mctx.PropertyErrorf("product_available",
"Rust modules do not yet support being available to the product image")
} else if mctx.ProductSpecific() {
mctx.PropertyErrorf("product_specific", mctx.PropertyErrorf("product_specific",
"Rust modules do not yet support installing to the product image.") "Rust modules do not yet support installing to the product image.")
} else if Bool(mod.VendorProperties.Double_loadable) { } else if Bool(mod.VendorProperties.Double_loadable) {

View file

@ -808,7 +808,11 @@ func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
// Differentiate static libraries that are vendor available // Differentiate static libraries that are vendor available
if mod.UseVndk() { if mod.UseVndk() {
mod.Properties.SubName += cc.VendorSuffix if mod.InProduct() && !mod.OnlyInProduct() {
mod.Properties.SubName += cc.ProductSuffix
} else {
mod.Properties.SubName += cc.VendorSuffix
}
} else if mod.InVendorRamdisk() && !mod.OnlyInVendorRamdisk() { } else if mod.InVendorRamdisk() && !mod.OnlyInVendorRamdisk() {
mod.Properties.SubName += cc.VendorRamdiskSuffix mod.Properties.SubName += cc.VendorRamdiskSuffix
} else if mod.InRecovery() && !mod.OnlyInRecovery() { } else if mod.InRecovery() && !mod.OnlyInRecovery() {