diff --git a/cc/androidmk.go b/cc/androidmk.go index bda10067b..e95d5a793 100644 --- a/cc/androidmk.go +++ b/cc/androidmk.go @@ -24,12 +24,12 @@ import ( ) var ( - nativeBridgeSuffix = ".native_bridge" - productSuffix = ".product" + NativeBridgeSuffix = ".native_bridge" + ProductSuffix = ".product" VendorSuffix = ".vendor" - ramdiskSuffix = ".ramdisk" + RamdiskSuffix = ".ramdisk" VendorRamdiskSuffix = ".vendor_ramdisk" - recoverySuffix = ".recovery" + RecoverySuffix = ".recovery" sdkSuffix = ".sdk" ) @@ -182,7 +182,7 @@ func makeOverrideModuleNames(ctx AndroidMkContext, overrides []string) []string if ctx.Target().NativeBridge == android.NativeBridgeEnabled { var result []string for _, override := range overrides { - result = append(result, override+nativeBridgeSuffix) + result = append(result, override+NativeBridgeSuffix) } return result } diff --git a/cc/cc.go b/cc/cc.go index f65af3024..2006ecfe3 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -1632,7 +1632,7 @@ func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string return "" } vndkVersion = ctx.DeviceConfig().ProductVndkVersion() - nameSuffix = productSuffix + nameSuffix = ProductSuffix } else { vndkVersion = ctx.DeviceConfig().VndkVersion() nameSuffix = VendorSuffix @@ -1652,7 +1652,7 @@ func (c *Module) setSubnameProperty(actx android.ModuleContext) { c.Properties.SubName = "" if c.Target().NativeBridge == android.NativeBridgeEnabled { - c.Properties.SubName += nativeBridgeSuffix + c.Properties.SubName += NativeBridgeSuffix } llndk := c.IsLlndk() @@ -1668,11 +1668,11 @@ func (c *Module) setSubnameProperty(actx android.ModuleContext) { // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp. c.Properties.SubName += VendorSuffix } else if c.InRamdisk() && !c.OnlyInRamdisk() { - c.Properties.SubName += ramdiskSuffix + c.Properties.SubName += RamdiskSuffix } else if c.InVendorRamdisk() && !c.OnlyInVendorRamdisk() { c.Properties.SubName += VendorRamdiskSuffix } else if c.InRecovery() && !c.OnlyInRecovery() { - c.Properties.SubName += recoverySuffix + c.Properties.SubName += RecoverySuffix } else if c.IsSdkVariant() && (c.Properties.SdkAndPlatformVariantVisibleToMake || c.SplitPerApiLevel()) { c.Properties.SubName += sdkSuffix if c.SplitPerApiLevel() { @@ -3029,13 +3029,13 @@ func MakeLibName(ctx android.ModuleContext, c LinkableInterface, ccDep LinkableI // core module, so update the dependency name here accordingly. return libName + ccDep.SubName() } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() { - return libName + ramdiskSuffix + return libName + RamdiskSuffix } else if ccDep.InVendorRamdisk() && !ccDep.OnlyInVendorRamdisk() { return libName + VendorRamdiskSuffix } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() { - return libName + recoverySuffix + return libName + RecoverySuffix } else if ccDep.Target().NativeBridge == android.NativeBridgeEnabled { - return libName + nativeBridgeSuffix + return libName + NativeBridgeSuffix } else { return libName } diff --git a/cc/snapshot_prebuilt.go b/cc/snapshot_prebuilt.go index 9672c0fff..9570664c7 100644 --- a/cc/snapshot_prebuilt.go +++ b/cc/snapshot_prebuilt.go @@ -61,7 +61,7 @@ func (recoverySnapshotImage) imageVariantName(cfg android.DeviceConfig) string { } func (recoverySnapshotImage) moduleNameSuffix() string { - return recoverySuffix + return RecoverySuffix } // Override existing vendor and recovery snapshot for cc module specific extra functions diff --git a/rust/image.go b/rust/image.go index 3b54f12c7..5d7c02733 100644 --- a/rust/image.go +++ b/rust/image.go @@ -34,11 +34,11 @@ func (mod *Module) OdmAvailable() bool { } func (mod *Module) ProductAvailable() bool { - return false + return Bool(mod.VendorProperties.Product_available) } func (mod *Module) RamdiskAvailable() bool { - return false + return Bool(mod.Properties.Ramdisk_available) } func (mod *Module) VendorRamdiskAvailable() bool { @@ -50,7 +50,7 @@ func (mod *Module) AndroidModuleBase() *android.ModuleBase { } func (mod *Module) RecoveryAvailable() bool { - return false + return Bool(mod.Properties.Recovery_available) } func (mod *Module) ExtraVariants() []string { @@ -62,9 +62,7 @@ func (mod *Module) AppendExtraVariant(extraVariant string) { } func (mod *Module) SetRamdiskVariantNeeded(b bool) { - if b { - panic("Setting ramdisk variant needed for Rust module is unsupported: " + mod.BaseModuleName()) - } + mod.Properties.RamdiskVariantNeeded = b } func (mod *Module) SetVendorRamdiskVariantNeeded(b bool) { @@ -72,9 +70,7 @@ func (mod *Module) SetVendorRamdiskVariantNeeded(b bool) { } func (mod *Module) SetRecoveryVariantNeeded(b bool) { - if b { - panic("Setting recovery variant needed for Rust module is unsupported: " + mod.BaseModuleName()) - } + mod.Properties.RecoveryVariantNeeded = b } func (mod *Module) SetCoreVariantNeeded(b bool) { @@ -99,7 +95,7 @@ func (mod *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool { } func (mod *Module) RamdiskVariantNeeded(android.BaseModuleContext) bool { - return mod.InRamdisk() + return mod.Properties.RamdiskVariantNeeded } func (mod *Module) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { @@ -107,7 +103,7 @@ func (mod *Module) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool } func (mod *Module) RecoveryVariantNeeded(android.BaseModuleContext) bool { - return mod.InRecovery() + return mod.Properties.RecoveryVariantNeeded } func (mod *Module) ExtraImageVariations(android.BaseModuleContext) []string { @@ -144,8 +140,7 @@ func (ctx *moduleContext) ProductSpecific() bool { } func (mod *Module) InRecovery() bool { - // TODO(b/165791368) - return false + return mod.ModuleBase.InRecovery() || mod.ModuleBase.InstallInRecovery() } func (mod *Module) InVendorRamdisk() bool { @@ -166,6 +161,11 @@ func (mod *Module) OnlyInVendorRamdisk() bool { 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. func (mod *Module) HasVendorVariant() bool { return Bool(mod.VendorProperties.Vendor_available) || Bool(mod.VendorProperties.Odm_available) @@ -181,7 +181,7 @@ func (mod *Module) HasNonSystemVariants() 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 @@ -193,6 +193,8 @@ func (mod *Module) SetImageVariation(ctx android.BaseModuleContext, variant stri m := module.(*Module) if variant == android.VendorRamdiskVariation { m.MakeAsPlatform() + } else if variant == android.RecoveryVariation { + m.MakeAsPlatform() } else if strings.HasPrefix(variant, cc.VendorVariationPrefix) { m.Properties.ImageVariationPrefix = cc.VendorVariationPrefix m.Properties.VndkVersion = strings.TrimPrefix(variant, cc.VendorVariationPrefix) @@ -204,6 +206,9 @@ func (mod *Module) SetImageVariation(ctx android.BaseModuleContext, variant stri m.Properties.HideFromMake = true m.HideFromMake() } + } else if strings.HasPrefix(variant, cc.ProductVariationPrefix) { + m.Properties.ImageVariationPrefix = cc.ProductVariationPrefix + m.Properties.VndkVersion = strings.TrimPrefix(variant, cc.ProductVariationPrefix) } } @@ -211,10 +216,7 @@ func (mod *Module) ImageMutatorBegin(mctx android.BaseModuleContext) { // Rust does not support installing to the product image yet. vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific() - if Bool(mod.VendorProperties.Product_available) { - mctx.PropertyErrorf("product_available", - "Rust modules do not yet support being available to the product image") - } else if mctx.ProductSpecific() { + if mctx.ProductSpecific() { mctx.PropertyErrorf("product_specific", "Rust modules do not yet support installing to the product image.") } else if Bool(mod.VendorProperties.Double_loadable) { diff --git a/rust/rust.go b/rust/rust.go index 4ceeef1d1..ba395ec6e 100644 --- a/rust/rust.go +++ b/rust/rust.go @@ -84,6 +84,8 @@ type BaseProperties struct { // Set by imageMutator CoreVariantNeeded bool `blueprint:"mutated"` VendorRamdiskVariantNeeded bool `blueprint:"mutated"` + RamdiskVariantNeeded bool `blueprint:"mutated"` + RecoveryVariantNeeded bool `blueprint:"mutated"` ExtraVariants []string `blueprint:"mutated"` // Allows this module to use non-APEX version of libraries. Useful @@ -94,11 +96,18 @@ type BaseProperties struct { SnapshotSharedLibs []string `blueprint:"mutated"` SnapshotStaticLibs []string `blueprint:"mutated"` + // Make this module available when building for ramdisk. + // On device without a dedicated recovery partition, the module is only + // available after switching root into + // /first_stage_ramdisk. To expose the module before switching root, install + // the recovery variant instead. + Ramdisk_available *bool + // Make this module available when building for vendor ramdisk. // On device without a dedicated recovery partition, the module is only // available after switching root into // /first_stage_ramdisk. To expose the module before switching root, install - // the recovery variant instead (TODO(b/165791368) recovery not yet supported) + // the recovery variant instead Vendor_ramdisk_available *bool // Normally Soong uses the directory structure to decide which modules @@ -115,6 +124,9 @@ type BaseProperties struct { // framework module from the recovery snapshot. Exclude_from_recovery_snapshot *bool + // Make this module available when building for recovery + Recovery_available *bool + // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX). Min_sdk_version *string @@ -762,6 +774,10 @@ func (ctx *baseModuleContext) toolchain() config.Toolchain { } func (mod *Module) nativeCoverage() bool { + // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage + if mod.Target().NativeBridge == android.NativeBridgeEnabled { + return false + } return mod.compiler != nil && mod.compiler.nativeCoverage() } @@ -804,9 +820,21 @@ func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { // Differentiate static libraries that are vendor available 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.InRamdisk() && !mod.OnlyInRamdisk() { + mod.Properties.SubName += cc.RamdiskSuffix } else if mod.InVendorRamdisk() && !mod.OnlyInVendorRamdisk() { mod.Properties.SubName += cc.VendorRamdiskSuffix + } else if mod.InRecovery() && !mod.OnlyInRecovery() { + mod.Properties.SubName += cc.RecoverySuffix + } + + if mod.Target().NativeBridge == android.NativeBridgeEnabled { + mod.Properties.SubName += cc.NativeBridgeSuffix } if !toolchain.Supported() {