Merge "Add bp2build converter for override_apex." am: 49611b39a9
am: 9acec92f04
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2092595 Change-Id: I4bcef1a0da29197a01dea449997e533a37e330cd Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
71
apex/apex.go
71
apex/apex.go
@@ -50,7 +50,7 @@ func registerApexBuildComponents(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
|
||||
ctx.RegisterModuleType("apex_defaults", defaultsFactory)
|
||||
ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
|
||||
ctx.RegisterModuleType("override_apex", overrideApexFactory)
|
||||
ctx.RegisterModuleType("override_apex", OverrideApexFactory)
|
||||
ctx.RegisterModuleType("apex_set", apexSetFactory)
|
||||
|
||||
ctx.PreArchMutators(registerPreArchMutators)
|
||||
@@ -2451,6 +2451,7 @@ func DefaultsFactory(props ...interface{}) android.Module {
|
||||
type OverrideApex struct {
|
||||
android.ModuleBase
|
||||
android.OverrideModuleBase
|
||||
android.BazelModuleBase
|
||||
}
|
||||
|
||||
func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
@@ -2459,16 +2460,64 @@ func (o *OverrideApex) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
|
||||
// override_apex is used to create an apex module based on another apex module by overriding some of
|
||||
// its properties.
|
||||
func overrideApexFactory() android.Module {
|
||||
func OverrideApexFactory() android.Module {
|
||||
m := &OverrideApex{}
|
||||
|
||||
m.AddProperties(&overridableProperties{})
|
||||
|
||||
android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
|
||||
android.InitOverrideModule(m)
|
||||
android.InitBazelModule(m)
|
||||
return m
|
||||
}
|
||||
|
||||
func (o *OverrideApex) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
|
||||
if ctx.ModuleType() != "override_apex" {
|
||||
return
|
||||
}
|
||||
|
||||
baseApexModuleName := o.OverrideModuleBase.GetOverriddenModuleName()
|
||||
baseModule, baseApexExists := ctx.ModuleFromName(baseApexModuleName)
|
||||
if !baseApexExists {
|
||||
panic(fmt.Errorf("Base apex module doesn't exist: %s", baseApexModuleName))
|
||||
}
|
||||
|
||||
a, baseModuleIsApex := baseModule.(*apexBundle)
|
||||
if !baseModuleIsApex {
|
||||
panic(fmt.Errorf("Base module is not apex module: %s", baseApexModuleName))
|
||||
}
|
||||
attrs, props := convertWithBp2build(a, ctx)
|
||||
|
||||
for _, p := range o.GetProperties() {
|
||||
overridableProperties, ok := p.(*overridableProperties)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
// Key
|
||||
if overridableProperties.Key != nil {
|
||||
attrs.Key = bazel.LabelAttribute{}
|
||||
attrs.Key.SetValue(android.BazelLabelForModuleDepSingle(ctx, *overridableProperties.Key))
|
||||
}
|
||||
|
||||
// Certificate
|
||||
if overridableProperties.Certificate != nil {
|
||||
attrs.Certificate = bazel.LabelAttribute{}
|
||||
attrs.Certificate.SetValue(android.BazelLabelForModuleDepSingle(ctx, *overridableProperties.Certificate))
|
||||
}
|
||||
|
||||
// Prebuilts
|
||||
prebuiltsLabelList := android.BazelLabelForModuleDeps(ctx, overridableProperties.Prebuilts)
|
||||
attrs.Prebuilts = bazel.MakeLabelListAttribute(prebuiltsLabelList)
|
||||
|
||||
// Compressible
|
||||
if overridableProperties.Compressible != nil {
|
||||
attrs.Compressible = bazel.BoolAttribute{Value: overridableProperties.Compressible}
|
||||
}
|
||||
}
|
||||
|
||||
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: o.Name()}, &attrs)
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Vality check routines
|
||||
//
|
||||
@@ -3154,6 +3203,11 @@ func (a *apexBundle) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
|
||||
return
|
||||
}
|
||||
|
||||
attrs, props := convertWithBp2build(a, ctx)
|
||||
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: a.Name()}, &attrs)
|
||||
}
|
||||
|
||||
func convertWithBp2build(a *apexBundle, ctx android.TopDownMutatorContext) (bazelApexBundleAttributes, bazel.BazelTargetModuleProperties) {
|
||||
var manifestLabelAttribute bazel.LabelAttribute
|
||||
if a.properties.Manifest != nil {
|
||||
manifestLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *a.properties.Manifest))
|
||||
@@ -3165,8 +3219,15 @@ func (a *apexBundle) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
|
||||
}
|
||||
|
||||
var fileContextsLabelAttribute bazel.LabelAttribute
|
||||
if a.properties.File_contexts != nil {
|
||||
if a.properties.File_contexts == nil {
|
||||
// See buildFileContexts(), if file_contexts is not specified the default one is used, which is //system/sepolicy/apex:<module name>-file_contexts
|
||||
fileContextsLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, a.Name()+"-file_contexts"))
|
||||
} else if strings.HasPrefix(*a.properties.File_contexts, ":") {
|
||||
// File_contexts is a module
|
||||
fileContextsLabelAttribute.SetValue(android.BazelLabelForModuleDepSingle(ctx, *a.properties.File_contexts))
|
||||
} else {
|
||||
// File_contexts is a file
|
||||
fileContextsLabelAttribute.SetValue(android.BazelLabelForModuleSrcSingle(ctx, *a.properties.File_contexts))
|
||||
}
|
||||
|
||||
// TODO(b/219503907) this would need to be set to a.MinSdkVersionValue(ctx) but
|
||||
@@ -3224,7 +3285,7 @@ func (a *apexBundle) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
|
||||
compressibleAttribute.Value = a.overridableProperties.Compressible
|
||||
}
|
||||
|
||||
attrs := &bazelApexBundleAttributes{
|
||||
attrs := bazelApexBundleAttributes{
|
||||
Manifest: manifestLabelAttribute,
|
||||
Android_manifest: androidManifestLabelAttribute,
|
||||
File_contexts: fileContextsLabelAttribute,
|
||||
@@ -3245,7 +3306,7 @@ func (a *apexBundle) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
|
||||
Bzl_load_location: "//build/bazel/rules/apex:apex.bzl",
|
||||
}
|
||||
|
||||
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: a.Name()}, attrs)
|
||||
return attrs, props
|
||||
}
|
||||
|
||||
// The following conversions are based on this table where the rows are the compile_multilib
|
||||
|
Reference in New Issue
Block a user