Create helper function for BazelTargetModuleProperties in java/android

Prevents inconsistent load locations from being added for java_library,
android_library, kt_jvm_library targets that are generated in multiple
places.

Change-Id: I66ae5af137d7dff3f6fa6660dee539cf9ab22b9e
Test: go test ./bp2build
This commit is contained in:
Alix
2023-03-16 21:06:13 +00:00
parent f5f6073ff5
commit 3254002a7c
3 changed files with 28 additions and 32 deletions

View File

@@ -1067,10 +1067,7 @@ func (a *AARImport) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
neverlink := true
ctx.CreateBazelTargetModule(
bazel.BazelTargetModuleProperties{
Rule_class: "android_library",
Bzl_load_location: "//build/bazel/rules/android:rules.bzl",
},
AndroidLibraryBazelTargetModuleProperties(),
android.CommonAttributes{Name: name + "-neverlink"},
&bazelAndroidLibrary{
javaLibraryAttributes: &javaLibraryAttributes{
@@ -1081,6 +1078,12 @@ func (a *AARImport) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
)
}
func AndroidLibraryBazelTargetModuleProperties() bazel.BazelTargetModuleProperties {
return bazel.BazelTargetModuleProperties{
Rule_class: "android_library",
Bzl_load_location: "//build/bazel/rules/android:rules.bzl",
}
}
func (a *AndroidLibrary) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
commonAttrs, bp2buildInfo := a.convertLibraryAttrsBp2Build(ctx)
@@ -1093,10 +1096,7 @@ func (a *AndroidLibrary) ConvertWithBp2build(ctx android.TopDownMutatorContext)
ctx.ModuleErrorf("Module has direct dependencies but no sources. Bazel will not allow this.")
}
name := a.Name()
props := bazel.BazelTargetModuleProperties{
Rule_class: "android_library",
Bzl_load_location: "//build/bazel/rules/android:rules.bzl",
}
props := AndroidLibraryBazelTargetModuleProperties()
ctx.CreateBazelTargetModule(
props,