Merge "Create helper function for BazelTargetModuleProperties in java/android"

This commit is contained in:
Alix Espino
2023-03-17 17:43:39 +00:00
committed by Gerrit Code Review
3 changed files with 28 additions and 32 deletions

View File

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

View File

@@ -1535,10 +1535,7 @@ func (a *AndroidApp) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
} else { } else {
ktName := a.Name() + "_kt" ktName := a.Name() + "_kt"
ctx.CreateBazelTargetModule( ctx.CreateBazelTargetModule(
bazel.BazelTargetModuleProperties{ AndroidLibraryBazelTargetModuleProperties(),
Rule_class: "android_library",
Bzl_load_location: "//build/bazel/rules/android:rules.bzl",
},
android.CommonAttributes{Name: ktName}, android.CommonAttributes{Name: ktName},
&bazelAndroidLibrary{ &bazelAndroidLibrary{
javaLibraryAttributes: &javaLibraryAttributes{ javaLibraryAttributes: &javaLibraryAttributes{

View File

@@ -2815,6 +2815,20 @@ type kotlinAttributes struct {
Kotlincflags *[]string Kotlincflags *[]string
} }
func ktJvmLibraryBazelTargetModuleProperties() bazel.BazelTargetModuleProperties {
return bazel.BazelTargetModuleProperties{
Rule_class: "kt_jvm_library",
Bzl_load_location: "//build/bazel/rules/kotlin:rules.bzl",
}
}
func javaLibraryBazelTargetModuleProperties() bazel.BazelTargetModuleProperties {
return bazel.BazelTargetModuleProperties{
Rule_class: "java_library",
Bzl_load_location: "//build/bazel/rules/java:rules.bzl",
}
}
func javaLibraryBp2Build(ctx android.TopDownMutatorContext, m *Library) { func javaLibraryBp2Build(ctx android.TopDownMutatorContext, m *Library) {
commonAttrs, bp2BuildInfo := m.convertLibraryAttrsBp2Build(ctx) commonAttrs, bp2BuildInfo := m.convertLibraryAttrsBp2Build(ctx)
depLabels := bp2BuildInfo.DepLabels depLabels := bp2BuildInfo.DepLabels
@@ -2844,15 +2858,9 @@ func javaLibraryBp2Build(ctx android.TopDownMutatorContext, m *Library) {
name := m.Name() name := m.Name()
if !bp2BuildInfo.hasKotlin { if !bp2BuildInfo.hasKotlin {
props = bazel.BazelTargetModuleProperties{ props = javaLibraryBazelTargetModuleProperties()
Rule_class: "java_library",
Bzl_load_location: "//build/bazel/rules/java:rules.bzl",
}
} else { } else {
props = bazel.BazelTargetModuleProperties{ props = ktJvmLibraryBazelTargetModuleProperties()
Rule_class: "kt_jvm_library",
Bzl_load_location: "//build/bazel/rules/kotlin:rules.bzl",
}
} }
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name}, attrs) ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name}, attrs)
@@ -2949,15 +2957,9 @@ func javaBinaryHostBp2Build(ctx android.TopDownMutatorContext, m *Binary) {
libName := m.Name() + "_lib" libName := m.Name() + "_lib"
var libProps bazel.BazelTargetModuleProperties var libProps bazel.BazelTargetModuleProperties
if bp2BuildInfo.hasKotlin { if bp2BuildInfo.hasKotlin {
libProps = bazel.BazelTargetModuleProperties{ libProps = ktJvmLibraryBazelTargetModuleProperties()
Rule_class: "kt_jvm_library",
Bzl_load_location: "//build/bazel/rules/kotlin:rules.bzl",
}
} else { } else {
libProps = bazel.BazelTargetModuleProperties{ libProps = javaLibraryBazelTargetModuleProperties()
Rule_class: "java_library",
Bzl_load_location: "//build/bazel/rules/java:rules.bzl",
}
} }
libAttrs := &javaLibraryAttributes{ libAttrs := &javaLibraryAttributes{
Deps: deps, Deps: deps,
@@ -3007,10 +3009,7 @@ func (i *Import) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
Exports: bazel.MakeSingleLabelListAttribute(bazel.Label{Label: ":" + name}), Exports: bazel.MakeSingleLabelListAttribute(bazel.Label{Label: ":" + name}),
} }
ctx.CreateBazelTargetModule( ctx.CreateBazelTargetModule(
bazel.BazelTargetModuleProperties{ javaLibraryBazelTargetModuleProperties(),
Rule_class: "java_library",
Bzl_load_location: "//build/bazel/rules/java:rules.bzl",
},
android.CommonAttributes{Name: name + "-neverlink"}, android.CommonAttributes{Name: name + "-neverlink"},
neverlinkAttrs) neverlinkAttrs)