platform_build_soong/bp2build/rust_protobuf_conversion_test.go
Vinh Tran 47faaad254 Add bp2build for rust_protobuf module
We only supported bp2build for rust_protobuf_host because the non-host toolchain for rust is not checked in yet. aosp/2759750 changed a converted module from rust_protobuf_host to rust_protobuf and broke CI.

This CL adds bp2build support for rust_protobuf but makes the target incompatible with android os for now untilnon-host rust toolchain is checked in.

Bug: 301956497
Test: b build //build/make/tools/aconfig:all --config=android
Change-Id: I739896c79f32674000c2603e394f16860a6fc57d
2023-09-25 17:37:59 -04:00

89 lines
2.7 KiB
Go

// Copyright 2023 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package bp2build
import (
"android/soong/android"
"android/soong/rust"
"testing"
)
func runRustProtobufTestCase(t *testing.T, tc Bp2buildTestCase) {
t.Helper()
RunBp2BuildTestCase(t, registerRustProtobufModuleTypes, tc)
}
func registerRustProtobufModuleTypes(ctx android.RegistrationContext) {
ctx.RegisterModuleType("rust_protobuf_host", rust.RustProtobufHostFactory)
ctx.RegisterModuleType("rust_protobuf", rust.RustProtobufHostFactory)
}
func TestRustProtobufHostTestCase(t *testing.T) {
runRustProtobufTestCase(t, Bp2buildTestCase{
Dir: "external/rust/crates/foo",
Blueprint: "",
Filesystem: map[string]string{
"external/rust/crates/foo/src/lib.rs": "",
"external/rust/crates/foo/src/helper.rs": "",
"external/rust/crates/foo/Android.bp": `
rust_protobuf_host {
name: "libfoo",
crate_name: "foo",
protos: ["src/foo.proto"],
bazel_module: { bp2build_available: true },
}
`,
},
ExpectedBazelTargets: []string{
makeBazelTargetHostOrDevice("proto_library", "libfoo_proto", AttrNameToString{
"srcs": `["src/foo.proto"]`,
}, android.HostSupported),
makeBazelTargetHostOrDevice("rust_proto_library", "libfoo", AttrNameToString{
"crate_name": `"foo"`,
"deps": `[":libfoo_proto"]`,
}, android.HostSupported),
},
},
)
}
func TestRustProtobufTestCase(t *testing.T) {
runRustProtobufTestCase(t, Bp2buildTestCase{
Dir: "external/rust/crates/foo",
Blueprint: "",
Filesystem: map[string]string{
"external/rust/crates/foo/src/lib.rs": "",
"external/rust/crates/foo/src/helper.rs": "",
"external/rust/crates/foo/Android.bp": `
rust_protobuf {
name: "libfoo",
crate_name: "foo",
protos: ["src/foo.proto"],
bazel_module: { bp2build_available: true },
}
`,
},
ExpectedBazelTargets: []string{
makeBazelTargetHostOrDevice("proto_library", "libfoo_proto", AttrNameToString{
"srcs": `["src/foo.proto"]`,
}, android.HostSupported),
makeBazelTargetHostOrDevice("rust_proto_library", "libfoo", AttrNameToString{
"crate_name": `"foo"`,
"deps": `[":libfoo_proto"]`,
}, android.HostSupported),
},
},
)
}