Merge "Support asset_dirs property in bp2build for android_{app,library}" into main
This commit is contained in:
@@ -40,6 +40,7 @@ func TestMinimalAndroidApp(t *testing.T) {
|
||||
"app.java": "",
|
||||
"res/res.png": "",
|
||||
"AndroidManifest.xml": "",
|
||||
"assets/asset.png": "",
|
||||
},
|
||||
Blueprint: `
|
||||
android_app {
|
||||
@@ -54,6 +55,8 @@ android_app {
|
||||
"manifest": `"AndroidManifest.xml"`,
|
||||
"resource_files": `["res/res.png"]`,
|
||||
"sdk_version": `"current"`,
|
||||
"assets": `["assets/asset.png"]`,
|
||||
"assets_dir": `"assets"`,
|
||||
}),
|
||||
}})
|
||||
}
|
||||
@@ -68,6 +71,7 @@ func TestAndroidAppAllSupportedFields(t *testing.T) {
|
||||
"resa/res.png": "",
|
||||
"resb/res.png": "",
|
||||
"manifest/AndroidManifest.xml": "",
|
||||
"assets_/asset.png": "",
|
||||
},
|
||||
Blueprint: simpleModuleDoNotConvertBp2build("android_app", "static_lib_dep") + `
|
||||
android_app {
|
||||
@@ -81,6 +85,7 @@ android_app {
|
||||
java_version: "7",
|
||||
certificate: "foocert",
|
||||
required: ["static_lib_dep"],
|
||||
asset_dirs: ["assets_"],
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
@@ -91,6 +96,8 @@ android_app {
|
||||
"resa/res.png",
|
||||
"resb/res.png",
|
||||
]`,
|
||||
"assets": `["assets_/asset.png"]`,
|
||||
"assets_dir": `"assets_"`,
|
||||
"custom_package": `"com.google"`,
|
||||
"deps": `[":static_lib_dep"]`,
|
||||
"java_version": `"7"`,
|
||||
|
33
java/aar.go
33
java/aar.go
@@ -23,6 +23,7 @@ import (
|
||||
"android/soong/android"
|
||||
"android/soong/bazel"
|
||||
"android/soong/dexpreopt"
|
||||
"android/soong/ui/metrics/bp2build_metrics_proto"
|
||||
|
||||
"github.com/google/blueprint"
|
||||
"github.com/google/blueprint/proptools"
|
||||
@@ -1228,6 +1229,8 @@ func AARImportFactory() android.Module {
|
||||
type bazelAapt struct {
|
||||
Manifest bazel.Label
|
||||
Resource_files bazel.LabelListAttribute
|
||||
Assets_dir bazel.StringAttribute
|
||||
Assets bazel.LabelListAttribute
|
||||
}
|
||||
|
||||
type bazelAndroidLibrary struct {
|
||||
@@ -1242,7 +1245,7 @@ type bazelAndroidLibraryImport struct {
|
||||
Sdk_version bazel.StringAttribute
|
||||
}
|
||||
|
||||
func (a *aapt) convertAaptAttrsWithBp2Build(ctx android.TopDownMutatorContext) *bazelAapt {
|
||||
func (a *aapt) convertAaptAttrsWithBp2Build(ctx android.TopDownMutatorContext) (*bazelAapt, bool) {
|
||||
manifest := proptools.StringDefault(a.aaptProperties.Manifest, "AndroidManifest.xml")
|
||||
|
||||
resourceFiles := bazel.LabelList{
|
||||
@@ -1252,10 +1255,30 @@ func (a *aapt) convertAaptAttrsWithBp2Build(ctx android.TopDownMutatorContext) *
|
||||
files := android.RootToModuleRelativePaths(ctx, androidResourceGlob(ctx, dir))
|
||||
resourceFiles.Includes = append(resourceFiles.Includes, files...)
|
||||
}
|
||||
|
||||
assetsDir := bazel.StringAttribute{}
|
||||
var assets bazel.LabelList
|
||||
for i, dir := range android.PathsWithOptionalDefaultForModuleSrc(ctx, a.aaptProperties.Asset_dirs, "assets") {
|
||||
if i > 0 {
|
||||
ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_PROPERTY_UNSUPPORTED, "multiple asset_dirs")
|
||||
return &bazelAapt{}, false
|
||||
}
|
||||
// Assets_dirs are relative to the module dir when specified, but if the default in used in
|
||||
// PathsWithOptionalDefaultForModuleSrc, then dir is relative to the top.
|
||||
assetsRelDir, error := filepath.Rel(ctx.ModuleDir(), dir.Rel())
|
||||
if error != nil {
|
||||
assetsRelDir = dir.Rel()
|
||||
}
|
||||
assetsDir.Value = proptools.StringPtr(assetsRelDir)
|
||||
assets = bazel.MakeLabelList(android.RootToModuleRelativePaths(ctx, androidResourceGlob(ctx, dir)))
|
||||
|
||||
}
|
||||
return &bazelAapt{
|
||||
android.BazelLabelForModuleSrcSingle(ctx, manifest),
|
||||
bazel.MakeLabelListAttribute(resourceFiles),
|
||||
}
|
||||
assetsDir,
|
||||
bazel.MakeLabelListAttribute(assets),
|
||||
}, true
|
||||
}
|
||||
|
||||
func (a *AARImport) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
|
||||
@@ -1328,6 +1351,10 @@ func (a *AndroidLibrary) ConvertWithBp2build(ctx android.TopDownMutatorContext)
|
||||
name := a.Name()
|
||||
props := AndroidLibraryBazelTargetModuleProperties()
|
||||
|
||||
aaptAttrs, supported := a.convertAaptAttrsWithBp2Build(ctx)
|
||||
if !supported {
|
||||
return
|
||||
}
|
||||
ctx.CreateBazelTargetModule(
|
||||
props,
|
||||
android.CommonAttributes{Name: name},
|
||||
@@ -1337,7 +1364,7 @@ func (a *AndroidLibrary) ConvertWithBp2build(ctx android.TopDownMutatorContext)
|
||||
Deps: deps,
|
||||
Exports: depLabels.StaticDeps,
|
||||
},
|
||||
a.convertAaptAttrsWithBp2Build(ctx),
|
||||
aaptAttrs,
|
||||
},
|
||||
)
|
||||
|
||||
|
@@ -1628,8 +1628,10 @@ func (a *AndroidApp) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
|
||||
deps := depLabels.Deps
|
||||
deps.Append(depLabels.StaticDeps)
|
||||
|
||||
aapt := a.convertAaptAttrsWithBp2Build(ctx)
|
||||
|
||||
aapt, supported := a.convertAaptAttrsWithBp2Build(ctx)
|
||||
if !supported {
|
||||
return
|
||||
}
|
||||
certificate, certificateName := android.BazelStringOrLabelFromProp(ctx, a.overridableAppProperties.Certificate)
|
||||
|
||||
manifestValues := &manifestValueAttribute{}
|
||||
|
Reference in New Issue
Block a user