Author: Dan Albert Date: 2020-12-02T13:26:28-08:00 New Revision: 0849047860a343d8bcf1f828a82d585e89079943
URL: https://github.com/llvm/llvm-project/commit/0849047860a343d8bcf1f828a82d585e89079943 DIFF: https://github.com/llvm/llvm-project/commit/0849047860a343d8bcf1f828a82d585e89079943.diff LOG: Add a less ambiguous macro for Android version. Android has a handful of API levels relevant to developers described here: https://developer.android.com/studio/build#module-level. `__ANDROID_API__` is too vague and confuses a lot of people. Introduce a new macro name that is explicit about which one it represents. Keep the old name around because code has been using it for a decade. Added: Modified: clang/lib/Basic/Targets/OSTargets.h clang/test/Preprocessor/init.c Removed: ################################################################################ diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h index 60e47bcacbf4..0d5d6f553093 100644 --- a/clang/lib/Basic/Targets/OSTargets.h +++ b/clang/lib/Basic/Targets/OSTargets.h @@ -383,8 +383,12 @@ class LLVM_LIBRARY_VISIBILITY LinuxTargetInfo : public OSTargetInfo<Target> { Triple.getEnvironmentVersion(Maj, Min, Rev); this->PlatformName = "android"; this->PlatformMinVersion = VersionTuple(Maj, Min, Rev); - if (Maj) - Builder.defineMacro("__ANDROID_API__", Twine(Maj)); + if (Maj) { + Builder.defineMacro("__ANDROID_MIN_SDK_VERSION__", Twine(Maj)); + // This historical but ambiguous name for the minSdkVersion macro. Keep + // defined for compatibility. + Builder.defineMacro("__ANDROID_API__", "__ANDROID_MIN_SDK_VERSION__"); + } } else { Builder.defineMacro("__gnu_linux__"); } diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c index 079ec6e021f8..e599d9afb42e 100644 --- a/clang/test/Preprocessor/init.c +++ b/clang/test/Preprocessor/init.c @@ -1397,6 +1397,7 @@ // // RUN: %clang_cc1 -triple arm-linux-androideabi -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix ANDROID %s // ANDROID-NOT:#define __ANDROID_API__ +// ANDROID-NOT:#define __ANDROID_MIN_SDK_VERSION__ // ANDROID:#define __ANDROID__ 1 // ANDROID-NOT:#define __gnu_linux__ // @@ -1407,7 +1408,8 @@ // X86_64-ANDROID-CXX:#define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL // // RUN: %clang_cc1 -triple arm-linux-androideabi20 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix ANDROID20 %s -// ANDROID20:#define __ANDROID_API__ 20 +// ANDROID20:#define __ANDROID_API__ __ANDROID_MIN_SDK_VERSION__ +// ANDROID20:#define __ANDROID_MIN_SDK_VERSION__ 20 // ANDROID20:#define __ANDROID__ 1 // ANDROID-NOT:#define __gnu_linux__ // _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits