Merge changes from topic "import-sdk-version-none" into main

* changes:
  Do not convert sdk_version: "none"
  Don't use java_library for java_import neverlink
This commit is contained in:
Treehugger Robot 2023-10-18 17:17:59 +00:00 committed by Gerrit Code Review
commit a815d9bf79
2 changed files with 64 additions and 39 deletions

View file

@ -52,13 +52,15 @@ java_import {
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("java_import", "example_import", AttrNameToString{
"jars": `["import.jar"]`,
MakeBazelTarget("filegroup", "example_import-jars", AttrNameToString{
"srcs": `["import.jar"]`,
}),
MakeBazelTarget("java_library", "example_import-neverlink", AttrNameToString{
"exports": `[":example_import"]`,
"neverlink": `True`,
"sdk_version": `"none"`,
MakeBazelTarget("java_import", "example_import", AttrNameToString{
"jars": `[":example_import-jars"]`,
}),
MakeBazelTarget("java_import", "example_import-neverlink", AttrNameToString{
"jars": `[":example_import-jars"]`,
"neverlink": `True`,
}),
}})
}
@ -86,17 +88,19 @@ java_import {
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("java_import", "example_import", AttrNameToString{
"jars": `select({
MakeBazelTarget("filegroup", "example_import-jars", AttrNameToString{
"srcs": `select({
"//build/bazel_common_rules/platforms/os:android": ["android.jar"],
"//build/bazel_common_rules/platforms/os:linux_glibc": ["linux.jar"],
"//conditions:default": [],
})`,
}),
MakeBazelTarget("java_library", "example_import-neverlink", AttrNameToString{
"exports": `[":example_import"]`,
"neverlink": `True`,
"sdk_version": `"none"`,
MakeBazelTarget("java_import", "example_import", AttrNameToString{
"jars": `[":example_import-jars"]`,
}),
MakeBazelTarget("java_import", "example_import-neverlink", AttrNameToString{
"jars": `[":example_import-jars"]`,
"neverlink": `True`,
}),
}})
}
@ -117,13 +121,15 @@ java_import_host {
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("java_import", "example_import", AttrNameToString{
"jars": `["import.jar"]`,
MakeBazelTarget("filegroup", "example_import-jars", AttrNameToString{
"srcs": `["import.jar"]`,
}),
MakeBazelTarget("java_library", "example_import-neverlink", AttrNameToString{
"exports": `[":example_import"]`,
"neverlink": `True`,
"sdk_version": `"none"`,
MakeBazelTarget("java_import", "example_import", AttrNameToString{
"jars": `[":example_import-jars"]`,
}),
MakeBazelTarget("java_import", "example_import-neverlink", AttrNameToString{
"jars": `[":example_import-jars"]`,
"neverlink": `True`,
}),
}})
}
@ -142,13 +148,15 @@ func TestJavaImportSameNameAsJavaLibrary(t *testing.T) {
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("java_import", "test_lib", AttrNameToString{
"jars": `["test.jar"]`,
MakeBazelTarget("filegroup", "test_lib-jars", AttrNameToString{
"srcs": `["test.jar"]`,
}),
MakeBazelTarget("java_library", "test_lib-neverlink", AttrNameToString{
"exports": `[":test_lib"]`,
"neverlink": `True`,
"sdk_version": `"none"`,
MakeBazelTarget("java_import", "test_lib", AttrNameToString{
"jars": `[":test_lib-jars"]`,
}),
MakeBazelTarget("java_import", "test_lib-neverlink", AttrNameToString{
"jars": `[":test_lib-jars"]`,
"neverlink": `True`,
}),
},
}, func(ctx android.RegistrationContext) {

View file

@ -2970,6 +2970,10 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.Bp2buildMutatorContext
// TODO(b/297356582): handle core_platform in bp2build
ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_PROPERTY_UNSUPPORTED, "sdk_version core_platform")
return &javaCommonAttributes{}, &bp2BuildJavaInfo{}, false
} else if proptools.String(m.deviceProperties.Sdk_version) == "none" {
// TODO(b/297356703): handle system_modules
ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_PROPERTY_UNSUPPORTED, "sdk_version none")
return &javaCommonAttributes{}, &bp2BuildJavaInfo{}, false
}
archVariantProps := m.GetArchVariantProperties(ctx, &CommonProperties{})
@ -3403,9 +3407,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 +3430,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)
}