Define __ANDROID_VENDOR__ and __ANDROID_PRODUCT__
__ANDROID_VNDK__ is defined for the modules that are able to use the VNDK libraries. As both product and vendor variants define __ANDROID_VNDK__, we don't know if a module is built for vendor or product on build time. __ANDROID_VENDOR__ and __ANDROID_PRODUCT__ macros can be used to specify the image-variant-dependent codes. Bug: 180646847 Test: m nothing Change-Id: Id6c3e1e3d47deaf3684c0c02964718658cf2fec5
This commit is contained in:
parent
aa52d66cd5
commit
13decfb0bb
|
@ -2678,6 +2678,40 @@ func TestVendorApex_use_vndk_as_stable(t *testing.T) {
|
||||||
ensureListContains(t, requireNativeLibs, ":vndk")
|
ensureListContains(t, requireNativeLibs, ":vndk")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestProductVariant(t *testing.T) {
|
||||||
|
ctx := testApex(t, `
|
||||||
|
apex {
|
||||||
|
name: "myapex",
|
||||||
|
key: "myapex.key",
|
||||||
|
updatable: false,
|
||||||
|
product_specific: true,
|
||||||
|
binaries: ["foo"],
|
||||||
|
}
|
||||||
|
|
||||||
|
apex_key {
|
||||||
|
name: "myapex.key",
|
||||||
|
public_key: "testkey.avbpubkey",
|
||||||
|
private_key: "testkey.pem",
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_binary {
|
||||||
|
name: "foo",
|
||||||
|
product_available: true,
|
||||||
|
apex_available: ["myapex"],
|
||||||
|
srcs: ["foo.cpp"],
|
||||||
|
}
|
||||||
|
`, func(fs map[string][]byte, config android.Config) {
|
||||||
|
config.TestProductVariables.ProductVndkVersion = proptools.StringPtr("current")
|
||||||
|
})
|
||||||
|
|
||||||
|
cflags := strings.Fields(
|
||||||
|
ctx.ModuleForTests("foo", "android_product.VER_arm64_armv8-a_apex10000").Rule("cc").Args["cFlags"])
|
||||||
|
ensureListContains(t, cflags, "-D__ANDROID_VNDK__")
|
||||||
|
ensureListContains(t, cflags, "-D__ANDROID_APEX__")
|
||||||
|
ensureListContains(t, cflags, "-D__ANDROID_PRODUCT__")
|
||||||
|
ensureListNotContains(t, cflags, "-D__ANDROID_VENDOR__")
|
||||||
|
}
|
||||||
|
|
||||||
func TestApex_withPrebuiltFirmware(t *testing.T) {
|
func TestApex_withPrebuiltFirmware(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
|
|
|
@ -2065,6 +2065,7 @@ func TestEnforceProductVndkVersion(t *testing.T) {
|
||||||
vendor_available: true,
|
vendor_available: true,
|
||||||
product_available: true,
|
product_available: true,
|
||||||
nocrt: true,
|
nocrt: true,
|
||||||
|
srcs: ["foo.c"],
|
||||||
target: {
|
target: {
|
||||||
vendor: {
|
vendor: {
|
||||||
suffix: "-vendor",
|
suffix: "-vendor",
|
||||||
|
@ -2108,12 +2109,7 @@ func TestEnforceProductVndkVersion(t *testing.T) {
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
config := TestConfig(buildDir, android.Android, nil, bp, nil)
|
ctx := ccFixtureFactory.RunTestWithBp(t, bp).TestContext
|
||||||
config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
|
|
||||||
config.TestProductVariables.ProductVndkVersion = StringPtr("current")
|
|
||||||
config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
|
|
||||||
|
|
||||||
ctx := testCcWithConfig(t, config)
|
|
||||||
|
|
||||||
checkVndkModule(t, ctx, "libvndk", "", false, "", productVariant)
|
checkVndkModule(t, ctx, "libvndk", "", false, "", productVariant)
|
||||||
checkVndkModule(t, ctx, "libvndk_sp", "", true, "", productVariant)
|
checkVndkModule(t, ctx, "libvndk_sp", "", true, "", productVariant)
|
||||||
|
@ -2123,6 +2119,33 @@ func TestEnforceProductVndkVersion(t *testing.T) {
|
||||||
|
|
||||||
mod_product := ctx.ModuleForTests("libboth_available", productVariant).Module().(*Module)
|
mod_product := ctx.ModuleForTests("libboth_available", productVariant).Module().(*Module)
|
||||||
assertString(t, mod_product.outputFile.Path().Base(), "libboth_available-product.so")
|
assertString(t, mod_product.outputFile.Path().Base(), "libboth_available-product.so")
|
||||||
|
|
||||||
|
ensureStringContains := func(t *testing.T, str string, substr string) {
|
||||||
|
t.Helper()
|
||||||
|
if !strings.Contains(str, substr) {
|
||||||
|
t.Errorf("%q is not found in %v", substr, str)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ensureStringNotContains := func(t *testing.T, str string, substr string) {
|
||||||
|
t.Helper()
|
||||||
|
if strings.Contains(str, substr) {
|
||||||
|
t.Errorf("%q is found in %v", substr, str)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// _static variant is used since _shared reuses *.o from the static variant
|
||||||
|
vendor_static := ctx.ModuleForTests("libboth_available", strings.Replace(vendorVariant, "_shared", "_static", 1))
|
||||||
|
product_static := ctx.ModuleForTests("libboth_available", strings.Replace(productVariant, "_shared", "_static", 1))
|
||||||
|
|
||||||
|
vendor_cflags := vendor_static.Rule("cc").Args["cFlags"]
|
||||||
|
ensureStringContains(t, vendor_cflags, "-D__ANDROID_VNDK__")
|
||||||
|
ensureStringContains(t, vendor_cflags, "-D__ANDROID_VENDOR__")
|
||||||
|
ensureStringNotContains(t, vendor_cflags, "-D__ANDROID_PRODUCT__")
|
||||||
|
|
||||||
|
product_cflags := product_static.Rule("cc").Args["cFlags"]
|
||||||
|
ensureStringContains(t, product_cflags, "-D__ANDROID_VNDK__")
|
||||||
|
ensureStringContains(t, product_cflags, "-D__ANDROID_PRODUCT__")
|
||||||
|
ensureStringNotContains(t, product_cflags, "-D__ANDROID_VENDOR__")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEnforceProductVndkVersionErrors(t *testing.T) {
|
func TestEnforceProductVndkVersionErrors(t *testing.T) {
|
||||||
|
|
|
@ -357,6 +357,11 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
|
||||||
|
|
||||||
if ctx.useVndk() {
|
if ctx.useVndk() {
|
||||||
flags.Global.CommonFlags = append(flags.Global.CommonFlags, "-D__ANDROID_VNDK__")
|
flags.Global.CommonFlags = append(flags.Global.CommonFlags, "-D__ANDROID_VNDK__")
|
||||||
|
if ctx.inVendor() {
|
||||||
|
flags.Global.CommonFlags = append(flags.Global.CommonFlags, "-D__ANDROID_VENDOR__")
|
||||||
|
} else if ctx.inProduct() {
|
||||||
|
flags.Global.CommonFlags = append(flags.Global.CommonFlags, "-D__ANDROID_PRODUCT__")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.inRecovery() {
|
if ctx.inRecovery() {
|
||||||
|
|
Loading…
Reference in New Issue