From 4e00b0929b3806667be974b0fd1efab06cca063e Mon Sep 17 00:00:00 2001 From: Liz Kammer Date: Wed, 11 Oct 2023 15:24:24 -0400 Subject: 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 --- java/java.go | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index 990a084f7..0594a8b93 100644 --- a/java/java.go +++ b/java/java.go @@ -3403,9 +3403,14 @@ func createLibraryTarget(ctx android.Bp2buildMutatorContext, libInfo libraryCrea 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 @@ func (i *Import) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) { } } - 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) } -- cgit v1.2.3-59-g8ed1b