diff options
| author | Alix <agespino@google.com> | 2023-03-16 21:06:13 +0000 |
|---|---|---|
| committer | Alix <agespino@google.com> | 2023-03-16 21:29:01 +0000 |
| commit | 3254002a7ca69303fdb8df45fca769eb25cc823d (patch) | |
| tree | e4979f9fedf8fa5d8d14b6285124497939194076 /java/java.go | |
| parent | f5f6073ff5876c6828bfa985e1ab58ffd098ba8e (diff) | |
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
Diffstat (limited to 'java/java.go')
| -rw-r--r-- | java/java.go | 39 |
1 files changed, 19 insertions, 20 deletions
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) |
