Don't use java_library for java_import neverlink
Restricting use of sdk_version = "none" to only the rule types that will
correctly handled sdk_version = "none" by also handling system_module
attr
Test: CI && go tests
Change-Id: Ifa1c60ba8f5e3fcb28986cc84cdfaedcbd2d2957
diff --git a/java/java.go b/java/java.go
index 990a084..0594a8b 100644
--- a/java/java.go
+++ b/java/java.go
@@ -3403,9 +3403,14 @@
return libName
}
-type bazelJavaImportAttributes struct {
- Jars bazel.LabelListAttribute
- Exports bazel.LabelListAttribute
+type importAttributes struct {
+ Jars bazel.LabelListAttribute
+ Exports bazel.LabelListAttribute
+ Neverlink *bool
+}
+
+type filegroupAttrs struct {
+ Srcs bazel.LabelListAttribute
}
// java_import bp2Build converter.
@@ -3421,28 +3426,36 @@
}
}
- attrs := &bazelJavaImportAttributes{
- Jars: jars,
+ name := android.RemoveOptionalPrebuiltPrefix(i.Name())
+ filegroupTargetName := name + "-jars"
+
+ ctx.CreateBazelTargetModule(
+ bazel.BazelTargetModuleProperties{
+ Rule_class: "filegroup",
+ Bzl_load_location: "//build/bazel/rules:filegroup.bzl",
+ },
+ android.CommonAttributes{Name: filegroupTargetName},
+ &filegroupAttrs{
+ Srcs: jars,
+ },
+ )
+
+ attrs := &importAttributes{
+ Jars: bazel.MakeSingleLabelListAttribute(bazel.Label{Label: ":" + filegroupTargetName}),
}
props := bazel.BazelTargetModuleProperties{
Rule_class: "java_import",
Bzl_load_location: "//build/bazel/rules/java:import.bzl",
}
- name := android.RemoveOptionalPrebuiltPrefix(i.Name())
-
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: name}, attrs)
- neverlink := true
- neverlinkAttrs := &javaLibraryAttributes{
- Neverlink: bazel.BoolAttribute{Value: &neverlink},
- Exports: bazel.MakeSingleLabelListAttribute(bazel.Label{Label: ":" + name}),
- javaCommonAttributes: &javaCommonAttributes{
- Sdk_version: bazel.StringAttribute{Value: proptools.StringPtr("none")},
- },
+ neverlinkAttrs := &importAttributes{
+ Jars: attrs.Jars,
+ Neverlink: proptools.BoolPtr(true),
}
ctx.CreateBazelTargetModule(
- javaLibraryBazelTargetModuleProperties(),
+ props,
android.CommonAttributes{Name: name + "-neverlink"},
neverlinkAttrs)
}