Enable bp2build for cc modules relying on sysprop

Bug: 244439349
Test: m bp2build
Test: Inspect BUILD.bazel files
Test: Unit tests
Change-Id: I85bfb9fa69cb3f96b15bdbeb797dba86b3349804
This commit is contained in:
Trevor Radcliffe
2022-09-06 19:31:25 +00:00
parent e53c7ea256
commit cee4e056aa
10 changed files with 454 additions and 53 deletions

View File

@@ -573,43 +573,14 @@ func syspropLibraryHook(ctx android.LoadHookContext, m *syspropLibrary) {
}
// TODO(b/240463568): Additional properties will be added for API validation
type bazelSyspropLibraryAttributes struct {
Srcs bazel.LabelListAttribute
}
type bazelCcSyspropLibraryAttributes struct {
Dep bazel.LabelAttribute
Min_sdk_version *string
}
func (m *syspropLibrary) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
ctx.CreateBazelTargetModule(
bazel.BazelTargetModuleProperties{
Rule_class: "sysprop_library",
Bzl_load_location: "//build/bazel/rules/sysprop:sysprop_library.bzl",
},
android.CommonAttributes{Name: m.Name()},
&bazelSyspropLibraryAttributes{
Srcs: bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, m.properties.Srcs)),
})
attrs := &bazelCcSyspropLibraryAttributes{
Dep: *bazel.MakeLabelAttribute(":" + m.Name()),
Min_sdk_version: m.properties.Cpp.Min_sdk_version,
labels := cc.SyspropLibraryLabels{
SyspropLibraryLabel: m.BaseModuleName(),
SharedLibraryLabel: m.CcImplementationModuleName(),
StaticLibraryLabel: cc.BazelLabelNameForStaticModule(m.CcImplementationModuleName()),
}
ctx.CreateBazelTargetModule(
bazel.BazelTargetModuleProperties{
Rule_class: "cc_sysprop_library_shared",
Bzl_load_location: "//build/bazel/rules/cc:cc_sysprop_library.bzl",
},
android.CommonAttributes{Name: m.CcImplementationModuleName()},
attrs)
ctx.CreateBazelTargetModule(
bazel.BazelTargetModuleProperties{
Rule_class: "cc_sysprop_library_static",
Bzl_load_location: "//build/bazel/rules/cc:cc_sysprop_library.bzl",
},
android.CommonAttributes{Name: m.CcImplementationModuleName() + "_bp2build_cc_library_static"},
attrs)
cc.Bp2buildSysprop(ctx,
labels,
bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, m.properties.Srcs)),
m.properties.Cpp.Min_sdk_version)
}

View File

@@ -41,7 +41,7 @@ sysprop_library {
`,
ExpectedBazelTargets: []string{
bp2build.MakeBazelTargetNoRestrictions("sysprop_library",
"sysprop_foo_sysprop_library",
"sysprop_foo",
bp2build.AttrNameToString{
"srcs": `[
"foo.sysprop",
@@ -51,12 +51,12 @@ sysprop_library {
bp2build.MakeBazelTargetNoRestrictions("cc_sysprop_library_shared",
"libsysprop_foo",
bp2build.AttrNameToString{
"dep": `":sysprop_foo_sysprop_library"`,
"dep": `":sysprop_foo"`,
}),
bp2build.MakeBazelTargetNoRestrictions("cc_sysprop_library_static",
"libsysprop_foo_bp2build_cc_library_static",
bp2build.AttrNameToString{
"dep": `":sysprop_foo_sysprop_library"`,
"dep": `":sysprop_foo"`,
}),
},
})
@@ -86,7 +86,7 @@ sysprop_library {
`,
ExpectedBazelTargets: []string{
bp2build.MakeBazelTargetNoRestrictions("sysprop_library",
"sysprop_foo_sysprop_library",
"sysprop_foo",
bp2build.AttrNameToString{
"srcs": `[
"foo.sysprop",
@@ -96,13 +96,13 @@ sysprop_library {
bp2build.MakeBazelTargetNoRestrictions("cc_sysprop_library_shared",
"libsysprop_foo",
bp2build.AttrNameToString{
"dep": `":sysprop_foo_sysprop_library"`,
"dep": `":sysprop_foo"`,
"min_sdk_version": `"5"`,
}),
bp2build.MakeBazelTargetNoRestrictions("cc_sysprop_library_static",
"libsysprop_foo_bp2build_cc_library_static",
bp2build.AttrNameToString{
"dep": `":sysprop_foo_sysprop_library"`,
"dep": `":sysprop_foo"`,
"min_sdk_version": `"5"`,
}),
},