summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Alix Espino <agespino@google.com> 2023-03-17 17:43:39 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2023-03-17 17:43:39 +0000
commit2eb2ecfec06a9f02946c4910f82518805c3dbab8 (patch)
tree5fd8f6078e2cb7d808364f60f27505542285eb94
parentbebe607db4183657d4ce367900f8df903e58c077 (diff)
parent3254002a7ca69303fdb8df45fca769eb25cc823d (diff)
Merge "Create helper function for BazelTargetModuleProperties in java/android"
-rw-r--r--java/aar.go16
-rwxr-xr-xjava/app.go5
-rw-r--r--java/java.go39
3 files changed, 28 insertions, 32 deletions
diff --git a/java/aar.go b/java/aar.go
index 7c45efee6..4bc5465aa 100644
--- a/java/aar.go
+++ b/java/aar.go
@@ -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,
diff --git a/java/app.go b/java/app.go
index f5966735c..4cc9e198e 100755
--- a/java/app.go
+++ b/java/app.go
@@ -1535,10 +1535,7 @@ func (a *AndroidApp) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
} else {
ktName := a.Name() + "_kt"
ctx.CreateBazelTargetModule(
- bazel.BazelTargetModuleProperties{
- Rule_class: "android_library",
- Bzl_load_location: "//build/bazel/rules/android:rules.bzl",
- },
+ AndroidLibraryBazelTargetModuleProperties(),
android.CommonAttributes{Name: ktName},
&bazelAndroidLibrary{
javaLibraryAttributes: &javaLibraryAttributes{
diff --git a/java/java.go b/java/java.go
index 071f0fb82..0841dad5e 100644
--- a/java/java.go
+++ b/java/java.go
@@ -2815,6 +2815,20 @@ type kotlinAttributes struct {
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) {
commonAttrs, bp2BuildInfo := m.convertLibraryAttrsBp2Build(ctx)
depLabels := bp2BuildInfo.DepLabels
@@ -2844,15 +2858,9 @@ func javaLibraryBp2Build(ctx android.TopDownMutatorContext, m *Library) {
name := m.Name()
if !bp2BuildInfo.hasKotlin {
- props = bazel.BazelTargetModuleProperties{
- Rule_class: "java_library",
- Bzl_load_location: "//build/bazel/rules/java:rules.bzl",
- }
+ props = javaLibraryBazelTargetModuleProperties()
} else {
- props = bazel.BazelTargetModuleProperties{
- Rule_class: "kt_jvm_library",
- Bzl_load_location: "//build/bazel/rules/kotlin:rules.bzl",
- }
+ props = ktJvmLibraryBazelTargetModuleProperties()
}
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name}, attrs)
@@ -2949,15 +2957,9 @@ func javaBinaryHostBp2Build(ctx android.TopDownMutatorContext, m *Binary) {
libName := m.Name() + "_lib"
var libProps bazel.BazelTargetModuleProperties
if bp2BuildInfo.hasKotlin {
- libProps = bazel.BazelTargetModuleProperties{
- Rule_class: "kt_jvm_library",
- Bzl_load_location: "//build/bazel/rules/kotlin:rules.bzl",
- }
+ libProps = ktJvmLibraryBazelTargetModuleProperties()
} else {
- libProps = bazel.BazelTargetModuleProperties{
- Rule_class: "java_library",
- Bzl_load_location: "//build/bazel/rules/java:rules.bzl",
- }
+ libProps = javaLibraryBazelTargetModuleProperties()
}
libAttrs := &javaLibraryAttributes{
Deps: deps,
@@ -3007,10 +3009,7 @@ func (i *Import) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
Exports: bazel.MakeSingleLabelListAttribute(bazel.Label{Label: ":" + name}),
}
ctx.CreateBazelTargetModule(
- bazel.BazelTargetModuleProperties{
- Rule_class: "java_library",
- Bzl_load_location: "//build/bazel/rules/java:rules.bzl",
- },
+ javaLibraryBazelTargetModuleProperties(),
android.CommonAttributes{Name: name + "-neverlink"},
neverlinkAttrs)