From e11182283f088d1b10a8f03b45339607f6da6fa7 Mon Sep 17 00:00:00 2001 From: Liz Kammer Date: Wed, 18 Oct 2023 20:38:37 +0000 Subject: [PATCH] Revert "Don't use java_library for java_import neverlink" Revert submission 2786699-import-sdk-version-none Reason for revert: b/306220520 Reverted changes: /q/submissionid:2786699-import-sdk-version-none Change-Id: I4fbe5fa54dc11fac898a7f15704833f01b9fa269 --- bp2build/java_import_conversion_test.go | 50 +++++++++++-------------- java/java.go | 43 ++++++++------------- 2 files changed, 36 insertions(+), 57 deletions(-) diff --git a/bp2build/java_import_conversion_test.go b/bp2build/java_import_conversion_test.go index ad69ed5ad..bba2f5077 100644 --- a/bp2build/java_import_conversion_test.go +++ b/bp2build/java_import_conversion_test.go @@ -52,15 +52,13 @@ java_import { } `, ExpectedBazelTargets: []string{ - MakeBazelTarget("filegroup", "example_import-jars", AttrNameToString{ - "srcs": `["import.jar"]`, - }), MakeBazelTarget("java_import", "example_import", AttrNameToString{ - "jars": `[":example_import-jars"]`, + "jars": `["import.jar"]`, }), - MakeBazelTarget("java_import", "example_import-neverlink", AttrNameToString{ - "jars": `[":example_import-jars"]`, - "neverlink": `True`, + MakeBazelTarget("java_library", "example_import-neverlink", AttrNameToString{ + "exports": `[":example_import"]`, + "neverlink": `True`, + "sdk_version": `"none"`, }), }}) } @@ -88,19 +86,17 @@ java_import { } `, ExpectedBazelTargets: []string{ - MakeBazelTarget("filegroup", "example_import-jars", AttrNameToString{ - "srcs": `select({ + MakeBazelTarget("java_import", "example_import", AttrNameToString{ + "jars": `select({ "//build/bazel_common_rules/platforms/os:android": ["android.jar"], "//build/bazel_common_rules/platforms/os:linux_glibc": ["linux.jar"], "//conditions:default": [], })`, }), - MakeBazelTarget("java_import", "example_import", AttrNameToString{ - "jars": `[":example_import-jars"]`, - }), - MakeBazelTarget("java_import", "example_import-neverlink", AttrNameToString{ - "jars": `[":example_import-jars"]`, - "neverlink": `True`, + MakeBazelTarget("java_library", "example_import-neverlink", AttrNameToString{ + "exports": `[":example_import"]`, + "neverlink": `True`, + "sdk_version": `"none"`, }), }}) } @@ -121,15 +117,13 @@ java_import_host { } `, ExpectedBazelTargets: []string{ - MakeBazelTarget("filegroup", "example_import-jars", AttrNameToString{ - "srcs": `["import.jar"]`, - }), MakeBazelTarget("java_import", "example_import", AttrNameToString{ - "jars": `[":example_import-jars"]`, + "jars": `["import.jar"]`, }), - MakeBazelTarget("java_import", "example_import-neverlink", AttrNameToString{ - "jars": `[":example_import-jars"]`, - "neverlink": `True`, + MakeBazelTarget("java_library", "example_import-neverlink", AttrNameToString{ + "exports": `[":example_import"]`, + "neverlink": `True`, + "sdk_version": `"none"`, }), }}) } @@ -148,15 +142,13 @@ func TestJavaImportSameNameAsJavaLibrary(t *testing.T) { } `, ExpectedBazelTargets: []string{ - MakeBazelTarget("filegroup", "test_lib-jars", AttrNameToString{ - "srcs": `["test.jar"]`, - }), MakeBazelTarget("java_import", "test_lib", AttrNameToString{ - "jars": `[":test_lib-jars"]`, + "jars": `["test.jar"]`, }), - MakeBazelTarget("java_import", "test_lib-neverlink", AttrNameToString{ - "jars": `[":test_lib-jars"]`, - "neverlink": `True`, + MakeBazelTarget("java_library", "test_lib-neverlink", AttrNameToString{ + "exports": `[":test_lib"]`, + "neverlink": `True`, + "sdk_version": `"none"`, }), }, }, func(ctx android.RegistrationContext) { diff --git a/java/java.go b/java/java.go index 0594a8b93..990a084f7 100644 --- a/java/java.go +++ b/java/java.go @@ -3403,14 +3403,9 @@ func createLibraryTarget(ctx android.Bp2buildMutatorContext, libInfo libraryCrea return libName } -type importAttributes struct { - Jars bazel.LabelListAttribute - Exports bazel.LabelListAttribute - Neverlink *bool -} - -type filegroupAttrs struct { - Srcs bazel.LabelListAttribute +type bazelJavaImportAttributes struct { + Jars bazel.LabelListAttribute + Exports bazel.LabelListAttribute } // java_import bp2Build converter. @@ -3426,36 +3421,28 @@ func (i *Import) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) { } } - 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}), + attrs := &bazelJavaImportAttributes{ + Jars: jars, } 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) - neverlinkAttrs := &importAttributes{ - Jars: attrs.Jars, - Neverlink: proptools.BoolPtr(true), + 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")}, + }, } ctx.CreateBazelTargetModule( - props, + javaLibraryBazelTargetModuleProperties(), android.CommonAttributes{Name: name + "-neverlink"}, neverlinkAttrs) }