Merge "bp2build kt for android_binary"
This commit is contained in:
commit
69ef681c13
2 changed files with 115 additions and 8 deletions
|
@ -227,3 +227,82 @@ java_library{
|
|||
}),
|
||||
}})
|
||||
}
|
||||
|
||||
func TestAndroidAppKotlinSrcs(t *testing.T) {
|
||||
runAndroidAppTestCase(t, Bp2buildTestCase{
|
||||
Description: "Android app with kotlin sources and common_srcs",
|
||||
ModuleTypeUnderTest: "android_app",
|
||||
ModuleTypeUnderTestFactory: java.AndroidAppFactory,
|
||||
Filesystem: map[string]string{
|
||||
"res/res.png": "",
|
||||
},
|
||||
Blueprint: simpleModuleDoNotConvertBp2build("filegroup", "foocert") + `
|
||||
android_app {
|
||||
name: "foo",
|
||||
srcs: ["a.java", "b.kt"],
|
||||
certificate: ":foocert",
|
||||
manifest: "fooManifest.xml",
|
||||
libs: ["barLib"]
|
||||
}
|
||||
java_library{
|
||||
name: "barLib",
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("java_library", "barLib", AttrNameToString{}),
|
||||
MakeNeverlinkDuplicateTarget("java_library", "barLib"),
|
||||
MakeBazelTarget("android_library", "foo_kt", AttrNameToString{
|
||||
"srcs": `[
|
||||
"a.java",
|
||||
"b.kt",
|
||||
]`,
|
||||
"manifest": `"fooManifest.xml"`,
|
||||
"resource_files": `["res/res.png"]`,
|
||||
"deps": `[":barLib-neverlink"]`,
|
||||
}),
|
||||
MakeBazelTarget("android_binary", "foo", AttrNameToString{
|
||||
"deps": `[":foo_kt"]`,
|
||||
"certificate": `":foocert"`,
|
||||
"manifest": `"fooManifest.xml"`,
|
||||
}),
|
||||
}})
|
||||
}
|
||||
|
||||
func TestAndroidAppCommonSrcs(t *testing.T) {
|
||||
runAndroidAppTestCase(t, Bp2buildTestCase{
|
||||
Description: "Android app with common_srcs",
|
||||
ModuleTypeUnderTest: "android_app",
|
||||
ModuleTypeUnderTestFactory: java.AndroidAppFactory,
|
||||
Filesystem: map[string]string{
|
||||
"res/res.png": "",
|
||||
},
|
||||
Blueprint: simpleModuleDoNotConvertBp2build("filegroup", "foocert") + `
|
||||
android_app {
|
||||
name: "foo",
|
||||
srcs: ["a.java"],
|
||||
common_srcs: ["b.kt"],
|
||||
certificate: "foocert",
|
||||
manifest: "fooManifest.xml",
|
||||
libs: ["barLib"],
|
||||
}
|
||||
java_library{
|
||||
name: "barLib",
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("java_library", "barLib", AttrNameToString{}),
|
||||
MakeNeverlinkDuplicateTarget("java_library", "barLib"),
|
||||
MakeBazelTarget("android_library", "foo_kt", AttrNameToString{
|
||||
"srcs": `["a.java"]`,
|
||||
"common_srcs": `["b.kt"]`,
|
||||
"manifest": `"fooManifest.xml"`,
|
||||
"resource_files": `["res/res.png"]`,
|
||||
"deps": `[":barLib-neverlink"]`,
|
||||
}),
|
||||
MakeBazelTarget("android_binary", "foo", AttrNameToString{
|
||||
"deps": `[":foo_kt"]`,
|
||||
"certificate_name": `"foocert"`,
|
||||
"manifest": `"fooManifest.xml"`,
|
||||
}),
|
||||
}})
|
||||
}
|
||||
|
|
44
java/app.go
44
java/app.go
|
@ -1508,20 +1508,48 @@ func (a *AndroidApp) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
|
|||
|
||||
certificate, certificateName := android.BazelStringOrLabelFromProp(ctx, a.overridableAppProperties.Certificate)
|
||||
|
||||
attrs := &bazelAndroidAppAttributes{
|
||||
commonAttrs,
|
||||
aapt,
|
||||
deps,
|
||||
appAttrs := &bazelAndroidAppAttributes{
|
||||
// TODO(b/209576404): handle package name override by product variable PRODUCT_MANIFEST_PACKAGE_NAME_OVERRIDES
|
||||
a.overridableAppProperties.Package_name,
|
||||
certificate,
|
||||
certificateName,
|
||||
Custom_package: a.overridableAppProperties.Package_name,
|
||||
Certificate: certificate,
|
||||
Certificate_name: certificateName,
|
||||
}
|
||||
|
||||
props := bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "android_binary",
|
||||
Bzl_load_location: "//build/bazel/rules/android:rules.bzl",
|
||||
}
|
||||
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: a.Name()}, attrs)
|
||||
|
||||
if !bp2BuildInfo.hasKotlinSrcs && len(a.properties.Common_srcs) == 0 {
|
||||
appAttrs.javaCommonAttributes = commonAttrs
|
||||
appAttrs.bazelAapt = aapt
|
||||
appAttrs.Deps = deps
|
||||
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: a.Name()}, appAttrs)
|
||||
} else {
|
||||
ktName := a.Name() + "_kt"
|
||||
commonAttrs.Common_srcs = bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, a.properties.Common_srcs))
|
||||
ctx.CreateBazelTargetModule(
|
||||
bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "android_library",
|
||||
Bzl_load_location: "//build/bazel/rules/android:rules.bzl",
|
||||
},
|
||||
android.CommonAttributes{Name: ktName},
|
||||
&bazelAndroidLibrary{
|
||||
javaLibraryAttributes: &javaLibraryAttributes{
|
||||
javaCommonAttributes: commonAttrs,
|
||||
Deps: deps,
|
||||
},
|
||||
bazelAapt: aapt,
|
||||
},
|
||||
)
|
||||
|
||||
appAttrs.bazelAapt = &bazelAapt{Manifest: aapt.Manifest}
|
||||
appAttrs.Deps = bazel.MakeSingleLabelListAttribute(bazel.Label{Label: ":" + ktName})
|
||||
ctx.CreateBazelTargetModule(
|
||||
props,
|
||||
android.CommonAttributes{Name: a.Name()},
|
||||
appAttrs,
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue