2019-08-27 21:03:00 +02:00
|
|
|
// Copyright 2019 The Android Open Source Project
|
|
|
|
//
|
|
|
|
// 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 rust
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2019-09-03 22:49:39 +02:00
|
|
|
"runtime"
|
2019-09-24 22:23:50 +02:00
|
|
|
"strings"
|
2019-08-27 21:03:00 +02:00
|
|
|
"testing"
|
|
|
|
|
2020-04-09 15:56:02 +02:00
|
|
|
"github.com/google/blueprint/proptools"
|
|
|
|
|
2019-08-27 21:03:00 +02:00
|
|
|
"android/soong/android"
|
2021-03-07 20:18:38 +01:00
|
|
|
"android/soong/genrule"
|
2019-08-27 21:03:00 +02:00
|
|
|
)
|
|
|
|
|
2021-03-07 20:18:38 +01:00
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
os.Exit(m.Run())
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
|
|
|
|
2021-03-07 20:18:38 +01:00
|
|
|
var prepareForRustTest = android.GroupFixturePreparers(
|
|
|
|
android.PrepareForTestWithArchMutator,
|
|
|
|
android.PrepareForTestWithDefaults,
|
|
|
|
android.PrepareForTestWithPrebuilts,
|
2019-08-27 21:03:00 +02:00
|
|
|
|
2021-03-07 20:18:38 +01:00
|
|
|
genrule.PrepareForTestWithGenRuleBuildComponents,
|
2019-08-27 21:03:00 +02:00
|
|
|
|
2021-05-20 19:39:16 +02:00
|
|
|
PrepareForTestWithRustIncludeVndk,
|
|
|
|
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
|
|
|
|
variables.DeviceVndkVersion = StringPtr("current")
|
|
|
|
variables.ProductVndkVersion = StringPtr("current")
|
|
|
|
variables.Platform_vndk_version = StringPtr("29")
|
|
|
|
}),
|
2021-03-07 20:18:38 +01:00
|
|
|
)
|
2019-08-27 21:03:00 +02:00
|
|
|
|
2021-03-07 20:18:38 +01:00
|
|
|
var rustMockedFiles = android.MockFS{
|
2021-05-20 19:39:16 +02:00
|
|
|
"foo.rs": nil,
|
|
|
|
"foo.c": nil,
|
|
|
|
"src/bar.rs": nil,
|
|
|
|
"src/any.h": nil,
|
|
|
|
"c_includes/c_header.h": nil,
|
|
|
|
"rust_includes/rust_headers.h": nil,
|
|
|
|
"proto.proto": nil,
|
|
|
|
"proto/buf.proto": nil,
|
|
|
|
"buf.proto": nil,
|
|
|
|
"foo.proto": nil,
|
|
|
|
"liby.so": nil,
|
|
|
|
"libz.so": nil,
|
|
|
|
"data.txt": nil,
|
2021-06-01 21:09:53 +02:00
|
|
|
"liblog.map.txt": nil,
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
|
|
|
|
2020-10-07 14:30:03 +02:00
|
|
|
// testRust returns a TestContext in which a basic environment has been setup.
|
2021-03-07 20:18:38 +01:00
|
|
|
// This environment contains a few mocked files. See rustMockedFiles for the list of these files.
|
2020-10-07 14:30:03 +02:00
|
|
|
func testRust(t *testing.T, bp string) *android.TestContext {
|
2021-03-07 20:18:38 +01:00
|
|
|
skipTestIfOsNotSupported(t)
|
|
|
|
result := android.GroupFixturePreparers(
|
|
|
|
prepareForRustTest,
|
|
|
|
rustMockedFiles.AddToFixture(),
|
|
|
|
).
|
|
|
|
RunTestWithBp(t, bp)
|
|
|
|
return result.TestContext
|
2020-10-07 14:30:03 +02:00
|
|
|
}
|
|
|
|
|
2021-02-12 15:55:06 +01:00
|
|
|
func testRustVndk(t *testing.T, bp string) *android.TestContext {
|
2021-05-20 19:39:16 +02:00
|
|
|
return testRustVndkFs(t, bp, rustMockedFiles)
|
|
|
|
}
|
|
|
|
|
2021-06-01 21:09:53 +02:00
|
|
|
const (
|
2021-11-09 22:23:40 +01:00
|
|
|
sharedVendorVariant = "android_vendor.29_arm64_armv8-a_shared"
|
|
|
|
rlibVendorVariant = "android_vendor.29_arm64_armv8-a_rlib_rlib-std"
|
|
|
|
sharedRecoveryVariant = "android_recovery_arm64_armv8-a_shared"
|
|
|
|
rlibRecoveryVariant = "android_recovery_arm64_armv8-a_rlib_rlib-std"
|
2023-01-25 01:36:02 +01:00
|
|
|
binaryCoreVariant = "android_arm64_armv8-a"
|
|
|
|
binaryVendorVariant = "android_vendor.29_arm64_armv8-a"
|
|
|
|
binaryProductVariant = "android_product.29_arm64_armv8-a"
|
|
|
|
binaryRecoveryVariant = "android_recovery_arm64_armv8-a"
|
2021-06-01 21:09:53 +02:00
|
|
|
)
|
2021-05-20 19:39:16 +02:00
|
|
|
|
|
|
|
func testRustVndkFs(t *testing.T, bp string, fs android.MockFS) *android.TestContext {
|
2021-06-01 21:09:53 +02:00
|
|
|
return testRustVndkFsVersions(t, bp, fs, "current", "current", "29")
|
|
|
|
}
|
|
|
|
|
|
|
|
func testRustVndkFsVersions(t *testing.T, bp string, fs android.MockFS, device_version, product_version, vndk_version string) *android.TestContext {
|
2021-03-07 20:18:38 +01:00
|
|
|
skipTestIfOsNotSupported(t)
|
|
|
|
result := android.GroupFixturePreparers(
|
|
|
|
prepareForRustTest,
|
2021-05-20 19:39:16 +02:00
|
|
|
fs.AddToFixture(),
|
2021-03-07 20:18:38 +01:00
|
|
|
android.FixtureModifyProductVariables(
|
|
|
|
func(variables android.FixtureProductVariables) {
|
2021-06-01 21:09:53 +02:00
|
|
|
variables.DeviceVndkVersion = StringPtr(device_version)
|
|
|
|
variables.ProductVndkVersion = StringPtr(product_version)
|
|
|
|
variables.Platform_vndk_version = StringPtr(vndk_version)
|
2021-03-07 20:18:38 +01:00
|
|
|
},
|
|
|
|
),
|
|
|
|
).RunTestWithBp(t, bp)
|
|
|
|
return result.TestContext
|
2021-11-09 22:23:40 +01:00
|
|
|
}
|
2021-05-20 19:39:16 +02:00
|
|
|
|
2021-11-09 22:23:40 +01:00
|
|
|
func testRustRecoveryFsVersions(t *testing.T, bp string, fs android.MockFS, device_version, vndk_version, recovery_version string) *android.TestContext {
|
|
|
|
skipTestIfOsNotSupported(t)
|
|
|
|
result := android.GroupFixturePreparers(
|
|
|
|
prepareForRustTest,
|
|
|
|
fs.AddToFixture(),
|
|
|
|
android.FixtureModifyProductVariables(
|
|
|
|
func(variables android.FixtureProductVariables) {
|
|
|
|
variables.DeviceVndkVersion = StringPtr(device_version)
|
|
|
|
variables.RecoverySnapshotVersion = StringPtr(recovery_version)
|
|
|
|
variables.Platform_vndk_version = StringPtr(vndk_version)
|
|
|
|
},
|
|
|
|
),
|
|
|
|
).RunTestWithBp(t, bp)
|
|
|
|
return result.TestContext
|
2021-02-12 15:55:06 +01:00
|
|
|
}
|
|
|
|
|
2020-10-07 14:30:03 +02:00
|
|
|
// testRustCov returns a TestContext in which a basic environment has been
|
|
|
|
// setup. This environment explicitly enables coverage.
|
|
|
|
func testRustCov(t *testing.T, bp string) *android.TestContext {
|
2021-03-07 20:18:38 +01:00
|
|
|
skipTestIfOsNotSupported(t)
|
|
|
|
result := android.GroupFixturePreparers(
|
|
|
|
prepareForRustTest,
|
|
|
|
rustMockedFiles.AddToFixture(),
|
|
|
|
android.FixtureModifyProductVariables(
|
|
|
|
func(variables android.FixtureProductVariables) {
|
|
|
|
variables.ClangCoverage = proptools.BoolPtr(true)
|
|
|
|
variables.Native_coverage = proptools.BoolPtr(true)
|
|
|
|
variables.NativeCoveragePaths = []string{"*"}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
).RunTestWithBp(t, bp)
|
|
|
|
return result.TestContext
|
2020-10-07 14:30:03 +02:00
|
|
|
}
|
2019-12-14 05:41:13 +01:00
|
|
|
|
2020-10-07 14:30:03 +02:00
|
|
|
// testRustError ensures that at least one error was raised and its value
|
|
|
|
// matches the pattern provided. The error can be either in the parsing of the
|
|
|
|
// Blueprint or when generating the build actions.
|
|
|
|
func testRustError(t *testing.T, pattern string, bp string) {
|
2021-03-07 20:18:38 +01:00
|
|
|
skipTestIfOsNotSupported(t)
|
|
|
|
android.GroupFixturePreparers(
|
|
|
|
prepareForRustTest,
|
|
|
|
rustMockedFiles.AddToFixture(),
|
|
|
|
).
|
|
|
|
ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(pattern)).
|
|
|
|
RunTestWithBp(t, bp)
|
2020-10-07 14:30:03 +02:00
|
|
|
}
|
|
|
|
|
2021-04-02 18:41:32 +02:00
|
|
|
// testRustVndkError is similar to testRustError, but can be used to test VNDK-related errors.
|
|
|
|
func testRustVndkError(t *testing.T, pattern string, bp string) {
|
2021-05-20 19:39:16 +02:00
|
|
|
testRustVndkFsError(t, pattern, bp, rustMockedFiles)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testRustVndkFsError(t *testing.T, pattern string, bp string, fs android.MockFS) {
|
2021-04-02 18:41:32 +02:00
|
|
|
skipTestIfOsNotSupported(t)
|
|
|
|
android.GroupFixturePreparers(
|
|
|
|
prepareForRustTest,
|
2021-05-20 19:39:16 +02:00
|
|
|
fs.AddToFixture(),
|
2021-04-02 18:41:32 +02:00
|
|
|
android.FixtureModifyProductVariables(
|
|
|
|
func(variables android.FixtureProductVariables) {
|
|
|
|
variables.DeviceVndkVersion = StringPtr("current")
|
|
|
|
variables.ProductVndkVersion = StringPtr("current")
|
|
|
|
variables.Platform_vndk_version = StringPtr("VER")
|
|
|
|
},
|
|
|
|
),
|
|
|
|
).
|
|
|
|
ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(pattern)).
|
|
|
|
RunTestWithBp(t, bp)
|
|
|
|
}
|
|
|
|
|
2020-10-07 14:30:03 +02:00
|
|
|
// testRustCtx is used to build a particular test environment. Unless your
|
|
|
|
// tests requires a specific setup, prefer the wrapping functions: testRust,
|
|
|
|
// testRustCov or testRustError.
|
|
|
|
type testRustCtx struct {
|
|
|
|
bp string
|
|
|
|
fs map[string][]byte
|
|
|
|
env map[string]string
|
|
|
|
config *android.Config
|
|
|
|
}
|
|
|
|
|
2021-03-07 20:18:38 +01:00
|
|
|
func skipTestIfOsNotSupported(t *testing.T) {
|
2020-10-07 14:30:03 +02:00
|
|
|
// TODO (b/140435149)
|
|
|
|
if runtime.GOOS != "linux" {
|
|
|
|
t.Skip("Rust Soong tests can only be run on Linux hosts currently")
|
|
|
|
}
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that we can extract the link path from a lib path.
|
|
|
|
func TestLinkPathFromFilePath(t *testing.T) {
|
|
|
|
barPath := android.PathForTesting("out/soong/.intermediates/external/libbar/libbar/linux_glibc_x86_64_shared/libbar.so")
|
|
|
|
libName := linkPathFromFilePath(barPath)
|
|
|
|
expectedResult := "out/soong/.intermediates/external/libbar/libbar/linux_glibc_x86_64_shared/"
|
|
|
|
|
|
|
|
if libName != expectedResult {
|
|
|
|
t.Errorf("libNameFromFilePath returned the wrong name; expected '%#v', got '%#v'", expectedResult, libName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test to make sure dependencies are being picked up correctly.
|
|
|
|
func TestDepsTracking(t *testing.T) {
|
|
|
|
ctx := testRust(t, `
|
2023-03-28 22:54:00 +02:00
|
|
|
cc_library {
|
|
|
|
host_supported: true,
|
|
|
|
name: "cc_stubs_dep",
|
|
|
|
}
|
2020-06-23 23:28:53 +02:00
|
|
|
rust_ffi_host_static {
|
2019-10-18 23:49:46 +02:00
|
|
|
name: "libstatic",
|
|
|
|
srcs: ["foo.rs"],
|
2019-11-01 03:38:29 +01:00
|
|
|
crate_name: "static",
|
2019-10-18 23:49:46 +02:00
|
|
|
}
|
2021-03-23 20:53:44 +01:00
|
|
|
rust_ffi_host_static {
|
|
|
|
name: "libwholestatic",
|
|
|
|
srcs: ["foo.rs"],
|
|
|
|
crate_name: "wholestatic",
|
|
|
|
}
|
2020-06-23 23:28:53 +02:00
|
|
|
rust_ffi_host_shared {
|
2019-10-18 23:49:46 +02:00
|
|
|
name: "libshared",
|
|
|
|
srcs: ["foo.rs"],
|
2019-11-01 03:38:29 +01:00
|
|
|
crate_name: "shared",
|
2019-10-18 23:49:46 +02:00
|
|
|
}
|
2019-08-27 21:03:00 +02:00
|
|
|
rust_library_host_dylib {
|
2019-10-18 23:49:46 +02:00
|
|
|
name: "libdylib",
|
2019-08-27 21:03:00 +02:00
|
|
|
srcs: ["foo.rs"],
|
2019-11-01 03:38:29 +01:00
|
|
|
crate_name: "dylib",
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
|
|
|
rust_library_host_rlib {
|
2019-10-18 23:49:46 +02:00
|
|
|
name: "librlib",
|
2020-07-10 03:03:28 +02:00
|
|
|
srcs: ["foo.rs"],
|
2019-11-01 03:38:29 +01:00
|
|
|
crate_name: "rlib",
|
2021-02-05 18:27:08 +01:00
|
|
|
static_libs: ["libstatic"],
|
2021-03-23 20:53:44 +01:00
|
|
|
whole_static_libs: ["libwholestatic"],
|
2023-03-28 22:54:00 +02:00
|
|
|
shared_libs: ["cc_stubs_dep"],
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
|
|
|
rust_proc_macro {
|
|
|
|
name: "libpm",
|
|
|
|
srcs: ["foo.rs"],
|
2019-11-01 03:38:29 +01:00
|
|
|
crate_name: "pm",
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
|
|
|
rust_binary_host {
|
2020-07-10 03:03:28 +02:00
|
|
|
name: "fizz-buzz",
|
2019-10-18 23:49:46 +02:00
|
|
|
dylibs: ["libdylib"],
|
|
|
|
rlibs: ["librlib"],
|
2019-08-27 21:03:00 +02:00
|
|
|
proc_macros: ["libpm"],
|
2019-10-18 23:49:46 +02:00
|
|
|
static_libs: ["libstatic"],
|
|
|
|
shared_libs: ["libshared"],
|
2020-07-10 03:03:28 +02:00
|
|
|
srcs: ["foo.rs"],
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
|
|
|
`)
|
2020-07-10 03:03:28 +02:00
|
|
|
module := ctx.ModuleForTests("fizz-buzz", "linux_glibc_x86_64").Module().(*Module)
|
2021-02-05 18:27:08 +01:00
|
|
|
rustc := ctx.ModuleForTests("librlib", "linux_glibc_x86_64_rlib_rlib-std").Rule("rustc")
|
2019-08-27 21:03:00 +02:00
|
|
|
|
|
|
|
// Since dependencies are added to AndroidMk* properties, we can check these to see if they've been picked up.
|
2019-10-18 23:49:46 +02:00
|
|
|
if !android.InList("libdylib", module.Properties.AndroidMkDylibs) {
|
2019-08-27 21:03:00 +02:00
|
|
|
t.Errorf("Dylib dependency not detected (dependency missing from AndroidMkDylibs)")
|
|
|
|
}
|
|
|
|
|
2020-09-08 18:46:52 +02:00
|
|
|
if !android.InList("librlib.rlib-std", module.Properties.AndroidMkRlibs) {
|
2019-08-27 21:03:00 +02:00
|
|
|
t.Errorf("Rlib dependency not detected (dependency missing from AndroidMkRlibs)")
|
|
|
|
}
|
|
|
|
|
|
|
|
if !android.InList("libpm", module.Properties.AndroidMkProcMacroLibs) {
|
|
|
|
t.Errorf("Proc_macro dependency not detected (dependency missing from AndroidMkProcMacroLibs)")
|
|
|
|
}
|
|
|
|
|
2019-10-18 23:49:46 +02:00
|
|
|
if !android.InList("libshared", module.Properties.AndroidMkSharedLibs) {
|
|
|
|
t.Errorf("Shared library dependency not detected (dependency missing from AndroidMkSharedLibs)")
|
|
|
|
}
|
|
|
|
|
|
|
|
if !android.InList("libstatic", module.Properties.AndroidMkStaticLibs) {
|
|
|
|
t.Errorf("Static library dependency not detected (dependency missing from AndroidMkStaticLibs)")
|
|
|
|
}
|
2021-02-04 17:29:41 +01:00
|
|
|
|
2021-03-23 20:53:44 +01:00
|
|
|
if !strings.Contains(rustc.Args["rustcFlags"], "-lstatic=wholestatic") {
|
|
|
|
t.Errorf("-lstatic flag not being passed to rustc for static library %#v", rustc.Args["rustcFlags"])
|
2021-02-04 17:29:41 +01:00
|
|
|
}
|
|
|
|
|
2023-03-28 22:54:00 +02:00
|
|
|
if !strings.Contains(rustc.Args["linkFlags"], "cc_stubs_dep.so") {
|
|
|
|
t.Errorf("shared cc_library not being passed to rustc linkFlags %#v", rustc.Args["linkFlags"])
|
|
|
|
}
|
|
|
|
|
|
|
|
if !android.SuffixInList(rustc.OrderOnly.Strings(), "cc_stubs_dep.so") {
|
|
|
|
t.Errorf("shared cc dep not being passed as order-only to rustc %#v", rustc.OrderOnly.Strings())
|
|
|
|
}
|
|
|
|
|
|
|
|
if !android.SuffixInList(rustc.Implicits.Strings(), "cc_stubs_dep.so.toc") {
|
|
|
|
t.Errorf("shared cc dep TOC not being passed as implicit to rustc %#v", rustc.Implicits.Strings())
|
|
|
|
}
|
2019-08-27 21:03:00 +02:00
|
|
|
}
|
2019-09-24 22:23:50 +02:00
|
|
|
|
2020-07-10 03:03:28 +02:00
|
|
|
func TestSourceProviderDeps(t *testing.T) {
|
|
|
|
ctx := testRust(t, `
|
|
|
|
rust_binary {
|
|
|
|
name: "fizz-buzz-dep",
|
|
|
|
srcs: [
|
|
|
|
"foo.rs",
|
|
|
|
":my_generator",
|
|
|
|
":libbindings",
|
|
|
|
],
|
2020-07-31 19:40:31 +02:00
|
|
|
rlibs: ["libbindings"],
|
2020-07-10 03:03:28 +02:00
|
|
|
}
|
|
|
|
rust_proc_macro {
|
|
|
|
name: "libprocmacro",
|
|
|
|
srcs: [
|
|
|
|
"foo.rs",
|
|
|
|
":my_generator",
|
|
|
|
":libbindings",
|
|
|
|
],
|
2020-07-31 19:40:31 +02:00
|
|
|
rlibs: ["libbindings"],
|
2020-07-10 03:03:28 +02:00
|
|
|
crate_name: "procmacro",
|
|
|
|
}
|
|
|
|
rust_library {
|
|
|
|
name: "libfoo",
|
|
|
|
srcs: [
|
|
|
|
"foo.rs",
|
|
|
|
":my_generator",
|
2020-07-31 19:40:31 +02:00
|
|
|
":libbindings",
|
|
|
|
],
|
|
|
|
rlibs: ["libbindings"],
|
2020-07-10 03:03:28 +02:00
|
|
|
crate_name: "foo",
|
|
|
|
}
|
|
|
|
genrule {
|
|
|
|
name: "my_generator",
|
|
|
|
tools: ["any_rust_binary"],
|
|
|
|
cmd: "$(location) -o $(out) $(in)",
|
|
|
|
srcs: ["src/any.h"],
|
|
|
|
out: ["src/any.rs"],
|
|
|
|
}
|
2020-11-11 03:12:15 +01:00
|
|
|
rust_binary_host {
|
|
|
|
name: "any_rust_binary",
|
|
|
|
srcs: [
|
|
|
|
"foo.rs",
|
|
|
|
],
|
|
|
|
}
|
2020-07-10 03:03:28 +02:00
|
|
|
rust_bindgen {
|
|
|
|
name: "libbindings",
|
2020-07-31 19:40:31 +02:00
|
|
|
crate_name: "bindings",
|
|
|
|
source_stem: "bindings",
|
2020-07-10 03:03:28 +02:00
|
|
|
host_supported: true,
|
|
|
|
wrapper_src: "src/any.h",
|
2023-03-28 22:54:00 +02:00
|
|
|
}
|
2020-07-10 03:03:28 +02:00
|
|
|
`)
|
|
|
|
|
2020-09-08 18:46:52 +02:00
|
|
|
libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_rlib_dylib-std").Rule("rustc")
|
2020-07-10 03:03:28 +02:00
|
|
|
if !android.SuffixInList(libfoo.Implicits.Strings(), "/out/bindings.rs") {
|
|
|
|
t.Errorf("rust_bindgen generated source not included as implicit input for libfoo; Implicits %#v", libfoo.Implicits.Strings())
|
|
|
|
}
|
|
|
|
if !android.SuffixInList(libfoo.Implicits.Strings(), "/out/any.rs") {
|
|
|
|
t.Errorf("genrule generated source not included as implicit input for libfoo; Implicits %#v", libfoo.Implicits.Strings())
|
|
|
|
}
|
|
|
|
|
|
|
|
fizzBuzz := ctx.ModuleForTests("fizz-buzz-dep", "android_arm64_armv8-a").Rule("rustc")
|
|
|
|
if !android.SuffixInList(fizzBuzz.Implicits.Strings(), "/out/bindings.rs") {
|
|
|
|
t.Errorf("rust_bindgen generated source not included as implicit input for fizz-buzz-dep; Implicits %#v", libfoo.Implicits.Strings())
|
|
|
|
}
|
|
|
|
if !android.SuffixInList(fizzBuzz.Implicits.Strings(), "/out/any.rs") {
|
|
|
|
t.Errorf("genrule generated source not included as implicit input for fizz-buzz-dep; Implicits %#v", libfoo.Implicits.Strings())
|
|
|
|
}
|
|
|
|
|
|
|
|
libprocmacro := ctx.ModuleForTests("libprocmacro", "linux_glibc_x86_64").Rule("rustc")
|
|
|
|
if !android.SuffixInList(libprocmacro.Implicits.Strings(), "/out/bindings.rs") {
|
|
|
|
t.Errorf("rust_bindgen generated source not included as implicit input for libprocmacro; Implicits %#v", libfoo.Implicits.Strings())
|
|
|
|
}
|
|
|
|
if !android.SuffixInList(libprocmacro.Implicits.Strings(), "/out/any.rs") {
|
|
|
|
t.Errorf("genrule generated source not included as implicit input for libprocmacro; Implicits %#v", libfoo.Implicits.Strings())
|
|
|
|
}
|
2020-07-31 19:40:31 +02:00
|
|
|
|
|
|
|
// Check that our bindings are picked up as crate dependencies as well
|
|
|
|
libfooMod := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_dylib").Module().(*Module)
|
2020-09-08 18:46:52 +02:00
|
|
|
if !android.InList("libbindings.dylib-std", libfooMod.Properties.AndroidMkRlibs) {
|
2020-07-31 19:40:31 +02:00
|
|
|
t.Errorf("bindgen dependency not detected as a rlib dependency (dependency missing from AndroidMkRlibs)")
|
|
|
|
}
|
|
|
|
fizzBuzzMod := ctx.ModuleForTests("fizz-buzz-dep", "android_arm64_armv8-a").Module().(*Module)
|
2020-09-08 18:46:52 +02:00
|
|
|
if !android.InList("libbindings.dylib-std", fizzBuzzMod.Properties.AndroidMkRlibs) {
|
2020-07-31 19:40:31 +02:00
|
|
|
t.Errorf("bindgen dependency not detected as a rlib dependency (dependency missing from AndroidMkRlibs)")
|
|
|
|
}
|
|
|
|
libprocmacroMod := ctx.ModuleForTests("libprocmacro", "linux_glibc_x86_64").Module().(*Module)
|
2020-09-08 18:46:52 +02:00
|
|
|
if !android.InList("libbindings.rlib-std", libprocmacroMod.Properties.AndroidMkRlibs) {
|
2020-07-31 19:40:31 +02:00
|
|
|
t.Errorf("bindgen dependency not detected as a rlib dependency (dependency missing from AndroidMkRlibs)")
|
|
|
|
}
|
2020-07-10 03:03:28 +02:00
|
|
|
}
|
|
|
|
|
2020-07-22 22:09:13 +02:00
|
|
|
func TestSourceProviderTargetMismatch(t *testing.T) {
|
|
|
|
// This might error while building the dependency tree or when calling depsToPaths() depending on the lunched
|
|
|
|
// target, which results in two different errors. So don't check the error, just confirm there is one.
|
|
|
|
testRustError(t, ".*", `
|
|
|
|
rust_proc_macro {
|
|
|
|
name: "libprocmacro",
|
|
|
|
srcs: [
|
|
|
|
"foo.rs",
|
|
|
|
":libbindings",
|
|
|
|
],
|
|
|
|
crate_name: "procmacro",
|
|
|
|
}
|
|
|
|
rust_bindgen {
|
|
|
|
name: "libbindings",
|
2020-07-31 19:40:31 +02:00
|
|
|
crate_name: "bindings",
|
|
|
|
source_stem: "bindings",
|
2020-07-22 22:09:13 +02:00
|
|
|
wrapper_src: "src/any.h",
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
2019-09-24 22:23:50 +02:00
|
|
|
// Test to make sure proc_macros use host variants when building device modules.
|
|
|
|
func TestProcMacroDeviceDeps(t *testing.T) {
|
|
|
|
ctx := testRust(t, `
|
|
|
|
rust_library_host_rlib {
|
|
|
|
name: "libbar",
|
|
|
|
srcs: ["foo.rs"],
|
2019-11-01 03:38:29 +01:00
|
|
|
crate_name: "bar",
|
2019-09-24 22:23:50 +02:00
|
|
|
}
|
|
|
|
rust_proc_macro {
|
|
|
|
name: "libpm",
|
|
|
|
rlibs: ["libbar"],
|
|
|
|
srcs: ["foo.rs"],
|
2019-11-01 03:38:29 +01:00
|
|
|
crate_name: "pm",
|
2019-09-24 22:23:50 +02:00
|
|
|
}
|
|
|
|
rust_binary {
|
|
|
|
name: "fizz-buzz",
|
|
|
|
proc_macros: ["libpm"],
|
|
|
|
srcs: ["foo.rs"],
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
rustc := ctx.ModuleForTests("libpm", "linux_glibc_x86_64").Rule("rustc")
|
|
|
|
|
|
|
|
if !strings.Contains(rustc.Args["libFlags"], "libbar/linux_glibc_x86_64") {
|
|
|
|
t.Errorf("Proc_macro is not using host variant of dependent modules.")
|
|
|
|
}
|
|
|
|
}
|
2019-10-31 18:44:40 +01:00
|
|
|
|
|
|
|
// Test that no_stdlibs suppresses dependencies on rust standard libraries
|
|
|
|
func TestNoStdlibs(t *testing.T) {
|
|
|
|
ctx := testRust(t, `
|
|
|
|
rust_binary {
|
|
|
|
name: "fizz-buzz",
|
|
|
|
srcs: ["foo.rs"],
|
2020-04-28 16:10:23 +02:00
|
|
|
no_stdlibs: true,
|
2019-10-31 18:44:40 +01:00
|
|
|
}`)
|
2019-11-21 01:39:12 +01:00
|
|
|
module := ctx.ModuleForTests("fizz-buzz", "android_arm64_armv8-a").Module().(*Module)
|
2019-10-31 18:44:40 +01:00
|
|
|
|
|
|
|
if android.InList("libstd", module.Properties.AndroidMkDylibs) {
|
|
|
|
t.Errorf("no_stdlibs did not suppress dependency on libstd")
|
|
|
|
}
|
|
|
|
}
|
2020-04-28 16:10:23 +02:00
|
|
|
|
|
|
|
// Test that libraries provide both 32-bit and 64-bit variants.
|
|
|
|
func TestMultilib(t *testing.T) {
|
|
|
|
ctx := testRust(t, `
|
|
|
|
rust_library_rlib {
|
|
|
|
name: "libfoo",
|
|
|
|
srcs: ["foo.rs"],
|
|
|
|
crate_name: "foo",
|
|
|
|
}`)
|
|
|
|
|
2020-09-08 18:46:52 +02:00
|
|
|
_ = ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_rlib_dylib-std")
|
|
|
|
_ = ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_rlib_dylib-std")
|
2020-04-28 16:10:23 +02:00
|
|
|
}
|
2021-04-14 11:18:47 +02:00
|
|
|
|
|
|
|
// Test that library size measurements are generated.
|
|
|
|
func TestLibrarySizes(t *testing.T) {
|
|
|
|
ctx := testRust(t, `
|
|
|
|
rust_library_dylib {
|
|
|
|
name: "libwaldo",
|
|
|
|
srcs: ["foo.rs"],
|
|
|
|
crate_name: "waldo",
|
|
|
|
}`)
|
|
|
|
|
|
|
|
m := ctx.SingletonForTests("file_metrics")
|
2021-11-05 21:36:47 +01:00
|
|
|
m.Output("unstripped/libwaldo.dylib.so.bloaty.csv")
|
2021-04-14 11:18:47 +02:00
|
|
|
m.Output("libwaldo.dylib.so.bloaty.csv")
|
|
|
|
}
|
2021-11-01 15:27:54 +01:00
|
|
|
|
|
|
|
func assertString(t *testing.T, got, expected string) {
|
|
|
|
t.Helper()
|
|
|
|
if got != expected {
|
|
|
|
t.Errorf("expected %q got %q", expected, got)
|
|
|
|
}
|
|
|
|
}
|