From 853e391eca18c5ec0990f03c3127f74171139b08 Mon Sep 17 00:00:00 2001 From: Kiyoung Kim Date: Tue, 9 Jan 2024 09:51:00 +0900 Subject: [PATCH] Generate VNDK independent image variant with cc genrule Image variants for CC modules were covered to work without VNDK version from previous commit, but CC genrule has its own image variant rule, so it should be also updated to generate vendor / product image variant without VNDK version. Bug: 316829758 Test: m nothing --no-skip-soong-tests passed Test: AOSP cuttlefish build succeeded Change-Id: I425dd425efcc57c7ff8f9964b303ad6f539c3b57 --- cc/genrule.go | 53 +++++++++++++++++++++++----------------------- cc/genrule_test.go | 24 +++++++++++++++++++++ 2 files changed, 50 insertions(+), 27 deletions(-) diff --git a/cc/genrule.go b/cc/genrule.go index 0c06ae6dd..0fb3e2d1f 100644 --- a/cc/genrule.go +++ b/cc/genrule.go @@ -79,15 +79,7 @@ var _ android.ImageInterface = (*GenruleExtraProperties)(nil) func (g *GenruleExtraProperties) ImageMutatorBegin(ctx android.BaseModuleContext) {} func (g *GenruleExtraProperties) CoreVariantNeeded(ctx android.BaseModuleContext) bool { - if ctx.DeviceConfig().VndkVersion() == "" { - return true - } - - if ctx.ProductSpecific() { - return false - } - - return !(ctx.SocSpecific() || ctx.DeviceSpecific()) + return !(ctx.SocSpecific() || ctx.DeviceSpecific() || ctx.ProductSpecific()) } func (g *GenruleExtraProperties) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool { @@ -115,26 +107,33 @@ func (g *GenruleExtraProperties) RecoveryVariantNeeded(ctx android.BaseModuleCon } func (g *GenruleExtraProperties) ExtraImageVariations(ctx android.BaseModuleContext) []string { - if ctx.DeviceConfig().VndkVersion() == "" { - return nil - } - var variants []string - if Bool(g.Vendor_available) || Bool(g.Odm_available) || ctx.SocSpecific() || ctx.DeviceSpecific() { - vndkVersion := ctx.DeviceConfig().VndkVersion() - // If vndkVersion is current, we can always use PlatformVndkVersion. - // If not, we assume modules under proprietary paths are compatible for - // BOARD_VNDK_VERSION. The other modules are regarded as AOSP, that is - // PLATFORM_VNDK_VERSION. - if vndkVersion == "current" || !snapshot.IsVendorProprietaryModule(ctx) { - variants = append(variants, VendorVariationPrefix+ctx.DeviceConfig().PlatformVndkVersion()) - } else { - variants = append(variants, VendorVariationPrefix+vndkVersion) - } - } + vndkVersion := ctx.DeviceConfig().VndkVersion() + vendorVariantRequired := Bool(g.Vendor_available) || Bool(g.Odm_available) || ctx.SocSpecific() || ctx.DeviceSpecific() + productVariantRequired := Bool(g.Product_available) || ctx.ProductSpecific() - if Bool(g.Product_available) || ctx.ProductSpecific() { - variants = append(variants, ProductVariationPrefix+ctx.DeviceConfig().PlatformVndkVersion()) + if vndkVersion == "" { + if vendorVariantRequired { + variants = append(variants, VendorVariation) + } + if productVariantRequired { + variants = append(variants, ProductVariation) + } + } else { + if vendorVariantRequired { + // If vndkVersion is current, we can always use PlatformVndkVersion. + // If not, we assume modules under proprietary paths are compatible for + // BOARD_VNDK_VERSION. The other modules are regarded as AOSP, that is + // PLATFORM_VNDK_VERSION. + if vndkVersion == "current" || !snapshot.IsVendorProprietaryModule(ctx) { + variants = append(variants, VendorVariationPrefix+ctx.DeviceConfig().PlatformVndkVersion()) + } else { + variants = append(variants, VendorVariationPrefix+vndkVersion) + } + } + if productVariantRequired { + variants = append(variants, ProductVariationPrefix+ctx.DeviceConfig().PlatformVndkVersion()) + } } return variants diff --git a/cc/genrule_test.go b/cc/genrule_test.go index 929524480..05c644f1e 100644 --- a/cc/genrule_test.go +++ b/cc/genrule_test.go @@ -16,6 +16,7 @@ package cc import ( "reflect" + "slices" "testing" "android/soong/android" @@ -186,3 +187,26 @@ func TestCmdPrefix(t *testing.T) { }) } } + +func TestVendorProductVariantGenrule(t *testing.T) { + bp := ` + cc_genrule { + name: "gen", + tool_files: ["tool"], + cmd: "$(location tool) $(in) $(out)", + out: ["out"], + vendor_available: true, + product_available: true, + } + ` + t.Helper() + ctx := PrepareForTestWithCcIncludeVndk.RunTestWithBp(t, bp) + + variants := ctx.ModuleVariantsForTests("gen") + if !slices.Contains(variants, "android_vendor_arm64_armv8-a") { + t.Errorf(`expected vendor variant, but does not exist in %v`, variants) + } + if !slices.Contains(variants, "android_product_arm64_armv8-a") { + t.Errorf(`expected product variant, but does not exist in %v`, variants) + } +}