Merge "rust: Emit android vndk cfg flag."
This commit is contained in:
commit
36eb24b3ab
3 changed files with 43 additions and 3 deletions
|
@ -232,6 +232,10 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flag
|
|||
flags.LinkFlags = append(flags.LinkFlags, "-Wl,-rpath,"+rpathPrefix+"../"+rpath)
|
||||
}
|
||||
|
||||
if ctx.RustModule().UseVndk() {
|
||||
flags.RustFlags = append(flags.RustFlags, "--cfg 'android_vndk'")
|
||||
}
|
||||
|
||||
return flags
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
package rust
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
|
@ -23,7 +24,7 @@ import (
|
|||
|
||||
// Test that cc modules can link against vendor_available rust_ffi_static libraries.
|
||||
func TestVendorLinkage(t *testing.T) {
|
||||
ctx := testRust(t, `
|
||||
ctx := testRustVndk(t, `
|
||||
cc_binary {
|
||||
name: "fizz_vendor",
|
||||
static_libs: ["libfoo_vendor"],
|
||||
|
@ -37,16 +38,34 @@ func TestVendorLinkage(t *testing.T) {
|
|||
}
|
||||
`)
|
||||
|
||||
vendorBinary := ctx.ModuleForTests("fizz_vendor", "android_arm64_armv8-a").Module().(*cc.Module)
|
||||
vendorBinary := ctx.ModuleForTests("fizz_vendor", "android_vendor.VER_arm64_armv8-a").Module().(*cc.Module)
|
||||
|
||||
if !android.InList("libfoo_vendor", vendorBinary.Properties.AndroidMkStaticLibs) {
|
||||
t.Errorf("vendorBinary should have a dependency on libfoo_vendor")
|
||||
}
|
||||
}
|
||||
|
||||
// Test that variants which use the vndk emit the appropriate cfg flag.
|
||||
func TestImageVndkCfgFlag(t *testing.T) {
|
||||
ctx := testRustVndk(t, `
|
||||
rust_ffi_static {
|
||||
name: "libfoo",
|
||||
crate_name: "foo",
|
||||
srcs: ["foo.rs"],
|
||||
vendor_available: true,
|
||||
}
|
||||
`)
|
||||
|
||||
vendor := ctx.ModuleForTests("libfoo", "android_vendor.VER_arm64_armv8-a_static").Rule("rustc")
|
||||
|
||||
if !strings.Contains(vendor.Args["rustcFlags"], "--cfg 'android_vndk'") {
|
||||
t.Errorf("missing \"--cfg 'android_vndk'\" for libfoo vendor variant, rustcFlags: %#v", vendor.Args["rustcFlags"])
|
||||
}
|
||||
}
|
||||
|
||||
// Test that cc modules can link against vendor_ramdisk_available rust_ffi_static libraries.
|
||||
func TestVendorRamdiskLinkage(t *testing.T) {
|
||||
ctx := testRust(t, `
|
||||
ctx := testRustVndk(t, `
|
||||
cc_library_static {
|
||||
name: "libcc_vendor_ramdisk",
|
||||
static_libs: ["libfoo_vendor_ramdisk"],
|
||||
|
|
|
@ -64,6 +64,14 @@ func testRust(t *testing.T, bp string) *android.TestContext {
|
|||
return tctx.parse(t)
|
||||
}
|
||||
|
||||
func testRustVndk(t *testing.T, bp string) *android.TestContext {
|
||||
tctx := newTestRustCtx(t, bp)
|
||||
tctx.useMockedFs()
|
||||
tctx.generateConfig()
|
||||
tctx.setVndk(t)
|
||||
return tctx.parse(t)
|
||||
}
|
||||
|
||||
// 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 {
|
||||
|
@ -140,6 +148,15 @@ func (tctx *testRustCtx) enableCoverage(t *testing.T) {
|
|||
tctx.config.TestProductVariables.NativeCoveragePaths = []string{"*"}
|
||||
}
|
||||
|
||||
func (tctx *testRustCtx) setVndk(t *testing.T) {
|
||||
if tctx.config == nil {
|
||||
t.Fatalf("tctx.config not been generated yet. Please call generateConfig first.")
|
||||
}
|
||||
tctx.config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
|
||||
tctx.config.TestProductVariables.ProductVndkVersion = StringPtr("current")
|
||||
tctx.config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
|
||||
}
|
||||
|
||||
// parse validates the configuration and parses the Blueprint file. It returns
|
||||
// a TestContext which can be used to retrieve the generated modules via
|
||||
// ModuleForTests.
|
||||
|
|
Loading…
Reference in a new issue