From 68b20ca4d9c4bee2c2ad5a9240599b3e4b78d0ba Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 6 Feb 2018 19:17:41 +0000 Subject: [PATCH] Fix building libc++ with the macOS 10.13 SDK with -mmacosx-version-min=10.12 or lower. The 10.13 SDK always defines utimensat() (with an availability(macosx=10.13) annotation) and unconditionally defines UTIME_OMIT, so use the compile-time availability macros on Apple platforms instead. For people statically linking libc++, it might make sense to also provide an opt-in option for using __builtin_available() to dynamically check for the OS version, but for now let's do the smallest thing needed to unbreak the build. Based on a patch by Eric Fiselier : https://reviews.llvm.org/D34249 Fixes PR33469. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@324385 91177308-0d34-0410-b5e6-96231b3b80d8 --- src/experimental/filesystem/operations.cpp | 33 +++++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/src/experimental/filesystem/operations.cpp b/src/experimental/filesystem/operations.cpp index 2bc28c21d..bd173893c 100644 --- a/src/experimental/filesystem/operations.cpp +++ b/src/experimental/filesystem/operations.cpp @@ -21,7 +21,34 @@ #include #include #include /* values for fchmodat */ -#if !defined(UTIME_OMIT) + +#if (__APPLE__) +#if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) +#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101300 +#define _LIBCXX_USE_UTIMENSAT +#endif +#elif defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) +#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 110000 +#define _LIBCXX_USE_UTIMENSAT +#endif +#elif defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) +#if __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ >= 110000 +#define _LIBCXX_USE_UTIMENSAT +#endif +#elif defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) +#if __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ >= 40000 +#define _LIBCXX_USE_UTIMENSAT +#endif +#endif // __ENVIRONMENT_.*_VERSION_MIN_REQUIRED__ +#else +// We can use the presence of UTIME_OMIT to detect platforms that provide +// utimensat. +#if defined(UTIME_OMIT) +#define _LIBCXX_USE_UTIMENSAT +#endif +#endif // __APPLE__ + +#if !defined(_LIBCXX_USE_UTIMENSAT) #include // for ::utimes as used in __last_write_time #endif @@ -560,9 +587,7 @@ void __last_write_time(const path& p, file_time_type new_time, using namespace std::chrono; std::error_code m_ec; - // We can use the presence of UTIME_OMIT to detect platforms that do not - // provide utimensat. -#if !defined(UTIME_OMIT) +#if !defined(_LIBCXX_USE_UTIMENSAT) // This implementation has a race condition between determining the // last access time and attempting to set it to the same value using // ::utimes