summaryrefslogtreecommitdiff
path: root/java/java.go
diff options
context:
space:
mode:
author Romain Jobredeaux <jobredeaux@google.com> 2023-03-17 12:30:15 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2023-03-17 12:30:15 +0000
commitd3d2be26360bb0490e9d33215837baaaf3acc549 (patch)
tree800c6894a26ce0380c37440ba0a5bd59c5f8f66a /java/java.go
parentbb37c196a30aa6c05ececb382acd617df1b92565 (diff)
parentf5f6073ff5876c6828bfa985e1ab58ffd098ba8e (diff)
Merge "Create an intermediate java library for every java_binary target"
Diffstat (limited to 'java/java.go')
-rw-r--r--java/java.go38
1 files changed, 23 insertions, 15 deletions
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 {