From 680fd80663ac11ca7586b69cd68c373da1557e81 Mon Sep 17 00:00:00 2001 From: Ryan Prichard Date: Wed, 20 Sep 2023 14:45:55 -0700 Subject: [PATCH] Use std::filesystem when libc++ is new enough _LIBCPP_VERSION in external/libcxx is 8000. When _LIBCPP_VERSION is newer, assume it's the new libc++ toolchain prebuilt, which has a finalized std::filesystem, and use std::filesystem instead. To make Soong happy, keep the android.hardware.automotive@libc++fs library for now but stub out the C++ source files and make the android::hardware::automotive::filesystem namespace an alias for std::filesystem. Bug: 152067309 Bug: 175635923 Test: treehugger Test: m android.hardware.automotive.can@1.0-service Test: m android.hardware.automotive@libc++fs Change-Id: I7aede74cda0122434d972a075d7c7a9933845450 --- .../default/libc++fs/include/automotive/filesystem | 14 ++++++++++++++ .../libc++fs/src/filesystem/directory_iterator.cpp | 8 ++++++++ .../default/libc++fs/src/filesystem/operations.cpp | 7 +++++++ 3 files changed, 29 insertions(+) diff --git a/automotive/can/1.0/default/libc++fs/include/automotive/filesystem b/automotive/can/1.0/default/libc++fs/include/automotive/filesystem index 660ad09745..bd3dda5518 100644 --- a/automotive/can/1.0/default/libc++fs/include/automotive/filesystem +++ b/automotive/can/1.0/default/libc++fs/include/automotive/filesystem @@ -9,6 +9,18 @@ //===----------------------------------------------------------------------===// #ifndef _LIBAUTO_FILESYSTEM #define _LIBAUTO_FILESYSTEM + +// TODO(152067309): Remove this once the libc++ upgrade is complete. +#include <__config> +#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION > 8000 + +#include +namespace android::hardware::automotive { +namespace filesystem = std::filesystem; +} + +#else + /* filesystem synopsis @@ -2696,4 +2708,6 @@ end(const recursive_directory_iterator&) noexcept { _LIBCPP_POP_MACROS +#endif // defined(_LIBCPP_VERSION) && _LIBCPP_VERSION > 8000 + #endif // _LIBAUTO_FILESYSTEM diff --git a/automotive/can/1.0/default/libc++fs/src/filesystem/directory_iterator.cpp b/automotive/can/1.0/default/libc++fs/src/filesystem/directory_iterator.cpp index 37c863bfcb..0dbf492106 100644 --- a/automotive/can/1.0/default/libc++fs/src/filesystem/directory_iterator.cpp +++ b/automotive/can/1.0/default/libc++fs/src/filesystem/directory_iterator.cpp @@ -6,9 +6,15 @@ // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// + +// TODO(152067309): Remove this once the libc++ upgrade is complete. +#include <__config> +#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION <= 8000 + /* clang-format off */ #include "automotive/filesystem" #include <__config> + #if defined(_LIBCPP_WIN32API) #define WIN32_LEAN_AND_MEAN #include @@ -395,3 +401,5 @@ bool recursive_directory_iterator::__try_recursion(error_code* ec) { } // namespace android::hardware::automotive::filesystem /* clang-format on */ + +#endif // defined(_LIBCPP_VERSION) && _LIBCPP_VERSION <= 8000 diff --git a/automotive/can/1.0/default/libc++fs/src/filesystem/operations.cpp b/automotive/can/1.0/default/libc++fs/src/filesystem/operations.cpp index 404c0bd4c9..6a76bdce55 100644 --- a/automotive/can/1.0/default/libc++fs/src/filesystem/operations.cpp +++ b/automotive/can/1.0/default/libc++fs/src/filesystem/operations.cpp @@ -6,6 +6,11 @@ // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// + +// TODO(152067309): Remove this once the libc++ upgrade is complete. +#include <__config> +#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION <= 8000 + /* clang-format off */ #include "automotive/filesystem" #include @@ -1771,3 +1776,5 @@ error_code directory_entry::__do_refresh() noexcept { #endif } // namespace android::hardware::automotive::filesystem /* clang-format on */ + +#endif // defined(_LIBCPP_VERSION) && _LIBCPP_VERSION <= 8000