Convert cc_aconfig_library to bazel.

Bug: 297358249
Test: Unit test and CI
Change-Id: Ic84128b0df16efe4255b52b83670ec9902c09383
This commit is contained in:
Yu Liu
2023-09-14 15:10:03 -07:00
parent f2d858e5ba
commit 855cfc2fac
6 changed files with 94 additions and 5 deletions

View File

@@ -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
}