diff --git a/aconfig/cc_aconfig_library.go b/aconfig/cc_aconfig_library.go index ec86af7f9..0583befc0 100644 --- a/aconfig/cc_aconfig_library.go +++ b/aconfig/cc_aconfig_library.go @@ -16,6 +16,7 @@ package aconfig import ( "android/soong/android" + "android/soong/bazel" "android/soong/cc" "github.com/google/blueprint" @@ -31,6 +32,8 @@ type ccDeclarationsTagType struct { var ccDeclarationsTag = ccDeclarationsTagType{} +const baseLibDep = "server_configurable_flags" + type CcAconfigLibraryProperties struct { // name of the aconfig_declarations module to generate a library for Aconfig_declarations string @@ -72,7 +75,7 @@ func (this *CcAconfigLibraryCallbacks) GeneratorDeps(ctx cc.DepsContext, deps cc } // Add a dependency for the aconfig flags base library - deps.SharedLibs = append(deps.SharedLibs, "server_configurable_flags") + deps.SharedLibs = append(deps.SharedLibs, baseLibDep) // TODO: It'd be really nice if we could reexport this library and not make everyone do it. return deps @@ -138,3 +141,33 @@ func (this *CcAconfigLibraryCallbacks) GeneratorBuildActions(ctx cc.ModuleContex }, }) } + +type bazelCcAconfigLibraryAttributes struct { + Aconfig_declarations bazel.LabelAttribute + Dynamic_deps bazel.LabelListAttribute +} + +// Convert the cc_aconfig_library module to bazel. +// +// This method is called from cc.ConvertWithBp2build to actually convert the +// cc_aconfig_library module. This is necessary since the factory method of this +// module type returns a cc library and the bp2build conversion is called on the +// cc library type. + +func (this *CcAconfigLibraryCallbacks) GeneratorBp2build(ctx android.Bp2buildMutatorContext) bool { + if ctx.ModuleType() != "cc_aconfig_library" { + return false + } + + attrs := bazelCcAconfigLibraryAttributes{ + Aconfig_declarations: *bazel.MakeLabelAttribute(android.BazelLabelForModuleDepSingle(ctx, this.properties.Aconfig_declarations).Label), + Dynamic_deps: bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, []string{baseLibDep})), + } + props := bazel.BazelTargetModuleProperties{ + Rule_class: "cc_aconfig_library", + Bzl_load_location: "//build/bazel/rules/cc:cc_aconfig_library.bzl", + } + + ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: ctx.ModuleName()}, &attrs) + return true +} diff --git a/android/allowlists/allowlists.go b/android/allowlists/allowlists.go index 5b77ba97d..6b9e34006 100644 --- a/android/allowlists/allowlists.go +++ b/android/allowlists/allowlists.go @@ -922,6 +922,7 @@ var ( "aconfig_values", "aidl_interface_headers", "bpf", + "cc_aconfig_library", "cc_prebuilt_library", "cc_prebuilt_library_headers", "cc_prebuilt_library_shared", diff --git a/android/config.go b/android/config.go index 445c6cddc..25a91f199 100644 --- a/android/config.go +++ b/android/config.go @@ -200,7 +200,7 @@ func (c Config) ReleaseVersion() string { // The aconfig value set passed to aconfig, derived from RELEASE_VERSION func (c Config) ReleaseAconfigValueSets() string { // This logic to handle both Soong module name and bazel target is temporary in order to - // provide backward compatibility where aosp and vendor/google both have the release + // provide backward compatibility where aosp and internal both have the release // aconfig value set but can't be updated at the same time to use bazel target value := strings.Split(c.config.productVariables.ReleaseAconfigValueSets, ":") value_len := len(value) diff --git a/bp2build/aconfig_conversion_test.go b/bp2build/aconfig_conversion_test.go index ddb62f783..cbf42ac06 100644 --- a/bp2build/aconfig_conversion_test.go +++ b/bp2build/aconfig_conversion_test.go @@ -19,10 +19,12 @@ import ( "android/soong/aconfig" "android/soong/android" + "android/soong/cc" ) func registerAconfigModuleTypes(ctx android.RegistrationContext) { aconfig.RegisterBuildComponents(ctx) + ctx.RegisterModuleType("cc_library", cc.LibraryFactory) } func TestAconfigDeclarations(t *testing.T) { @@ -90,3 +92,46 @@ func TestAconfigValues(t *testing.T) { ExpectedBazelTargets: expectedBazelTargets, }) } + +func TestCcAconfigLibrary(t *testing.T) { + bp := ` + aconfig_declarations { + name: "foo_aconfig_declarations", + srcs: [ + "foo1.aconfig", + ], + package: "com.android.foo", + } + cc_library { + name: "server_configurable_flags", + srcs: ["bar.cc"], + bazel_module: { bp2build_available: false }, + } + cc_aconfig_library { + name: "foo", + aconfig_declarations: "foo_aconfig_declarations", + } + ` + expectedBazelTargets := []string{ + MakeBazelTargetNoRestrictions( + "aconfig_declarations", + "foo_aconfig_declarations", + AttrNameToString{ + "srcs": `["foo1.aconfig"]`, + "package": `"com.android.foo"`, + }, + ), + MakeBazelTargetNoRestrictions( + "cc_aconfig_library", + "foo", + AttrNameToString{ + "aconfig_declarations": `":foo_aconfig_declarations"`, + "dynamic_deps": `[":server_configurable_flags"]`, + "target_compatible_with": `["//build/bazel/platforms/os:android"]`, + }, + )} + RunBp2BuildTestCase(t, registerAconfigModuleTypes, Bp2buildTestCase{ + Blueprint: bp, + ExpectedBazelTargets: expectedBazelTargets, + }) +} diff --git a/cc/cc.go b/cc/cc.go index 9aa0cac37..81a6cd64e 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -589,6 +589,7 @@ type Generator interface { GeneratorFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags GeneratorSources(ctx ModuleContext) GeneratedSource GeneratorBuildActions(ctx ModuleContext, flags Flags, deps PathDeps) + GeneratorBp2build(ctx android.Bp2buildMutatorContext) bool } // compiler is the interface for a compiler helper object. Different module decorators may implement @@ -4215,6 +4216,16 @@ func (c *Module) typ() moduleType { // ConvertWithBp2build converts Module to Bazel for bp2build. func (c *Module) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) { + if len(c.generators) > 0 { + allConverted := true + for _, generator := range c.generators { + allConverted = allConverted && generator.GeneratorBp2build(ctx) + } + if allConverted { + return + } + } + prebuilt := c.IsPrebuilt() switch c.typ() { case binary: diff --git a/cc/generated_cc_library.go b/cc/generated_cc_library.go index 55e19f9a9..8428e9420 100644 --- a/cc/generated_cc_library.go +++ b/cc/generated_cc_library.go @@ -28,9 +28,8 @@ func GeneratedCcLibraryModuleFactory(moduleName string, callbacks Generator) and staticAndSharedLibrarySdkMemberType, } - // TODO: Need to be bazelable - // module.bazelable = true - // module.bazelHandler = &ccLibraryBazelHandler{module: module} + module.bazelable = true + module.bazelHandler = &ccLibraryBazelHandler{module: module} module.generators = append(module.generators, callbacks)