From f1868af5d577c3d6aaae7208f636976bf91db02b Mon Sep 17 00:00:00 2001 From: Ivan Lozano Date: Tue, 12 Apr 2022 13:08:36 -0400 Subject: [PATCH] rust: Don't append '.vendor' to vendor modules. Rust vendor-only modules would have the '.vendor' subname appended to them, which meant that 'm ' would not work -- instead you would need to call 'm .vendor', which leads to some confusion. This CL fixes the behavior by using the same SubName logic as the cc module. Bug: 205577906 Test: m # works without .vendor suffix Change-Id: I6ba18ce1d7281a1f8342ed6014644b48009d78e0 --- cc/cc.go | 47 ++++++++++++++++++++++++++++++----------------- cc/linkable.go | 4 ++++ rust/rust.go | 33 +++++++++++++++------------------ 3 files changed, 49 insertions(+), 35 deletions(-) diff --git a/cc/cc.go b/cc/cc.go index ac6da05e8..00b82d552 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -1218,6 +1218,17 @@ func (c *Module) IsVendorPublicLibrary() bool { return c.VendorProperties.IsVendorPublicLibrary } +func (c *Module) IsVndkPrebuiltLibrary() bool { + if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok { + return true + } + return false +} + +func (c *Module) SdkAndPlatformVariantVisibleToMake() bool { + return c.Properties.SdkAndPlatformVariantVisibleToMake +} + func (c *Module) HasLlndkStubs() bool { lib := moduleLibraryInterface(c) return lib != nil && lib.hasLLNDKStubs() @@ -1699,7 +1710,7 @@ func (c *Module) DataPaths() []android.DataPath { return nil } -func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string { +func getNameSuffixWithVndkVersion(ctx android.ModuleContext, c LinkableInterface) string { // Returns the name suffix for product and vendor variants. If the VNDK version is not // "current", it will append the VNDK version to the name suffix. var vndkVersion string @@ -1719,19 +1730,19 @@ func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string if vndkVersion == "current" { vndkVersion = ctx.DeviceConfig().PlatformVndkVersion() } - if c.Properties.VndkVersion != vndkVersion && c.Properties.VndkVersion != "" { + if c.VndkVersion() != vndkVersion && c.VndkVersion() != "" { // add version suffix only if the module is using different vndk version than the // version in product or vendor partition. - nameSuffix += "." + c.Properties.VndkVersion + nameSuffix += "." + c.VndkVersion() } return nameSuffix } -func (c *Module) setSubnameProperty(actx android.ModuleContext) { - c.Properties.SubName = "" +func GetSubnameProperty(actx android.ModuleContext, c LinkableInterface) string { + var subName = "" if c.Target().NativeBridge == android.NativeBridgeEnabled { - c.Properties.SubName += NativeBridgeSuffix + subName += NativeBridgeSuffix } llndk := c.IsLlndk() @@ -1739,25 +1750,27 @@ func (c *Module) setSubnameProperty(actx android.ModuleContext) { // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is // added for product variant only when we have vendor and product variants with core // variant. The suffix is not added for vendor-only or product-only module. - c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx) + subName += getNameSuffixWithVndkVersion(actx, c) } else if c.IsVendorPublicLibrary() { - c.Properties.SubName += vendorPublicLibrarySuffix - } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok { + subName += vendorPublicLibrarySuffix + } else if c.IsVndkPrebuiltLibrary() { // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp. - c.Properties.SubName += VendorSuffix + subName += VendorSuffix } else if c.InRamdisk() && !c.OnlyInRamdisk() { - c.Properties.SubName += RamdiskSuffix + subName += RamdiskSuffix } else if c.InVendorRamdisk() && !c.OnlyInVendorRamdisk() { - c.Properties.SubName += VendorRamdiskSuffix + subName += VendorRamdiskSuffix } else if c.InRecovery() && !c.OnlyInRecovery() { - c.Properties.SubName += RecoverySuffix - } else if c.IsSdkVariant() && (c.Properties.SdkAndPlatformVariantVisibleToMake || c.SplitPerApiLevel()) { - c.Properties.SubName += sdkSuffix + subName += RecoverySuffix + } else if c.IsSdkVariant() && (c.SdkAndPlatformVariantVisibleToMake() || c.SplitPerApiLevel()) { + subName += sdkSuffix if c.SplitPerApiLevel() { - c.Properties.SubName += "." + c.SdkVersion() + subName += "." + c.SdkVersion() } } + + return subName } // Returns true if Bazel was successfully used for the analysis of this module. @@ -1795,7 +1808,7 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { return } - c.setSubnameProperty(actx) + c.Properties.SubName = GetSubnameProperty(actx, c) apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo) if !apexInfo.IsForPlatform() { c.hideApexVariantFromMake = true diff --git a/cc/linkable.go b/cc/linkable.go index d4b477060..6bec30c54 100644 --- a/cc/linkable.go +++ b/cc/linkable.go @@ -176,10 +176,14 @@ type LinkableInterface interface { IsVndk() bool IsVndkExt() bool IsVndkPrivate() bool + IsVendorPublicLibrary() bool + IsVndkPrebuiltLibrary() bool HasVendorVariant() bool HasProductVariant() bool HasNonSystemVariants() bool + ProductSpecific() bool InProduct() bool + SdkAndPlatformVariantVisibleToMake() bool // SubName returns the modules SubName, used for image and NDK/SDK variations. SubName() string diff --git a/rust/rust.go b/rust/rust.go index d62726162..2a7bdcfb3 100644 --- a/rust/rust.go +++ b/rust/rust.go @@ -332,6 +332,20 @@ func (mod *Module) IsVndkSp() bool { return false } +func (mod *Module) IsVndkPrebuiltLibrary() bool { + // Rust modules do not provide VNDK prebuilts + return false +} + +func (mod *Module) IsVendorPublicLibrary() bool { + return mod.VendorProperties.IsVendorPublicLibrary +} + +func (mod *Module) SdkAndPlatformVariantVisibleToMake() bool { + // Rust modules to not provide Sdk variants + return false +} + func (c *Module) IsVndkPrivate() bool { return false } @@ -841,24 +855,7 @@ func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { toolchain := mod.toolchain(ctx) mod.makeLinkType = cc.GetMakeLinkType(actx, mod) - // Differentiate static libraries that are vendor available - if mod.UseVndk() { - 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 - } + mod.Properties.SubName = cc.GetSubnameProperty(actx, mod) if !toolchain.Supported() { // This toolchain's unsupported, there's nothing to do for this mod.