Implement directed vendor snapshot

Vendors can now generate only needed modules by setting the following
Makefile variables:

- DIRECTED_VENDOR_SNAPSHOT: set to true
- VENDOR_SNAPSHOT_MODULES: list of snapshot candidates

e.g.

DIRECTED_VENDOR_SNAPSHOT := true
VENDOR_SNAPSHOT_MODULES := toybox_vendor sh_vendor libbase libcutils ...

Bug: 157967325
Test: m dist vendor-snapshot after setting those in BoardConfig.mk
Change-Id: I6515a43d9358d94483d7c7fa2b066f9dd457f6aa
This commit is contained in:
Inseob Kim
2021-01-06 23:06:52 +09:00
parent 4d31a041c7
commit 7cf1465d2e
6 changed files with 127 additions and 3 deletions

View File

@@ -1266,6 +1266,95 @@ func TestVendorSnapshotCapture(t *testing.T) {
}
}
func TestVendorSnapshotDirected(t *testing.T) {
bp := `
cc_library_shared {
name: "libvendor",
vendor: true,
nocrt: true,
}
cc_library_shared {
name: "libvendor_available",
vendor_available: true,
nocrt: true,
}
genrule {
name: "libfoo_gen",
cmd: "",
out: ["libfoo.so"],
}
cc_prebuilt_library_shared {
name: "libfoo",
vendor: true,
prefer: true,
srcs: [":libfoo_gen"],
}
cc_library_shared {
name: "libfoo",
vendor: true,
nocrt: true,
}
`
config := TestConfig(buildDir, android.Android, nil, bp, nil)
config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
config.TestProductVariables.DirectedVendorSnapshot = true
config.TestProductVariables.VendorSnapshotModules = make(map[string]bool)
config.TestProductVariables.VendorSnapshotModules["libvendor"] = true
config.TestProductVariables.VendorSnapshotModules["libfoo"] = true
ctx := testCcWithConfig(t, config)
// Check Vendor snapshot output.
snapshotDir := "vendor-snapshot"
snapshotVariantPath := filepath.Join(buildDir, 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.VER_%s_%s_shared", archType, archVariant)
sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
// Included modules
checkSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json"))
// Check that snapshot captures "prefer: true" prebuilt
checkSnapshot(t, ctx, snapshotSingleton, "prebuilt_libfoo", "libfoo.so", sharedDir, sharedVariant)
includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libfoo.so.json"))
// Excluded modules
checkSnapshotExclude(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant)
excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libvendor_available.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 {