summaryrefslogtreecommitdiff
path: root/rust
diff options
context:
space:
mode:
Diffstat (limited to 'rust')
-rw-r--r--rust/Android.bp4
-rw-r--r--rust/androidmk.go6
-rw-r--r--rust/bindgen.go2
-rw-r--r--rust/bindgen_test.go32
-rw-r--r--rust/builder.go4
-rw-r--r--rust/config/arm64_device.go2
-rw-r--r--rust/config/arm_device.go2
-rw-r--r--rust/config/global.go19
-rw-r--r--rust/config/x86_64_device.go2
-rw-r--r--rust/config/x86_device.go2
-rw-r--r--rust/image.go8
-rw-r--r--rust/image_test.go16
-rw-r--r--rust/library.go54
-rw-r--r--rust/rust.go61
-rw-r--r--rust/rust_test.go78
-rw-r--r--rust/sanitize.go6
-rw-r--r--rust/snapshot_prebuilt.go208
-rw-r--r--rust/snapshot_utils.go81
-rw-r--r--rust/testing.go7
-rw-r--r--rust/vendor_snapshot_test.go1573
20 files changed, 81 insertions, 2086 deletions
diff --git a/rust/Android.bp b/rust/Android.bp
index 637042d45..53c94621e 100644
--- a/rust/Android.bp
+++ b/rust/Android.bp
@@ -12,7 +12,6 @@ bootstrap_go_package {
"soong-bloaty",
"soong-cc",
"soong-rust-config",
- "soong-snapshot",
"soong-testing",
],
srcs: [
@@ -36,8 +35,6 @@ bootstrap_go_package {
"rust.go",
"sanitize.go",
"source_provider.go",
- "snapshot_prebuilt.go",
- "snapshot_utils.go",
"strip.go",
"test.go",
"testing.go",
@@ -62,7 +59,6 @@ bootstrap_go_package {
"sanitize_test.go",
"source_provider_test.go",
"test_test.go",
- "vendor_snapshot_test.go",
],
pluginFor: ["soong_build"],
}
diff --git a/rust/androidmk.go b/rust/androidmk.go
index e0cb3ceae..021dd6067 100644
--- a/rust/androidmk.go
+++ b/rust/androidmk.go
@@ -62,6 +62,7 @@ func (mod *Module) AndroidMkEntries() []android.AndroidMkEntries {
entries.AddStrings("LOCAL_PROC_MACRO_LIBRARIES", mod.Properties.AndroidMkProcMacroLibs...)
entries.AddStrings("LOCAL_SHARED_LIBRARIES", mod.transitiveAndroidMkSharedLibs.ToList()...)
entries.AddStrings("LOCAL_STATIC_LIBRARIES", mod.Properties.AndroidMkStaticLibs...)
+ entries.AddStrings("LOCAL_HEADER_LIBRARIES", mod.Properties.AndroidMkHeaderLibs...)
entries.AddStrings("LOCAL_SOONG_LINK_TYPE", mod.makeLinkType)
if mod.InVendor() {
entries.SetBool("LOCAL_IN_VENDOR", true)
@@ -154,11 +155,6 @@ func (library *libraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.An
})
}
-func (library *snapshotLibraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
- ctx.SubAndroidMk(ret, library.libraryDecorator)
- ret.SubName = library.SnapshotAndroidMkSuffix()
-}
-
func (procMacro *procMacroDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkEntries) {
ctx.SubAndroidMk(ret, procMacro.baseCompiler)
diff --git a/rust/bindgen.go b/rust/bindgen.go
index 454dd8798..11ba74d45 100644
--- a/rust/bindgen.go
+++ b/rust/bindgen.go
@@ -346,6 +346,6 @@ func (b *bindgenDecorator) SourceProviderDeps(ctx DepsContext, deps Deps) Deps {
deps.SharedLibs = append(deps.SharedLibs, b.ClangProperties.Shared_libs...)
deps.StaticLibs = append(deps.StaticLibs, b.ClangProperties.Static_libs...)
- deps.HeaderLibs = append(deps.StaticLibs, b.ClangProperties.Header_libs...)
+ deps.HeaderLibs = append(deps.HeaderLibs, b.ClangProperties.Header_libs...)
return deps
}
diff --git a/rust/bindgen_test.go b/rust/bindgen_test.go
index 0ba0ff840..0c0a6dad0 100644
--- a/rust/bindgen_test.go
+++ b/rust/bindgen_test.go
@@ -17,6 +17,8 @@ package rust
import (
"strings"
"testing"
+
+ "android/soong/android"
)
func TestRustBindgen(t *testing.T) {
@@ -31,7 +33,21 @@ func TestRustBindgen(t *testing.T) {
bindgen_flags: ["--bindgen-flag.*"],
cflags: ["--clang-flag()"],
shared_libs: ["libfoo_shared"],
+ }
+ rust_bindgen {
+ name: "libbindgen_staticlib",
+ wrapper_src: "src/any.h",
+ crate_name: "bindgen_staticlib",
+ stem: "libbindgen_staticlib",
+ source_stem: "bindings",
static_libs: ["libfoo_static"],
+ }
+ rust_bindgen {
+ name: "libbindgen_headerlib",
+ wrapper_src: "src/any.h",
+ crate_name: "bindgen_headerlib",
+ stem: "libbindgen_headerlib",
+ source_stem: "bindings",
header_libs: ["libfoo_header"],
}
cc_library_shared {
@@ -52,6 +68,9 @@ func TestRustBindgen(t *testing.T) {
}
`)
libbindgen := ctx.ModuleForTests("libbindgen", "android_arm64_armv8-a_source").Output("bindings.rs")
+ libbindgenStatic := ctx.ModuleForTests("libbindgen_staticlib", "android_arm64_armv8-a_source").Output("bindings.rs")
+ libbindgenHeader := ctx.ModuleForTests("libbindgen_headerlib", "android_arm64_armv8-a_source").Output("bindings.rs")
+ libbindgenHeaderModule := ctx.ModuleForTests("libbindgen_headerlib", "android_arm64_armv8-a_source").Module().(*Module)
// Ensure that the flags are present and escaped
if !strings.Contains(libbindgen.Args["flags"], "'--bindgen-flag.*'") {
t.Errorf("missing bindgen flags in rust_bindgen rule: flags %#v", libbindgen.Args["flags"])
@@ -62,12 +81,17 @@ func TestRustBindgen(t *testing.T) {
if !strings.Contains(libbindgen.Args["cflags"], "-Ishared_include") {
t.Errorf("missing shared_libs exported includes in rust_bindgen rule: cflags %#v", libbindgen.Args["cflags"])
}
- if !strings.Contains(libbindgen.Args["cflags"], "-Istatic_include") {
- t.Errorf("missing static_libs exported includes in rust_bindgen rule: cflags %#v", libbindgen.Args["cflags"])
+ if !strings.Contains(libbindgenStatic.Args["cflags"], "-Istatic_include") {
+ t.Errorf("missing static_libs exported includes in rust_bindgen rule: cflags %#v", libbindgenStatic.Args["cflags"])
}
- if !strings.Contains(libbindgen.Args["cflags"], "-Iheader_include") {
- t.Errorf("missing static_libs exported includes in rust_bindgen rule: cflags %#v", libbindgen.Args["cflags"])
+ if !strings.Contains(libbindgenHeader.Args["cflags"], "-Iheader_include") {
+ t.Errorf("missing header_libs exported includes in rust_bindgen rule: cflags %#v", libbindgenHeader.Args["cflags"])
}
+
+ if android.InList("libfoo_static", libbindgenHeaderModule.Properties.AndroidMkHeaderLibs) {
+ t.Errorf("Static library dependency should not be in HeaderLibs list")
+ }
+
if !strings.Contains(libbindgen.Args["cflags"], "--default-flag") {
t.Errorf("rust_bindgen missing cflags defined in cc_defaults: cflags %#v", libbindgen.Args["cflags"])
}
diff --git a/rust/builder.go b/rust/builder.go
index c855cfbd2..4f45e33c1 100644
--- a/rust/builder.go
+++ b/rust/builder.go
@@ -32,7 +32,7 @@ var (
"-C linker=${config.RustLinker} " +
"-C link-args=\"${crtBegin} ${earlyLinkFlags} ${linkFlags} ${crtEnd}\" " +
"--emit link -o $out --emit dep-info=$out.d.raw $in ${libFlags} $rustcFlags" +
- " && grep \"^$out:\" $out.d.raw > $out.d",
+ " && grep ^$out: $out.d.raw > $out.d",
CommandDeps: []string{"$rustcCmd"},
// Rustc deps-info writes out make compatible dep files: https://github.com/rust-lang/rust/issues/7633
// Rustc emits unneeded dependency lines for the .d and input .rs files.
@@ -61,7 +61,7 @@ var (
// Use the metadata output as it has the smallest footprint.
"--emit metadata -o $out --emit dep-info=$out.d.raw $in ${libFlags} " +
"$rustcFlags $clippyFlags" +
- " && grep \"^$out:\" $out.d.raw > $out.d",
+ " && grep ^$out: $out.d.raw > $out.d",
CommandDeps: []string{"$clippyCmd"},
Deps: blueprint.DepsGCC,
Depfile: "$out.d",
diff --git a/rust/config/arm64_device.go b/rust/config/arm64_device.go
index 6c021c7ae..9850570c2 100644
--- a/rust/config/arm64_device.go
+++ b/rust/config/arm64_device.go
@@ -54,7 +54,7 @@ func init() {
strings.Join(rustFlags, " "))
}
- ExportedVars.ExportStringListStaticVariable("DEVICE_ARM64_RUSTC_FLAGS", Arm64RustFlags)
+ pctx.StaticVariable("DEVICE_ARM64_RUSTC_FLAGS", strings.Join(Arm64RustFlags, " "))
}
type toolchainArm64 struct {
diff --git a/rust/config/arm_device.go b/rust/config/arm_device.go
index a5f4afb92..5394e8a09 100644
--- a/rust/config/arm_device.go
+++ b/rust/config/arm_device.go
@@ -44,7 +44,7 @@ func init() {
strings.Join(rustFlags, " "))
}
- ExportedVars.ExportStringListStaticVariable("DEVICE_ARM_RUSTC_FLAGS", ArmRustFlags)
+ pctx.StaticVariable("DEVICE_ARM_RUSTC_FLAGS", strings.Join(ArmRustFlags, " "))
}
type toolchainArm struct {
diff --git a/rust/config/global.go b/rust/config/global.go
index e28dbaaea..ba085600b 100644
--- a/rust/config/global.go
+++ b/rust/config/global.go
@@ -22,10 +22,9 @@ import (
)
var (
- pctx = android.NewPackageContext("android/soong/rust/config")
- ExportedVars = android.NewExportedVariables(pctx)
+ pctx = android.NewPackageContext("android/soong/rust/config")
- RustDefaultVersion = "1.76.0"
+ RustDefaultVersion = "1.77.1"
RustDefaultBase = "prebuilts/rust/"
DefaultEdition = "2021"
Stdlibs = []string{
@@ -112,17 +111,17 @@ func init() {
pctx.StaticVariable("DeviceGlobalLinkFlags", strings.Join(deviceGlobalLinkFlags, " "))
- ExportedVars.ExportStringStaticVariable("RUST_DEFAULT_VERSION", RustDefaultVersion)
- ExportedVars.ExportStringListStaticVariable("GLOBAL_RUSTC_FLAGS", GlobalRustFlags)
- ExportedVars.ExportStringListStaticVariable("LINUX_HOST_GLOBAL_LINK_FLAGS", LinuxHostGlobalLinkFlags)
+ pctx.StaticVariable("RUST_DEFAULT_VERSION", RustDefaultVersion)
+ pctx.StaticVariable("GLOBAL_RUSTC_FLAGS", strings.Join(GlobalRustFlags, " "))
+ pctx.StaticVariable("LINUX_HOST_GLOBAL_LINK_FLAGS", strings.Join(LinuxHostGlobalLinkFlags, " "))
- ExportedVars.ExportStringListStaticVariable("DEVICE_GLOBAL_RUSTC_FLAGS", deviceGlobalRustFlags)
- ExportedVars.ExportStringListStaticVariable("DEVICE_GLOBAL_LINK_FLAGS",
- android.RemoveListFromList(deviceGlobalLinkFlags, []string{
+ pctx.StaticVariable("DEVICE_GLOBAL_RUSTC_FLAGS", strings.Join(deviceGlobalRustFlags, " "))
+ pctx.StaticVariable("DEVICE_GLOBAL_LINK_FLAGS",
+ strings.Join(android.RemoveListFromList(deviceGlobalLinkFlags, []string{
// The cc_config flags are retrieved from cc_toolchain by rust rules.
"${cc_config.DeviceGlobalLldflags}",
"-B${cc_config.ClangBin}",
- }))
+ }), " "))
}
func HostPrebuiltTag(config android.Config) string {
diff --git a/rust/config/x86_64_device.go b/rust/config/x86_64_device.go
index 49f7c772e..fee1923b0 100644
--- a/rust/config/x86_64_device.go
+++ b/rust/config/x86_64_device.go
@@ -54,7 +54,7 @@ func init() {
pctx.StaticVariable("X86_64"+variant+"VariantRustFlags",
strings.Join(rustFlags, " "))
}
- ExportedVars.ExportStringListStaticVariable("DEVICE_X86_64_RUSTC_FLAGS", x86_64RustFlags)
+ pctx.StaticVariable("DEVICE_X86_64_RUSTC_FLAGS", strings.Join(x86_64RustFlags, " "))
}
type toolchainX86_64 struct {
diff --git a/rust/config/x86_device.go b/rust/config/x86_device.go
index 2a57e73bb..5d9d88aef 100644
--- a/rust/config/x86_device.go
+++ b/rust/config/x86_device.go
@@ -56,7 +56,7 @@ func init() {
strings.Join(rustFlags, " "))
}
- ExportedVars.ExportStringListStaticVariable("DEVICE_X86_RUSTC_FLAGS", x86RustFlags)
+ pctx.StaticVariable("DEVICE_X86_RUSTC_FLAGS", strings.Join(x86RustFlags, " "))
}
type toolchainX86 struct {
diff --git a/rust/image.go b/rust/image.go
index 530c56edd..e0d267d61 100644
--- a/rust/image.go
+++ b/rust/image.go
@@ -208,14 +208,6 @@ func (mod *Module) SetImageVariation(ctx android.BaseModuleContext, variant stri
if strings.HasPrefix(variant, cc.VendorVariationPrefix) {
m.Properties.VndkVersion = strings.TrimPrefix(variant, cc.VendorVariationPrefix)
}
-
- // Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION.
- // Hide other vendor variants to avoid collision.
- vndkVersion := ctx.DeviceConfig().VndkVersion()
- if vndkVersion != "current" && vndkVersion != "" && vndkVersion != m.Properties.VndkVersion {
- m.Properties.HideFromMake = true
- m.HideFromMake()
- }
} else if strings.HasPrefix(variant, cc.ProductVariation) {
m.Properties.ImageVariation = cc.ProductVariation
if strings.HasPrefix(variant, cc.ProductVariationPrefix) {
diff --git a/rust/image_test.go b/rust/image_test.go
index fb4d9c170..ba94906c6 100644
--- a/rust/image_test.go
+++ b/rust/image_test.go
@@ -24,7 +24,7 @@ import (
// Test that cc modules can link against vendor_available rust_ffi_static libraries.
func TestVendorLinkage(t *testing.T) {
- ctx := testRustVndk(t, `
+ ctx := testRust(t, `
cc_binary {
name: "fizz_vendor",
static_libs: ["libfoo_vendor"],
@@ -38,7 +38,7 @@ func TestVendorLinkage(t *testing.T) {
}
`)
- vendorBinary := ctx.ModuleForTests("fizz_vendor", "android_vendor.29_arm64_armv8-a").Module().(*cc.Module)
+ vendorBinary := ctx.ModuleForTests("fizz_vendor", "android_vendor_arm64_armv8-a").Module().(*cc.Module)
if !android.InList("libfoo_vendor.vendor", vendorBinary.Properties.AndroidMkStaticLibs) {
t.Errorf("vendorBinary should have a dependency on libfoo_vendor: %#v", vendorBinary.Properties.AndroidMkStaticLibs)
@@ -46,8 +46,8 @@ func TestVendorLinkage(t *testing.T) {
}
// Test that variants which use the vndk emit the appropriate cfg flag.
-func TestImageVndkCfgFlag(t *testing.T) {
- ctx := testRustVndk(t, `
+func TestImageCfgFlag(t *testing.T) {
+ ctx := testRust(t, `
rust_ffi_static {
name: "libfoo",
crate_name: "foo",
@@ -57,7 +57,7 @@ func TestImageVndkCfgFlag(t *testing.T) {
}
`)
- vendor := ctx.ModuleForTests("libfoo", "android_vendor.29_arm64_armv8-a_static").Rule("rustc")
+ vendor := ctx.ModuleForTests("libfoo", "android_vendor_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"])
@@ -69,7 +69,7 @@ func TestImageVndkCfgFlag(t *testing.T) {
t.Errorf("unexpected \"--cfg 'android_product'\" for libfoo vendor variant, rustcFlags: %#v", vendor.Args["rustcFlags"])
}
- product := ctx.ModuleForTests("libfoo", "android_product.29_arm64_armv8-a_static").Rule("rustc")
+ product := ctx.ModuleForTests("libfoo", "android_product_arm64_armv8-a_static").Rule("rustc")
if !strings.Contains(product.Args["rustcFlags"], "--cfg 'android_vndk'") {
t.Errorf("missing \"--cfg 'android_vndk'\" for libfoo product variant, rustcFlags: %#v", product.Args["rustcFlags"])
}
@@ -95,7 +95,7 @@ func TestImageVndkCfgFlag(t *testing.T) {
// Test that cc modules can link against vendor_ramdisk_available rust_ffi_static libraries.
func TestVendorRamdiskLinkage(t *testing.T) {
- ctx := testRustVndk(t, `
+ ctx := testRust(t, `
cc_library_static {
name: "libcc_vendor_ramdisk",
static_libs: ["libfoo_vendor_ramdisk"],
@@ -119,7 +119,7 @@ func TestVendorRamdiskLinkage(t *testing.T) {
// Test that prebuilt libraries cannot be made vendor available.
func TestForbiddenVendorLinkage(t *testing.T) {
- testRustVndkError(t, "Rust prebuilt modules not supported for non-system images.", `
+ testRustError(t, "Rust prebuilt modules not supported for non-system images.", `
rust_prebuilt_library {
name: "librust_prebuilt",
crate_name: "rust_prebuilt",
diff --git a/rust/library.go b/rust/library.go
index 3560d73ed..6be4917bf 100644
--- a/rust/library.go
+++ b/rust/library.go
@@ -104,8 +104,6 @@ type libraryDecorator struct {
includeDirs android.Paths
sourceProvider SourceProvider
- collectedSnapshotHeaders android.Paths
-
// table-of-contents file for cdylib crates to optimize out relinking when possible
tocFile android.OptionalPath
}
@@ -749,55 +747,3 @@ func LibstdMutator(mctx android.BottomUpMutatorContext) {
}
}
}
-
-func (l *libraryDecorator) snapshotHeaders() android.Paths {
- if l.collectedSnapshotHeaders == nil {
- panic("snapshotHeaders() must be called after collectHeadersForSnapshot()")
- }
- return l.collectedSnapshotHeaders
-}
-
-// collectHeadersForSnapshot collects all exported headers from library.
-// It globs header files in the source tree for exported include directories,
-// and tracks generated header files separately.
-//
-// This is to be called from GenerateAndroidBuildActions, and then collected
-// header files can be retrieved by snapshotHeaders().
-func (l *libraryDecorator) collectHeadersForSnapshot(ctx android.ModuleContext, deps PathDeps) {
- ret := android.Paths{}
-
- // Glob together the headers from the modules include_dirs property
- for _, path := range android.CopyOfPaths(l.includeDirs) {
- dir := path.String()
- globDir := dir + "/**/*"
- glob, err := ctx.GlobWithDeps(globDir, nil)
- if err != nil {
- ctx.ModuleErrorf("glob of %q failed: %s", globDir, err)
- return
- }
-
- for _, header := range glob {
- // Filter out only the files with extensions that are headers.
- found := false
- for _, ext := range cc.HeaderExts {
- if strings.HasSuffix(header, ext) {
- found = true
- break
- }
- }
- if !found {
- continue
- }
- ret = append(ret, android.PathForSource(ctx, header))
- }
- }
-
- // Glob together the headers from C dependencies as well, starting with non-generated headers.
- ret = append(ret, cc.GlobHeadersForSnapshot(ctx, append(android.CopyOfPaths(deps.depIncludePaths), deps.depSystemIncludePaths...))...)
-
- // Collect generated headers from C dependencies.
- ret = append(ret, cc.GlobGeneratedHeadersForSnapshot(ctx, deps.depGeneratedHeaders)...)
-
- // TODO(185577950): If support for generated headers is added, they need to be collected here as well.
- l.collectedSnapshotHeaders = ret
-}
diff --git a/rust/rust.go b/rust/rust.go
index 7d81c721e..c2b61515c 100644
--- a/rust/rust.go
+++ b/rust/rust.go
@@ -30,7 +30,6 @@ import (
"android/soong/fuzz"
"android/soong/multitree"
"android/soong/rust/config"
- "android/soong/snapshot"
)
var pctx = android.NewPackageContext("android/soong/rust")
@@ -69,6 +68,7 @@ type BaseProperties struct {
AndroidMkDylibs []string `blueprint:"mutated"`
AndroidMkProcMacroLibs []string `blueprint:"mutated"`
AndroidMkStaticLibs []string `blueprint:"mutated"`
+ AndroidMkHeaderLibs []string `blueprint:"mutated"`
ImageVariation string `blueprint:"mutated"`
VndkVersion string `blueprint:"mutated"`
@@ -971,14 +971,6 @@ func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
ctx.CheckbuildFile(mod.docTimestampFile.Path())
}
- // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current or
- // RECOVERY_SNAPSHOT_VERSION is current.
- if lib, ok := mod.compiler.(snapshotLibraryInterface); ok {
- if cc.ShouldCollectHeadersForSnapshot(ctx, mod, apexInfo) {
- lib.collectHeadersForSnapshot(ctx, deps)
- }
- }
-
apexInfo, _ := android.ModuleProvider(actx, android.ApexInfoProvider)
if !proptools.BoolDefault(mod.Installable(), mod.EverInstallable()) && !mod.ProcMacro() {
// If the module has been specifically configure to not be installed then
@@ -1124,6 +1116,11 @@ func (mod *Module) Prebuilt() *android.Prebuilt {
return nil
}
+func (mod *Module) Symlinks() []string {
+ // TODO update this to return the list of symlinks when Rust supports defining symlinks
+ return nil
+}
+
func rustMakeLibName(ctx android.ModuleContext, c cc.LinkableInterface, dep cc.LinkableInterface, depName string) string {
if rustDep, ok := dep.(*Module); ok {
// Use base module name for snapshots when exporting to Makefile.
@@ -1403,6 +1400,7 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...)
depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...)
+ mod.Properties.AndroidMkHeaderLibs = append(mod.Properties.AndroidMkHeaderLibs, makeLibName)
case depTag == cc.CrtBeginDepTag:
depPaths.CrtBegin = append(depPaths.CrtBegin, linkObject.Path())
case depTag == cc.CrtEndDepTag:
@@ -1544,7 +1542,6 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
deps := mod.deps(ctx)
var commonDepVariations []blueprint.Variation
- var snapshotInfo *cc.SnapshotInfo
apiImportInfo := cc.GetApiImports(mod, actx)
if mod.usePublicApi() || mod.useVendorApi() {
@@ -1554,7 +1551,7 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
}
if ctx.Os() == android.Android {
- deps.SharedLibs, _ = cc.RewriteLibs(mod, &snapshotInfo, actx, ctx.Config(), deps.SharedLibs)
+ deps.SharedLibs, _ = cc.FilterNdkLibs(mod, ctx.Config(), deps.SharedLibs)
}
stdLinkage := "dylib-std"
@@ -1573,15 +1570,13 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
rlibDepVariations = append(rlibDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: rlibVariation})
for _, lib := range deps.Rlibs {
depTag := rlibDepTag
- lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Rlibs)
-
actx.AddVariationDependencies(rlibDepVariations, depTag, lib)
}
// dylibs
dylibDepVariations := append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: dylibVariation})
for _, lib := range deps.Dylibs {
- addDylibDependency(actx, lib, mod, &snapshotInfo, dylibDepVariations, dylibDepTag)
+ actx.AddVariationDependencies(dylibDepVariations, dylibDepTag, lib)
}
// rustlibs
@@ -1591,7 +1586,8 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
autoDep := mod.compiler.(autoDeppable).autoDep(ctx)
if autoDep.depTag == rlibDepTag {
// Handle the rlib deptag case
- addRlibDependency(actx, lib, mod, &snapshotInfo, rlibDepVariations)
+ actx.AddVariationDependencies(rlibDepVariations, rlibDepTag, lib)
+
} else {
// autoDep.depTag is a dylib depTag. Not all rustlibs may be available as a dylib however.
// Check for the existence of the dylib deptag variant. Select it if available,
@@ -1599,23 +1595,22 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
autoDepVariations := append(commonDepVariations,
blueprint.Variation{Mutator: "rust_libraries", Variation: autoDep.variation})
- replacementLib := cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Dylibs)
+ if actx.OtherModuleDependencyVariantExists(autoDepVariations, lib) {
+ actx.AddVariationDependencies(autoDepVariations, autoDep.depTag, lib)
- if actx.OtherModuleDependencyVariantExists(autoDepVariations, replacementLib) {
- addDylibDependency(actx, lib, mod, &snapshotInfo, autoDepVariations, autoDep.depTag)
} else {
// If there's no dylib dependency available, try to add the rlib dependency instead.
- addRlibDependency(actx, lib, mod, &snapshotInfo, rlibDepVariations)
+ actx.AddVariationDependencies(rlibDepVariations, rlibDepTag, lib)
+
}
}
}
} else if _, ok := mod.sourceProvider.(*protobufDecorator); ok {
for _, lib := range deps.Rustlibs {
- replacementLib := cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Dylibs)
srcProviderVariations := append(commonDepVariations,
blueprint.Variation{Mutator: "rust_libraries", Variation: "source"})
- if actx.OtherModuleDependencyVariantExists(srcProviderVariations, replacementLib) {
+ if actx.OtherModuleDependencyVariantExists(srcProviderVariations, lib) {
actx.AddVariationDependencies(srcProviderVariations, sourceDepTag, lib)
}
}
@@ -1626,13 +1621,13 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
if deps.Stdlibs != nil {
if mod.compiler.stdLinkage(ctx) == RlibLinkage {
for _, lib := range deps.Stdlibs {
- lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Rlibs)
actx.AddVariationDependencies(append(commonDepVariations, []blueprint.Variation{{Mutator: "rust_libraries", Variation: "rlib"}}...),
rlibDepTag, lib)
}
} else {
for _, lib := range deps.Stdlibs {
- addDylibDependency(actx, lib, mod, &snapshotInfo, dylibDepVariations, dylibDepTag)
+ actx.AddVariationDependencies(dylibDepVariations, dylibDepTag, lib)
+
}
}
}
@@ -1657,7 +1652,6 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
for _, lib := range deps.WholeStaticLibs {
depTag := cc.StaticDepTag(true)
- lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).StaticLibs)
actx.AddVariationDependencies([]blueprint.Variation{
{Mutator: "link", Variation: "static"},
@@ -1666,7 +1660,6 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
for _, lib := range deps.StaticLibs {
depTag := cc.StaticDepTag(false)
- lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).StaticLibs)
actx.AddVariationDependencies([]blueprint.Variation{
{Mutator: "link", Variation: "static"},
@@ -1677,12 +1670,10 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
crtVariations := cc.GetCrtVariations(ctx, mod)
for _, crt := range deps.CrtBegin {
- actx.AddVariationDependencies(crtVariations, cc.CrtBeginDepTag,
- cc.GetReplaceModuleName(crt, cc.GetSnapshot(mod, &snapshotInfo, actx).Objects))
+ actx.AddVariationDependencies(crtVariations, cc.CrtBeginDepTag, crt)
}
for _, crt := range deps.CrtEnd {
- actx.AddVariationDependencies(crtVariations, cc.CrtEndDepTag,
- cc.GetReplaceModuleName(crt, cc.GetSnapshot(mod, &snapshotInfo, actx).Objects))
+ actx.AddVariationDependencies(crtVariations, cc.CrtEndDepTag, crt)
}
if mod.sourceProvider != nil {
@@ -1705,17 +1696,6 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
mod.afdo.addDep(ctx, actx)
}
-// addRlibDependency will add an rlib dependency, rewriting to the snapshot library if available.
-func addRlibDependency(actx android.BottomUpMutatorContext, lib string, mod *Module, snapshotInfo **cc.SnapshotInfo, variations []blueprint.Variation) {
- lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, snapshotInfo, actx).Rlibs)
- actx.AddVariationDependencies(variations, rlibDepTag, lib)
-}
-
-func addDylibDependency(actx android.BottomUpMutatorContext, lib string, mod *Module, snapshotInfo **cc.SnapshotInfo, variations []blueprint.Variation, depTag dependencyTag) {
- lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, snapshotInfo, actx).Dylibs)
- actx.AddVariationDependencies(variations, depTag, lib)
-}
-
func BeginMutator(ctx android.BottomUpMutatorContext) {
if mod, ok := ctx.Module().(*Module); ok && mod.Enabled() {
mod.beginMutator(ctx)
@@ -1747,7 +1727,6 @@ func (mod *Module) disableClippy() {
}
var _ android.HostToolProvider = (*Module)(nil)
-var _ snapshot.RelativeInstallPath = (*Module)(nil)
func (mod *Module) HostToolPath() android.OptionalPath {
if !mod.Host() {
diff --git a/rust/rust_test.go b/rust/rust_test.go
index 295a734b6..6d083f69f 100644
--- a/rust/rust_test.go
+++ b/rust/rust_test.go
@@ -37,11 +37,7 @@ var prepareForRustTest = android.GroupFixturePreparers(
genrule.PrepareForTestWithGenRuleBuildComponents,
- PrepareForTestWithRustIncludeVndk,
- android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
- variables.DeviceVndkVersion = StringPtr("current")
- variables.Platform_vndk_version = StringPtr("29")
- }),
+ PrepareForIntegrationTestWithRust,
)
var rustMockedFiles = android.MockFS{
@@ -73,60 +69,21 @@ func testRust(t *testing.T, bp string) *android.TestContext {
return result.TestContext
}
-func testRustVndk(t *testing.T, bp string) *android.TestContext {
- return testRustVndkFs(t, bp, rustMockedFiles)
-}
-
const (
- sharedVendorVariant = "android_vendor.29_arm64_armv8-a_shared"
- rlibVendorVariant = "android_vendor.29_arm64_armv8-a_rlib_rlib-std"
- rlibDylibStdVendorVariant = "android_vendor.29_arm64_armv8-a_rlib_rlib-std"
- dylibVendorVariant = "android_vendor.29_arm64_armv8-a_dylib"
+ sharedVendorVariant = "android_vendor_arm64_armv8-a_shared"
+ rlibVendorVariant = "android_vendor_arm64_armv8-a_rlib_rlib-std"
+ rlibDylibStdVendorVariant = "android_vendor_arm64_armv8-a_rlib_rlib-std"
+ dylibVendorVariant = "android_vendor_arm64_armv8-a_dylib"
sharedRecoveryVariant = "android_recovery_arm64_armv8-a_shared"
rlibRecoveryVariant = "android_recovery_arm64_armv8-a_rlib_dylib-std"
rlibRlibStdRecoveryVariant = "android_recovery_arm64_armv8-a_rlib_rlib-std"
dylibRecoveryVariant = "android_recovery_arm64_armv8-a_dylib"
binaryCoreVariant = "android_arm64_armv8-a"
- binaryVendorVariant = "android_vendor.29_arm64_armv8-a"
- binaryProductVariant = "android_product.29_arm64_armv8-a"
+ binaryVendorVariant = "android_vendor_arm64_armv8-a"
+ binaryProductVariant = "android_product_arm64_armv8-a"
binaryRecoveryVariant = "android_recovery_arm64_armv8-a"
)
-func testRustVndkFs(t *testing.T, bp string, fs android.MockFS) *android.TestContext {
- 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 {
- skipTestIfOsNotSupported(t)
- result := android.GroupFixturePreparers(
- prepareForRustTest,
- fs.AddToFixture(),
- android.FixtureModifyProductVariables(
- func(variables android.FixtureProductVariables) {
- variables.DeviceVndkVersion = StringPtr(device_version)
- variables.Platform_vndk_version = StringPtr(vndk_version)
- },
- ),
- ).RunTestWithBp(t, bp)
- return result.TestContext
-}
-
-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
-}
-
// 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 {
@@ -158,27 +115,6 @@ func testRustError(t *testing.T, pattern string, bp string) {
RunTestWithBp(t, bp)
}
-// testRustVndkError is similar to testRustError, but can be used to test VNDK-related errors.
-func testRustVndkError(t *testing.T, pattern string, bp string) {
- testRustVndkFsError(t, pattern, bp, rustMockedFiles)
-}
-
-func testRustVndkFsError(t *testing.T, pattern string, bp string, fs android.MockFS) {
- skipTestIfOsNotSupported(t)
- android.GroupFixturePreparers(
- prepareForRustTest,
- fs.AddToFixture(),
- android.FixtureModifyProductVariables(
- func(variables android.FixtureProductVariables) {
- variables.DeviceVndkVersion = StringPtr("current")
- variables.Platform_vndk_version = StringPtr("VER")
- },
- ),
- ).
- ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(pattern)).
- RunTestWithBp(t, bp)
-}
-
// testRustCtx is used to build a particular test environment. Unless your
// tests requires a specific setup, prefer the wrapping functions: testRust,
// testRustCov or testRustError.
diff --git a/rust/sanitize.go b/rust/sanitize.go
index 3c08cd8fd..bfd397155 100644
--- a/rust/sanitize.go
+++ b/rust/sanitize.go
@@ -267,12 +267,6 @@ func rustSanitizerRuntimeMutator(mctx android.BottomUpMutatorContext) {
if Bool(mod.sanitize.Properties.Sanitize.Diag.Memtag_heap) {
noteDep = "note_memtag_heap_sync"
}
- // If we're using snapshots, redirect to snapshot whenever possible
- // TODO(b/178470649): clean manual snapshot redirections
- snapshot, _ := android.ModuleProvider(mctx, cc.SnapshotInfoProvider)
- if lib, ok := snapshot.StaticLibs[noteDep]; ok {
- noteDep = lib
- }
depTag := cc.StaticDepTag(true)
variations := append(mctx.Target().Variations(),
blueprint.Variation{Mutator: "link", Variation: "static"})
diff --git a/rust/snapshot_prebuilt.go b/rust/snapshot_prebuilt.go
deleted file mode 100644
index 42e3cef38..000000000
--- a/rust/snapshot_prebuilt.go
+++ /dev/null
@@ -1,208 +0,0 @@
-// Copyright 2021 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 (
- "fmt"
-
- "android/soong/android"
- "android/soong/cc"
-
- "github.com/google/blueprint/proptools"
-)
-
-type snapshotLibraryDecorator struct {
- cc.BaseSnapshotDecorator
- *libraryDecorator
- properties cc.SnapshotLibraryProperties
- sanitizerProperties struct {
- SanitizerVariation cc.SanitizerType `blueprint:"mutated"`
-
- //TODO: Library flags for cfi variant when CFI is supported.
- //Cfi cc.SnapshotLibraryProperties `android:"arch_variant"`
-
- // Library flags for hwasan variant.
- Hwasan cc.SnapshotLibraryProperties `android:"arch_variant"`
- }
-}
-
-var _ cc.SnapshotSanitizer = (*snapshotLibraryDecorator)(nil)
-
-func (library *snapshotLibraryDecorator) IsSanitizerAvailable(t cc.SanitizerType) bool {
- switch t {
- //TODO: When CFI is supported, add a check here as well
- case cc.Hwasan:
- return library.sanitizerProperties.Hwasan.Src != nil
- default:
- return false
- }
-}
-
-func (library *snapshotLibraryDecorator) SetSanitizerVariation(t cc.SanitizerType, enabled bool) {
- if !enabled || library.IsSanitizerEnabled(t) {
- return
- }
- if !library.IsUnsanitizedVariant() {
- panic(fmt.Errorf("snapshot Sanitizer must be one of Cfi or Hwasan but not both"))
- }
- library.sanitizerProperties.SanitizerVariation = t
-}
-
-func (library *snapshotLibraryDecorator) IsSanitizerEnabled(t cc.SanitizerType) bool {
- return library.sanitizerProperties.SanitizerVariation == t
-}
-
-func (library *snapshotLibraryDecorator) IsUnsanitizedVariant() bool {
- //TODO: When CFI is supported, add a check here as well
- return !library.IsSanitizerEnabled(cc.Hwasan)
-}
-
-func init() {
- registerRustSnapshotModules(android.InitRegistrationContext)
-}
-
-func (mod *Module) IsSnapshotSanitizerAvailable(t cc.SanitizerType) bool {
- if ss, ok := mod.compiler.(cc.SnapshotSanitizer); ok {
- return ss.IsSanitizerAvailable(t)
- }
- return false
-}
-
-func (mod *Module) SetSnapshotSanitizerVariation(t cc.SanitizerType, enabled bool) {
- if ss, ok := mod.compiler.(cc.SnapshotSanitizer); ok {
- ss.SetSanitizerVariation(t, enabled)
- } else {
- panic(fmt.Errorf("Calling SetSnapshotSanitizerVariation on a non-snapshotLibraryDecorator: %s", mod.Name()))
- }
-}
-
-func (mod *Module) IsSnapshotUnsanitizedVariant() bool {
- if ss, ok := mod.compiler.(cc.SnapshotSanitizer); ok {
- return ss.IsUnsanitizedVariant()
- }
- return false
-}
-
-func (mod *Module) IsSnapshotSanitizer() bool {
- if _, ok := mod.compiler.(cc.SnapshotSanitizer); ok {
- return true
- }
- return false
-}
-
-func registerRustSnapshotModules(ctx android.RegistrationContext) {
- cc.VendorSnapshotImageSingleton.RegisterAdditionalModule(ctx,
- "vendor_snapshot_rlib", VendorSnapshotRlibFactory)
- cc.VendorSnapshotImageSingleton.RegisterAdditionalModule(ctx,
- "vendor_snapshot_dylib", VendorSnapshotDylibFactory)
- cc.RecoverySnapshotImageSingleton.RegisterAdditionalModule(ctx,
- "recovery_snapshot_rlib", RecoverySnapshotRlibFactory)
-}
-
-func snapshotLibraryFactory(image cc.SnapshotImage, moduleSuffix string) (*Module, *snapshotLibraryDecorator) {
- module, library := NewRustLibrary(android.DeviceSupported)
-
- module.sanitize = nil
- library.stripper.StripProperties.Strip.None = proptools.BoolPtr(true)
-
- prebuilt := &snapshotLibraryDecorator{
- libraryDecorator: library,
- }
-
- module.compiler = prebuilt
-
- prebuilt.Init(module, image, moduleSuffix)
- module.AddProperties(
- &prebuilt.properties,
- &prebuilt.sanitizerProperties,
- )
-
- return module, prebuilt
-}
-
-func (library *snapshotLibraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) buildOutput {
- var variant string
- if library.static() {
- variant = cc.SnapshotStaticSuffix
- } else if library.shared() {
- variant = cc.SnapshotSharedSuffix
- } else if library.rlib() {
- variant = cc.SnapshotRlibSuffix
- } else if library.dylib() {
- variant = cc.SnapshotDylibSuffix
- }
-
- library.SetSnapshotAndroidMkSuffix(ctx, variant)
-
- if library.IsSanitizerEnabled(cc.Hwasan) {
- library.properties = library.sanitizerProperties.Hwasan
- }
- if !library.MatchesWithDevice(ctx.DeviceConfig()) {
- return buildOutput{}
- }
- outputFile := android.PathForModuleSrc(ctx, *library.properties.Src)
- library.unstrippedOutputFile = outputFile
- return buildOutput{outputFile: outputFile}
-}
-
-func (library *snapshotLibraryDecorator) rustdoc(ctx ModuleContext, flags Flags, deps PathDeps) android.OptionalPath {
- return android.OptionalPath{}
-}
-
-// vendor_snapshot_rlib is a special prebuilt rlib library which is auto-generated by
-// development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_rlib
-// overrides the vendor variant of the rust rlib library with the same name, if BOARD_VNDK_VERSION
-// is set.
-func VendorSnapshotRlibFactory() android.Module {
- module, prebuilt := snapshotLibraryFactory(cc.VendorSnapshotImageSingleton, cc.SnapshotRlibSuffix)
- prebuilt.libraryDecorator.BuildOnlyRlib()
- prebuilt.libraryDecorator.setNoStdlibs()
- return module.Init()
-}
-
-// vendor_snapshot_dylib is a special prebuilt dylib library which is auto-generated by
-// development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_dylib
-// overrides the vendor variant of the rust dylib library with the same name, if BOARD_VNDK_VERSION
-// is set.
-func VendorSnapshotDylibFactory() android.Module {
- module, prebuilt := snapshotLibraryFactory(cc.VendorSnapshotImageSingleton, cc.SnapshotDylibSuffix)
- prebuilt.libraryDecorator.BuildOnlyDylib()
- prebuilt.libraryDecorator.setNoStdlibs()
- return module.Init()
-}
-
-func RecoverySnapshotRlibFactory() android.Module {
- module, prebuilt := snapshotLibraryFactory(cc.RecoverySnapshotImageSingleton, cc.SnapshotRlibSuffix)
- prebuilt.libraryDecorator.BuildOnlyRlib()
- prebuilt.libraryDecorator.setNoStdlibs()
- return module.Init()
-}
-
-func (library *snapshotLibraryDecorator) MatchesWithDevice(config android.DeviceConfig) bool {
- arches := config.Arches()
- if len(arches) == 0 || arches[0].ArchType.String() != library.Arch() {
- return false
- }
- if library.properties.Src == nil {
- return false
- }
- return true
-}
-
-func (library *snapshotLibraryDecorator) IsSnapshotPrebuilt() bool {
- return true
-}
-
-var _ cc.SnapshotInterface = (*snapshotLibraryDecorator)(nil)
diff --git a/rust/snapshot_utils.go b/rust/snapshot_utils.go
deleted file mode 100644
index 55c85e668..000000000
--- a/rust/snapshot_utils.go
+++ /dev/null
@@ -1,81 +0,0 @@
-// Copyright 2021 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 (
- "android/soong/android"
-)
-
-// snapshotLibraryInterface is an interface for libraries captured to VNDK / vendor snapshots.
-type snapshotLibraryInterface interface {
- libraryInterface
-
- // collectHeadersForSnapshot is called in GenerateAndroidBuildActions for snapshot aware
- // modules (See isSnapshotAware below).
- // This function should gather all headers needed for snapshot.
- collectHeadersForSnapshot(ctx android.ModuleContext, deps PathDeps)
-
- // snapshotHeaders should return collected headers by collectHeadersForSnapshot.
- // Calling snapshotHeaders before collectHeadersForSnapshot is an error.
- snapshotHeaders() android.Paths
-}
-
-func (mod *Module) ExcludeFromVendorSnapshot() bool {
- return Bool(mod.Properties.Exclude_from_vendor_snapshot)
-}
-
-func (mod *Module) ExcludeFromRecoverySnapshot() bool {
- return Bool(mod.Properties.Exclude_from_recovery_snapshot)
-}
-
-func (mod *Module) IsSnapshotLibrary() bool {
- if lib, ok := mod.compiler.(libraryInterface); ok {
- return lib.shared() || lib.static() || lib.rlib() || lib.dylib()
- }
- return false
-}
-
-func (mod *Module) SnapshotRuntimeLibs() []string {
- // TODO Rust does not yet support a runtime libs notion similar to CC
- return []string{}
-}
-
-func (mod *Module) SnapshotSharedLibs() []string {
- return mod.Properties.SnapshotSharedLibs
-}
-
-func (mod *Module) SnapshotStaticLibs() []string {
- return mod.Properties.SnapshotStaticLibs
-}
-
-func (mod *Module) SnapshotRlibs() []string {
- return mod.Properties.SnapshotRlibs
-}
-
-func (mod *Module) SnapshotDylibs() []string {
- return mod.Properties.SnapshotDylibs
-}
-
-func (mod *Module) Symlinks() []string {
- // TODO update this to return the list of symlinks when Rust supports defining symlinks
- return nil
-}
-
-func (m *Module) SnapshotHeaders() android.Paths {
- if l, ok := m.compiler.(snapshotLibraryInterface); ok {
- return l.snapshotHeaders()
- }
- return android.Paths{}
-}
diff --git a/rust/testing.go b/rust/testing.go
index d9cacdc27..5837dccde 100644
--- a/rust/testing.go
+++ b/rust/testing.go
@@ -43,11 +43,7 @@ var PrepareForTestWithRustDefaultModules = android.GroupFixturePreparers(
// Preparer that will allow use of all rust modules fully.
var PrepareForIntegrationTestWithRust = android.GroupFixturePreparers(
PrepareForTestWithRustDefaultModules,
-)
-
-var PrepareForTestWithRustIncludeVndk = android.GroupFixturePreparers(
- PrepareForIntegrationTestWithRust,
- cc.PrepareForTestWithCcIncludeVndk,
+ cc.PrepareForIntegrationTestWithCc,
)
func GatherRequiredDepsForTest() string {
@@ -201,5 +197,4 @@ func registerRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
ctx.BottomUp("rust_sanitizers", rustSanitizerRuntimeMutator).Parallel()
})
- registerRustSnapshotModules(ctx)
}
diff --git a/rust/vendor_snapshot_test.go b/rust/vendor_snapshot_test.go
deleted file mode 100644
index a6ed0e5f2..000000000
--- a/rust/vendor_snapshot_test.go
+++ /dev/null
@@ -1,1573 +0,0 @@
-// Copyright 2021 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 (
- "fmt"
- "path/filepath"
- "reflect"
- "strings"
- "testing"
-
- "android/soong/android"
- "android/soong/cc"
-)
-
-func TestVendorSnapshotCapture(t *testing.T) {
- bp := `
- rust_ffi {
- name: "libffivendor_available",
- crate_name: "ffivendor_available",
- srcs: ["lib.rs"],
- vendor_available: true,
- export_include_dirs: ["rust_headers/"],
- }
-
- rust_ffi {
- name: "libffivendor",
- crate_name: "ffivendor",
- srcs: ["lib.rs"],
- vendor: true,
- export_include_dirs: ["rust_headers/"],
- }
-
- rust_library {
- name: "librustvendor_available",
- crate_name: "rustvendor_available",
- srcs: ["lib.rs"],
- vendor_available: true,
- }
-
- rust_library {
- name: "librustvendor",
- crate_name: "rustvendor",
- srcs: ["lib.rs"],
- vendor: true,
- }
-
- rust_binary {
- name: "vendor_available_bin",
- vendor_available: true,
- srcs: ["srcs/lib.rs"],
- }
-
- rust_binary {
- name: "vendor_bin",
- vendor: true,
- srcs: ["srcs/lib.rs"],
- }
- `
- skipTestIfOsNotSupported(t)
- result := android.GroupFixturePreparers(
- prepareForRustTest,
- rustMockedFiles.AddToFixture(),
- android.FixtureModifyProductVariables(
- func(variables android.FixtureProductVariables) {
- variables.DeviceVndkVersion = StringPtr("current")
- variables.Platform_vndk_version = StringPtr("29")
- },
- ),
- ).RunTestWithBp(t, bp)
- ctx := result.TestContext
-
- // Check Vendor snapshot output.
-
- snapshotDir := "vendor-snapshot"
- snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
- snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
- var jsonFiles []string
- for _, arch := range [][]string{
- []string{"arm64", "armv8-a"},
- []string{"arm", "armv7-a-neon"},
- } {
- archType := arch[0]
- archVariant := arch[1]
- archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
-
- // For shared libraries, only non-VNDK vendor_available modules are captured
- sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
- sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "libffivendor_available", "libffivendor_available.so", sharedDir, sharedVariant)
- jsonFiles = append(jsonFiles,
- filepath.Join(sharedDir, "libffivendor_available.so.json"))
-
- // For static libraries, all vendor:true and vendor_available modules (including VNDK) are captured.
- staticVariant := fmt.Sprintf("android_vendor.29_%s_%s_static", archType, archVariant)
- staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "libffivendor_available", "libffivendor_available.a", staticDir, staticVariant)
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "libffivendor", "libffivendor.a", staticDir, staticVariant)
- jsonFiles = append(jsonFiles,
- filepath.Join(staticDir, "libffivendor_available.a.json"))
- jsonFiles = append(jsonFiles,
- filepath.Join(staticDir, "libffivendor.a.json"))
-
- // For rlib libraries, all vendor:true and vendor_available modules (including VNDK) are captured.
- rlibVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_dylib-std", archType, archVariant)
- rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib")
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor_available", "librustvendor_available.rlib", rlibDir, rlibVariant)
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor", "librustvendor.rlib", rlibDir, rlibVariant)
- jsonFiles = append(jsonFiles,
- filepath.Join(rlibDir, "librustvendor_available.rlib.json"))
- jsonFiles = append(jsonFiles,
- filepath.Join(rlibDir, "librustvendor.rlib.json"))
-
- // For rlib libraries, all rlib-std variants vendor:true and vendor_available modules (including VNDK) are captured.
- rlibStdVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_rlib-std", archType, archVariant)
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor_available", "librustvendor_available.rlib-std.rlib", rlibDir, rlibStdVariant)
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor", "librustvendor.rlib-std.rlib", rlibDir, rlibStdVariant)
- jsonFiles = append(jsonFiles,
- filepath.Join(rlibDir, "librustvendor_available.rlib.json"))
- jsonFiles = append(jsonFiles,
- filepath.Join(rlibDir, "librustvendor.rlib.json"))
-
- // For dylib libraries, all vendor:true and vendor_available modules (including VNDK) are captured.
- dylibVariant := fmt.Sprintf("android_vendor.29_%s_%s_dylib", archType, archVariant)
- dylibDir := filepath.Join(snapshotVariantPath, archDir, "dylib")
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor_available", "librustvendor_available.dylib.so", dylibDir, dylibVariant)
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor", "librustvendor.dylib.so", dylibDir, dylibVariant)
- jsonFiles = append(jsonFiles,
- filepath.Join(dylibDir, "librustvendor_available.dylib.so.json"))
- jsonFiles = append(jsonFiles,
- filepath.Join(dylibDir, "librustvendor.dylib.so.json"))
-
- // For binary executables, all vendor:true and vendor_available modules are captured.
- if archType == "arm64" {
- binaryVariant := fmt.Sprintf("android_vendor.29_%s_%s", archType, archVariant)
- binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "vendor_available_bin", "vendor_available_bin", binaryDir, binaryVariant)
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "vendor_bin", "vendor_bin", binaryDir, binaryVariant)
- jsonFiles = append(jsonFiles,
- filepath.Join(binaryDir, "vendor_available_bin.json"))
- jsonFiles = append(jsonFiles,
- filepath.Join(binaryDir, "vendor_bin.json"))
- }
- }
-
- for _, jsonFile := range jsonFiles {
- // verify all json files exist
- if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
- t.Errorf("%q expected but not found; #%v", jsonFile, jsonFiles)
- }
- }
-
- // fake snapshot should have all outputs in the normal snapshot.
- fakeSnapshotSingleton := ctx.SingletonForTests("vendor-fake-snapshot")
-
- for _, output := range snapshotSingleton.AllOutputs() {
- fakeOutput := strings.Replace(output, "/vendor-snapshot/", "/fake/vendor-snapshot/", 1)
- if fakeSnapshotSingleton.MaybeOutput(fakeOutput).Rule == nil {
- t.Errorf("%q expected but not found", fakeOutput)
- }
- }
-}
-
-func TestVendorSnapshotDirected(t *testing.T) {
- bp := `
- rust_ffi_shared {
- name: "libffivendor_available",
- crate_name: "ffivendor_available",
- srcs: ["lib.rs"],
- vendor_available: true,
- }
-
- rust_library {
- name: "librustvendor_available",
- crate_name: "rustvendor_available",
- srcs: ["lib.rs"],
- vendor_available: true,
- }
-
- rust_ffi_shared {
- name: "libffivendor_exclude",
- crate_name: "ffivendor_exclude",
- srcs: ["lib.rs"],
- vendor_available: true,
- }
-
- rust_library {
- name: "librustvendor_exclude",
- crate_name: "rustvendor_exclude",
- srcs: ["lib.rs"],
- vendor_available: true,
- }
-`
- ctx := testRustVndk(t, bp)
- ctx.Config().TestProductVariables.VendorSnapshotModules = make(map[string]bool)
- ctx.Config().TestProductVariables.VendorSnapshotModules["librustvendor_available"] = true
- ctx.Config().TestProductVariables.VendorSnapshotModules["libffivendor_available"] = true
- ctx.Config().TestProductVariables.DirectedVendorSnapshot = true
-
- // Check Vendor snapshot output.
-
- snapshotDir := "vendor-snapshot"
- snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
- snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
-
- var includeJsonFiles []string
-
- for _, arch := range [][]string{
- []string{"arm64", "armv8-a"},
- []string{"arm", "armv7-a-neon"},
- } {
- archType := arch[0]
- archVariant := arch[1]
- archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
-
- sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
- rlibVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_dylib-std", archType, archVariant)
- rlibRlibStdVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_rlib-std", archType, archVariant)
- sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
- rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib")
- dylibVariant := fmt.Sprintf("android_vendor.29_%s_%s_dylib", archType, archVariant)
- dylibDir := filepath.Join(snapshotVariantPath, archDir, "dylib")
-
- // Included modules
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor_available", "librustvendor_available.rlib", rlibDir, rlibVariant)
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor_available", "librustvendor_available.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor_available", "librustvendor_available.dylib.so", dylibDir, dylibVariant)
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "libffivendor_available", "libffivendor_available.so", sharedDir, sharedVariant)
- includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librustvendor_available.rlib.json"))
- includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librustvendor_available.rlib-std.rlib.json"))
- includeJsonFiles = append(includeJsonFiles, filepath.Join(dylibDir, "librustvendor_available.dylib.so.json"))
- includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libffivendor_available.so.json"))
-
- // Excluded modules. Modules not included in the directed vendor snapshot
- // are still include as fake modules.
- cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librustvendor_exclude", "librustvendor_exclude.rlib", rlibDir, rlibVariant)
- cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librustvendor_exclude", "librustvendor_exclude.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
- cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librustvendor_exclude", "librustvendor_exclude.dylib.so", dylibDir, dylibVariant)
- cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "libffivendor_exclude", "libffivendor_exclude.so", sharedDir, sharedVariant)
- includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librustvendor_exclude.rlib.json"))
- includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librustvendor_exclude.rlib-std.rlib.json"))
- includeJsonFiles = append(includeJsonFiles, filepath.Join(dylibDir, "librustvendor_exclude.dylib.so.json"))
- includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libffivendor_exclude.so.json"))
- }
-
- // Verify that each json file for an included module has a rule.
- for _, jsonFile := range includeJsonFiles {
- if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
- t.Errorf("include json file %q not found", jsonFile)
- }
- }
-}
-
-func TestVendorSnapshotExclude(t *testing.T) {
-
- // This test verifies that the exclude_from_vendor_snapshot property
- // makes its way from the Android.bp source file into the module data
- // structure. It also verifies that modules are correctly included or
- // excluded in the vendor snapshot based on their path (framework or
- // vendor) and the exclude_from_vendor_snapshot property.
-
- frameworkBp := `
- rust_ffi_shared {
- name: "libinclude",
- crate_name: "include",
- srcs: ["include.rs"],
- vendor_available: true,
- }
-
- rust_ffi_shared {
- name: "libexclude",
- crate_name: "exclude",
- srcs: ["exclude.rs"],
- vendor: true,
- exclude_from_vendor_snapshot: true,
- }
-
- rust_ffi_shared {
- name: "libavailable_exclude",
- crate_name: "available_exclude",
- srcs: ["lib.rs"],
- vendor_available: true,
- exclude_from_vendor_snapshot: true,
- }
-
- rust_library {
- name: "librust_include",
- crate_name: "rust_include",
- srcs: ["include.rs"],
- vendor_available: true,
- }
-
- rust_library {
- name: "librust_exclude",
- crate_name: "rust_exclude",
- srcs: ["exclude.rs"],
- vendor: true,
- exclude_from_vendor_snapshot: true,
- }
-
- rust_library {
- name: "librust_available_exclude",
- crate_name: "rust_available_exclude",
- srcs: ["lib.rs"],
- vendor_available: true,
- exclude_from_vendor_snapshot: true,
- }
- `
-
- mockFS := map[string][]byte{
- "framework/Android.bp": []byte(frameworkBp),
- "framework/include.rs": nil,
- "framework/exclude.rs": nil,
- }
-
- ctx := testRustVndkFs(t, "", mockFS)
-
- // Test an include and exclude framework module.
- cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "libinclude", false, sharedVendorVariant)
- cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "libexclude", true, sharedVendorVariant)
- cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "libavailable_exclude", true, sharedVendorVariant)
-
- cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_include", false, rlibVendorVariant)
- cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_exclude", true, rlibVendorVariant)
- cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_available_exclude", true, rlibVendorVariant)
-
- cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_include", false, rlibDylibStdVendorVariant)
- cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_exclude", true, rlibDylibStdVendorVariant)
- cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_available_exclude", true, rlibDylibStdVendorVariant)
-
- cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_include", false, dylibVendorVariant)
- cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_exclude", true, dylibVendorVariant)
- cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_available_exclude", true, dylibVendorVariant)
-
- // Verify the content of the vendor snapshot.
-
- snapshotDir := "vendor-snapshot"
- snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
- snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
-
- var includeJsonFiles []string
- var excludeJsonFiles []string
-
- for _, arch := range [][]string{
- []string{"arm64", "armv8-a"},
- []string{"arm", "armv7-a-neon"},
- } {
- archType := arch[0]
- archVariant := arch[1]
- archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
-
- sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
- sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
-
- rlibVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_dylib-std", archType, archVariant)
- rlibRlibStdVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_rlib-std", archType, archVariant)
- rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib")
- dylibVariant := fmt.Sprintf("android_vendor.29_%s_%s_dylib", archType, archVariant)
- dylibDir := filepath.Join(snapshotVariantPath, archDir, "dylib")
-
- // Included modules
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
- includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "librust_include", "librust_include.rlib", rlibDir, rlibVariant)
- includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librust_include.rlib.json"))
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "librust_include", "librust_include.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
- includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librust_include.rlib-std.rlib.json"))
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "librust_include", "librust_include.dylib.so", dylibDir, dylibVariant)
- includeJsonFiles = append(includeJsonFiles, filepath.Join(dylibDir, "librust_include.dylib.so.json"))
-
- // Excluded modules
- cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
- excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
- cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
- excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
- cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librust_exclude", "librust_exclude.rlib", rlibDir, rlibVariant)
- excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librust_exclude.rlib.json"))
- cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librust_available_exclude", "librust_available_exclude.rlib", rlibDir, rlibVariant)
- excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librust_available_exclude.rlib.json"))
- cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librust_available_exclude", "librust_available_exclude.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
- excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librust_available_exclude.rlib.rlib-std.json"))
- cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librust_exclude", "librust_exclude.dylib.so", dylibDir, dylibVariant)
- excludeJsonFiles = append(excludeJsonFiles, filepath.Join(dylibDir, "librust_exclude.dylib.so.json"))
- cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librust_available_exclude", "librust_available_exclude.dylib.so", dylibDir, dylibVariant)
- excludeJsonFiles = append(excludeJsonFiles, filepath.Join(dylibDir, "librust_available_exclude.dylib.so.json"))
- }
-
- // Verify that each json file for an included module has a rule.
- for _, jsonFile := range includeJsonFiles {
- if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
- t.Errorf("include json file %q not found", jsonFile)
- }
- }
-
- // Verify that each json file for an excluded module has no rule.
- for _, jsonFile := range excludeJsonFiles {
- if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
- t.Errorf("exclude json file %q found", jsonFile)
- }
- }
-}
-
-func TestVendorSnapshotUse(t *testing.T) {
- frameworkBp := `
- cc_library {
- name: "libvndk",
- vendor_available: true,
- product_available: true,
- vndk: {
- enabled: true,
- },
- nocrt: true,
- }
-
- cc_library {
- name: "libvendor",
- vendor: true,
- nocrt: true,
- no_libcrt: true,
- stl: "none",
- system_shared_libs: [],
- }
-
- cc_library {
- name: "libvendor_available",
- vendor_available: true,
- nocrt: true,
- no_libcrt: true,
- stl: "none",
- system_shared_libs: [],
- }
-
- cc_library {
- name: "lib32",
- vendor: true,
- nocrt: true,
- no_libcrt: true,
- stl: "none",
- system_shared_libs: [],
- compile_multilib: "32",
- }
-
- cc_library {
- name: "lib64",
- vendor: true,
- nocrt: true,
- no_libcrt: true,
- stl: "none",
- system_shared_libs: [],
- compile_multilib: "64",
- }
-
- rust_binary {
- name: "bin",
- vendor: true,
- srcs: ["bin.rs"],
- }
-
- rust_binary {
- name: "bin32",
- vendor: true,
- compile_multilib: "32",
- srcs: ["bin.rs"],
- }
-
- rust_library {
- name: "librust_vendor_available",
- crate_name: "rust_vendor",
- vendor_available: true,
- srcs: ["client.rs"],
- }
-
-`
-
- vndkBp := `
- vndk_prebuilt_shared {
- name: "libvndk",
- version: "30",
- target_arch: "arm64",
- vendor_available: true,
- product_available: true,
- vndk: {
- enabled: true,
- },
- arch: {
- arm64: {
- srcs: ["libvndk.so"],
- export_include_dirs: ["include/libvndk"],
- },
- arm: {
- srcs: ["libvndk.so"],
- export_include_dirs: ["include/libvndk"],
- },
- },
- }
-
- // old snapshot module which has to be ignored
- vndk_prebuilt_shared {
- name: "libvndk",
- version: "26",
- target_arch: "arm64",
- vendor_available: true,
- product_available: true,
- vndk: {
- enabled: true,
- },
- arch: {
- arm64: {
- srcs: ["libvndk.so"],
- export_include_dirs: ["include/libvndk"],
- },
- arm: {
- srcs: ["libvndk.so"],
- export_include_dirs: ["include/libvndk"],
- },
- },
- }
-
- // different arch snapshot which has to be ignored
- vndk_prebuilt_shared {
- name: "libvndk",
- version: "30",
- target_arch: "arm",
- vendor_available: true,
- product_available: true,
- vndk: {
- enabled: true,
- },
- arch: {
- arm: {
- srcs: ["libvndk.so"],
- export_include_dirs: ["include/libvndk"],
- },
- },
- }
-`
-
- vendorProprietaryBp := `
- cc_library {
- name: "libvendor_without_snapshot",
- vendor: true,
- nocrt: true,
- no_libcrt: true,
- no_crt_pad_segment: true,
- stl: "none",
- system_shared_libs: [],
- }
-
- rust_ffi_shared {
- name: "libclient",
- crate_name: "client",
- vendor: true,
- shared_libs: ["libvndk", "libvendor_available"],
- static_libs: ["libvendor", "libvendor_without_snapshot"],
- rustlibs: ["librust_vendor_available"],
- arch: {
- arm64: {
- shared_libs: ["lib64"],
- },
- arm: {
- shared_libs: ["lib32"],
- },
- },
- srcs: ["client.rs"],
- }
-
- rust_library {
- name: "libclient_rust",
- crate_name: "client_rust",
- vendor: true,
- shared_libs: ["libvndk", "libvendor_available"],
- static_libs: ["libvendor", "libvendor_without_snapshot"],
- rustlibs: ["librust_vendor_available"],
- arch: {
- arm64: {
- shared_libs: ["lib64"],
- },
- arm: {
- shared_libs: ["lib32"],
- },
- },
- srcs: ["client.rs"],
- }
-
- rust_binary {
- name: "bin_without_snapshot",
- vendor: true,
- static_libs: ["libvndk"],
- srcs: ["bin.rs"],
- rustlibs: ["librust_vendor_available"],
- }
-
- vendor_snapshot {
- name: "vendor_snapshot",
- version: "30",
- arch: {
- arm64: {
- vndk_libs: [
- "libvndk",
- ],
- static_libs: [
- "libvendor",
- "libvndk",
- "libclang_rt.builtins",
- "note_memtag_heap_sync",
- ],
- shared_libs: [
- "libvendor_available",
- "lib64",
- ],
- rlibs: [
- "libstd",
- "librust_vendor_available",
- "librust_vendor_available.rlib-std"
- ],
- dylibs: [
- "libstd",
- "librust_vendor_available",
- ],
- binaries: [
- "bin",
- ],
- objects: [
- "crtend_so",
- "crtbegin_so",
- "crtbegin_dynamic",
- "crtend_android"
- ],
- },
- arm: {
- vndk_libs: [
- "libvndk",
- ],
- static_libs: [
- "libvendor",
- "libvndk",
- "libclang_rt.builtins",
- ],
- shared_libs: [
- "libvendor_available",
- "lib32",
- ],
- rlibs: [
- "libstd",
- "librust_vendor_available",
- ],
- dylibs: [
- "libstd",
- "librust_vendor_available",
- ],
- binaries: [
- "bin32",
- ],
- objects: [
- "crtend_so",
- "crtbegin_so",
- "crtbegin_dynamic",
- "crtend_android"
- ],
-
- },
- }
- }
-
- vendor_snapshot_object {
- name: "crtend_so",
- version: "30",
- target_arch: "arm64",
- vendor: true,
- stl: "none",
- crt: true,
- arch: {
- arm64: {
- src: "crtend_so.o",
- },
- arm: {
- src: "crtend_so.o",
- },
- },
- }
-
- vendor_snapshot_object {
- name: "crtbegin_so",
- version: "30",
- target_arch: "arm64",
- vendor: true,
- stl: "none",
- crt: true,
- arch: {
- arm64: {
- src: "crtbegin_so.o",
- },
- arm: {
- src: "crtbegin_so.o",
- },
- },
- }
-
- vendor_snapshot_rlib {
- name: "libstd",
- version: "30",
- target_arch: "arm64",
- vendor: true,
- sysroot: true,
- arch: {
- arm64: {
- src: "libstd.rlib",
- },
- arm: {
- src: "libstd.rlib",
- },
- },
- }
-
- vendor_snapshot_rlib {
- name: "librust_vendor_available",
- version: "30",
- target_arch: "arm64",
- vendor: true,
- arch: {
- arm64: {
- src: "librust_vendor_available.rlib",
- },
- arm: {
- src: "librust_vendor_available.rlib",
- },
- },
- }
-
- vendor_snapshot_rlib {
- name: "librust_vendor_available.rlib-std",
- version: "30",
- target_arch: "arm64",
- vendor: true,
- arch: {
- arm64: {
- src: "librust_vendor_available.rlib-std.rlib",
- },
- arm: {
- src: "librust_vendor_available.rlib-std.rlib",
- },
- },
- }
-
- vendor_snapshot_dylib {
- name: "libstd",
- version: "30",
- target_arch: "arm64",
- vendor: true,
- sysroot: true,
- arch: {
- arm64: {
- src: "libstd.dylib.so",
- },
- arm: {
- src: "libstd.dylib.so",
- },
- },
- }
-
- vendor_snapshot_dylib {
- name: "librust_vendor_available",
- version: "30",
- target_arch: "arm64",
- vendor: true,
- arch: {
- arm64: {
- src: "librust_vendor_available.dylib.so",
- },
- arm: {
- src: "librust_vendor_available.dylib.so",
- },
- },
- }
-
- vendor_snapshot_object {
- name: "crtend_android",
- version: "30",
- target_arch: "arm64",
- vendor: true,
- stl: "none",
- crt: true,
- arch: {
- arm64: {
- src: "crtend_so.o",
- },
- arm: {
- src: "crtend_so.o",
- },
- },
- }
-
- vendor_snapshot_object {
- name: "crtbegin_dynamic",
- version: "30",
- target_arch: "arm64",
- vendor: true,
- stl: "none",
- crt: true,
- arch: {
- arm64: {
- src: "crtbegin_so.o",
- },
- arm: {
- src: "crtbegin_so.o",
- },
- },
- }
-
- vendor_snapshot_static {
- name: "libvndk",
- version: "30",
- target_arch: "arm64",
- compile_multilib: "both",
- vendor: true,
- arch: {
- arm64: {
- src: "libvndk.a",
- },
- arm: {
- src: "libvndk.a",
- },
- },
- shared_libs: ["libvndk"],
- export_shared_lib_headers: ["libvndk"],
- }
-
- vendor_snapshot_static {
- name: "libclang_rt.builtins",
- version: "30",
- target_arch: "arm64",
- vendor: true,
- arch: {
- arm: {
- src: "libclang_rt.builtins-arm-android.a",
- },
- arm64: {
- src: "libclang_rt.builtins-aarch64-android.a",
- },
- },
- }
-
- vendor_snapshot_shared {
- name: "lib32",
- version: "30",
- target_arch: "arm64",
- compile_multilib: "32",
- vendor: true,
- no_crt_pad_segment: true,
- arch: {
- arm: {
- src: "lib32.so",
- },
- },
- }
-
- vendor_snapshot_shared {
- name: "lib64",
- version: "30",
- target_arch: "arm64",
- compile_multilib: "64",
- vendor: true,
- no_crt_pad_segment: true,
- arch: {
- arm64: {
- src: "lib64.so",
- },
- },
- }
- vendor_snapshot_shared {
- name: "liblog",
- version: "30",
- target_arch: "arm64",
- compile_multilib: "64",
- vendor: true,
- no_crt_pad_segment: true,
- arch: {
- arm64: {
- src: "liblog.so",
- },
- },
- }
-
- vendor_snapshot_static {
- name: "libvendor",
- version: "30",
- target_arch: "arm64",
- compile_multilib: "both",
- vendor: true,
- arch: {
- arm64: {
- src: "libvendor.a",
- export_include_dirs: ["include/libvendor"],
- },
- arm: {
- src: "libvendor.a",
- export_include_dirs: ["include/libvendor"],
- },
- },
- }
-
- vendor_snapshot_shared {
- name: "libvendor_available",
- version: "30",
- target_arch: "arm64",
- compile_multilib: "both",
- vendor: true,
- no_crt_pad_segment: true,
- arch: {
- arm64: {
- src: "libvendor_available.so",
- export_include_dirs: ["include/libvendor"],
- },
- arm: {
- src: "libvendor_available.so",
- export_include_dirs: ["include/libvendor"],
- },
- },
- }
-
- vendor_snapshot_binary {
- name: "bin",
- version: "30",
- target_arch: "arm64",
- compile_multilib: "64",
- vendor: true,
- arch: {
- arm64: {
- src: "bin",
- },
- },
- }
-
- vendor_snapshot_binary {
- name: "bin32",
- version: "30",
- target_arch: "arm64",
- compile_multilib: "32",
- vendor: true,
- arch: {
- arm: {
- src: "bin32",
- },
- },
- }
-
- // Test sanitizers use the snapshot libraries
- rust_binary {
- name: "memtag_binary",
- srcs: ["vendor/bin.rs"],
- vendor: true,
- compile_multilib: "64",
- sanitize: {
- memtag_heap: true,
- diag: {
- memtag_heap: true,
- }
- },
- }
-
- // old snapshot module which has to be ignored
- vendor_snapshot_binary {
- name: "bin",
- version: "26",
- target_arch: "arm64",
- compile_multilib: "first",
- vendor: true,
- arch: {
- arm64: {
- src: "bin",
- },
- },
- }
-
- // different arch snapshot which has to be ignored
- vendor_snapshot_binary {
- name: "bin",
- version: "30",
- target_arch: "arm",
- compile_multilib: "first",
- vendor: true,
- arch: {
- arm64: {
- src: "bin",
- },
- },
- }
-
- vendor_snapshot_static {
- name: "note_memtag_heap_sync",
- vendor: true,
- target_arch: "arm64",
- version: "30",
- arch: {
- arm64: {
- src: "note_memtag_heap_sync.a",
- },
- },
- }
-
-`
-
- mockFS := android.MockFS{
- "framework/Android.bp": []byte(frameworkBp),
- "framework/bin.rs": nil,
- "note_memtag_heap_sync.a": nil,
- "vendor/Android.bp": []byte(vendorProprietaryBp),
- "vendor/bin": nil,
- "vendor/bin32": nil,
- "vendor/bin.rs": nil,
- "vendor/client.rs": nil,
- "vendor/include/libvndk/a.h": nil,
- "vendor/include/libvendor/b.h": nil,
- "vendor/libvndk.a": nil,
- "vendor/libvendor.a": nil,
- "vendor/libvendor.so": nil,
- "vendor/lib32.so": nil,
- "vendor/lib64.so": nil,
- "vendor/liblog.so": nil,
- "vendor/libstd.rlib": nil,
- "vendor/librust_vendor_available.rlib": nil,
- "vendor/librust_vendor_available.rlib-std.rlib": nil,
- "vendor/libstd.dylib.so": nil,
- "vendor/librust_vendor_available.dylib.so": nil,
- "vendor/crtbegin_so.o": nil,
- "vendor/crtend_so.o": nil,
- "vendor/libclang_rt.builtins-aarch64-android.a": nil,
- "vendor/libclang_rt.builtins-arm-android.a": nil,
- "vndk/Android.bp": []byte(vndkBp),
- "vndk/include/libvndk/a.h": nil,
- "vndk/libvndk.so": nil,
- }
-
- sharedVariant := "android_vendor.30_arm64_armv8-a_shared"
- rlibVariant := "android_vendor.30_arm64_armv8-a_rlib_dylib-std"
- rlibRlibStdVariant := "android_vendor.30_arm64_armv8-a_rlib_rlib-std"
- dylibVariant := "android_vendor.30_arm64_armv8-a_dylib"
- staticVariant := "android_vendor.30_arm64_armv8-a_static"
- binaryVariant := "android_vendor.30_arm64_armv8-a"
-
- shared32Variant := "android_vendor.30_arm_armv7-a-neon_shared"
- binary32Variant := "android_vendor.30_arm_armv7-a-neon"
-
- ctx := testRustVndkFsVersions(t, "", mockFS, "30", "current", "31")
-
- // libclient uses libvndk.vndk.30.arm64, libvendor.vendor_static.30.arm64, libvendor_without_snapshot
- libclientLdFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("rustc").Args["linkFlags"]
- for _, input := range [][]string{
- []string{sharedVariant, "libvndk.vndk.30.arm64"},
- []string{staticVariant, "libvendor.vendor_static.30.arm64"},
- []string{staticVariant, "libvendor_without_snapshot"},
- } {
- outputPaths := cc.GetOutputPaths(ctx, input[0] /* variant */, []string{input[1]} /* module name */)
- if !strings.Contains(libclientLdFlags, outputPaths[0].String()) {
- t.Errorf("libflags for libclient must contain %#v, but was %#v", outputPaths[0], libclientLdFlags)
- }
- }
-
- libclientAndroidMkSharedLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).transitiveAndroidMkSharedLibs.ToList()
- if g, w := libclientAndroidMkSharedLibs, []string{"libvndk.vendor", "libvendor_available.vendor", "lib64", "liblog.vendor", "libc.vendor", "libm.vendor", "libdl.vendor"}; !reflect.DeepEqual(g, w) {
- t.Errorf("wanted libclient AndroidMkSharedLibs %q, got %q", w, g)
- }
-
- libclientAndroidMkStaticLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkStaticLibs
- if g, w := libclientAndroidMkStaticLibs, []string{"libvendor", "libvendor_without_snapshot", "libclang_rt.builtins.vendor"}; !reflect.DeepEqual(g, w) {
- t.Errorf("wanted libclient AndroidMkStaticLibs %q, got %q", w, g)
- }
-
- libclientAndroidMkDylibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkDylibs
- if g, w := libclientAndroidMkDylibs, []string{"librust_vendor_available.vendor", "libstd.vendor"}; !reflect.DeepEqual(g, w) {
- t.Errorf("wanted libclient libclientAndroidMkDylibs %q, got %q", w, libclientAndroidMkDylibs)
- }
-
- libclient32AndroidMkSharedLibs := ctx.ModuleForTests("libclient", shared32Variant).Module().(*Module).transitiveAndroidMkSharedLibs.ToList()
- if g, w := libclient32AndroidMkSharedLibs, []string{"libvndk.vendor", "libvendor_available.vendor", "lib32", "liblog.vendor", "libc.vendor", "libm.vendor", "libdl.vendor"}; !reflect.DeepEqual(g, w) {
- t.Errorf("wanted libclient32 AndroidMkSharedLibs %q, got %q", w, g)
- }
-
- libclientRustAndroidMkRlibs := ctx.ModuleForTests("libclient_rust", rlibVariant).Module().(*Module).Properties.AndroidMkRlibs
- if g, w := libclientRustAndroidMkRlibs, []string{"librust_vendor_available.vendor"}; !reflect.DeepEqual(g, w) {
- t.Errorf("wanted rlib libclient libclientAndroidMkRlibs %q, got %q", w, g)
- }
-
- libclientRlibStdRustAndroidMkRlibs := ctx.ModuleForTests("libclient_rust", rlibRlibStdVariant).Module().(*Module).Properties.AndroidMkRlibs
- if g, w := libclientRlibStdRustAndroidMkRlibs, []string{"librust_vendor_available.vendor.rlib-std", "libstd.vendor"}; !reflect.DeepEqual(g, w) {
- t.Errorf("wanted rlib libclient libclientAndroidMkRlibs %q, got %q", w, g)
- }
-
- libclientRustDylibAndroidMkDylibs := ctx.ModuleForTests("libclient_rust", dylibVariant).Module().(*Module).Properties.AndroidMkDylibs
- if g, w := libclientRustDylibAndroidMkDylibs, []string{"librust_vendor_available.vendor", "libstd.vendor"}; !reflect.DeepEqual(g, w) {
- t.Errorf("wanted dylib libclient libclientRustDylibAndroidMkDylibs %q, got %q", w, g)
- }
-
- // rust vendor snapshot must have ".vendor" suffix in AndroidMk
- librustVendorAvailableSnapshotModule := ctx.ModuleForTests("librust_vendor_available.vendor_rlib.30.arm64", rlibVariant).Module()
- librustVendorSnapshotMkName := android.AndroidMkEntriesForTest(t, ctx, librustVendorAvailableSnapshotModule)[0].EntryMap["LOCAL_MODULE"][0]
- expectedRustVendorSnapshotName := "librust_vendor_available.vendor"
- if librustVendorSnapshotMkName != expectedRustVendorSnapshotName {
- t.Errorf("Unexpected rust vendor snapshot name in AndroidMk: %q, expected: %q\n", librustVendorSnapshotMkName, expectedRustVendorSnapshotName)
- }
-
- librustVendorAvailableDylibSnapshotModule := ctx.ModuleForTests("librust_vendor_available.vendor_dylib.30.arm64", dylibVariant).Module()
- librustVendorSnapshotDylibMkName := android.AndroidMkEntriesForTest(t, ctx, librustVendorAvailableDylibSnapshotModule)[0].EntryMap["LOCAL_MODULE"][0]
- expectedRustVendorDylibSnapshotName := "librust_vendor_available.vendor"
- if librustVendorSnapshotDylibMkName != expectedRustVendorDylibSnapshotName {
- t.Errorf("Unexpected rust vendor snapshot name in AndroidMk: %q, expected: %q\n", librustVendorSnapshotDylibMkName, expectedRustVendorDylibSnapshotName)
- }
-
- rustVendorBinModule := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Module()
- rustVendorBinMkDylibName := android.AndroidMkEntriesForTest(t, ctx, rustVendorBinModule)[0].EntryMap["LOCAL_DYLIB_LIBRARIES"][0]
- if rustVendorBinMkDylibName != expectedRustVendorSnapshotName {
- t.Errorf("Unexpected rust rlib name in AndroidMk: %q, expected: %q\n", rustVendorBinMkDylibName, expectedRustVendorSnapshotName)
- }
-
- binWithoutSnapshotLdFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("rustc").Args["linkFlags"]
- libVndkStaticOutputPaths := cc.GetOutputPaths(ctx, staticVariant, []string{"libvndk.vendor_static.30.arm64"})
- if !strings.Contains(binWithoutSnapshotLdFlags, libVndkStaticOutputPaths[0].String()) {
- t.Errorf("libflags for bin_without_snapshot must contain %#v, but was %#v",
- libVndkStaticOutputPaths[0], binWithoutSnapshotLdFlags)
- }
-
- // bin is installed by bin.vendor_binary.30.arm64
- ctx.ModuleForTests("bin.vendor_binary.30.arm64", binaryVariant).Output("bin")
-
- // bin32 is installed by bin32.vendor_binary.30.arm64
- ctx.ModuleForTests("bin32.vendor_binary.30.arm64", binary32Variant).Output("bin32")
-
- // bin_without_snapshot is installed by bin_without_snapshot
- ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Output("bin_without_snapshot")
-
- // libvendor, libvendor_available and bin don't have vendor.30 variant
- libvendorVariants := ctx.ModuleVariantsForTests("libvendor")
- if android.InList(sharedVariant, libvendorVariants) {
- t.Errorf("libvendor must not have variant %#v, but it does", sharedVariant)
- }
-
- libvendorAvailableVariants := ctx.ModuleVariantsForTests("libvendor_available")
- if android.InList(sharedVariant, libvendorAvailableVariants) {
- t.Errorf("libvendor_available must not have variant %#v, but it does", sharedVariant)
- }
-
- binVariants := ctx.ModuleVariantsForTests("bin")
- if android.InList(binaryVariant, binVariants) {
- t.Errorf("bin must not have variant %#v, but it does", sharedVariant)
- }
-
- memtagStaticLibs := ctx.ModuleForTests("memtag_binary", "android_vendor.30_arm64_armv8-a").Module().(*Module).Properties.AndroidMkStaticLibs
- if g, w := memtagStaticLibs, []string{"libclang_rt.builtins.vendor", "note_memtag_heap_sync.vendor"}; !reflect.DeepEqual(g, w) {
- t.Errorf("wanted memtag_binary AndroidMkStaticLibs %q, got %q", w, g)
- }
-}
-
-func TestRecoverySnapshotCapture(t *testing.T) {
- bp := `
- rust_ffi {
- name: "librecovery",
- recovery: true,
- srcs: ["foo.rs"],
- crate_name: "recovery",
- }
-
- rust_ffi {
- name: "librecovery_available",
- recovery_available: true,
- srcs: ["foo.rs"],
- crate_name: "recovery_available",
- }
-
- rust_library {
- name: "librecovery_rustlib",
- recovery: true,
- srcs: ["foo.rs"],
- crate_name: "recovery_rustlib",
- }
-
- rust_library {
- name: "librecovery_available_rustlib",
- recovery_available: true,
- srcs: ["foo.rs"],
- crate_name: "recovery_available_rustlib",
- }
-
- rust_binary {
- name: "recovery_bin",
- recovery: true,
- srcs: ["foo.rs"],
- }
-
- rust_binary {
- name: "recovery_available_bin",
- recovery_available: true,
- srcs: ["foo.rs"],
- }
-
-`
- // Check Recovery snapshot output.
-
- ctx := testRustRecoveryFsVersions(t, bp, rustMockedFiles, "", "29", "current")
- snapshotDir := "recovery-snapshot"
- snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
- snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
-
- var jsonFiles []string
-
- for _, arch := range [][]string{
- []string{"arm64", "armv8-a"},
- } {
- archType := arch[0]
- archVariant := arch[1]
- archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
-
- // For shared libraries, all recovery:true and recovery_available modules are captured.
- sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
- sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
- jsonFiles = append(jsonFiles,
- filepath.Join(sharedDir, "librecovery.so.json"),
- filepath.Join(sharedDir, "librecovery_available.so.json"))
-
- // For static libraries, all recovery:true and recovery_available modules are captured.
- staticVariant := fmt.Sprintf("android_recovery_%s_%s_static", archType, archVariant)
- staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.a", staticDir, staticVariant)
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.a", staticDir, staticVariant)
- jsonFiles = append(jsonFiles,
- filepath.Join(staticDir, "librecovery.a.json"),
- filepath.Join(staticDir, "librecovery_available.a.json"))
-
- // For rlib libraries, all recovery:true and recovery_available modules are captured.
- rlibVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_dylib-std", archType, archVariant)
- rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib")
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.rlib", rlibDir, rlibVariant)
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available_rustlib", "librecovery_available_rustlib.rlib", rlibDir, rlibVariant)
- jsonFiles = append(jsonFiles,
- filepath.Join(rlibDir, "librecovery_rustlib.rlib.json"),
- filepath.Join(rlibDir, "librecovery_available_rustlib.rlib.json"))
-
- rlibRlibStdVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_rlib-std", archType, archVariant)
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available_rustlib", "librecovery_available_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
- jsonFiles = append(jsonFiles,
- filepath.Join(rlibDir, "librecovery_rustlib.rlib-std.rlib.json"),
- filepath.Join(rlibDir, "librecovery_available_rustlib.rlib-std.rlib.json"))
-
- // For dylib libraries, all recovery:true and recovery_available modules are captured.
- dylibVariant := fmt.Sprintf("android_recovery_%s_%s_dylib", archType, archVariant)
- dylibDir := filepath.Join(snapshotVariantPath, archDir, "dylib")
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.dylib.so", dylibDir, dylibVariant)
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available_rustlib", "librecovery_available_rustlib.dylib.so", dylibDir, dylibVariant)
- jsonFiles = append(jsonFiles,
- filepath.Join(dylibDir, "librecovery_rustlib.dylib.so.json"),
- filepath.Join(dylibDir, "librecovery_available_rustlib.dylib.so.json"))
-
- // For binary executables, all recovery:true and recovery_available modules are captured.
- if archType == "arm64" {
- binaryVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
- binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "recovery_bin", "recovery_bin", binaryDir, binaryVariant)
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "recovery_available_bin", "recovery_available_bin", binaryDir, binaryVariant)
- jsonFiles = append(jsonFiles,
- filepath.Join(binaryDir, "recovery_bin.json"),
- filepath.Join(binaryDir, "recovery_available_bin.json"))
- }
- }
-
- for _, jsonFile := range jsonFiles {
- // verify all json files exist
- if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
- t.Errorf("%q expected but not found", jsonFile)
- }
- }
-}
-
-func TestRecoverySnapshotExclude(t *testing.T) {
- // This test verifies that the exclude_from_recovery_snapshot property
- // makes its way from the Android.bp source file into the module data
- // structure. It also verifies that modules are correctly included or
- // excluded in the recovery snapshot based on their path (framework or
- // vendor) and the exclude_from_recovery_snapshot property.
-
- frameworkBp := `
- rust_ffi_shared {
- name: "libinclude",
- srcs: ["src/include.rs"],
- recovery_available: true,
- crate_name: "include",
- }
- rust_ffi_shared {
- name: "libexclude",
- srcs: ["src/exclude.rs"],
- recovery: true,
- exclude_from_recovery_snapshot: true,
- crate_name: "exclude",
- }
- rust_ffi_shared {
- name: "libavailable_exclude",
- srcs: ["src/exclude.rs"],
- recovery_available: true,
- exclude_from_recovery_snapshot: true,
- crate_name: "available_exclude",
- }
- rust_library {
- name: "libinclude_rustlib",
- srcs: ["src/include.rs"],
- recovery_available: true,
- crate_name: "include_rustlib",
- }
- rust_library {
- name: "libexclude_rustlib",
- srcs: ["src/exclude.rs"],
- recovery: true,
- exclude_from_recovery_snapshot: true,
- crate_name: "exclude_rustlib",
- }
- rust_library {
- name: "libavailable_exclude_rustlib",
- srcs: ["src/exclude.rs"],
- recovery_available: true,
- exclude_from_recovery_snapshot: true,
- crate_name: "available_exclude_rustlib",
- }
- `
-
- vendorProprietaryBp := `
- rust_ffi_shared {
- name: "librecovery",
- srcs: ["recovery.rs"],
- recovery: true,
- crate_name: "recovery",
- }
- rust_library {
- name: "librecovery_rustlib",
- srcs: ["recovery.rs"],
- recovery: true,
- crate_name: "recovery_rustlib",
- }
- `
-
- mockFS := map[string][]byte{
- "framework/Android.bp": []byte(frameworkBp),
- "framework/include.rs": nil,
- "framework/exclude.rs": nil,
- "device/Android.bp": []byte(vendorProprietaryBp),
- "device/recovery.rs": nil,
- }
-
- ctx := testRustRecoveryFsVersions(t, "", mockFS, "", "29", "current")
-
- // Test an include and exclude framework module.
- cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude", false, sharedRecoveryVariant)
- cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude", true, sharedRecoveryVariant)
- cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude", true, sharedRecoveryVariant)
-
- cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude_rustlib", false, rlibRecoveryVariant)
- cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude_rustlib", true, rlibRecoveryVariant)
- cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude_rustlib", true, rlibRlibStdRecoveryVariant)
-
- cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude_rustlib", false, rlibRlibStdRecoveryVariant)
- cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude_rustlib", true, rlibRlibStdRecoveryVariant)
- cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude_rustlib", true, rlibRlibStdRecoveryVariant)
-
- cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude_rustlib", false, dylibRecoveryVariant)
- cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude_rustlib", true, dylibRecoveryVariant)
- cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude_rustlib", true, dylibRecoveryVariant)
-
- // A recovery module is excluded, but by its path not the exclude_from_recovery_snapshot property
- // ('device/' and 'vendor/' are default excluded). See snapshot/recovery_snapshot.go for more detail.
- cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery", false, sharedRecoveryVariant)
- cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery_rustlib", false, rlibRecoveryVariant)
- cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery_rustlib", false, rlibRlibStdRecoveryVariant)
- cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery_rustlib", false, dylibRecoveryVariant)
-
- // Verify the content of the recovery snapshot.
-
- snapshotDir := "recovery-snapshot"
- snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
- snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
-
- var includeJsonFiles []string
- var excludeJsonFiles []string
-
- for _, arch := range [][]string{
- []string{"arm64", "armv8-a"},
- } {
- archType := arch[0]
- archVariant := arch[1]
- archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
-
- sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
- rlibVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_dylib-std", archType, archVariant)
- rlibRlibStdVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_rlib-std", archType, archVariant)
- dylibVariant := fmt.Sprintf("android_recovery_%s_%s_dylib", archType, archVariant)
- sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
- rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib")
- dylibDir := filepath.Join(snapshotVariantPath, archDir, "dylib")
-
- // Included modules
-
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
- includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "libinclude_rustlib", "libinclude_rustlib.rlib", rlibDir, rlibVariant)
- includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "libinclude_rustlib.rlib.json"))
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "libinclude_rustlib", "libinclude_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
- includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "libinclude_rustlib.rlib-std.rlib.json"))
-
- // Excluded modules
- cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
- excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
- cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
- excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
- cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
- excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
-
- cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude_rustlib", "libexclude_rustlib.rlib", rlibDir, rlibVariant)
- excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libexclude_rustlib.rlib.json"))
- cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.rlib", rlibDir, rlibVariant)
- excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librecovery_rustlib.rlib.json"))
- cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude_rustlib", "libavailable_exclude_rustlib.rlib", rlibDir, rlibVariant)
- excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libavailable_exclude_rustlib.rlib.json"))
-
- cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude_rustlib", "libexclude_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
- excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libexclude_rustlib.rlib-std.rlib.json"))
- cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
- excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librecovery_rustlib.rlib-std.rlib.json"))
- cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude_rustlib", "libavailable_exclude_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
- excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libavailable_exclude_rustlib.rlib-std.rlib.json"))
-
- cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude_rustlib", "libexclude_rustlib.dylib.so", dylibDir, dylibVariant)
- excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libexclude_rustlib.dylib.so.json"))
- cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.dylib.so", dylibDir, dylibVariant)
- excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librecovery_rustlib.dylib.so.json"))
- cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude_rustlib", "libavailable_exclude_rustlib.dylib.so", dylibDir, dylibVariant)
- excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libavailable_exclude_rustlib.dylib.so.json"))
- }
-
- // Verify that each json file for an included module has a rule.
- for _, jsonFile := range includeJsonFiles {
- if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
- t.Errorf("include json file %q not found", jsonFile)
- }
- }
-
- // Verify that each json file for an excluded module has no rule.
- for _, jsonFile := range excludeJsonFiles {
- if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
- t.Errorf("exclude json file %q found", jsonFile)
- }
- }
-}
-
-func TestRecoverySnapshotDirected(t *testing.T) {
- bp := `
- rust_ffi_shared {
- name: "librecovery",
- recovery: true,
- crate_name: "recovery",
- srcs: ["foo.rs"],
- }
-
- rust_ffi_shared {
- name: "librecovery_available",
- recovery_available: true,
- crate_name: "recovery_available",
- srcs: ["foo.rs"],
- }
-
- rust_library {
- name: "librecovery_rustlib",
- recovery: true,
- crate_name: "recovery",
- srcs: ["foo.rs"],
- }
-
- rust_library {
- name: "librecovery_available_rustlib",
- recovery_available: true,
- crate_name: "recovery_available",
- srcs: ["foo.rs"],
- }
-
- /* TODO: Uncomment when Rust supports the "prefer" property for prebuilts
- rust_library_rlib {
- name: "libfoo_rlib",
- recovery: true,
- crate_name: "foo",
- }
-
- rust_prebuilt_rlib {
- name: "libfoo_rlib",
- recovery: true,
- prefer: true,
- srcs: ["libfoo.rlib"],
- crate_name: "foo",
- }
- */
-`
- ctx := testRustRecoveryFsVersions(t, bp, rustMockedFiles, "current", "29", "current")
- ctx.Config().TestProductVariables.RecoverySnapshotModules = make(map[string]bool)
- ctx.Config().TestProductVariables.RecoverySnapshotModules["librecovery"] = true
- ctx.Config().TestProductVariables.RecoverySnapshotModules["librecovery_rustlib"] = true
- ctx.Config().TestProductVariables.DirectedRecoverySnapshot = true
-
- // Check recovery snapshot output.
- snapshotDir := "recovery-snapshot"
- snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
- snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
-
- var includeJsonFiles []string
-
- for _, arch := range [][]string{
- []string{"arm64", "armv8-a"},
- } {
- archType := arch[0]
- archVariant := arch[1]
- archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
-
- sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
- rlibVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_dylib-std", archType, archVariant)
- rlibRlibStdVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_rlib-std", archType, archVariant)
- dylibVariant := fmt.Sprintf("android_recovery_%s_%s_dylib", archType, archVariant)
- sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
- rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib")
- dylibDir := filepath.Join(snapshotVariantPath, archDir, "dylib")
-
- // Included modules
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
- includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.rlib", rlibDir, rlibVariant)
- includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librecovery_rustlib.rlib.json"))
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
- includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librecovery_rustlib.rlib-std.rlib.json"))
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.dylib.so", dylibDir, dylibVariant)
- includeJsonFiles = append(includeJsonFiles, filepath.Join(dylibDir, "librecovery_rustlib.dylib.so.json"))
-
- // TODO: When Rust supports the "prefer" property for prebuilts, perform this check.
- /*
- // Check that snapshot captures "prefer: true" prebuilt
- cc.CheckSnapshot(t, ctx, snapshotSingleton, "prebuilt_libfoo_rlib", "libfoo_rlib.rlib", rlibDir, rlibVariant)
- includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libfoo_rlib.rlib.json"))
- */
-
- // Excluded modules. Modules not included in the directed recovery snapshot
- // are still included as fake modules.
- cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
- includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery_available.so.json"))
- cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available_rustlib", "librecovery_available_rustlib.rlib", rlibDir, rlibVariant)
- includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librecovery_available_rustlib.rlib.json"))
- cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available_rustlib", "librecovery_available_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
- includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librecovery_available_rustlib.rlib-std.rlib.json"))
- cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available_rustlib", "librecovery_available_rustlib.dylib.so", dylibDir, dylibVariant)
- includeJsonFiles = append(includeJsonFiles, filepath.Join(dylibDir, "librecovery_available_rustlib.dylib.so.json"))
- }
-
- // Verify that each json file for an included module has a rule.
- for _, jsonFile := range includeJsonFiles {
- if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
- t.Errorf("include json file %q not found, %#v", jsonFile, includeJsonFiles)
- }
- }
-}