Merge "Implement bp2build for Sysprop Java" into main

This commit is contained in:
Trevor Radcliffe 2023-10-05 15:59:53 +00:00 committed by Gerrit Code Review
commit e3e930d260
7 changed files with 189 additions and 42 deletions

View file

@ -18,6 +18,7 @@ bootstrap_go_package {
"soong-genrule",
"soong-multitree",
"soong-snapshot",
"soong-sysprop-bp2build",
"soong-tradefed",
],
srcs: [
@ -49,7 +50,6 @@ bootstrap_go_package {
"snapshot_utils.go",
"stl.go",
"strip.go",
"sysprop.go",
"tidy.go",
"util.go",
"vendor_snapshot.go",

View file

@ -20,6 +20,7 @@ import (
"android/soong/aidl_library"
"android/soong/bazel"
"android/soong/sysprop/bp2build"
"github.com/google/blueprint"
@ -240,12 +241,13 @@ func genSysprop(ctx android.ModuleContext, syspropFile android.Path) (android.Pa
}
func bp2buildCcSysprop(ctx android.Bp2buildMutatorContext, moduleName string, minSdkVersion *string, srcs bazel.LabelListAttribute) *bazel.LabelAttribute {
labels := SyspropLibraryLabels{
SyspropLibraryLabel: moduleName + "_sysprop_library",
StaticLibraryLabel: moduleName + "_cc_sysprop_library_static",
labels := bp2build.SyspropLibraryLabels{
SyspropLibraryLabel: moduleName + "_sysprop_library",
CcStaticLibraryLabel: moduleName + "_cc_sysprop_library_static",
}
Bp2buildSysprop(ctx, labels, srcs, minSdkVersion)
return createLabelAttributeCorrespondingToSrcs(":"+labels.StaticLibraryLabel, srcs)
bp2build.Bp2buildBaseSyspropLibrary(ctx, labels.SyspropLibraryLabel, srcs)
bp2build.Bp2buildSyspropCc(ctx, labels, minSdkVersion)
return createLabelAttributeCorrespondingToSrcs(":"+labels.CcStaticLibraryLabel, srcs)
}
// Creates a LabelAttribute for a given label where the value is only set for

View file

@ -12,6 +12,7 @@ bootstrap_go_package {
"soong-bp2build",
"soong-cc",
"soong-java",
"soong-sysprop-bp2build",
],
srcs: [
"sysprop_library.go",

View file

@ -0,0 +1,16 @@
package {
default_applicable_licenses: ["Android-Apache-2.0"],
}
bootstrap_go_package {
name: "soong-sysprop-bp2build",
pkgPath: "android/soong/sysprop/bp2build",
deps: [
"soong-android",
"soong-bazel",
],
srcs: [
"bp2build.go",
],
pluginFor: ["soong_build"],
}

View file

@ -12,44 +12,50 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package cc
package bp2build
import (
"android/soong/android"
"android/soong/bazel"
)
type SyspropLibraryLabels struct {
SyspropLibraryLabel string
CcSharedLibraryLabel string
CcStaticLibraryLabel string
JavaLibraryLabel string
}
// TODO(b/240463568): Additional properties will be added for API validation
type bazelSyspropLibraryAttributes struct {
Srcs bazel.LabelListAttribute
Tags bazel.StringListAttribute
}
func Bp2buildBaseSyspropLibrary(ctx android.Bp2buildMutatorContext, name string, srcs bazel.LabelListAttribute) {
apexAvailableTags := android.ApexAvailableTagsWithoutTestApexes(ctx.(android.Bp2buildMutatorContext), ctx.Module())
ctx.CreateBazelTargetModule(
bazel.BazelTargetModuleProperties{
Rule_class: "sysprop_library",
Bzl_load_location: "//build/bazel/rules/sysprop:sysprop_library.bzl",
},
android.CommonAttributes{Name: name},
&bazelSyspropLibraryAttributes{
Srcs: srcs,
Tags: apexAvailableTags,
},
)
}
type bazelCcSyspropLibraryAttributes struct {
Dep bazel.LabelAttribute
Min_sdk_version *string
Tags bazel.StringListAttribute
}
type SyspropLibraryLabels struct {
SyspropLibraryLabel string
SharedLibraryLabel string
StaticLibraryLabel string
}
func Bp2buildSysprop(ctx android.Bp2buildMutatorContext, labels SyspropLibraryLabels, srcs bazel.LabelListAttribute, minSdkVersion *string) {
apexAvailableTags := android.ApexAvailableTagsWithoutTestApexes(ctx, ctx.Module())
ctx.CreateBazelTargetModule(
bazel.BazelTargetModuleProperties{
Rule_class: "sysprop_library",
Bzl_load_location: "//build/bazel/rules/sysprop:sysprop_library.bzl",
},
android.CommonAttributes{Name: labels.SyspropLibraryLabel},
&bazelSyspropLibraryAttributes{
Srcs: srcs,
Tags: apexAvailableTags,
},
)
func Bp2buildSyspropCc(ctx android.Bp2buildMutatorContext, labels SyspropLibraryLabels, minSdkVersion *string) {
apexAvailableTags := android.ApexAvailableTagsWithoutTestApexes(ctx.(android.Bp2buildMutatorContext), ctx.Module())
attrs := &bazelCcSyspropLibraryAttributes{
Dep: *bazel.MakeLabelAttribute(":" + labels.SyspropLibraryLabel),
@ -57,21 +63,44 @@ func Bp2buildSysprop(ctx android.Bp2buildMutatorContext, labels SyspropLibraryLa
Tags: apexAvailableTags,
}
if labels.SharedLibraryLabel != "" {
if labels.CcSharedLibraryLabel != "" {
ctx.CreateBazelTargetModule(
bazel.BazelTargetModuleProperties{
Rule_class: "cc_sysprop_library_shared",
Bzl_load_location: "//build/bazel/rules/cc:cc_sysprop_library.bzl",
},
android.CommonAttributes{Name: labels.SharedLibraryLabel},
android.CommonAttributes{Name: labels.CcSharedLibraryLabel},
attrs)
}
if labels.CcStaticLibraryLabel != "" {
ctx.CreateBazelTargetModule(
bazel.BazelTargetModuleProperties{
Rule_class: "cc_sysprop_library_static",
Bzl_load_location: "//build/bazel/rules/cc:cc_sysprop_library.bzl",
},
android.CommonAttributes{Name: labels.CcStaticLibraryLabel},
attrs)
}
}
type bazelJavaLibraryAttributes struct {
Dep bazel.LabelAttribute
Min_sdk_version *string
Tags bazel.StringListAttribute
}
func Bp2buildSyspropJava(ctx android.Bp2buildMutatorContext, labels SyspropLibraryLabels, minSdkVersion *string) {
apexAvailableTags := android.ApexAvailableTagsWithoutTestApexes(ctx.(android.Bp2buildMutatorContext), ctx.Module())
ctx.CreateBazelTargetModule(
bazel.BazelTargetModuleProperties{
Rule_class: "cc_sysprop_library_static",
Bzl_load_location: "//build/bazel/rules/cc:cc_sysprop_library.bzl",
Rule_class: "java_sysprop_library",
Bzl_load_location: "//build/bazel/rules/java:java_sysprop_library.bzl",
},
android.CommonAttributes{Name: labels.StaticLibraryLabel},
attrs)
android.CommonAttributes{Name: labels.JavaLibraryLabel},
&bazelJavaLibraryAttributes{
Dep: *bazel.MakeLabelAttribute(":" + labels.SyspropLibraryLabel),
Min_sdk_version: minSdkVersion,
Tags: apexAvailableTags,
})
}

View file

@ -24,6 +24,8 @@ import (
"sync"
"android/soong/bazel"
"android/soong/sysprop/bp2build"
"android/soong/ui/metrics/bp2build_metrics_proto"
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
@ -230,6 +232,10 @@ func (m *syspropLibrary) javaGenPublicStubName() string {
return m.BaseModuleName() + "_java_gen_public"
}
func (m *syspropLibrary) bp2buildJavaImplementationModuleName() string {
return m.BaseModuleName() + "_java_library"
}
func (m *syspropLibrary) BaseModuleName() string {
return m.ModuleBase.Name()
}
@ -431,6 +437,7 @@ type javaLibraryProperties struct {
Min_sdk_version *string
Bazel_module struct {
Bp2build_available *bool
Label *string
}
}
@ -551,8 +558,10 @@ func syspropLibraryHook(ctx android.LoadHookContext, m *syspropLibrary) {
Min_sdk_version: m.properties.Java.Min_sdk_version,
Bazel_module: struct {
Bp2build_available *bool
Label *string
}{
Bp2build_available: proptools.BoolPtr(false),
Label: proptools.StringPtr(
fmt.Sprintf("//%s:%s", ctx.ModuleDir(), m.bp2buildJavaImplementationModuleName())),
},
})
@ -573,6 +582,7 @@ func syspropLibraryHook(ctx android.LoadHookContext, m *syspropLibrary) {
Stem: proptools.StringPtr(m.BaseModuleName()),
Bazel_module: struct {
Bp2build_available *bool
Label *string
}{
Bp2build_available: proptools.BoolPtr(false),
},
@ -592,13 +602,17 @@ func syspropLibraryHook(ctx android.LoadHookContext, m *syspropLibrary) {
// TODO(b/240463568): Additional properties will be added for API validation
func (m *syspropLibrary) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) {
labels := cc.SyspropLibraryLabels{
SyspropLibraryLabel: m.BaseModuleName(),
SharedLibraryLabel: m.CcImplementationModuleName(),
StaticLibraryLabel: cc.BazelLabelNameForStaticModule(m.CcImplementationModuleName()),
if m.Owner() != "Platform" {
ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_UNSUPPORTED, "Only sysprop libraries owned by platform are supported at this time")
return
}
cc.Bp2buildSysprop(ctx,
labels,
bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, m.properties.Srcs)),
m.properties.Cpp.Min_sdk_version)
labels := bp2build.SyspropLibraryLabels{
SyspropLibraryLabel: m.BaseModuleName(),
CcSharedLibraryLabel: m.CcImplementationModuleName(),
CcStaticLibraryLabel: cc.BazelLabelNameForStaticModule(m.CcImplementationModuleName()),
JavaLibraryLabel: m.bp2buildJavaImplementationModuleName(),
}
bp2build.Bp2buildBaseSyspropLibrary(ctx, labels.SyspropLibraryLabel, bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, m.properties.Srcs)))
bp2build.Bp2buildSyspropCc(ctx, labels, m.properties.Cpp.Min_sdk_version)
bp2build.Bp2buildSyspropJava(ctx, labels, m.properties.Java.Min_sdk_version)
}

View file

@ -58,13 +58,18 @@ sysprop_library {
bp2build.AttrNameToString{
"dep": `":sysprop_foo"`,
}),
bp2build.MakeBazelTargetNoRestrictions("java_sysprop_library",
"sysprop_foo_java_library",
bp2build.AttrNameToString{
"dep": `":sysprop_foo"`,
}),
},
})
}
func TestSyspropLibraryCppMinSdkVersion(t *testing.T) {
bp2build.RunBp2BuildTestCaseSimple(t, bp2build.Bp2buildTestCase{
Description: "sysprop_library with min_sdk_version",
Description: "sysprop_library with cpp min_sdk_version",
ModuleTypeUnderTest: "sysprop_library",
ModuleTypeUnderTestFactory: syspropLibraryFactory,
Filesystem: map[string]string{
@ -105,6 +110,86 @@ sysprop_library {
"dep": `":sysprop_foo"`,
"min_sdk_version": `"5"`,
}),
bp2build.MakeBazelTargetNoRestrictions("java_sysprop_library",
"sysprop_foo_java_library",
bp2build.AttrNameToString{
"dep": `":sysprop_foo"`,
}),
},
})
}
func TestSyspropLibraryJavaMinSdkVersion(t *testing.T) {
bp2build.RunBp2BuildTestCaseSimple(t, bp2build.Bp2buildTestCase{
Description: "sysprop_library with java min_sdk_version",
ModuleTypeUnderTest: "sysprop_library",
ModuleTypeUnderTestFactory: syspropLibraryFactory,
Filesystem: map[string]string{
"foo.sysprop": "",
"bar.sysprop": "",
},
Blueprint: `
sysprop_library {
name: "sysprop_foo",
srcs: [
"foo.sysprop",
"bar.sysprop",
],
java: {
min_sdk_version: "5",
},
property_owner: "Platform",
}
`,
ExpectedBazelTargets: []string{
bp2build.MakeBazelTargetNoRestrictions("sysprop_library",
"sysprop_foo",
bp2build.AttrNameToString{
"srcs": `[
"foo.sysprop",
"bar.sysprop",
]`,
}),
bp2build.MakeBazelTargetNoRestrictions("cc_sysprop_library_shared",
"libsysprop_foo",
bp2build.AttrNameToString{
"dep": `":sysprop_foo"`,
}),
bp2build.MakeBazelTargetNoRestrictions("cc_sysprop_library_static",
"libsysprop_foo_bp2build_cc_library_static",
bp2build.AttrNameToString{
"dep": `":sysprop_foo"`,
}),
bp2build.MakeBazelTargetNoRestrictions("java_sysprop_library",
"sysprop_foo_java_library",
bp2build.AttrNameToString{
"dep": `":sysprop_foo"`,
"min_sdk_version": `"5"`,
}),
},
})
}
func TestSyspropLibraryOwnerNotPlatformUnconvertible(t *testing.T) {
bp2build.RunBp2BuildTestCaseSimple(t, bp2build.Bp2buildTestCase{
Description: "sysprop_library simple",
ModuleTypeUnderTest: "sysprop_library",
ModuleTypeUnderTestFactory: syspropLibraryFactory,
Filesystem: map[string]string{
"foo.sysprop": "",
"bar.sysprop": "",
},
Blueprint: `
sysprop_library {
name: "sysprop_foo",
srcs: [
"foo.sysprop",
"bar.sysprop",
],
property_owner: "Vendor",
device_specific: true,
}
`,
ExpectedBazelTargets: []string{},
})
}