Generate image variation without version

Current CC/Rust Image variations are generated with target VNDK version.
However, this is no longer valid if VNDK is deprecated. This change
generates image variation without version ("vendor", "product") if VNDK
is deprecated.

Bug: 316829758
Test: m nothing --no-skip-soong-tests passed
Test: aosp_cf_x86_64_phone build succeeded
Change-Id: I2387ed8a2632bfd9462621f882a947695ae1653d
This commit is contained in:
Kiyoung Kim
2024-01-03 14:24:34 +09:00
parent 202bc5b689
commit b5fdb2e966
8 changed files with 127 additions and 45 deletions

View File

@@ -147,6 +147,7 @@ func TestAndroidMkCcLibrary(t *testing.T) {
cc_library { cc_library {
name: "server_configurable_flags", name: "server_configurable_flags",
srcs: ["server_configurable_flags.cc"], srcs: ["server_configurable_flags.cc"],
vendor_available: true,
} }
` `
result := android.GroupFixturePreparers( result := android.GroupFixturePreparers(
@@ -154,7 +155,7 @@ func TestAndroidMkCcLibrary(t *testing.T) {
cc.PrepareForTestWithCcDefaultModules). cc.PrepareForTestWithCcDefaultModules).
ExtendWithErrorHandler(android.FixtureExpectsNoErrors).RunTestWithBp(t, bp) ExtendWithErrorHandler(android.FixtureExpectsNoErrors).RunTestWithBp(t, bp)
module := result.ModuleForTests("my_cc_library", "android_arm64_armv8-a_shared").Module() module := result.ModuleForTests("my_cc_library", "android_vendor_arm64_armv8-a_shared").Module()
entry := android.AndroidMkEntriesForTest(t, result.TestContext, module)[0] entry := android.AndroidMkEntriesForTest(t, result.TestContext, module)[0]

View File

@@ -719,7 +719,7 @@ func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
// getImageVariationPair returns a pair for the image variation name as its // getImageVariationPair returns a pair for the image variation name as its
// prefix and suffix. The prefix indicates whether it's core/vendor/product and the // prefix and suffix. The prefix indicates whether it's core/vendor/product and the
// suffix indicates the vndk version when it's vendor or product. // suffix indicates the vndk version for vendor/product if vndk is enabled.
// getImageVariation can simply join the result of this function to get the // getImageVariation can simply join the result of this function to get the
// image variation name. // image variation name.
func (a *apexBundle) getImageVariationPair(deviceConfig android.DeviceConfig) (string, string) { func (a *apexBundle) getImageVariationPair(deviceConfig android.DeviceConfig) (string, string) {
@@ -727,8 +727,8 @@ func (a *apexBundle) getImageVariationPair(deviceConfig android.DeviceConfig) (s
return cc.VendorVariationPrefix, a.vndkVersion(deviceConfig) return cc.VendorVariationPrefix, a.vndkVersion(deviceConfig)
} }
var prefix string prefix := android.CoreVariation
var vndkVersion string vndkVersion := ""
if deviceConfig.VndkVersion() != "" { if deviceConfig.VndkVersion() != "" {
if a.SocSpecific() || a.DeviceSpecific() { if a.SocSpecific() || a.DeviceSpecific() {
prefix = cc.VendorVariationPrefix prefix = cc.VendorVariationPrefix
@@ -737,15 +737,18 @@ func (a *apexBundle) getImageVariationPair(deviceConfig android.DeviceConfig) (s
prefix = cc.ProductVariationPrefix prefix = cc.ProductVariationPrefix
vndkVersion = deviceConfig.PlatformVndkVersion() vndkVersion = deviceConfig.PlatformVndkVersion()
} }
} else {
if a.SocSpecific() || a.DeviceSpecific() {
prefix = cc.VendorVariation
} else if a.ProductSpecific() {
prefix = cc.ProductVariation
}
} }
if vndkVersion == "current" { if vndkVersion == "current" {
vndkVersion = deviceConfig.PlatformVndkVersion() vndkVersion = deviceConfig.PlatformVndkVersion()
} }
if vndkVersion != "" {
return prefix, vndkVersion
}
return android.CoreVariation, "" // The usual case return prefix, vndkVersion
} }
// getImageVariation returns the image variant name for this apexBundle. In most cases, it's simply // getImageVariation returns the image variant name for this apexBundle. In most cases, it's simply

View File

@@ -25,6 +25,7 @@ import (
"strings" "strings"
"android/soong/testing" "android/soong/testing"
"github.com/google/blueprint" "github.com/google/blueprint"
"github.com/google/blueprint/proptools" "github.com/google/blueprint/proptools"
@@ -300,8 +301,8 @@ type BaseProperties struct {
// Set by DepsMutator. // Set by DepsMutator.
AndroidMkSystemSharedLibs []string `blueprint:"mutated"` AndroidMkSystemSharedLibs []string `blueprint:"mutated"`
// The name of the image this module is built for, suffixed with a '.' // The name of the image this module is built for
ImageVariationPrefix string `blueprint:"mutated"` ImageVariation string `blueprint:"mutated"`
// The VNDK version this module is built against. If empty, the module is not // The VNDK version this module is built against. If empty, the module is not
// build against the VNDK. // build against the VNDK.
@@ -2386,9 +2387,9 @@ func GetSnapshot(c LinkableInterface, snapshotInfo **SnapshotInfo, actx android.
// Only retrieve the snapshot on demand in order to avoid circular dependencies // Only retrieve the snapshot on demand in order to avoid circular dependencies
// between the modules in the snapshot and the snapshot itself. // between the modules in the snapshot and the snapshot itself.
var snapshotModule []blueprint.Module var snapshotModule []blueprint.Module
if c.InVendor() && c.VndkVersion() == actx.DeviceConfig().VndkVersion() { if c.InVendor() && c.VndkVersion() == actx.DeviceConfig().VndkVersion() && actx.OtherModuleExists("vendor_snapshot") {
snapshotModule = actx.AddVariationDependencies(nil, nil, "vendor_snapshot") snapshotModule = actx.AddVariationDependencies(nil, nil, "vendor_snapshot")
} else if recoverySnapshotVersion := actx.DeviceConfig().RecoverySnapshotVersion(); recoverySnapshotVersion != "current" && recoverySnapshotVersion != "" && c.InRecovery() { } else if recoverySnapshotVersion := actx.DeviceConfig().RecoverySnapshotVersion(); recoverySnapshotVersion != "current" && recoverySnapshotVersion != "" && c.InRecovery() && actx.OtherModuleExists("recovery_snapshot") {
snapshotModule = actx.AddVariationDependencies(nil, nil, "recovery_snapshot") snapshotModule = actx.AddVariationDependencies(nil, nil, "recovery_snapshot")
} }
if len(snapshotModule) > 0 && snapshotModule[0] != nil { if len(snapshotModule) > 0 && snapshotModule[0] != nil {

View File

@@ -26,6 +26,8 @@ import (
"android/soong/aidl_library" "android/soong/aidl_library"
"android/soong/android" "android/soong/android"
"github.com/google/blueprint"
) )
func init() { func init() {
@@ -45,6 +47,14 @@ var prepareForCcTest = android.GroupFixturePreparers(
}), }),
) )
// TODO(b/316829758) Update prepareForCcTest with this configuration and remove prepareForCcTestWithoutVndk
var prepareForCcTestWithoutVndk = android.GroupFixturePreparers(
PrepareForIntegrationTestWithCc,
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
variables.VendorApiLevel = StringPtr("202404")
}),
)
var apexVariationName = "apex28" var apexVariationName = "apex28"
var apexVersion = "28" var apexVersion = "28"
@@ -2640,6 +2650,7 @@ func TestLlndkLibrary(t *testing.T) {
name: "libexternal_headers", name: "libexternal_headers",
export_include_dirs: ["include"], export_include_dirs: ["include"],
vendor_available: true, vendor_available: true,
product_available: true,
} }
cc_library_headers { cc_library_headers {
name: "libexternal_llndk_headers", name: "libexternal_llndk_headers",
@@ -4784,3 +4795,51 @@ func TestStrippedAllOutputFile(t *testing.T) {
return return
} }
} }
// TODO(b/316829758) Remove this test and do not set VNDK version from other tests
func TestImageVariantsWithoutVndk(t *testing.T) {
t.Parallel()
bp := `
cc_binary {
name: "binfoo",
srcs: ["binfoo.cc"],
vendor_available: true,
product_available: true,
shared_libs: ["libbar"]
}
cc_library {
name: "libbar",
srcs: ["libbar.cc"],
vendor_available: true,
product_available: true,
}
`
ctx := prepareForCcTestWithoutVndk.RunTestWithBp(t, bp)
hasDep := func(m android.Module, wantDep android.Module) bool {
t.Helper()
var found bool
ctx.VisitDirectDeps(m, func(dep blueprint.Module) {
if dep == wantDep {
found = true
}
})
return found
}
testDepWithVariant := func(imageVariant string) {
imageVariantStr := ""
if imageVariant != "core" {
imageVariantStr = "_" + imageVariant
}
binFooModule := ctx.ModuleForTests("binfoo", "android"+imageVariantStr+"_arm64_armv8-a").Module()
libBarModule := ctx.ModuleForTests("libbar", "android"+imageVariantStr+"_arm64_armv8-a_shared").Module()
android.AssertBoolEquals(t, "binfoo should have dependency on libbar with image variant "+imageVariant, true, hasDep(binFooModule, libBarModule))
}
testDepWithVariant("core")
testDepWithVariant("vendor")
testDepWithVariant("product")
}

View File

@@ -42,10 +42,18 @@ const (
) )
const ( const (
// VendorVariation is the variant name used for /vendor code that does not
// compile against the VNDK.
VendorVariation = "vendor"
// VendorVariationPrefix is the variant prefix used for /vendor code that compiles // VendorVariationPrefix is the variant prefix used for /vendor code that compiles
// against the VNDK. // against the VNDK.
VendorVariationPrefix = "vendor." VendorVariationPrefix = "vendor."
// ProductVariation is the variant name used for /product code that does not
// compile against the VNDK.
ProductVariation = "product"
// ProductVariationPrefix is the variant prefix used for /product code that compiles // ProductVariationPrefix is the variant prefix used for /product code that compiles
// against the VNDK. // against the VNDK.
ProductVariationPrefix = "product." ProductVariationPrefix = "product."
@@ -112,12 +120,12 @@ func (c *Module) HasNonSystemVariants() bool {
// Returns true if the module is "product" variant. Usually these modules are installed in /product // Returns true if the module is "product" variant. Usually these modules are installed in /product
func (c *Module) InProduct() bool { func (c *Module) InProduct() bool {
return c.Properties.ImageVariationPrefix == ProductVariationPrefix return c.Properties.ImageVariation == ProductVariation
} }
// 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
func (c *Module) InVendor() bool { func (c *Module) InVendor() bool {
return c.Properties.ImageVariationPrefix == VendorVariationPrefix return c.Properties.ImageVariation == VendorVariation
} }
func (c *Module) InRamdisk() bool { func (c *Module) InRamdisk() bool {
@@ -439,10 +447,8 @@ func MutateImage(mctx android.BaseModuleContext, m ImageMutatableModule) {
// and vendor and product variants will be created with LLNDK stubs. // and vendor and product variants will be created with LLNDK stubs.
// The LLNDK libraries need vendor variants even if there is no VNDK. // The LLNDK libraries need vendor variants even if there is no VNDK.
coreVariantNeeded = true coreVariantNeeded = true
if platformVndkVersion != "" { vendorVariants = append(vendorVariants, platformVndkVersion)
vendorVariants = append(vendorVariants, platformVndkVersion) productVariants = append(productVariants, platformVndkVersion)
productVariants = append(productVariants, platformVndkVersion)
}
// Generate vendor variants for boardVndkVersion only if the VNDK snapshot does not // Generate vendor variants for boardVndkVersion only if the VNDK snapshot does not
// provide the LLNDK stub libraries. // provide the LLNDK stub libraries.
if needVndkVersionVendorVariantForLlndk { if needVndkVersionVendorVariantForLlndk {
@@ -453,13 +459,7 @@ func MutateImage(mctx android.BaseModuleContext, m ImageMutatableModule) {
// for system and product. // for system and product.
coreVariantNeeded = true coreVariantNeeded = true
vendorVariants = append(vendorVariants, boardVndkVersion) vendorVariants = append(vendorVariants, boardVndkVersion)
if platformVndkVersion != "" { productVariants = append(productVariants, platformVndkVersion)
productVariants = append(productVariants, platformVndkVersion)
}
} else if boardVndkVersion == "" {
// If the device isn't compiling against the VNDK, we always
// use the core mode.
coreVariantNeeded = true
} else if m.IsSnapshotPrebuilt() { } else if m.IsSnapshotPrebuilt() {
// Make vendor variants only for the versions in BOARD_VNDK_VERSION and // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
// PRODUCT_EXTRA_VNDK_VERSIONS. // PRODUCT_EXTRA_VNDK_VERSIONS.
@@ -557,11 +557,19 @@ func MutateImage(mctx android.BaseModuleContext, m ImageMutatableModule) {
} }
for _, variant := range android.FirstUniqueStrings(vendorVariants) { for _, variant := range android.FirstUniqueStrings(vendorVariants) {
m.AppendExtraVariant(VendorVariationPrefix + variant) if variant == "" {
m.AppendExtraVariant(VendorVariation)
} else {
m.AppendExtraVariant(VendorVariationPrefix + variant)
}
} }
for _, variant := range android.FirstUniqueStrings(productVariants) { for _, variant := range android.FirstUniqueStrings(productVariants) {
m.AppendExtraVariant(ProductVariationPrefix + variant) if variant == "" {
m.AppendExtraVariant(ProductVariation)
} else {
m.AppendExtraVariant(ProductVariationPrefix + variant)
}
} }
m.SetRamdiskVariantNeeded(ramdiskVariantNeeded) m.SetRamdiskVariantNeeded(ramdiskVariantNeeded)
@@ -672,9 +680,12 @@ func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string
} else if variant == android.RecoveryVariation { } else if variant == android.RecoveryVariation {
m.MakeAsPlatform() m.MakeAsPlatform()
squashRecoverySrcs(m) squashRecoverySrcs(m)
} else if strings.HasPrefix(variant, VendorVariationPrefix) { } else if strings.HasPrefix(variant, VendorVariation) {
m.Properties.ImageVariationPrefix = VendorVariationPrefix m.Properties.ImageVariation = VendorVariation
m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
if strings.HasPrefix(variant, VendorVariationPrefix) {
m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
}
squashVendorSrcs(m) squashVendorSrcs(m)
// Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION. // Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION.
@@ -684,9 +695,11 @@ func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string
m.Properties.HideFromMake = true m.Properties.HideFromMake = true
m.HideFromMake() m.HideFromMake()
} }
} else if strings.HasPrefix(variant, ProductVariationPrefix) { } else if strings.HasPrefix(variant, ProductVariation) {
m.Properties.ImageVariationPrefix = ProductVariationPrefix m.Properties.ImageVariation = ProductVariation
m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix) if strings.HasPrefix(variant, ProductVariationPrefix) {
m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix)
}
squashProductSrcs(m) squashProductSrcs(m)
} }

View File

@@ -2109,7 +2109,7 @@ func TestJNISDK(t *testing.T) {
Output("libjni.so").Output.String() Output("libjni.so").Output.String()
sdkJNI := ctx.ModuleForTests("libjni", "android_arm64_armv8-a_sdk_shared"). sdkJNI := ctx.ModuleForTests("libjni", "android_arm64_armv8-a_sdk_shared").
Output("libjni.so").Output.String() Output("libjni.so").Output.String()
vendorJNI := ctx.ModuleForTests("libvendorjni", "android_arm64_armv8-a_shared"). vendorJNI := ctx.ModuleForTests("libvendorjni", "android_vendor_arm64_armv8-a_shared").
Output("libvendorjni.so").Output.String() Output("libvendorjni.so").Output.String()
for _, test := range testCases { for _, test := range testCases {

View File

@@ -184,12 +184,12 @@ func (mod *Module) HasNonSystemVariants() bool {
} }
func (mod *Module) InProduct() bool { func (mod *Module) InProduct() bool {
return mod.Properties.ImageVariationPrefix == cc.ProductVariationPrefix return mod.Properties.ImageVariation == cc.ProductVariation
} }
// 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
func (mod *Module) InVendor() bool { func (mod *Module) InVendor() bool {
return mod.Properties.ImageVariationPrefix == cc.VendorVariationPrefix return mod.Properties.ImageVariation == cc.VendorVariation
} }
func (mod *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) { func (mod *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
@@ -198,9 +198,11 @@ func (mod *Module) SetImageVariation(ctx android.BaseModuleContext, variant stri
m.MakeAsPlatform() m.MakeAsPlatform()
} else if variant == android.RecoveryVariation { } else if variant == android.RecoveryVariation {
m.MakeAsPlatform() m.MakeAsPlatform()
} else if strings.HasPrefix(variant, cc.VendorVariationPrefix) { } else if strings.HasPrefix(variant, cc.VendorVariation) {
m.Properties.ImageVariationPrefix = cc.VendorVariationPrefix m.Properties.ImageVariation = cc.VendorVariation
m.Properties.VndkVersion = strings.TrimPrefix(variant, cc.VendorVariationPrefix) if strings.HasPrefix(variant, cc.VendorVariationPrefix) {
m.Properties.VndkVersion = strings.TrimPrefix(variant, cc.VendorVariationPrefix)
}
// Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION. // Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION.
// Hide other vendor variants to avoid collision. // Hide other vendor variants to avoid collision.
@@ -209,9 +211,11 @@ 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) { } else if strings.HasPrefix(variant, cc.ProductVariation) {
m.Properties.ImageVariationPrefix = cc.ProductVariationPrefix m.Properties.ImageVariation = cc.ProductVariation
m.Properties.VndkVersion = strings.TrimPrefix(variant, cc.ProductVariationPrefix) if strings.HasPrefix(variant, cc.ProductVariationPrefix) {
m.Properties.VndkVersion = strings.TrimPrefix(variant, cc.ProductVariationPrefix)
}
} }
} }

View File

@@ -20,6 +20,7 @@ import (
"android/soong/bloaty" "android/soong/bloaty"
"android/soong/testing" "android/soong/testing"
"github.com/google/blueprint" "github.com/google/blueprint"
"github.com/google/blueprint/proptools" "github.com/google/blueprint/proptools"
@@ -69,9 +70,9 @@ type BaseProperties struct {
AndroidMkProcMacroLibs []string `blueprint:"mutated"` AndroidMkProcMacroLibs []string `blueprint:"mutated"`
AndroidMkStaticLibs []string `blueprint:"mutated"` AndroidMkStaticLibs []string `blueprint:"mutated"`
ImageVariationPrefix string `blueprint:"mutated"` ImageVariation string `blueprint:"mutated"`
VndkVersion string `blueprint:"mutated"` VndkVersion string `blueprint:"mutated"`
SubName string `blueprint:"mutated"` SubName string `blueprint:"mutated"`
// SubName is used by CC for tracking image variants / SDK versions. RustSubName is used for Rust-specific // SubName is used by CC for tracking image variants / SDK versions. RustSubName is used for Rust-specific
// subnaming which shouldn't be visible to CC modules (such as the rlib stdlinkage subname). This should be // subnaming which shouldn't be visible to CC modules (such as the rlib stdlinkage subname). This should be