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) + } +}