Loading apex/apex_test.go +6 −2 Original line number Diff line number Diff line Loading @@ -1679,6 +1679,7 @@ func TestMacro(t *testing.T) { name: "otherapex", key: "myapex.key", native_shared_libs: ["mylib", "mylib2"], min_sdk_version: "29", } apex_key { Loading Loading @@ -1713,15 +1714,18 @@ func TestMacro(t *testing.T) { // non-APEX variant does not have __ANDROID_APEX__ defined mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") ensureContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=10000") // APEX variant has __ANDROID_APEX__ defined // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"] ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") ensureContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=10000") ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") // APEX variant has __ANDROID_APEX__ defined // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"] ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") ensureContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=29") ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") // When cc_library sets use_apex_name_macro: true Loading cc/cc.go +11 −1 Original line number Diff line number Diff line Loading @@ -290,6 +290,7 @@ type ModuleContextIntf interface { staticBinary() bool header() bool toolchain() config.Toolchain canUseSdk() bool useSdk() bool sdkVersion() string useVndk() bool Loading @@ -313,6 +314,7 @@ type ModuleContextIntf interface { useClangLld(actx ModuleContext) bool isForPlatform() bool apexName() string apexSdkVersion() int hasStubsVariants() bool isStubs() bool bootstrap() bool Loading Loading @@ -1045,8 +1047,12 @@ func (ctx *moduleContextImpl) header() bool { return ctx.mod.header() } func (ctx *moduleContextImpl) canUseSdk() bool { return ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRamdisk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() } func (ctx *moduleContextImpl) useSdk() bool { if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRamdisk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() { if ctx.canUseSdk() { return String(ctx.mod.Properties.Sdk_version) != "" } return false Loading Loading @@ -1179,6 +1185,10 @@ func (ctx *moduleContextImpl) apexName() string { return ctx.mod.ApexName() } func (ctx *moduleContextImpl) apexSdkVersion() int { return ctx.mod.ApexProperties.Info.MinSdkVersion } func (ctx *moduleContextImpl) hasStubsVariants() bool { return ctx.mod.HasStubsVariants() } Loading cc/compiler.go +12 −0 Original line number Diff line number Diff line Loading @@ -315,6 +315,18 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps "-isystem "+getCurrentIncludePath(ctx).Join(ctx, config.NDKTriple(tc)).String()) } if ctx.canUseSdk() { sdkVersion := ctx.sdkVersion() if sdkVersion == "" || sdkVersion == "current" { if ctx.isForPlatform() { sdkVersion = strconv.Itoa(android.FutureApiLevel) } else { sdkVersion = strconv.Itoa(ctx.apexSdkVersion()) } } flags.Global.CommonFlags = append(flags.Global.CommonFlags, "-D__ANDROID_SDK_VERSION__="+sdkVersion) } if ctx.useVndk() { flags.Global.CommonFlags = append(flags.Global.CommonFlags, "-D__ANDROID_VNDK__") } Loading Loading
apex/apex_test.go +6 −2 Original line number Diff line number Diff line Loading @@ -1679,6 +1679,7 @@ func TestMacro(t *testing.T) { name: "otherapex", key: "myapex.key", native_shared_libs: ["mylib", "mylib2"], min_sdk_version: "29", } apex_key { Loading Loading @@ -1713,15 +1714,18 @@ func TestMacro(t *testing.T) { // non-APEX variant does not have __ANDROID_APEX__ defined mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") ensureContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=10000") // APEX variant has __ANDROID_APEX__ defined // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"] ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") ensureContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=10000") ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") // APEX variant has __ANDROID_APEX__ defined // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"] ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") ensureContains(t, mylibCFlags, "-D__ANDROID_SDK_VERSION__=29") ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") // When cc_library sets use_apex_name_macro: true Loading
cc/cc.go +11 −1 Original line number Diff line number Diff line Loading @@ -290,6 +290,7 @@ type ModuleContextIntf interface { staticBinary() bool header() bool toolchain() config.Toolchain canUseSdk() bool useSdk() bool sdkVersion() string useVndk() bool Loading @@ -313,6 +314,7 @@ type ModuleContextIntf interface { useClangLld(actx ModuleContext) bool isForPlatform() bool apexName() string apexSdkVersion() int hasStubsVariants() bool isStubs() bool bootstrap() bool Loading Loading @@ -1045,8 +1047,12 @@ func (ctx *moduleContextImpl) header() bool { return ctx.mod.header() } func (ctx *moduleContextImpl) canUseSdk() bool { return ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRamdisk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() } func (ctx *moduleContextImpl) useSdk() bool { if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRamdisk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() { if ctx.canUseSdk() { return String(ctx.mod.Properties.Sdk_version) != "" } return false Loading Loading @@ -1179,6 +1185,10 @@ func (ctx *moduleContextImpl) apexName() string { return ctx.mod.ApexName() } func (ctx *moduleContextImpl) apexSdkVersion() int { return ctx.mod.ApexProperties.Info.MinSdkVersion } func (ctx *moduleContextImpl) hasStubsVariants() bool { return ctx.mod.HasStubsVariants() } Loading
cc/compiler.go +12 −0 Original line number Diff line number Diff line Loading @@ -315,6 +315,18 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps "-isystem "+getCurrentIncludePath(ctx).Join(ctx, config.NDKTriple(tc)).String()) } if ctx.canUseSdk() { sdkVersion := ctx.sdkVersion() if sdkVersion == "" || sdkVersion == "current" { if ctx.isForPlatform() { sdkVersion = strconv.Itoa(android.FutureApiLevel) } else { sdkVersion = strconv.Itoa(ctx.apexSdkVersion()) } } flags.Global.CommonFlags = append(flags.Global.CommonFlags, "-D__ANDROID_SDK_VERSION__="+sdkVersion) } if ctx.useVndk() { flags.Global.CommonFlags = append(flags.Global.CommonFlags, "-D__ANDROID_VNDK__") } Loading