diff options
Diffstat (limited to 'java/java.go')
| -rw-r--r-- | java/java.go | 85 |
1 files changed, 52 insertions, 33 deletions
diff --git a/java/java.go b/java/java.go index 61f5949bb..0841dad5e 100644 --- a/java/java.go +++ b/java/java.go @@ -2787,11 +2787,12 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext) depLabels.StaticDeps = bazel.MakeLabelListAttribute(staticDeps) hasKotlin := !kotlinSrcs.IsEmpty() + commonAttrs.kotlinAttributes = &kotlinAttributes{ + Kotlincflags: &m.properties.Kotlincflags, + } if len(m.properties.Common_srcs) != 0 { hasKotlin = true - commonAttrs.kotlinAttributes = &kotlinAttributes{ - bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, m.properties.Common_srcs)), - } + commonAttrs.kotlinAttributes.Common_srcs = bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, m.properties.Common_srcs)) } bp2BuildInfo := &bp2BuildJavaInfo{ @@ -2810,7 +2811,22 @@ type javaLibraryAttributes struct { } type kotlinAttributes struct { - Common_srcs bazel.LabelListAttribute + Common_srcs bazel.LabelListAttribute + 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) { @@ -2842,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:library.bzl", - } + props = javaLibraryBazelTargetModuleProperties() } else { - props = bazel.BazelTargetModuleProperties{ - Rule_class: "kt_jvm_library", - Bzl_load_location: "//build/bazel/rules/kotlin:kt_jvm_library.bzl", - } + props = ktJvmLibraryBazelTargetModuleProperties() } ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name}, attrs) @@ -2929,35 +2939,38 @@ func javaBinaryHostBp2Build(ctx android.TopDownMutatorContext, m *Binary) { } props := bazel.BazelTargetModuleProperties{ - Rule_class: "java_binary", + Rule_class: "java_binary", + Bzl_load_location: "//build/bazel/rules/java:rules.bzl", } - attrs := &javaBinaryHostAttributes{ + binAttrs := &javaBinaryHostAttributes{ Runtime_deps: runtimeDeps, Main_class: mainClass, Jvm_flags: jvmFlags, } - if !bp2BuildInfo.hasKotlin { - attrs.javaCommonAttributes = commonAttrs - attrs.Deps = deps - } else { - ktName := m.Name() + "_kt" - ktProps := bazel.BazelTargetModuleProperties{ - Rule_class: "kt_jvm_library", - Bzl_load_location: "//build/bazel/rules/kotlin:kt_jvm_library.bzl", - } - - ktAttrs := &javaLibraryAttributes{ - Deps: deps, - javaCommonAttributes: commonAttrs, - } + if commonAttrs.Srcs.IsEmpty() { + binAttrs.javaCommonAttributes = commonAttrs + ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: m.Name()}, binAttrs) + return + } - ctx.CreateBazelTargetModule(ktProps, android.CommonAttributes{Name: ktName}, ktAttrs) - attrs.Runtime_deps.Add(&bazel.LabelAttribute{Value: &bazel.Label{Label: ":" + ktName}}) + libName := m.Name() + "_lib" + var libProps bazel.BazelTargetModuleProperties + if bp2BuildInfo.hasKotlin { + libProps = ktJvmLibraryBazelTargetModuleProperties() + } else { + libProps = javaLibraryBazelTargetModuleProperties() + } + libAttrs := &javaLibraryAttributes{ + Deps: deps, + javaCommonAttributes: commonAttrs, } + ctx.CreateBazelTargetModule(libProps, android.CommonAttributes{Name: libName}, libAttrs) + binAttrs.Runtime_deps.Add(&bazel.LabelAttribute{Value: &bazel.Label{Label: ":" + libName}}) + // Create the BazelTargetModule. - ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: m.Name()}, attrs) + ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: m.Name()}, binAttrs) } type bazelJavaImportAttributes struct { @@ -2981,7 +2994,10 @@ func (i *Import) ConvertWithBp2build(ctx android.TopDownMutatorContext) { attrs := &bazelJavaImportAttributes{ Jars: jars, } - props := bazel.BazelTargetModuleProperties{Rule_class: "java_import"} + props := bazel.BazelTargetModuleProperties{ + Rule_class: "java_import", + Bzl_load_location: "//build/bazel/rules/java:rules.bzl", + } name := android.RemoveOptionalPrebuiltPrefix(i.Name()) @@ -2992,7 +3008,10 @@ func (i *Import) ConvertWithBp2build(ctx android.TopDownMutatorContext) { Neverlink: bazel.BoolAttribute{Value: &neverlink}, Exports: bazel.MakeSingleLabelListAttribute(bazel.Label{Label: ":" + name}), } - ctx.CreateBazelTargetModule(bazel.BazelTargetModuleProperties{Rule_class: "java_library"}, android.CommonAttributes{Name: name + "-neverlink"}, neverlinkAttrs) + ctx.CreateBazelTargetModule( + javaLibraryBazelTargetModuleProperties(), + android.CommonAttributes{Name: name + "-neverlink"}, + neverlinkAttrs) } |