Merge "Add bp2build converter for python protobuf files" am: 5317be265a
am: 06c53221cf
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2099296 Change-Id: I84c420d928dfaa6ec2eddb9fada5019d90d6750c Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
123a1fbabd
5 changed files with 78 additions and 3 deletions
|
@ -46,6 +46,7 @@ var (
|
|||
"bootable/recovery/tools/recovery_l10n": Bp2BuildDefaultTrue,
|
||||
"build/bazel/examples/apex/minimal": Bp2BuildDefaultTrueRecursively,
|
||||
"build/bazel/examples/soong_config_variables": Bp2BuildDefaultTrueRecursively,
|
||||
"build/bazel/examples/python": Bp2BuildDefaultTrueRecursively,
|
||||
"build/make/target/product/security": Bp2BuildDefaultTrue,
|
||||
"build/make/tools/signapk": Bp2BuildDefaultTrue,
|
||||
"build/make/tools/zipalign": Bp2BuildDefaultTrueRecursively,
|
||||
|
@ -328,9 +329,7 @@ var (
|
|||
"libbase_ndk", // TODO(b/186826477): fails to link libctscamera2_jni for device (required for CtsCameraTestCases)
|
||||
|
||||
// python protos
|
||||
"libprotobuf-python", // TODO(b/196084681): contains .proto sources
|
||||
"apex_build_info_proto", "apex_manifest_proto", // TODO(b/196084681): a python lib with proto sources
|
||||
"linker_config_proto", // TODO(b/196084681): contains .proto sources
|
||||
"libprotobuf-python", // Has a handcrafted alternative
|
||||
|
||||
// genrule incompatibilities
|
||||
"brotli-fuzzer-corpus", // TODO(b/202015218): outputs are in location incompatible with bazel genrule handling.
|
||||
|
|
|
@ -652,6 +652,11 @@ func MakeLabelListAttribute(value LabelList) LabelListAttribute {
|
|||
}
|
||||
}
|
||||
|
||||
// MakeSingleLabelListAttribute initializes a LabelListAttribute as a non-arch specific list with 1 element, the given Label.
|
||||
func MakeSingleLabelListAttribute(value Label) LabelListAttribute {
|
||||
return MakeLabelListAttribute(MakeLabelList([]Label{value}))
|
||||
}
|
||||
|
||||
func (lla *LabelListAttribute) SetValue(list LabelList) {
|
||||
lla.SetSelectValue(NoConfigAxis, "", list)
|
||||
}
|
||||
|
|
|
@ -305,3 +305,46 @@ func TestPythonArchVariance(t *testing.T) {
|
|||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestPythonLibraryWithProtobufs(t *testing.T) {
|
||||
runPythonLibraryTestCases(t, pythonLibBp2BuildTestCase{
|
||||
description: "test %s protobuf",
|
||||
filesystem: map[string]string{
|
||||
"dir/mylib.py": "",
|
||||
"dir/myproto.proto": "",
|
||||
},
|
||||
blueprint: `%s {
|
||||
name: "foo",
|
||||
srcs: [
|
||||
"dir/mylib.py",
|
||||
"dir/myproto.proto",
|
||||
],
|
||||
}`,
|
||||
expectedBazelTargets: []testBazelTarget{
|
||||
{
|
||||
typ: "proto_library",
|
||||
name: "foo_proto",
|
||||
attrs: attrNameToString{
|
||||
"srcs": `["dir/myproto.proto"]`,
|
||||
},
|
||||
},
|
||||
{
|
||||
typ: "py_proto_library",
|
||||
name: "foo_py_proto",
|
||||
attrs: attrNameToString{
|
||||
"deps": `[":foo_proto"]`,
|
||||
},
|
||||
},
|
||||
{
|
||||
typ: "py_library",
|
||||
name: "foo",
|
||||
attrs: attrNameToString{
|
||||
"srcs": `["dir/mylib.py"]`,
|
||||
"srcs_version": `"PY3"`,
|
||||
"imports": `["."]`,
|
||||
"deps": `[":foo_py_proto"]`,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
|
@ -50,6 +50,10 @@ type bazelPythonLibraryAttributes struct {
|
|||
Srcs_version *string
|
||||
}
|
||||
|
||||
type bazelPythonProtoLibraryAttributes struct {
|
||||
Deps bazel.LabelListAttribute
|
||||
}
|
||||
|
||||
func pythonLibBp2Build(ctx android.TopDownMutatorContext, m *Module) {
|
||||
// TODO(b/182306917): this doesn't fully handle all nested props versioned
|
||||
// by the python version, which would have been handled by the version split
|
||||
|
@ -96,6 +100,7 @@ func pythonLibBp2Build(ctx android.TopDownMutatorContext, m *Module) {
|
|||
}
|
||||
|
||||
baseAttrs := m.makeArchVariantBaseAttributes(ctx)
|
||||
|
||||
attrs := &bazelPythonLibraryAttributes{
|
||||
Srcs: baseAttrs.Srcs,
|
||||
Deps: baseAttrs.Deps,
|
||||
|
|
|
@ -207,6 +207,29 @@ func (m *Module) makeArchVariantBaseAttributes(ctx android.TopDownMutatorContext
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
partitionedSrcs := bazel.PartitionLabelListAttribute(ctx, &attrs.Srcs, bazel.LabelPartitions{
|
||||
"proto": android.ProtoSrcLabelPartition,
|
||||
"py": bazel.LabelPartition{Keep_remainder: true},
|
||||
})
|
||||
attrs.Srcs = partitionedSrcs["py"]
|
||||
|
||||
if !partitionedSrcs["proto"].IsEmpty() {
|
||||
protoInfo, _ := android.Bp2buildProtoProperties(ctx, &m.ModuleBase, partitionedSrcs["proto"])
|
||||
protoLabel := bazel.Label{Label: ":" + protoInfo.Name}
|
||||
|
||||
pyProtoLibraryName := m.Name() + "_py_proto"
|
||||
ctx.CreateBazelTargetModule(bazel.BazelTargetModuleProperties{
|
||||
Rule_class: "py_proto_library",
|
||||
Bzl_load_location: "//build/bazel/rules/python:py_proto.bzl",
|
||||
}, android.CommonAttributes{
|
||||
Name: pyProtoLibraryName,
|
||||
}, &bazelPythonProtoLibraryAttributes{
|
||||
Deps: bazel.MakeSingleLabelListAttribute(protoLabel),
|
||||
})
|
||||
|
||||
attrs.Deps.Add(bazel.MakeLabelAttribute(":" + pyProtoLibraryName))
|
||||
}
|
||||
return attrs
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue