Add partial bp2build support for APEX targets (second try). am: a9d76dd423 am: 37b29c925c

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1755109

Change-Id: Id29697a17140dccf5ca9764a95f6f5db51a8783a
This commit is contained in:
Rupert Shuttleworth
2021-07-02 13:38:14 +00:00
committed by Automerger Merge Worker
5 changed files with 122 additions and 0 deletions

View File

@@ -27,6 +27,7 @@ import (
"github.com/google/blueprint/proptools"
"android/soong/android"
"android/soong/bazel"
"android/soong/bpf"
"android/soong/cc"
prebuilt_etc "android/soong/etc"
@@ -53,6 +54,8 @@ func registerApexBuildComponents(ctx android.RegistrationContext) {
ctx.PreArchMutators(registerPreArchMutators)
ctx.PreDepsMutators(RegisterPreDepsMutators)
ctx.PostDepsMutators(RegisterPostDepsMutators)
android.RegisterBp2BuildMutator("apex", ApexBundleBp2Build)
}
func registerPreArchMutators(ctx android.RegisterMutatorsContext) {
@@ -322,6 +325,7 @@ type apexBundle struct {
android.DefaultableModuleBase
android.OverridableModuleBase
android.SdkBase
android.BazelModuleBase
// Properties
properties apexBundleProperties
@@ -3120,3 +3124,63 @@ func rModulesPackages() map[string][]string {
},
}
}
// For Bazel / bp2build
type bazelApexBundleAttributes struct {
Manifest bazel.LabelAttribute
}
type bazelApexBundle struct {
android.BazelTargetModuleBase
bazelApexBundleAttributes
}
func BazelApexBundleFactory() android.Module {
module := &bazelApexBundle{}
module.AddProperties(&module.bazelApexBundleAttributes)
android.InitBazelTargetModule(module)
return module
}
func ApexBundleBp2Build(ctx android.TopDownMutatorContext) {
module, ok := ctx.Module().(*apexBundle)
if !ok {
// Not an APEX bundle
return
}
if !module.ConvertWithBp2build(ctx) {
return
}
if ctx.ModuleType() != "apex" {
return
}
apexBundleBp2BuildInternal(ctx, module)
}
func apexBundleBp2BuildInternal(ctx android.TopDownMutatorContext, module *apexBundle) {
var manifestLabelAttribute bazel.LabelAttribute
manifestStringPtr := module.properties.Manifest
if module.properties.Manifest != nil {
manifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *manifestStringPtr))
}
attrs := &bazelApexBundleAttributes{
Manifest: manifestLabelAttribute,
}
props := bazel.BazelTargetModuleProperties{
Rule_class: "apex",
Bzl_load_location: "//build/bazel/rules:apex.bzl",
}
ctx.CreateBazelTargetModule(BazelApexBundleFactory, module.Name(), props, attrs)
}
func (m *bazelApexBundle) Name() string {
return m.BaseModuleName()
}
func (m *bazelApexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {}