Merge "Support asset_dirs property in bp2build for android_{app,library}" into main am: 491fa2fe50
am: 67a98d3520
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2715093 Change-Id: If857d6292742fc18bc7600d616aa8f13147def34 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -40,6 +40,7 @@ func TestMinimalAndroidApp(t *testing.T) {
|
|||||||
"app.java": "",
|
"app.java": "",
|
||||||
"res/res.png": "",
|
"res/res.png": "",
|
||||||
"AndroidManifest.xml": "",
|
"AndroidManifest.xml": "",
|
||||||
|
"assets/asset.png": "",
|
||||||
},
|
},
|
||||||
Blueprint: `
|
Blueprint: `
|
||||||
android_app {
|
android_app {
|
||||||
@@ -54,6 +55,8 @@ android_app {
|
|||||||
"manifest": `"AndroidManifest.xml"`,
|
"manifest": `"AndroidManifest.xml"`,
|
||||||
"resource_files": `["res/res.png"]`,
|
"resource_files": `["res/res.png"]`,
|
||||||
"sdk_version": `"current"`,
|
"sdk_version": `"current"`,
|
||||||
|
"assets": `["assets/asset.png"]`,
|
||||||
|
"assets_dir": `"assets"`,
|
||||||
}),
|
}),
|
||||||
}})
|
}})
|
||||||
}
|
}
|
||||||
@@ -68,6 +71,7 @@ func TestAndroidAppAllSupportedFields(t *testing.T) {
|
|||||||
"resa/res.png": "",
|
"resa/res.png": "",
|
||||||
"resb/res.png": "",
|
"resb/res.png": "",
|
||||||
"manifest/AndroidManifest.xml": "",
|
"manifest/AndroidManifest.xml": "",
|
||||||
|
"assets_/asset.png": "",
|
||||||
},
|
},
|
||||||
Blueprint: simpleModuleDoNotConvertBp2build("android_app", "static_lib_dep") + `
|
Blueprint: simpleModuleDoNotConvertBp2build("android_app", "static_lib_dep") + `
|
||||||
android_app {
|
android_app {
|
||||||
@@ -81,6 +85,7 @@ android_app {
|
|||||||
java_version: "7",
|
java_version: "7",
|
||||||
certificate: "foocert",
|
certificate: "foocert",
|
||||||
required: ["static_lib_dep"],
|
required: ["static_lib_dep"],
|
||||||
|
asset_dirs: ["assets_"],
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
ExpectedBazelTargets: []string{
|
ExpectedBazelTargets: []string{
|
||||||
@@ -91,6 +96,8 @@ android_app {
|
|||||||
"resa/res.png",
|
"resa/res.png",
|
||||||
"resb/res.png",
|
"resb/res.png",
|
||||||
]`,
|
]`,
|
||||||
|
"assets": `["assets_/asset.png"]`,
|
||||||
|
"assets_dir": `"assets_"`,
|
||||||
"custom_package": `"com.google"`,
|
"custom_package": `"com.google"`,
|
||||||
"deps": `[":static_lib_dep"]`,
|
"deps": `[":static_lib_dep"]`,
|
||||||
"java_version": `"7"`,
|
"java_version": `"7"`,
|
||||||
|
33
java/aar.go
33
java/aar.go
@@ -23,6 +23,7 @@ import (
|
|||||||
"android/soong/android"
|
"android/soong/android"
|
||||||
"android/soong/bazel"
|
"android/soong/bazel"
|
||||||
"android/soong/dexpreopt"
|
"android/soong/dexpreopt"
|
||||||
|
"android/soong/ui/metrics/bp2build_metrics_proto"
|
||||||
|
|
||||||
"github.com/google/blueprint"
|
"github.com/google/blueprint"
|
||||||
"github.com/google/blueprint/proptools"
|
"github.com/google/blueprint/proptools"
|
||||||
@@ -1228,6 +1229,8 @@ func AARImportFactory() android.Module {
|
|||||||
type bazelAapt struct {
|
type bazelAapt struct {
|
||||||
Manifest bazel.Label
|
Manifest bazel.Label
|
||||||
Resource_files bazel.LabelListAttribute
|
Resource_files bazel.LabelListAttribute
|
||||||
|
Assets_dir bazel.StringAttribute
|
||||||
|
Assets bazel.LabelListAttribute
|
||||||
}
|
}
|
||||||
|
|
||||||
type bazelAndroidLibrary struct {
|
type bazelAndroidLibrary struct {
|
||||||
@@ -1242,7 +1245,7 @@ type bazelAndroidLibraryImport struct {
|
|||||||
Sdk_version bazel.StringAttribute
|
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")
|
manifest := proptools.StringDefault(a.aaptProperties.Manifest, "AndroidManifest.xml")
|
||||||
|
|
||||||
resourceFiles := bazel.LabelList{
|
resourceFiles := bazel.LabelList{
|
||||||
@@ -1252,10 +1255,30 @@ func (a *aapt) convertAaptAttrsWithBp2Build(ctx android.TopDownMutatorContext) *
|
|||||||
files := android.RootToModuleRelativePaths(ctx, androidResourceGlob(ctx, dir))
|
files := android.RootToModuleRelativePaths(ctx, androidResourceGlob(ctx, dir))
|
||||||
resourceFiles.Includes = append(resourceFiles.Includes, files...)
|
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{
|
return &bazelAapt{
|
||||||
android.BazelLabelForModuleSrcSingle(ctx, manifest),
|
android.BazelLabelForModuleSrcSingle(ctx, manifest),
|
||||||
bazel.MakeLabelListAttribute(resourceFiles),
|
bazel.MakeLabelListAttribute(resourceFiles),
|
||||||
}
|
assetsDir,
|
||||||
|
bazel.MakeLabelListAttribute(assets),
|
||||||
|
}, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AARImport) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
|
func (a *AARImport) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
|
||||||
@@ -1328,6 +1351,10 @@ func (a *AndroidLibrary) ConvertWithBp2build(ctx android.TopDownMutatorContext)
|
|||||||
name := a.Name()
|
name := a.Name()
|
||||||
props := AndroidLibraryBazelTargetModuleProperties()
|
props := AndroidLibraryBazelTargetModuleProperties()
|
||||||
|
|
||||||
|
aaptAttrs, supported := a.convertAaptAttrsWithBp2Build(ctx)
|
||||||
|
if !supported {
|
||||||
|
return
|
||||||
|
}
|
||||||
ctx.CreateBazelTargetModule(
|
ctx.CreateBazelTargetModule(
|
||||||
props,
|
props,
|
||||||
android.CommonAttributes{Name: name},
|
android.CommonAttributes{Name: name},
|
||||||
@@ -1337,7 +1364,7 @@ func (a *AndroidLibrary) ConvertWithBp2build(ctx android.TopDownMutatorContext)
|
|||||||
Deps: deps,
|
Deps: deps,
|
||||||
Exports: depLabels.StaticDeps,
|
Exports: depLabels.StaticDeps,
|
||||||
},
|
},
|
||||||
a.convertAaptAttrsWithBp2Build(ctx),
|
aaptAttrs,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -1628,8 +1628,10 @@ func (a *AndroidApp) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
|
|||||||
deps := depLabels.Deps
|
deps := depLabels.Deps
|
||||||
deps.Append(depLabels.StaticDeps)
|
deps.Append(depLabels.StaticDeps)
|
||||||
|
|
||||||
aapt := a.convertAaptAttrsWithBp2Build(ctx)
|
aapt, supported := a.convertAaptAttrsWithBp2Build(ctx)
|
||||||
|
if !supported {
|
||||||
|
return
|
||||||
|
}
|
||||||
certificate, certificateName := android.BazelStringOrLabelFromProp(ctx, a.overridableAppProperties.Certificate)
|
certificate, certificateName := android.BazelStringOrLabelFromProp(ctx, a.overridableAppProperties.Certificate)
|
||||||
|
|
||||||
manifestValues := &manifestValueAttribute{}
|
manifestValues := &manifestValueAttribute{}
|
||||||
|
Reference in New Issue
Block a user