Loading rust/image.go +13 −14 Original line number Diff line number Diff line Loading @@ -129,6 +129,10 @@ func (ctx *moduleContext) DeviceSpecific() bool { return ctx.ModuleContext.DeviceSpecific() || (ctx.RustModule().InVendor() && ctx.RustModule().VendorVariantToOdm()) } func (ctx *moduleContext) SystemExtSpecific() bool { return ctx.ModuleContext.SystemExtSpecific() } // Returns true when this module creates a vendor variant and wants to install the vendor variant // to the odm partition. func (c *Module) VendorVariantToOdm() bool { Loading Loading @@ -158,22 +162,15 @@ func (mod *Module) InVendorRamdisk() bool { } func (mod *Module) OnlyInRamdisk() bool { // TODO(b/165791368) return false return mod.ModuleBase.InstallInRamdisk() } func (mod *Module) OnlyInRecovery() bool { // TODO(b/165791368) return false return mod.ModuleBase.InstallInRecovery() } func (mod *Module) OnlyInVendorRamdisk() bool { return false } func (mod *Module) OnlyInProduct() bool { //TODO(b/165791368) return false return mod.ModuleBase.InstallInVendorRamdisk() } // Returns true when this module is configured to have core and vendor variants. Loading Loading @@ -226,10 +223,7 @@ func (mod *Module) ImageMutatorBegin(mctx android.BaseModuleContext) { // Rust does not support installing to the product image yet. vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific() if mctx.ProductSpecific() { mctx.PropertyErrorf("product_specific", "Rust modules do not yet support installing to the product image.") } else if Bool(mod.VendorProperties.Double_loadable) { if Bool(mod.VendorProperties.Double_loadable) { mctx.PropertyErrorf("double_loadable", "Rust modules do not yet support double loading") } Loading @@ -243,6 +237,11 @@ func (mod *Module) ImageMutatorBegin(mctx android.BaseModuleContext) { mctx.PropertyErrorf("vendor", "Vendor-only dylibs are not yet supported, use rust_library_rlib.") } } if mctx.ProductSpecific() { if lib, ok := mod.compiler.(libraryInterface); ok && lib.buildDylib() { mctx.PropertyErrorf("product", "Product-only dylibs are not yet supported, use rust_library_rlib.") } } cc.MutateImage(mctx, mod) Loading rust/image_test.go +90 −0 Original line number Diff line number Diff line Loading @@ -103,3 +103,93 @@ func TestForbiddenVendorLinkage(t *testing.T) { } `) } func checkInstallPartition(t *testing.T, ctx *android.TestContext, name, variant, expected string) { mod := ctx.ModuleForTests(name, variant).Module().(*Module) partitionDefined := false checkPartition := func(specific bool, partition string) { if specific { if expected != partition && !partitionDefined { // The variant is installed to the 'partition' t.Errorf("%s variant of %q must not be installed to %s partition", variant, name, partition) } partitionDefined = true } else { // The variant is not installed to the 'partition' if expected == partition { t.Errorf("%s variant of %q must be installed to %s partition", variant, name, partition) } } } socSpecific := func(m *Module) bool { return m.SocSpecific() } deviceSpecific := func(m *Module) bool { return m.DeviceSpecific() } productSpecific := func(m *Module) bool { return m.ProductSpecific() || m.productSpecificModuleContext() } systemExtSpecific := func(m *Module) bool { return m.SystemExtSpecific() } checkPartition(socSpecific(mod), "vendor") checkPartition(deviceSpecific(mod), "odm") checkPartition(productSpecific(mod), "product") checkPartition(systemExtSpecific(mod), "system_ext") if !partitionDefined && expected != "system" { t.Errorf("%s variant of %q is expected to be installed to %s partition,"+ " but installed to system partition", variant, name, expected) } } func TestInstallPartition(t *testing.T) { t.Parallel() t.Helper() ctx := testRust(t, ` rust_binary { name: "sample_system", crate_name: "sample", srcs: ["foo.rs"], } rust_binary { name: "sample_system_ext", crate_name: "sample", srcs: ["foo.rs"], system_ext_specific: true, } rust_binary { name: "sample_product", crate_name: "sample", srcs: ["foo.rs"], product_specific: true, } rust_binary { name: "sample_vendor", crate_name: "sample", srcs: ["foo.rs"], vendor: true, } rust_binary { name: "sample_odm", crate_name: "sample", srcs: ["foo.rs"], device_specific: true, } rust_binary { name: "sample_all_available", crate_name: "sample", srcs: ["foo.rs"], vendor_available: true, product_available: true, } `) checkInstallPartition(t, ctx, "sample_system", binaryCoreVariant, "system") checkInstallPartition(t, ctx, "sample_system_ext", binaryCoreVariant, "system_ext") checkInstallPartition(t, ctx, "sample_product", binaryProductVariant, "product") checkInstallPartition(t, ctx, "sample_vendor", binaryVendorVariant, "vendor") checkInstallPartition(t, ctx, "sample_odm", binaryVendorVariant, "odm") checkInstallPartition(t, ctx, "sample_all_available", binaryCoreVariant, "system") } rust/rust_test.go +4 −0 Original line number Diff line number Diff line Loading @@ -83,6 +83,10 @@ const ( 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" 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" ) func testRustVndkFs(t *testing.T, bp string, fs android.MockFS) *android.TestContext { Loading rust/testing.go +1 −0 Original line number Diff line number Diff line Loading @@ -104,6 +104,7 @@ func GatherRequiredDepsForTest() string { crate_name: "std", srcs: ["foo.rs"], no_stdlibs: true, product_available: true, host_supported: true, vendor_available: true, vendor_ramdisk_available: true, Loading Loading
rust/image.go +13 −14 Original line number Diff line number Diff line Loading @@ -129,6 +129,10 @@ func (ctx *moduleContext) DeviceSpecific() bool { return ctx.ModuleContext.DeviceSpecific() || (ctx.RustModule().InVendor() && ctx.RustModule().VendorVariantToOdm()) } func (ctx *moduleContext) SystemExtSpecific() bool { return ctx.ModuleContext.SystemExtSpecific() } // Returns true when this module creates a vendor variant and wants to install the vendor variant // to the odm partition. func (c *Module) VendorVariantToOdm() bool { Loading Loading @@ -158,22 +162,15 @@ func (mod *Module) InVendorRamdisk() bool { } func (mod *Module) OnlyInRamdisk() bool { // TODO(b/165791368) return false return mod.ModuleBase.InstallInRamdisk() } func (mod *Module) OnlyInRecovery() bool { // TODO(b/165791368) return false return mod.ModuleBase.InstallInRecovery() } func (mod *Module) OnlyInVendorRamdisk() bool { return false } func (mod *Module) OnlyInProduct() bool { //TODO(b/165791368) return false return mod.ModuleBase.InstallInVendorRamdisk() } // Returns true when this module is configured to have core and vendor variants. Loading Loading @@ -226,10 +223,7 @@ func (mod *Module) ImageMutatorBegin(mctx android.BaseModuleContext) { // Rust does not support installing to the product image yet. vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific() if mctx.ProductSpecific() { mctx.PropertyErrorf("product_specific", "Rust modules do not yet support installing to the product image.") } else if Bool(mod.VendorProperties.Double_loadable) { if Bool(mod.VendorProperties.Double_loadable) { mctx.PropertyErrorf("double_loadable", "Rust modules do not yet support double loading") } Loading @@ -243,6 +237,11 @@ func (mod *Module) ImageMutatorBegin(mctx android.BaseModuleContext) { mctx.PropertyErrorf("vendor", "Vendor-only dylibs are not yet supported, use rust_library_rlib.") } } if mctx.ProductSpecific() { if lib, ok := mod.compiler.(libraryInterface); ok && lib.buildDylib() { mctx.PropertyErrorf("product", "Product-only dylibs are not yet supported, use rust_library_rlib.") } } cc.MutateImage(mctx, mod) Loading
rust/image_test.go +90 −0 Original line number Diff line number Diff line Loading @@ -103,3 +103,93 @@ func TestForbiddenVendorLinkage(t *testing.T) { } `) } func checkInstallPartition(t *testing.T, ctx *android.TestContext, name, variant, expected string) { mod := ctx.ModuleForTests(name, variant).Module().(*Module) partitionDefined := false checkPartition := func(specific bool, partition string) { if specific { if expected != partition && !partitionDefined { // The variant is installed to the 'partition' t.Errorf("%s variant of %q must not be installed to %s partition", variant, name, partition) } partitionDefined = true } else { // The variant is not installed to the 'partition' if expected == partition { t.Errorf("%s variant of %q must be installed to %s partition", variant, name, partition) } } } socSpecific := func(m *Module) bool { return m.SocSpecific() } deviceSpecific := func(m *Module) bool { return m.DeviceSpecific() } productSpecific := func(m *Module) bool { return m.ProductSpecific() || m.productSpecificModuleContext() } systemExtSpecific := func(m *Module) bool { return m.SystemExtSpecific() } checkPartition(socSpecific(mod), "vendor") checkPartition(deviceSpecific(mod), "odm") checkPartition(productSpecific(mod), "product") checkPartition(systemExtSpecific(mod), "system_ext") if !partitionDefined && expected != "system" { t.Errorf("%s variant of %q is expected to be installed to %s partition,"+ " but installed to system partition", variant, name, expected) } } func TestInstallPartition(t *testing.T) { t.Parallel() t.Helper() ctx := testRust(t, ` rust_binary { name: "sample_system", crate_name: "sample", srcs: ["foo.rs"], } rust_binary { name: "sample_system_ext", crate_name: "sample", srcs: ["foo.rs"], system_ext_specific: true, } rust_binary { name: "sample_product", crate_name: "sample", srcs: ["foo.rs"], product_specific: true, } rust_binary { name: "sample_vendor", crate_name: "sample", srcs: ["foo.rs"], vendor: true, } rust_binary { name: "sample_odm", crate_name: "sample", srcs: ["foo.rs"], device_specific: true, } rust_binary { name: "sample_all_available", crate_name: "sample", srcs: ["foo.rs"], vendor_available: true, product_available: true, } `) checkInstallPartition(t, ctx, "sample_system", binaryCoreVariant, "system") checkInstallPartition(t, ctx, "sample_system_ext", binaryCoreVariant, "system_ext") checkInstallPartition(t, ctx, "sample_product", binaryProductVariant, "product") checkInstallPartition(t, ctx, "sample_vendor", binaryVendorVariant, "vendor") checkInstallPartition(t, ctx, "sample_odm", binaryVendorVariant, "odm") checkInstallPartition(t, ctx, "sample_all_available", binaryCoreVariant, "system") }
rust/rust_test.go +4 −0 Original line number Diff line number Diff line Loading @@ -83,6 +83,10 @@ const ( 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" 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" ) func testRustVndkFs(t *testing.T, bp string, fs android.MockFS) *android.TestContext { Loading
rust/testing.go +1 −0 Original line number Diff line number Diff line Loading @@ -104,6 +104,7 @@ func GatherRequiredDepsForTest() string { crate_name: "std", srcs: ["foo.rs"], no_stdlibs: true, product_available: true, host_supported: true, vendor_available: true, vendor_ramdisk_available: true, Loading