Merge "Initial bp2build converter for android_app."
This commit is contained in:
@@ -43,7 +43,7 @@ var androidResourceIgnoreFilenames = []string{
|
||||
|
||||
// androidResourceGlob returns the list of files in the given directory, using the standard
|
||||
// exclusion patterns for Android resources.
|
||||
func androidResourceGlob(ctx android.ModuleContext, dir android.Path) android.Paths {
|
||||
func androidResourceGlob(ctx android.EarlyModuleContext, dir android.Path) android.Paths {
|
||||
return ctx.GlobFiles(filepath.Join(dir.String(), "**/*"), androidResourceIgnoreFilenames)
|
||||
}
|
||||
|
||||
|
46
java/app.go
46
java/app.go
@@ -45,6 +45,7 @@ func RegisterAppBuildComponents(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("override_android_test", OverrideAndroidTestModuleFactory)
|
||||
|
||||
android.RegisterBp2BuildMutator("android_app_certificate", AndroidAppCertificateBp2Build)
|
||||
android.RegisterBp2BuildMutator("android_app", AppBp2Build)
|
||||
}
|
||||
|
||||
// AndroidManifest.xml merging
|
||||
@@ -139,6 +140,7 @@ type overridableAppProperties struct {
|
||||
}
|
||||
|
||||
type AndroidApp struct {
|
||||
android.BazelModuleBase
|
||||
Library
|
||||
aapt
|
||||
android.OverridableModuleBase
|
||||
@@ -1438,3 +1440,47 @@ func androidAppCertificateBp2BuildInternal(ctx android.TopDownMutatorContext, mo
|
||||
|
||||
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name()}, attrs)
|
||||
}
|
||||
|
||||
type bazelAndroidAppAttributes struct {
|
||||
Srcs bazel.LabelListAttribute
|
||||
Manifest bazel.Label
|
||||
Custom_package *string
|
||||
Resource_files bazel.LabelListAttribute
|
||||
}
|
||||
|
||||
// AppBp2Build is used for android_app.
|
||||
func AppBp2Build(ctx android.TopDownMutatorContext) {
|
||||
a, ok := ctx.Module().(*AndroidApp)
|
||||
if !ok || !a.ConvertWithBp2build(ctx) {
|
||||
return
|
||||
}
|
||||
if ctx.ModuleType() != "android_app" {
|
||||
return
|
||||
}
|
||||
|
||||
//TODO(b/209577426): Support multiple arch variants
|
||||
srcs := bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrcExcludes(ctx, a.properties.Srcs, a.properties.Exclude_srcs))
|
||||
|
||||
manifest := proptools.StringDefault(a.aaptProperties.Manifest, "AndroidManifest.xml")
|
||||
|
||||
resourceFiles := bazel.LabelList{
|
||||
Includes: []bazel.Label{},
|
||||
}
|
||||
for _, dir := range android.PathsWithOptionalDefaultForModuleSrc(ctx, a.aaptProperties.Resource_dirs, "res") {
|
||||
files := android.RootToModuleRelativePaths(ctx, androidResourceGlob(ctx, dir))
|
||||
resourceFiles.Includes = append(resourceFiles.Includes, files...)
|
||||
}
|
||||
|
||||
attrs := &bazelAndroidAppAttributes{
|
||||
Srcs: srcs,
|
||||
Manifest: android.BazelLabelForModuleSrcSingle(ctx, manifest),
|
||||
// TODO(b/209576404): handle package name override by product variable PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES
|
||||
Custom_package: a.overridableAppProperties.Package_name,
|
||||
Resource_files: bazel.MakeLabelListAttribute(resourceFiles),
|
||||
}
|
||||
props := bazel.BazelTargetModuleProperties{Rule_class: "android_binary",
|
||||
Bzl_load_location: "@rules_android//rules:rules.bzl"}
|
||||
|
||||
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: a.Name()}, attrs)
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user