Merge changes from topic "ktResourceStrip"
* changes: code cleanup for bp2build java_binary with kt srcs resource_strip_prefix support for kotlin srcs
This commit is contained in:
@@ -221,6 +221,11 @@ func TestJavaBinaryHostKotlinWithResourceDir(t *testing.T) {
|
|||||||
"a.java",
|
"a.java",
|
||||||
"b.kt",
|
"b.kt",
|
||||||
]`,
|
]`,
|
||||||
|
"resources": `[
|
||||||
|
"res/a.res",
|
||||||
|
"res/dir1/b.res",
|
||||||
|
]`,
|
||||||
|
"resource_strip_prefix": `"res"`,
|
||||||
"target_compatible_with": `select({
|
"target_compatible_with": `select({
|
||||||
"//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
|
"//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
|
||||||
"//conditions:default": [],
|
"//conditions:default": [],
|
||||||
@@ -229,11 +234,6 @@ func TestJavaBinaryHostKotlinWithResourceDir(t *testing.T) {
|
|||||||
MakeBazelTarget("java_binary", "java-binary-host", AttrNameToString{
|
MakeBazelTarget("java_binary", "java-binary-host", AttrNameToString{
|
||||||
"main_class": `"com.android.test.MainClass"`,
|
"main_class": `"com.android.test.MainClass"`,
|
||||||
"runtime_deps": `[":java-binary-host_kt"]`,
|
"runtime_deps": `[":java-binary-host_kt"]`,
|
||||||
"resources": `[
|
|
||||||
"res/a.res",
|
|
||||||
"res/dir1/b.res",
|
|
||||||
]`,
|
|
||||||
"resource_strip_prefix": `"res"`,
|
|
||||||
"target_compatible_with": `select({
|
"target_compatible_with": `select({
|
||||||
"//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
|
"//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
|
||||||
"//conditions:default": [],
|
"//conditions:default": [],
|
||||||
|
24
java/java.go
24
java/java.go
@@ -2838,7 +2838,7 @@ func javaLibraryBp2Build(ctx android.TopDownMutatorContext, m *Library) {
|
|||||||
|
|
||||||
props = bazel.BazelTargetModuleProperties{
|
props = bazel.BazelTargetModuleProperties{
|
||||||
Rule_class: "kt_jvm_library",
|
Rule_class: "kt_jvm_library",
|
||||||
Bzl_load_location: "@rules_kotlin//kotlin:jvm_library.bzl",
|
Bzl_load_location: "//build/bazel/rules/kotlin:kt_jvm_library.bzl",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2933,14 +2933,15 @@ func javaBinaryHostBp2Build(ctx android.TopDownMutatorContext, m *Binary) {
|
|||||||
ktName := m.Name() + "_kt"
|
ktName := m.Name() + "_kt"
|
||||||
ktProps := bazel.BazelTargetModuleProperties{
|
ktProps := bazel.BazelTargetModuleProperties{
|
||||||
Rule_class: "kt_jvm_library",
|
Rule_class: "kt_jvm_library",
|
||||||
Bzl_load_location: "@rules_kotlin//kotlin:jvm_library.bzl",
|
Bzl_load_location: "//build/bazel/rules/kotlin:kt_jvm_library.bzl",
|
||||||
}
|
}
|
||||||
ktAttrs := &javaLibraryAttributes{
|
ktAttrs := &javaLibraryAttributes{
|
||||||
Deps: deps,
|
Deps: deps,
|
||||||
javaCommonAttributes: &javaCommonAttributes{
|
javaCommonAttributes: &javaCommonAttributes{
|
||||||
Srcs: commonAttrs.Srcs,
|
Srcs: commonAttrs.Srcs,
|
||||||
Plugins: commonAttrs.Plugins,
|
Plugins: commonAttrs.Plugins,
|
||||||
Javacopts: commonAttrs.Javacopts,
|
Javacopts: commonAttrs.Javacopts,
|
||||||
|
javaResourcesAttributes: commonAttrs.javaResourcesAttributes,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2948,19 +2949,6 @@ func javaBinaryHostBp2Build(ctx android.TopDownMutatorContext, m *Binary) {
|
|||||||
ktAttrs.javaCommonAttributes.Common_srcs = bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, m.properties.Common_srcs))
|
ktAttrs.javaCommonAttributes.Common_srcs = bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, m.properties.Common_srcs))
|
||||||
}
|
}
|
||||||
|
|
||||||
// kt_jvm_library does not support resource_strip_prefix, if this attribute
|
|
||||||
// is set, than javaResourcesAttributes needs to be set in the
|
|
||||||
// javaCommonAttributes of the java_binary target
|
|
||||||
if commonAttrs.javaResourcesAttributes != nil {
|
|
||||||
if commonAttrs.javaResourcesAttributes.Resource_strip_prefix != nil {
|
|
||||||
attrs.javaCommonAttributes = &javaCommonAttributes{
|
|
||||||
javaResourcesAttributes: commonAttrs.javaResourcesAttributes,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ktAttrs.javaCommonAttributes.javaResourcesAttributes = commonAttrs.javaResourcesAttributes
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.CreateBazelTargetModule(ktProps, android.CommonAttributes{Name: ktName}, ktAttrs)
|
ctx.CreateBazelTargetModule(ktProps, android.CommonAttributes{Name: ktName}, ktAttrs)
|
||||||
attrs.Runtime_deps.Add(&bazel.LabelAttribute{Value: &bazel.Label{Label: ":" + ktName}})
|
attrs.Runtime_deps.Add(&bazel.LabelAttribute{Value: &bazel.Label{Label: ":" + ktName}})
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user