diff options
Diffstat (limited to 'Source/kwsys')
-rw-r--r-- | Source/kwsys/.gitattributes | 13 | ||||
-rw-r--r-- | Source/kwsys/CMakeLists.txt | 160 | ||||
-rw-r--r-- | Source/kwsys/Directory.cxx | 4 | ||||
-rw-r--r-- | Source/kwsys/ProcessUNIX.c | 3 | ||||
-rw-r--r-- | Source/kwsys/RegularExpression.cxx | 5 | ||||
-rw-r--r-- | Source/kwsys/SystemTools.cxx | 184 | ||||
-rw-r--r-- | Source/kwsys/SystemTools.hxx.in | 25 | ||||
-rw-r--r-- | Source/kwsys/kwsysPlatformTestsCXX.cxx | 6 | ||||
-rw-r--r-- | Source/kwsys/testDirectory.cxx | 79 | ||||
-rw-r--r-- | Source/kwsys/testIOS.cxx | 139 | ||||
-rw-r--r-- | Source/kwsys/testSystemTools.cxx | 32 |
11 files changed, 258 insertions, 392 deletions
diff --git a/Source/kwsys/.gitattributes b/Source/kwsys/.gitattributes deleted file mode 100644 index 7065eb5cb..000000000 --- a/Source/kwsys/.gitattributes +++ /dev/null @@ -1,13 +0,0 @@ -.git* export-ignore - -*.c kwsys-c-style -*.c.in kwsys-c-style -*.cxx kwsys-c-style -*.h kwsys-c-style -*.h.in kwsys-c-style -*.hxx kwsys-c-style -*.hxx.in kwsys-c-style - -*.cmake whitespace=tab-in-indent -*.rst whitespace=tab-in-indent conflict-marker-size=79 -*.txt whitespace=tab-in-indent diff --git a/Source/kwsys/CMakeLists.txt b/Source/kwsys/CMakeLists.txt index e915b1a80..21568bbed 100644 --- a/Source/kwsys/CMakeLists.txt +++ b/Source/kwsys/CMakeLists.txt @@ -20,6 +20,21 @@ # KWSYS_HEADER_ROOT = The directory into which to generate the kwsys headers. # A directory called "${KWSYS_NAMESPACE}" will be # created under this root directory to hold the files. +# KWSYS_SPLIT_OBJECTS_FROM_INTERFACE +# = Instead of creating a single ${KWSYS_NAMESPACE} library +# target, create three separate targets: +# ${KWSYS_NAMESPACE} +# - An INTERFACE library only containing usage +# requirements. +# ${KWSYS_NAMESPACE}_objects +# - An OBJECT library for the built kwsys objects. +# Note: This is omitted from the install rules +# ${KWSYS_NAMESPACE}_private +# - An INTERFACE library combining both that is +# appropriate for use with PRIVATE linking in +# target_link_libraries. Because of how interface +# properties propagate, this target is not suitable +# for use with PUBLIC or INTERFACE linking. # # Example: # @@ -79,6 +94,10 @@ FOREACH(p ENDFOREACH() SET(CMAKE_LEGACY_CYGWIN_WIN32 0) +IF(CMAKE_VERSION VERSION_LESS 3.0) + SET(KWSYS_SPLIT_OBJECTS_FROM_INTERFACE 0) +ENDIF() + #----------------------------------------------------------------------------- # If a namespace is not specified, use "kwsys" and enable testing. # This should be the case only when kwsys is not included inside @@ -430,6 +449,11 @@ SET_SOURCE_FILES_PROPERTIES(ProcessUNIX.c System.c PROPERTIES COMPILE_FLAGS "-DKWSYS_C_HAS_PTRDIFF_T=${KWSYS_C_HAS_PTRDIFF_T} -DKWSYS_C_HAS_SSIZE_T=${KWSYS_C_HAS_SSIZE_T}" ) +IF(DEFINED KWSYS_PROCESS_USE_SELECT) + GET_PROPERTY(ProcessUNIX_FLAGS SOURCE ProcessUNIX.c PROPERTY COMPILE_FLAGS) + SET_PROPERTY(SOURCE ProcessUNIX.c PROPERTY COMPILE_FLAGS "${ProcessUNIX_FLAGS} -DKWSYSPE_USE_SELECT=${KWSYSPE_USE_SELECT}") +ENDIF() + IF(KWSYS_USE_DynamicLoader) GET_PROPERTY(KWSYS_SUPPORTS_SHARED_LIBS GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS) IF(KWSYS_SUPPORTS_SHARED_LIBS) @@ -795,68 +819,144 @@ ENDFOREACH() #----------------------------------------------------------------------------- # Add the library with the configured name and list of sources. IF(KWSYS_C_SRCS OR KWSYS_CXX_SRCS) - ADD_LIBRARY(${KWSYS_NAMESPACE} ${KWSYS_LIBRARY_TYPE} - ${KWSYS_C_SRCS} ${KWSYS_CXX_SRCS}) - SET_PROPERTY(TARGET ${KWSYS_NAMESPACE} PROPERTY C_CLANG_TIDY "") - SET_PROPERTY(TARGET ${KWSYS_NAMESPACE} PROPERTY CXX_CLANG_TIDY "") - SET_PROPERTY(TARGET ${KWSYS_NAMESPACE} PROPERTY C_INCLUDE_WHAT_YOU_USE "") - SET_PROPERTY(TARGET ${KWSYS_NAMESPACE} PROPERTY CXX_INCLUDE_WHAT_YOU_USE "") - SET_PROPERTY(TARGET ${KWSYS_NAMESPACE} PROPERTY LABELS ${KWSYS_LABELS_LIB}) + IF(KWSYS_SPLIT_OBJECTS_FROM_INTERFACE) + SET(KWSYS_TARGET_INTERFACE ${KWSYS_NAMESPACE}) + SET(KWSYS_TARGET_OBJECT ${KWSYS_NAMESPACE}_objects) + SET(KWSYS_TARGET_LINK ${KWSYS_NAMESPACE}_private) + SET(KWSYS_TARGET_INSTALL ${KWSYS_TARGET_INTERFACE} ${KWSYS_TARGET_LINK}) + SET(KWSYS_LINK_DEPENDENCY INTERFACE) + ADD_LIBRARY(${KWSYS_TARGET_OBJECT} OBJECT + ${KWSYS_C_SRCS} ${KWSYS_CXX_SRCS}) + IF(KWSYS_BUILD_SHARED) + SET_PROPERTY(TARGET ${KWSYS_TARGET_OBJECT} PROPERTY + POSITION_INDEPENDENT_CODE TRUE) + ENDIF() + ADD_LIBRARY(${KWSYS_TARGET_INTERFACE} INTERFACE) + ADD_LIBRARY(${KWSYS_TARGET_LINK} INTERFACE) + TARGET_LINK_LIBRARIES(${KWSYS_TARGET_LINK} INTERFACE + ${KWSYS_TARGET_INTERFACE}) + TARGET_SOURCES(${KWSYS_TARGET_LINK} INTERFACE + $<TARGET_OBJECTS:${KWSYS_TARGET_OBJECT}>) + ELSE() + SET(KWSYS_TARGET_INTERFACE ${KWSYS_NAMESPACE}) + SET(KWSYS_TARGET_OBJECT ${KWSYS_NAMESPACE}) + SET(KWSYS_TARGET_LINK ${KWSYS_NAMESPACE}) + set(KWSYS_TARGET_INSTALL ${KWSYS_TARGET_LINK}) + SET(KWSYS_LINK_DEPENDENCY PUBLIC) + ADD_LIBRARY(${KWSYS_TARGET_INTERFACE} ${KWSYS_LIBRARY_TYPE} + ${KWSYS_C_SRCS} ${KWSYS_CXX_SRCS}) + ENDIF() + SET_TARGET_PROPERTIES(${KWSYS_TARGET_OBJECT} PROPERTIES + C_CLANG_TIDY "" + CXX_CLANG_TIDY "" + C_INCLUDE_WHAT_YOU_USE "" + CXX_INCLUDE_WHAT_YOU_USE "" + LABELS "${KWSYS_LABELS_LIB}") IF(KWSYS_USE_DynamicLoader) IF(UNIX) - TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} ${CMAKE_DL_LIBS}) + TARGET_LINK_LIBRARIES(${KWSYS_TARGET_INTERFACE} ${KWSYS_LINK_DEPENDENCY} + ${CMAKE_DL_LIBS}) ENDIF() ENDIF() IF(KWSYS_USE_SystemInformation) IF(WIN32) - TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} ws2_32) + TARGET_LINK_LIBRARIES(${KWSYS_TARGET_INTERFACE} ${KWSYS_LINK_DEPENDENCY} ws2_32) IF(KWSYS_SYS_HAS_PSAPI) - TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} Psapi) + TARGET_LINK_LIBRARIES(${KWSYS_TARGET_INTERFACE} ${KWSYS_LINK_DEPENDENCY} + Psapi) ENDIF() ELSEIF(UNIX) IF (EXECINFO_LIB AND KWSYS_CXX_HAS_BACKTRACE) # backtrace on FreeBSD is not in libc - TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} ${EXECINFO_LIB}) + TARGET_LINK_LIBRARIES(${KWSYS_TARGET_INTERFACE} ${KWSYS_LINK_DEPENDENCY} + ${EXECINFO_LIB}) ENDIF() IF (KWSYS_CXX_HAS_DLADDR) # for symbol lookup using dladdr - TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} ${CMAKE_DL_LIBS}) + TARGET_LINK_LIBRARIES(${KWSYS_TARGET_INTERFACE} ${KWSYS_LINK_DEPENDENCY} + ${CMAKE_DL_LIBS}) ENDIF() IF (CMAKE_SYSTEM_NAME STREQUAL "SunOS") - TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} socket) + TARGET_LINK_LIBRARIES(${KWSYS_TARGET_INTERFACE} ${KWSYS_LINK_DEPENDENCY} + socket) ENDIF() ENDIF() ENDIF() # Apply user-defined target properties to the library. IF(KWSYS_PROPERTIES_CXX) - SET_TARGET_PROPERTIES(${KWSYS_NAMESPACE} PROPERTIES - ${KWSYS_PROPERTIES_CXX} - ) + SET_TARGET_PROPERTIES(${KWSYS_TARGET_INTERFACE} PROPERTIES + ${KWSYS_PROPERTIES_CXX}) + ENDIF() + + # Set up include usage requirement + IF(COMMAND TARGET_INCLUDE_DIRECTORIES) + TARGET_INCLUDE_DIRECTORIES(${KWSYS_TARGET_INTERFACE} INTERFACE + $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>) + IF(KWSYS_INSTALL_INCLUDE_DIR) + TARGET_INCLUDE_DIRECTORIES(${KWSYS_TARGET_INTERFACE} INTERFACE + $<INSTALL_INTERFACE:${KWSYS_INSTALL_INCLUDE_DIR}>) + ENDIF() ENDIF() # Create an install target for the library. IF(KWSYS_INSTALL_LIBRARY_RULE) - INSTALL(TARGETS ${KWSYS_NAMESPACE} ${KWSYS_INSTALL_LIBRARY_RULE}) + INSTALL(TARGETS ${KWSYS_TARGET_INSTALL} ${KWSYS_INSTALL_LIBRARY_RULE}) ENDIF() ENDIF() # Add a C-only library if requested. IF(KWSYS_ENABLE_C AND KWSYS_C_SRCS) - ADD_LIBRARY(${KWSYS_NAMESPACE}_c ${KWSYS_LIBRARY_TYPE} ${KWSYS_C_SRCS}) - SET_PROPERTY(TARGET ${KWSYS_NAMESPACE}_c PROPERTY LABELS ${KWSYS_LABELS_LIB}) + IF(KWSYS_SPLIT_OBJECTS_FROM_INTERFACE) + SET(KWSYS_TARGET_C_INTERFACE ${KWSYS_NAMESPACE}_c) + SET(KWSYS_TARGET_C_OBJECT ${KWSYS_NAMESPACE}_c_objects) + SET(KWSYS_TARGET_C_LINK ${KWSYS_NAMESPACE}_c_private) + SET(KWSYS_TARGET_C_INSTALL + ${KWSYS_TARGET_C_INTERFACE} ${KWSYS_TARGET_C_LINK}) + SET(KWSYS_LINK_DEPENDENCY INTERFACE) + ADD_LIBRARY(${KWSYS_TARGET_C_OBJECT} OBJECT ${KWSYS_C_SRCS}) + IF(KWSYS_BUILD_SHARED) + SET_PROPERTY(TARGET ${KWSYS_TARGET_C_OBJECT} PROPERTY + POSITION_INDEPENDENT_CODE TRUE) + ENDIF() + ADD_LIBRARY(${KWSYS_TARGET_C_INTERFACE} INTERFACE) + ADD_LIBRARY(${KWSYS_TARGET_C_LINK} INTERFACE) + TARGET_LINK_LIBRARIES(${KWSYS_TARGET_C_LINK} INTERFACE + ${KWSYS_TARGET_C_INTERFACE}) + TARGET_SOURCES(${KWSYS_TARGET_C_LINK} INTERFACE + $<TARGET_OBJECTS:${KWSYS_TARGET_C_OBJECT}>) + ELSE() + SET(KWSYS_TARGET_C_INTERFACE ${KWSYS_NAMESPACE}_c) + SET(KWSYS_TARGET_C_OBJECT ${KWSYS_NAMESPACE}_c) + SET(KWSYS_TARGET_C_LINK ${KWSYS_NAMESPACE}_c) + SET(KWSYS_TARGET_C_INSTALL ${KWSYS_TARGET_C_LINK}) + SET(KWSYS_LINK_DEPENDENCY PUBLIC) + ADD_LIBRARY(${KWSYS_TARGET_C_INTERFACE} ${KWSYS_LIBRARY_TYPE} + ${KWSYS_C_SRCS}) + ENDIF() + SET_TARGET_PROPERTIES(${KWSYS_TARGET_C_OBJECT} PROPERTIES + LABELS "${KWSYS_LABELS_LIB}") # Apply user-defined target properties to the library. IF(KWSYS_PROPERTIES_C) - SET_TARGET_PROPERTIES(${KWSYS_NAMESPACE}_c PROPERTIES - ${KWSYS_PROPERTIES_C} - ) + SET_TARGET_PROPERTIES(${KWSYS_TARGET_C_INTERFACE} PROPERTIES + ${KWSYS_PROPERTIES_C}) + ENDIF() + + # Set up include usage requirement + IF(COMMAND TARGET_INCLUDE_DIRECTORIES) + TARGET_INCLUDE_DIRECTORIES(${KWSYS_TARGET_C_INTERFACE} INTERFACE + $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>) + IF(KWSYS_INSTALL_INCLUDE_DIR) + TARGET_INCLUDE_DIRECTORIES(${KWSYS_TARGET_C_INTERFACE} INTERFACE + $<INSTALL_INTERFACE:${KWSYS_INSTALL_INCLUDE_DIR}>) + ENDIF() ENDIF() # Create an install target for the library. IF(KWSYS_INSTALL_LIBRARY_RULE) - INSTALL(TARGETS ${KWSYS_NAMESPACE}_c ${KWSYS_INSTALL_LIBRARY_RULE}) + INSTALL(TARGETS ${KWSYS_TARGET_C_INSTALL}) ENDIF() ENDIF() @@ -915,7 +1015,7 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR) ) ADD_EXECUTABLE(${KWSYS_NAMESPACE}TestsC ${KWSYS_C_TEST_SRCS}) SET_PROPERTY(TARGET ${KWSYS_NAMESPACE}TestsC PROPERTY LABELS ${KWSYS_LABELS_EXE}) - TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE}TestsC ${KWSYS_NAMESPACE}_c) + TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE}TestsC ${KWSYS_TARGET_C_LINK}) FOREACH(test ${KWSYS_C_TESTS}) ADD_TEST(kwsys.${test} ${EXEC_DIR}/${KWSYS_NAMESPACE}TestsC ${test} ${KWSYS_TEST_ARGS_${test}}) SET_PROPERTY(TEST kwsys.${test} PROPERTY LABELS ${KWSYS_LABELS_TEST}) @@ -928,10 +1028,10 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR) ) ENDIF() SET(KWSYS_CXX_TESTS ${KWSYS_CXX_TESTS} - testIOS testSystemTools testCommandLineArguments testCommandLineArguments1 + testDirectory ) IF(KWSYS_STL_HAS_WSTRING) SET(KWSYS_CXX_TESTS ${KWSYS_CXX_TESTS} @@ -950,7 +1050,7 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR) SET_PROPERTY(TARGET testConsoleBufChild PROPERTY C_INCLUDE_WHAT_YOU_USE "") SET_PROPERTY(TARGET testConsoleBufChild PROPERTY CXX_INCLUDE_WHAT_YOU_USE "") SET_PROPERTY(TARGET testConsoleBufChild PROPERTY LABELS ${KWSYS_LABELS_EXE}) - TARGET_LINK_LIBRARIES(testConsoleBufChild ${KWSYS_NAMESPACE}) + TARGET_LINK_LIBRARIES(testConsoleBufChild ${KWSYS_TARGET_LINK}) SET(KWSYS_CXX_TESTS ${KWSYS_CXX_TESTS} testConsoleBuf ) @@ -969,7 +1069,7 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR) # If kwsys contains the DynamicLoader, need extra library ADD_LIBRARY(${KWSYS_NAMESPACE}TestDynload MODULE testDynload.c) SET_PROPERTY(TARGET ${KWSYS_NAMESPACE}TestDynload PROPERTY LABELS ${KWSYS_LABELS_LIB}) - ADD_DEPENDENCIES(${KWSYS_NAMESPACE}TestDynload ${KWSYS_NAMESPACE}) + ADD_DEPENDENCIES(${KWSYS_NAMESPACE}TestDynload ${KWSYS_TARGET_INTERFACE}) ENDIF() CREATE_TEST_SOURCELIST( KWSYS_CXX_TEST_SRCS ${KWSYS_NAMESPACE}TestsCxx.cxx @@ -981,7 +1081,7 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR) SET_PROPERTY(TARGET ${KWSYS_NAMESPACE}TestsCxx PROPERTY C_INCLUDE_WHAT_YOU_USE "") SET_PROPERTY(TARGET ${KWSYS_NAMESPACE}TestsCxx PROPERTY CXX_INCLUDE_WHAT_YOU_USE "") SET_PROPERTY(TARGET ${KWSYS_NAMESPACE}TestsCxx PROPERTY LABELS ${KWSYS_LABELS_EXE}) - TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE}TestsCxx ${KWSYS_NAMESPACE}) + TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE}TestsCxx ${KWSYS_TARGET_LINK}) SET(TEST_SYSTEMTOOLS_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") SET(TEST_SYSTEMTOOLS_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}") @@ -1032,7 +1132,7 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR) # Process tests. ADD_EXECUTABLE(${KWSYS_NAMESPACE}TestProcess testProcess.c) SET_PROPERTY(TARGET ${KWSYS_NAMESPACE}TestProcess PROPERTY LABELS ${KWSYS_LABELS_EXE}) - TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE}TestProcess ${KWSYS_NAMESPACE}_c) + TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE}TestProcess ${KWSYS_TARGET_C_LINK}) IF(NOT CYGWIN) SET(KWSYS_TEST_PROCESS_7 7) ENDIF() @@ -1060,7 +1160,7 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR) ADD_EXECUTABLE(${KWSYS_NAMESPACE}TestSharedForward ${PROJECT_BINARY_DIR}/testSharedForward.c) SET_PROPERTY(TARGET ${KWSYS_NAMESPACE}TestSharedForward PROPERTY LABELS ${KWSYS_LABELS_EXE}) - ADD_DEPENDENCIES(${KWSYS_NAMESPACE}TestSharedForward ${KWSYS_NAMESPACE}_c) + ADD_DEPENDENCIES(${KWSYS_NAMESPACE}TestSharedForward ${KWSYS_TARGET_C_LINK}) ADD_TEST(kwsys.testSharedForward ${EXEC_DIR}/${KWSYS_NAMESPACE}TestSharedForward 1) SET_PROPERTY(TEST kwsys.testSharedForward PROPERTY LABELS ${KWSYS_LABELS_TEST}) diff --git a/Source/kwsys/Directory.cxx b/Source/kwsys/Directory.cxx index 5141d4519..69068aaf8 100644 --- a/Source/kwsys/Directory.cxx +++ b/Source/kwsys/Directory.cxx @@ -118,8 +118,8 @@ bool Directory::Load(const std::string& name) struct _wfinddata_t data; // data of current file // Now put them into the file array - srchHandle = - _wfindfirst_func((wchar_t*)Encoding::ToWide(buf).c_str(), &data); + srchHandle = _wfindfirst_func( + (wchar_t*)Encoding::ToWindowsExtendedPath(buf).c_str(), &data); delete[] buf; if (srchHandle == -1) { diff --git a/Source/kwsys/ProcessUNIX.c b/Source/kwsys/ProcessUNIX.c index 9ebcfce59..3b32ca7d0 100644 --- a/Source/kwsys/ProcessUNIX.c +++ b/Source/kwsys/ProcessUNIX.c @@ -99,7 +99,8 @@ static inline void kwsysProcess_usleep(unsigned int msec) * pipes' file handles to be non-blocking and just poll them directly * without select(). */ -#if !defined(__BEOS__) && !defined(__VMS) && !defined(__MINT__) +#if !defined(__BEOS__) && !defined(__VMS) && !defined(__MINT__) && \ + !defined(KWSYSPE_USE_SELECT) #define KWSYSPE_USE_SELECT 1 #endif diff --git a/Source/kwsys/RegularExpression.cxx b/Source/kwsys/RegularExpression.cxx index 6d7f83295..26e84e04e 100644 --- a/Source/kwsys/RegularExpression.cxx +++ b/Source/kwsys/RegularExpression.cxx @@ -258,11 +258,6 @@ const unsigned char MAGIC = 0234; #define UCHARAT(p) (reinterpret_cast<const unsigned char*>(p))[0] -#define FAIL(m) \ - { \ - regerror(m); \ - return (0); \ - } #define ISMULT(c) ((c) == '*' || (c) == '+' || (c) == '?') #define META "^$.[()|?+*\\" diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index 1c4fe3389..ecfa3319b 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -22,7 +22,6 @@ #include KWSYS_HEADER(FStream.hxx) #include KWSYS_HEADER(Encoding.hxx) -#include <algorithm> #include <fstream> #include <iostream> #include <set> @@ -848,6 +847,8 @@ void SystemTools::ReplaceString(std::string& source, const char* replace, free(orig); } +#if defined(_WIN32) && !defined(__CYGWIN__) + #if defined(KEY_WOW64_32KEY) && defined(KEY_WOW64_64KEY) #define KWSYS_ST_KEY_WOW64_32KEY KEY_WOW64_32KEY #define KWSYS_ST_KEY_WOW64_64KEY KEY_WOW64_64KEY @@ -856,7 +857,6 @@ void SystemTools::ReplaceString(std::string& source, const char* replace, #define KWSYS_ST_KEY_WOW64_64KEY 0x0100 #endif -#if defined(_WIN32) && !defined(__CYGWIN__) static bool SystemToolsParseRegistryKey(const std::string& key, HKEY& primaryKey, std::string& second, std::string& valuename) @@ -2269,11 +2269,7 @@ bool SystemTools::CopyADirectory(const std::string& source, const std::string& destination, bool always) { Directory dir; -#ifdef _WIN32 - dir.Load(Encoding::ToNarrow(Encoding::ToWindowsExtendedPath(source))); -#else dir.Load(source); -#endif size_t fileNum; if (!SystemTools::MakeDirectory(destination)) { return false; @@ -2375,104 +2371,6 @@ long int SystemTools::CreationTime(const std::string& filename) return ct; } -bool SystemTools::ConvertDateMacroString(const char* str, time_t* tmt) -{ - if (!str || !tmt || strlen(str) > 11) { - return false; - } - - struct tm tmt2; - - // __DATE__ - // The compilation date of the current source file. The date is a string - // literal of the form Mmm dd yyyy. The month name Mmm is the same as for - // dates generated by the library function asctime declared in TIME.H. - - // index: 012345678901 - // format: Mmm dd yyyy - // example: Dec 19 2003 - - static char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec"; - - char buffer[12]; - strcpy(buffer, str); - - buffer[3] = 0; - char* ptr = strstr(month_names, buffer); - if (!ptr) { - return false; - } - - int month = static_cast<int>((ptr - month_names) / 3); - int day = atoi(buffer + 4); - int year = atoi(buffer + 7); - - tmt2.tm_isdst = -1; - tmt2.tm_hour = 0; - tmt2.tm_min = 0; - tmt2.tm_sec = 0; - tmt2.tm_wday = 0; - tmt2.tm_yday = 0; - tmt2.tm_mday = day; - tmt2.tm_mon = month; - tmt2.tm_year = year - 1900; - - *tmt = mktime(&tmt2); - return true; -} - -bool SystemTools::ConvertTimeStampMacroString(const char* str, time_t* tmt) -{ - if (!str || !tmt || strlen(str) > 26) { - return false; - } - - struct tm tmt2; - - // __TIMESTAMP__ - // The date and time of the last modification of the current source file, - // expressed as a string literal in the form Ddd Mmm Date hh:mm:ss yyyy, - /// where Ddd is the abbreviated day of the week and Date is an integer - // from 1 to 31. - - // index: 0123456789 - // 0123456789 - // 0123456789 - // format: Ddd Mmm Date hh:mm:ss yyyy - // example: Fri Dec 19 14:34:58 2003 - - static char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec"; - - char buffer[27]; - strcpy(buffer, str); - - buffer[7] = 0; - char* ptr = strstr(month_names, buffer + 4); - if (!ptr) { - return false; - } - - int month = static_cast<int>((ptr - month_names) / 3); - int day = atoi(buffer + 8); - int hour = atoi(buffer + 11); - int min = atoi(buffer + 14); - int sec = atoi(buffer + 17); - int year = atoi(buffer + 20); - - tmt2.tm_isdst = -1; - tmt2.tm_hour = hour; - tmt2.tm_min = min; - tmt2.tm_sec = sec; - tmt2.tm_wday = 0; - tmt2.tm_yday = 0; - tmt2.tm_mday = day; - tmt2.tm_mon = month; - tmt2.tm_year = year - 1900; - - *tmt = mktime(&tmt2); - return true; -} - std::string SystemTools::GetLastSystemError() { int e = errno; @@ -2626,11 +2524,7 @@ bool SystemTools::RemoveADirectory(const std::string& source) } Directory dir; -#ifdef _WIN32 - dir.Load(Encoding::ToNarrow(Encoding::ToWindowsExtendedPath(source))); -#else dir.Load(source); -#endif size_t fileNum; for (fileNum = 0; fileNum < dir.GetNumberOfFiles(); ++fileNum) { if (strcmp(dir.GetFile(static_cast<unsigned long>(fileNum)), ".") && @@ -3709,16 +3603,6 @@ std::string SystemTools::JoinPath( return result; } -void SystemTools::RemoveEmptyPathElements(std::vector<std::string>& path) -{ - if (path.empty()) { - return; - } - - path.erase(std::remove(path.begin() + 1, path.end(), std::string("")), - path.end()); -} - bool SystemTools::ComparePath(const std::string& c1, const std::string& c2) { #if defined(_WIN32) || defined(__APPLE__) @@ -3807,11 +3691,7 @@ std::string SystemTools::GetFilenamePath(const std::string& filename) */ std::string SystemTools::GetFilenameName(const std::string& filename) { -#if defined(_WIN32) std::string::size_type slash_pos = filename.find_last_of("/\\"); -#else - std::string::size_type slash_pos = filename.rfind('/'); -#endif if (slash_pos != std::string::npos) { return filename.substr(slash_pos + 1); } else { @@ -4124,66 +4004,6 @@ bool SystemTools::GetShortPath(const std::string& path, std::string& shortPath) #endif } -void SystemTools::SplitProgramFromArgs(const std::string& path, - std::string& program, std::string& args) -{ - // see if this is a full path to a program - // if so then set program to path and args to nothing - if (SystemTools::FileExists(path)) { - program = path; - args = ""; - return; - } - // Try to find the program in the path, note the program - // may have spaces in its name so we have to look for it - std::vector<std::string> e; - std::string findProg = SystemTools::FindProgram(path, e); - if (!findProg.empty()) { - program = findProg; - args = ""; - return; - } - - // Now try and peel off space separated chunks from the end of the string - // so the largest path possible is found allowing for spaces in the path - std::string dir = path; - std::string::size_type spacePos = dir.rfind(' '); - while (spacePos != std::string::npos) { - std::string tryProg = dir.substr(0, spacePos); - // See if the file exists - if (SystemTools::FileExists(tryProg)) { - program = tryProg; - // remove trailing spaces from program - std::string::size_type pos = program.size() - 1; - while (program[pos] == ' ') { - program.erase(pos); - pos--; - } - args = dir.substr(spacePos, dir.size() - spacePos); - return; - } - // Now try and find the program in the path - findProg = SystemTools::FindProgram(tryProg, e); - if (!findProg.empty()) { - program = findProg; - // remove trailing spaces from program - std::string::size_type pos = program.size() - 1; - while (program[pos] == ' ') { - program.erase(pos); - pos--; - } - args = dir.substr(spacePos, dir.size() - spacePos); - return; - } - // move past the space for the next search - spacePos--; - spacePos = dir.rfind(' ', spacePos); - } - - program = ""; - args = ""; -} - std::string SystemTools::GetCurrentDateTime(const char* format) { char buf[1024]; diff --git a/Source/kwsys/SystemTools.hxx.in b/Source/kwsys/SystemTools.hxx.in index 5e091c2af..35bc1b19b 100644 --- a/Source/kwsys/SystemTools.hxx.in +++ b/Source/kwsys/SystemTools.hxx.in @@ -206,13 +206,6 @@ public: static int Strucmp(const char* s1, const char* s2); /** - * Convert a string in __DATE__ or __TIMESTAMP__ format into a time_t. - * Return false on error, true on success - */ - static bool ConvertDateMacroString(const char* str, time_t* tmt); - static bool ConvertTimeStampMacroString(const char* str, time_t* tmt); - - /** * Split a string on its newlines into multiple lines * Return false only if the last line stored had no newline */ @@ -461,6 +454,10 @@ public: * produce the original path. Home directory references are * automatically expanded if expand_home_dir is true and this * platform supports them. + * + * This does *not* normalize the input path. All components are + * preserved, including empty ones. Typically callers should use + * this only on paths that have already been normalized. */ static void SplitPath(const std::string& p, std::vector<std::string>& components, @@ -469,15 +466,15 @@ public: /** * Join components of a path name into a single string. See * SplitPath for the format of the components. + * + * This does *not* normalize the input path. All components are + * preserved, including empty ones. Typically callers should use + * this only on paths that have already been normalized. */ static std::string JoinPath(const std::vector<std::string>& components); static std::string JoinPath(std::vector<std::string>::const_iterator first, std::vector<std::string>::const_iterator last); - /** Removes empty components from path. - */ - static void RemoveEmptyPathElements(std::vector<std::string>& path); - /** * Compare a path or components of a path. */ @@ -494,12 +491,6 @@ public: static std::string GetFilenameName(const std::string&); /** - * Split a program from its arguments and handle spaces in the paths - */ - static void SplitProgramFromArgs(const std::string& path, - std::string& program, std::string& args); - - /** * Return longest file extension of a full filename (dot included) */ static std::string GetFilenameExtension(const std::string&); diff --git a/Source/kwsys/kwsysPlatformTestsCXX.cxx b/Source/kwsys/kwsysPlatformTestsCXX.cxx index 01c69514c..e67d43662 100644 --- a/Source/kwsys/kwsysPlatformTestsCXX.cxx +++ b/Source/kwsys/kwsysPlatformTestsCXX.cxx @@ -265,6 +265,12 @@ int main() #ifdef TEST_KWSYS_CXX_HAS_UTIMENSAT #include <fcntl.h> #include <sys/stat.h> +#if defined(__APPLE__) +#include <AvailabilityMacros.h> +#if MAC_OS_X_VERSION_MIN_REQUIRED < 101300 +#error "utimensat not available on macOS < 10.13" +#endif +#endif int main() { struct timespec times[2] = { { 0, UTIME_OMIT }, { 0, UTIME_NOW } }; diff --git a/Source/kwsys/testDirectory.cxx b/Source/kwsys/testDirectory.cxx new file mode 100644 index 000000000..983f2c631 --- /dev/null +++ b/Source/kwsys/testDirectory.cxx @@ -0,0 +1,79 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying +file Copyright.txt or https://cmake.org/licensing#kwsys for details. */ +#include "kwsysPrivate.h" +#include KWSYS_HEADER(Directory.hxx) +#include KWSYS_HEADER(Encoding.hxx) +#include KWSYS_HEADER(SystemTools.hxx) + +// Work-around CMake dependency scanning limitation. This must +// duplicate the above list of headers. +#if 0 +#include "Directory.hxx.in" +#include "Encoding.hxx.in" +#include "SystemTools.hxx.in" +#endif + +#include <fstream> +#include <iostream> +#include <sstream> + +#include <testSystemTools.h> + +int _doLongPathTest() +{ + using namespace kwsys; + static const int LONG_PATH_THRESHOLD = 512; + int res = 0; + std::string topdir(TEST_SYSTEMTOOLS_BINARY_DIR "/directory_testing/"); + std::stringstream testpathstrm; + std::string testdirpath; + std::string extendedtestdirpath; + + testpathstrm << topdir; + size_t pathlen = testpathstrm.str().length(); + testpathstrm.seekp(0, std::ios_base::end); + while (pathlen < LONG_PATH_THRESHOLD) { + testpathstrm << "0123456789/"; + pathlen = testpathstrm.str().length(); + } + + testdirpath = testpathstrm.str(); +#ifdef _WIN32 + extendedtestdirpath = + Encoding::ToNarrow(SystemTools::ConvertToWindowsExtendedPath(testdirpath)); +#else + extendedtestdirpath = testdirpath; +#endif + + if (SystemTools::MakeDirectory(extendedtestdirpath)) { + std::ofstream testfile1( + (extendedtestdirpath + "longfilepathtest1.txt").c_str()); + std::ofstream testfile2( + (extendedtestdirpath + "longfilepathtest2.txt").c_str()); + testfile1 << "foo"; + testfile2 << "bar"; + testfile1.close(); + testfile2.close(); + + Directory testdir; + // Set res to failure if the directory doesn't load + res += !testdir.Load(testdirpath); + // Increment res failure if the directory appears empty + res += testdir.GetNumberOfFiles() == 0; + // Increment res failures if the path has changed from + // what was provided. + res += testdirpath != testdir.GetPath(); + + SystemTools::RemoveADirectory(topdir); + } else { + std::cerr << "Failed to create directory with long path: " + << extendedtestdirpath << std::endl; + res += 1; + } + return res; +} + +int testDirectory(int, char* []) +{ + return _doLongPathTest(); +} diff --git a/Source/kwsys/testIOS.cxx b/Source/kwsys/testIOS.cxx deleted file mode 100644 index 3e4c325c7..000000000 --- a/Source/kwsys/testIOS.cxx +++ /dev/null @@ -1,139 +0,0 @@ -/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying - file Copyright.txt or https://cmake.org/licensing#kwsys for details. */ -#include "kwsysPrivate.h" -#include KWSYS_HEADER(Configure.hxx) - -#include <fstream> -#include <iostream> -#include <sstream> -#include <string.h> /* strlen */ -#include <vector> - -// Work-around CMake dependency scanning limitation. This must -// duplicate the above list of headers. -#if 0 -#include "Configure.hxx.in" -#endif - -int testIOS(int, char* []) -{ - std::ostringstream ostr; - const char hello[] = "hello"; - ostr << hello; - if (ostr.str() != hello) { - std::cerr << "failed to write hello to ostr" << std::endl; - return 1; - } - const char world[] = "world"; - std::ostringstream ostr2; - ostr2.write(hello, strlen(hello)); /* I could do sizeof */ - ostr2.put('\0'); - ostr2.write(world, strlen(world)); - if (ostr2.str().size() != strlen(hello) + 1 + strlen(world)) { - std::cerr << "failed to write hello to ostr2" << std::endl; - return 1; - } - static const unsigned char array[] = { - 0xff, 0x4f, 0xff, 0x51, 0x00, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, - 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0x01, 0x01, 0xff, 0x52, 0x00, - 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x05, 0x04, 0x04, 0x00, 0x01, 0xff, - 0x5c, 0x00, 0x13, 0x40, 0x40, 0x48, 0x48, 0x50, 0x48, 0x48, 0x50, 0x48, - 0x48, 0x50, 0x48, 0x48, 0x50, 0x48, 0x48, 0x50, 0xff, 0x64, 0x00, 0x2c, - 0x00, 0x00, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20, 0x62, 0x79, - 0x20, 0x49, 0x54, 0x4b, 0x2f, 0x47, 0x44, 0x43, 0x4d, 0x2f, 0x4f, 0x70, - 0x65, 0x6e, 0x4a, 0x50, 0x45, 0x47, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, - 0x6f, 0x6e, 0x20, 0x31, 0x2e, 0x30, 0xff, 0x90, 0x00, 0x0a, 0x00, 0x00, - 0x00, 0x00, 0x06, 0x2c, 0x00, 0x01, 0xff, 0x93, 0xcf, 0xb0, 0x18, 0x08, - 0x7f, 0xc6, 0x99, 0xbf, 0xff, 0xc0, 0xf8, 0xc1, 0xc1, 0xf3, 0x05, 0x81, - 0xf2, 0x83, 0x0a, 0xa5, 0xff, 0x10, 0x90, 0xbf, 0x2f, 0xff, 0x04, 0xa8, - 0x7f, 0xc0, 0xf8, 0xc4, 0xc1, 0xf3, 0x09, 0x81, 0xf3, 0x0c, 0x19, 0x34 - }; - const size_t narray = sizeof(array); // 180 - std::stringstream strstr; - strstr.write((char*)array, narray); - // strstr.seekp( narray / 2 ); // set position of put pointer in mid string - if (strstr.str().size() != narray) { - std::cerr << "failed to write array to strstr" << std::endl; - return 1; - } - - std::istringstream istr(" 10 20 str "); - std::string s; - int x; - if (istr >> x) { - if (x != 10) { - std::cerr << "x != 10" << std::endl; - return 1; - } - } else { - std::cerr << "Failed to read 10 from istr" << std::endl; - return 1; - } - if (istr >> x) { - if (x != 20) { - std::cerr << "x != 20" << std::endl; - return 1; - } - } else { - std::cerr << "Failed to read 20 from istr" << std::endl; - return 1; - } - if (istr >> s) { - if (s != "str") { - std::cerr << "s != \"str\"" << std::endl; - return 1; - } - } else { - std::cerr << "Failed to read str from istr" << std::endl; - return 1; - } - if (istr >> s) { - std::cerr << "Able to read past end of stream" << std::endl; - return 1; - } else { - // Clear the failure. - istr.clear(istr.rdstate() & ~std::ios::eofbit); - istr.clear(istr.rdstate() & ~std::ios::failbit); - } - istr.str("30"); - if (istr >> x) { - if (x != 30) { - std::cerr << "x != 30" << std::endl; - return 1; - } - } else { - std::cerr << "Failed to read 30 from istr" << std::endl; - return 1; - } - - std::stringstream sstr; - sstr << "40 str2"; - if (sstr >> x) { - if (x != 40) { - std::cerr << "x != 40" << std::endl; - return 1; - } - } else { - std::cerr << "Failed to read 40 from sstr" << std::endl; - return 1; - } - if (sstr >> s) { - if (s != "str2") { - std::cerr << "s != \"str2\"" << std::endl; - return 1; - } - } else { - std::cerr << "Failed to read str2 from sstr" << std::endl; - return 1; - } - - // Just try to compile this. - if (x == 12345) { - std::ifstream fin("/does_not_exist", std::ios::in | std::ios::binary); - } - - std::cout << "IOS tests passed" << std::endl; - return 0; -} diff --git a/Source/kwsys/testSystemTools.cxx b/Source/kwsys/testSystemTools.cxx index e6fbf6cda..768eb4d12 100644 --- a/Source/kwsys/testSystemTools.cxx +++ b/Source/kwsys/testSystemTools.cxx @@ -22,6 +22,7 @@ #include <iostream> #include <sstream> +#include <stdlib.h> /* free */ #include <string.h> /* strcmp */ #if defined(_WIN32) && !defined(__CYGWIN__) #include <io.h> /* _umask (MSVC) / umask (Borland) */ @@ -535,15 +536,14 @@ static bool CheckStringOperations() } delete[] cres; - char* cres2 = new char[strlen("Mary Had A Little Lamb.") + 1]; - strcpy(cres2, "Mary Had A Little Lamb."); + char* cres2 = strdup("Mary Had A Little Lamb."); kwsys::SystemTools::ReplaceChars(cres2, "aeiou", 'X'); if (strcmp(cres2, "MXry HXd A LXttlX LXmb.")) { std::cerr << "Problem with ReplaceChars " << "\"Mary Had A Little Lamb.\"" << std::endl; res = false; } - delete[] cres2; + free(cres2); if (!kwsys::SystemTools::StringStartsWith("Mary Had A Little Lamb.", "Mary ")) { @@ -758,6 +758,30 @@ static bool CheckGetPath() return res; } +static bool CheckGetFilenameName() +{ + const char* windowsFilepath = "C:\\somewhere\\something"; + const char* unixFilepath = "/somewhere/something"; + + std::string expectedFilename = "something"; + + bool res = true; + std::string filename = kwsys::SystemTools::GetFilenameName(windowsFilepath); + if (filename != expectedFilename) { + std::cerr << "GetFilenameName(" << windowsFilepath << ") yielded " + << filename << " instead of " << expectedFilename << std::endl; + res = false; + } + + filename = kwsys::SystemTools::GetFilenameName(unixFilepath); + if (filename != expectedFilename) { + std::cerr << "GetFilenameName(" << unixFilepath << ") yielded " << filename + << " instead of " << expectedFilename << std::endl; + res = false; + } + return res; +} + static bool CheckFind() { bool res = true; @@ -875,5 +899,7 @@ int testSystemTools(int, char* []) res &= CheckGetLineFromStream(); + res &= CheckGetFilenameName(); + return res ? 0 : 1; } |