[libcxx] locale_bionic.h: skip ndk-version.h on Android platform
authorzijunzhao <zijunzhao@google.com>
Mon, 11 Apr 2022 17:09:34 +0000 (17:09 +0000)
committerzijunzhao <zijunzhao@google.com>
Mon, 11 Apr 2022 17:51:12 +0000 (17:51 +0000)
The Android platform does not have ndk-version.h, but it will always
have up-to-date libc headers, so it does not need any compatibility
code intended for past versions of NDK_MAJOR. If ndk-version.h is missing,
assume NDK_MAJOR is (conceptually) infinite

Bug: https://buganizer.corp.google.com/issues/222341313
Test: None

libcxx/include/__support/android/locale_bionic.h

index 8c6d4bd..535bad7 100644 (file)
@@ -26,10 +26,15 @@ extern "C" {
 #if defined(__ANDROID__)
 
 #include <android/api-level.h>
-#include <android/ndk-version.h>
 #if __ANDROID_API__ < 21
 #include <__support/xlocale/__posix_l_fallback.h>
 #endif
+
+// If we do not have this header, we are in a platform build rather than an NDK
+// build, which will always be at least as new as the ToT NDK, in which case we
+// don't need any of the inlines below since libc provides them.
+#if __has_include(<android/ndk-version.h>)
+#include <android/ndk-version.h>
 // In NDK versions later than 16, locale-aware functions are provided by
 // legacy_stdlib_inlines.h
 #if __NDK_MAJOR__ <= 16
@@ -63,6 +68,7 @@ inline _LIBCPP_INLINE_VISIBILITY long strtol_l(const char* __nptr, char** __endp
 #endif // __ANDROID_API__ < 26
 
 #endif // __NDK_MAJOR__ <= 16
+#endif // __has_include(<android/ndk-version.h>)
 #endif // defined(__ANDROID__)
 
 #endif // defined(__BIONIC__)