From f5f6073ff5876c6828bfa985e1ab58ffd098ba8e Mon Sep 17 00:00:00 2001 From: Romain Jobredeaux Date: Thu, 16 Mar 2023 11:00:36 -0400 Subject: Create an intermediate java library for every java_binary target We're already doing this for kotlin libraries as java_binary does not support kotlin sources. Change-Id: I4967b3aca21dac8e0eaf54d48cc35d57a4c4923e --- java/java.go | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index 15ee4a995..071f0fb82 100644 --- a/java/java.go +++ b/java/java.go @@ -2934,33 +2934,41 @@ func javaBinaryHostBp2Build(ctx android.TopDownMutatorContext, m *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{ + if commonAttrs.Srcs.IsEmpty() { + binAttrs.javaCommonAttributes = commonAttrs + ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: m.Name()}, binAttrs) + return + } + + 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", } - - ktAttrs := &javaLibraryAttributes{ - Deps: deps, - javaCommonAttributes: commonAttrs, + } else { + libProps = bazel.BazelTargetModuleProperties{ + Rule_class: "java_library", + Bzl_load_location: "//build/bazel/rules/java:rules.bzl", } - - ctx.CreateBazelTargetModule(ktProps, android.CommonAttributes{Name: ktName}, ktAttrs) - attrs.Runtime_deps.Add(&bazel.LabelAttribute{Value: &bazel.Label{Label: ":" + ktName}}) } + 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 { -- cgit v1.2.3-59-g8ed1b