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
This commit is contained in:
Romain Jobredeaux
2023-03-16 11:00:36 -04:00
committed by Alix
parent 65e42ecd47
commit f5f6073ff5
2 changed files with 56 additions and 36 deletions

View File

@@ -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 {