Skip to content

Commit

Permalink
refs #142, solaris support for tests
Browse files Browse the repository at this point in the history
Took 51 minutes
  • Loading branch information
gulrak committed Apr 2, 2022
1 parent c4b507e commit 91e71f7
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ endif()
if(CMAKE_CXX_STANDARD LESS 11)
message(FATAL_ERROR "CMAKE_CXX_STANDARD is less than 11, ghc::filesystem only works with C++11 and above.")
endif()
message(STATUS "System name: ${CMAKE_SYSTEM_NAME}")
message(STATUS "Compiler ID: ${CMAKE_CXX_COMPILER_ID}")
message(STATUS "CMAKE_CXX_COMPILE_FEATURES: ${CMAKE_CXX_COMPILE_FEATURES}")

add_library(ghc_filesystem INTERFACE)
Expand Down
12 changes: 10 additions & 2 deletions cmake/GhcHelper.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
macro(AddExecutableWithStdFS targetName)

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND (CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 7.0 OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0))
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND (CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 7.0 OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0))
if(APPLE)
include_directories(/usr/local/opt/llvm/include)
link_directories(/usr/local/opt/llvm/lib)
Expand All @@ -20,6 +19,9 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND (CMAKE_CXX_COMPILER_VERSION
target_link_libraries(${targetName} -stdlib=libc++)
endif()
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "(SunOS|Solaris)")
target_link_libraries(filesystem_test xnet)
endif()
target_compile_definitions(${targetName} PRIVATE USE_STD_FS)
endif()

Expand All @@ -29,6 +31,9 @@ if (CMAKE_COMPILER_IS_GNUCXX AND (CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 8.0 O
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
target_link_libraries(${targetName} -lstdc++fs)
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "(SunOS|Solaris)")
target_link_libraries(${targetName} xnet)
endif()
target_compile_options(${targetName} PRIVATE $<$<BOOL:${CYGWIN}>:-Wa,-mbig-obj>)
target_compile_definitions(${targetName} PRIVATE USE_STD_FS)
endif()
Expand All @@ -47,6 +52,9 @@ macro(AddTestExecutableWithStdCpp cppStd)
add_executable(filesystem_test_cpp${cppStd} ${ARGN})
set_property(TARGET filesystem_test_cpp${cppStd} PROPERTY CXX_STANDARD ${cppStd})
target_link_libraries(filesystem_test_cpp${cppStd} ghc_filesystem)
if(${CMAKE_SYSTEM_NAME} MATCHES "(SunOS|Solaris)")
target_link_libraries(filesystem_test_cpp${cppStd} xnet)
endif()
target_compile_options(filesystem_test_cpp${cppStd} PRIVATE
$<$<BOOL:${EMSCRIPTEN}>:-s DISABLE_EXCEPTION_CATCHING=0>
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:-Wall -Wextra -Wshadow -Wconversion -Wsign-conversion -Wpedantic -Werror -Wno-error=deprecated-declarations>
Expand Down
18 changes: 17 additions & 1 deletion include/ghc/filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1316,22 +1316,38 @@ template <typename T>
GHC_INLINE file_type file_type_from_dirent_impl(const T& t, std::true_type)
{
switch (t.d_type) {
#ifdef DT_BLK
case DT_BLK:
return file_type::block;
#endif
#ifdef DT_CHR
case DT_CHR:
return file_type::character;
#endif
#ifdef DT_DIR
case DT_DIR:
return file_type::directory;
#endif
#ifdef DT_FIFO
case DT_FIFO:
return file_type::fifo;
#endif
#ifdef DT_LNK
case DT_LNK:
return file_type::symlink;
#endif
#ifdef DT_REG
case DT_REG:
return file_type::regular;
#endif
#ifdef DT_SOCK
case DT_SOCK:
return file_type::socket;
#endif
#ifdef DT_UNKNOWN
case DT_UNKNOWN:
return file_type::none;
#endif
default:
return file_type::unknown;
}
Expand Down Expand Up @@ -4624,7 +4640,7 @@ GHC_INLINE void last_write_time(const path& p, file_time_type new_time, std::err
#if defined(__ANDROID_API__) && __ANDROID_API__ < 12
if (syscall(__NR_utimensat, AT_FDCWD, p.c_str(), times, AT_SYMLINK_NOFOLLOW) != 0) {
#else
if (::utimensat(AT_FDCWD, p.c_str(), times, AT_SYMLINK_NOFOLLOW) != 0) {
if (::utimensat((int)AT_FDCWD, p.c_str(), times, AT_SYMLINK_NOFOLLOW) != 0) {
#endif
ec = detail::make_system_error();
}
Expand Down
6 changes: 6 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ if(GHC_COVERAGE)
target_compile_options(filesystem_test PUBLIC --coverage)
endif()
target_link_libraries(filesystem_test PUBLIC ghc_filesystem --coverage)
if(${CMAKE_SYSTEM_NAME} MATCHES "(SunOS|Solaris)")
target_link_libraries(filesystem_test PUBLIC xnet)
endif()
if("cxx_std_17" IN_LIST GHC_FILESYSTEM_TEST_COMPILE_FEATURES)
AddTestExecutableWithStdCpp(17 filesystem_test.cpp catch.hpp)
endif()
Expand All @@ -23,6 +26,9 @@ else()
message("Generating test runner for normal test...")
add_executable(filesystem_test filesystem_test.cpp catch.hpp)
target_link_libraries(filesystem_test ghc_filesystem)
if(${CMAKE_SYSTEM_NAME} MATCHES "(SunOS|Solaris)")
target_link_libraries(filesystem_test xnet)
endif()
target_compile_options(filesystem_test PRIVATE
$<$<BOOL:${EMSCRIPTEN}>:-s DISABLE_EXCEPTION_CATCHING=0>
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:-Wall -Wextra -Wshadow -Wconversion -Wsign-conversion -Wpedantic -Werror>
Expand Down
2 changes: 2 additions & 0 deletions test/filesystem_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2163,13 +2163,15 @@ class FileTypeMixFixture

fs::path character_path() const
{
#ifndef GHC_OS_SOLARIS
std::error_code ec;
if (fs::exists("/dev/null", ec)) {
return "/dev/null";
}
else if (fs::exists("NUL", ec)) {
return "NUL";
}
#endif
return fs::path();
}
fs::path temp_path() const { return _t.path(); }
Expand Down

0 comments on commit 91e71f7

Please sign in to comment.