Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e09ac174 authored by Justin Yun's avatar Justin Yun
Browse files

Check vndk-private with the IsVndkPrivate()

*_available will not provide if a module is VNDK-private or not.
Fixed it by using IsVndkPrivate() with private() interface.

By allowing exclude_from_vendor_snapshot for vendor_available
modules, available() interface is no longer required. Tests are
updated for exclude_from_vendor_snapshot on vendor_available modules.

Bug: 175768895
Test: m nothing
Change-Id: I9ff85256170d59b378a4c354d5c007cfbeacabc5
parent 9b564c5a
Loading
Loading
Loading
Loading
+39 −68
Original line number Diff line number Diff line
@@ -1624,17 +1624,19 @@ func TestVendorSnapshotSanitizer(t *testing.T) {
	assertString(t, staticCfiModule.outputFile.Path().Base(), "libsnapshot.cfi.a")
}

func assertExcludeFromVendorSnapshotIs(t *testing.T, c *Module, expected bool) {
func assertExcludeFromVendorSnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool) {
	t.Helper()
	if c.ExcludeFromVendorSnapshot() != expected {
		t.Errorf("expected %q ExcludeFromVendorSnapshot to be %t", c.String(), expected)
	m := ctx.ModuleForTests(name, vendorVariant).Module().(*Module)
	if m.ExcludeFromVendorSnapshot() != expected {
		t.Errorf("expected %q ExcludeFromVendorSnapshot to be %t", m.String(), expected)
	}
}

func assertExcludeFromRecoverySnapshotIs(t *testing.T, c *Module, expected bool) {
func assertExcludeFromRecoverySnapshotIs(t *testing.T, ctx *android.TestContext, name string, expected bool) {
	t.Helper()
	if c.ExcludeFromRecoverySnapshot() != expected {
		t.Errorf("expected %q ExcludeFromRecoverySnapshot to be %t", c.String(), expected)
	m := ctx.ModuleForTests(name, recoveryVariant).Module().(*Module)
	if m.ExcludeFromRecoverySnapshot() != expected {
		t.Errorf("expected %q ExcludeFromRecoverySnapshot to be %t", m.String(), expected)
	}
}

@@ -1658,6 +1660,12 @@ func TestVendorSnapshotExclude(t *testing.T) {
			vendor: true,
			exclude_from_vendor_snapshot: true,
		}
		cc_library_shared {
			name: "libavailable_exclude",
			srcs: ["src/exclude.cpp"],
			vendor_available: true,
			exclude_from_vendor_snapshot: true,
		}
	`

	vendorProprietaryBp := `
@@ -1691,13 +1699,13 @@ func TestVendorSnapshotExclude(t *testing.T) {
	android.FailIfErrored(t, errs)

	// Test an include and exclude framework module.
	assertExcludeFromVendorSnapshotIs(t, ctx.ModuleForTests("libinclude", coreVariant).Module().(*Module), false)
	assertExcludeFromVendorSnapshotIs(t, ctx.ModuleForTests("libinclude", vendorVariant).Module().(*Module), false)
	assertExcludeFromVendorSnapshotIs(t, ctx.ModuleForTests("libexclude", vendorVariant).Module().(*Module), true)
	assertExcludeFromVendorSnapshotIs(t, ctx, "libinclude", false)
	assertExcludeFromVendorSnapshotIs(t, ctx, "libexclude", true)
	assertExcludeFromVendorSnapshotIs(t, ctx, "libavailable_exclude", true)

	// A vendor module is excluded, but by its path, not the
	// exclude_from_vendor_snapshot property.
	assertExcludeFromVendorSnapshotIs(t, ctx.ModuleForTests("libvendor", vendorVariant).Module().(*Module), false)
	assertExcludeFromVendorSnapshotIs(t, ctx, "libvendor", false)

	// Verify the content of the vendor snapshot.

@@ -1728,6 +1736,8 @@ func TestVendorSnapshotExclude(t *testing.T) {
		excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
		checkSnapshotExclude(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
		excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json"))
		checkSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
		excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
	}

	// Verify that each json file for an included module has a rule.
@@ -1789,53 +1799,6 @@ func TestVendorSnapshotExcludeInVendorProprietaryPathErrors(t *testing.T) {
	})
}

func TestVendorSnapshotExcludeWithVendorAvailable(t *testing.T) {

	// This test verifies that using the exclude_from_vendor_snapshot
	// property on a module that is vendor available generates an error. A
	// vendor available module must be captured in the vendor snapshot and
	// must not built from source when building the vendor image against
	// the vendor snapshot.

	frameworkBp := `
		cc_library_shared {
			name: "libinclude",
			srcs: ["src/include.cpp"],
			vendor_available: true,
			exclude_from_vendor_snapshot: true,
		}
	`

	depsBp := GatherRequiredDepsForTest(android.Android)

	mockFS := map[string][]byte{
		"deps/Android.bp":       []byte(depsBp),
		"framework/Android.bp":  []byte(frameworkBp),
		"framework/include.cpp": nil,
	}

	config := TestConfig(buildDir, android.Android, nil, "", mockFS)
	config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
	config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
	ctx := CreateTestContext(config)
	ctx.Register()

	_, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp"})
	android.FailIfErrored(t, errs)

	_, errs = ctx.PrepareBuildActions(config)
	android.CheckErrorsAgainstExpectations(t, errs, []string{
		`module "libinclude\{.+,image:,arch:arm64_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`,
		`module "libinclude\{.+,image:,arch:arm_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`,
		`module "libinclude\{.+,image:vendor.+,arch:arm64_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`,
		`module "libinclude\{.+,image:vendor.+,arch:arm_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`,
		`module "libinclude\{.+,image:,arch:arm64_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`,
		`module "libinclude\{.+,image:,arch:arm_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`,
		`module "libinclude\{.+,image:vendor.+,arch:arm64_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`,
		`module "libinclude\{.+,image:vendor.+,arch:arm_.+\}" may not use both "vendor_available: true" and "exclude_from_vendor_snapshot: true"`,
	})
}

func TestRecoverySnapshotCapture(t *testing.T) {
	bp := `
	cc_library {
@@ -1981,12 +1944,18 @@ func TestRecoverySnapshotExclude(t *testing.T) {
			recovery: true,
			exclude_from_recovery_snapshot: true,
		}
		cc_library_shared {
			name: "libavailable_exclude",
			srcs: ["src/exclude.cpp"],
			recovery_available: true,
			exclude_from_recovery_snapshot: true,
		}
	`

	vendorProprietaryBp := `
		cc_library_shared {
			name: "libvendor",
			srcs: ["vendor.cpp"],
			name: "librecovery",
			srcs: ["recovery.cpp"],
			recovery: true,
		}
	`
@@ -1999,7 +1968,7 @@ func TestRecoverySnapshotExclude(t *testing.T) {
		"framework/include.cpp": nil,
		"framework/exclude.cpp": nil,
		"device/Android.bp":     []byte(vendorProprietaryBp),
		"device/vendor.cpp":     nil,
		"device/recovery.cpp":   nil,
	}

	config := TestConfig(buildDir, android.Android, nil, "", mockFS)
@@ -2014,13 +1983,13 @@ func TestRecoverySnapshotExclude(t *testing.T) {
	android.FailIfErrored(t, errs)

	// Test an include and exclude framework module.
	assertExcludeFromRecoverySnapshotIs(t, ctx.ModuleForTests("libinclude", coreVariant).Module().(*Module), false)
	assertExcludeFromRecoverySnapshotIs(t, ctx.ModuleForTests("libinclude", recoveryVariant).Module().(*Module), false)
	assertExcludeFromRecoverySnapshotIs(t, ctx.ModuleForTests("libexclude", recoveryVariant).Module().(*Module), true)
	assertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude", false)
	assertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude", true)
	assertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude", true)

	// A vendor module is excluded, but by its path, not the
	// A recovery module is excluded, but by its path, not the
	// exclude_from_recovery_snapshot property.
	assertExcludeFromRecoverySnapshotIs(t, ctx.ModuleForTests("libvendor", recoveryVariant).Module().(*Module), false)
	assertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery", false)

	// Verify the content of the recovery snapshot.

@@ -2048,8 +2017,10 @@ func TestRecoverySnapshotExclude(t *testing.T) {
		// Excluded modules
		checkSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
		excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
		checkSnapshotExclude(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
		excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json"))
		checkSnapshotExclude(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
		excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
		checkSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
		excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
	}

	// Verify that each json file for an included module has a rule.
+9 −8
Original line number Diff line number Diff line
@@ -40,10 +40,10 @@ type snapshotImage interface {
	// evalution of a function that may be not be defined.
	inImage(m *Module) func() bool

	// Returns the value of the "available" property for a given module for
	// and snapshot, e.g., "vendor_available", "recovery_available", etc.
	// or nil if the property is not defined.
	available(m *Module) *bool
	// Returns true if the module is private and must not be included in the
	// snapshot. For example VNDK-private modules must return true for the
	// vendor snapshots. But false for the recovery snapshots.
	private(m *Module) bool

	// Returns true if a dir under source tree is an SoC-owned proprietary
	// directory, such as device/, vendor/, etc.
@@ -112,8 +112,8 @@ func (vendorSnapshotImage) inImage(m *Module) func() bool {
	return m.InVendor
}

func (vendorSnapshotImage) available(m *Module) *bool {
	return m.VendorProperties.Vendor_available
func (vendorSnapshotImage) private(m *Module) bool {
	return m.IsVndkPrivate()
}

func (vendorSnapshotImage) isProprietaryPath(dir string) bool {
@@ -227,8 +227,9 @@ func (recoverySnapshotImage) inImage(m *Module) func() bool {
	return m.InRecovery
}

func (recoverySnapshotImage) available(m *Module) *bool {
	return m.Properties.Recovery_available
// recovery snapshot does not have private libraries.
func (recoverySnapshotImage) private(m *Module) bool {
	return false
}

func (recoverySnapshotImage) isProprietaryPath(dir string) bool {
+6 −19
Original line number Diff line number Diff line
@@ -23,8 +23,6 @@ import (
	"sort"
	"strings"

	"github.com/google/blueprint/proptools"

	"android/soong/android"
)

@@ -177,15 +175,15 @@ func isVendorProprietaryModule(ctx android.BaseModuleContext) bool {

func isRecoveryProprietaryModule(ctx android.BaseModuleContext) bool {

	// Any module in a vendor proprietary path is a vendor proprietary
	// Any module in a recovery proprietary path is a recovery proprietary
	// module.
	if isRecoveryProprietaryPath(ctx.ModuleDir()) {
		return true
	}

	// However if the module is not in a vendor proprietary path, it may
	// still be a vendor proprietary module. This happens for cc modules
	// that are excluded from the vendor snapshot, and it means that the
	// However if the module is not in a recovery proprietary path, it may
	// still be a recovery proprietary module. This happens for cc modules
	// that are excluded from the recovery snapshot, and it means that the
	// vendor has assumed control of the framework-provided module.

	if c, ok := ctx.Module().(*Module); ok {
@@ -264,7 +262,7 @@ func isSnapshotAware(cfg android.DeviceConfig, m *Module, inProprietaryPath bool
			}
		}
		if l.static() {
			return m.outputFile.Valid() && proptools.BoolDefault(image.available(m), true)
			return m.outputFile.Valid() && !image.private(m)
		}
		if l.shared() {
			if !m.outputFile.Valid() {
@@ -282,7 +280,7 @@ func isSnapshotAware(cfg android.DeviceConfig, m *Module, inProprietaryPath bool

	// Binaries and Objects
	if m.binary() || m.object() {
		return m.outputFile.Valid() && proptools.BoolDefault(image.available(m), true)
		return m.outputFile.Valid()
	}

	return false
@@ -526,17 +524,6 @@ func (c *snapshotSingleton) GenerateBuildActions(ctx android.SingletonContext) {
				ctx.Errorf("module %q in vendor proprietary path %q may not use \"exclude_from_vendor_snapshot: true\"", m.String(), moduleDir)
				return
			}
			if Bool(c.image.available(m)) {
				// Error: may not combine "vendor_available:
				// true" with "exclude_from_vendor_snapshot:
				// true".
				ctx.Errorf(
					"module %q may not use both \""+
						c.name+
						"_available: true\" and \"exclude_from_vendor_snapshot: true\"",
					m.String())
				return
			}
		}

		if !isSnapshotAware(ctx.DeviceConfig(), m, inProprietaryPath, apexInfo, c.image) {