KWSys 2017-04-12 (23a4c211)

Code extracted from:

    https://gitlab.kitware.com/utils/kwsys.git

at commit 23a4c211e90c1cfd399c3632141dbd549a5db8cf (master).

Upstream Shortlog
-----------------

Brad King (2):
      41a9dfef SystemInformation: Fix dynamic loader failure on WinXP SP2
      3ead6158 SystemTools: Fix stat() wrapper compilation with Borland

Daniel Pfeifer (1):
      ce5b0d34 Disable include-what-you-use

Mathieu Westphal (1):
      a2bf6bb3 SystemTools: Add cross-platform stat() wrapper
This commit is contained in:
KWSys Upstream 2017-04-12 09:08:58 -04:00 committed by Brad King
parent e9c5505bf9
commit 85841e8bd5
5 changed files with 95 additions and 4 deletions

View File

@ -796,6 +796,8 @@ ENDFOREACH()
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_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_USE_DynamicLoader)
IF(UNIX)
@ -940,6 +942,8 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
ENDIF()
IF(KWSYS_USE_ConsoleBuf)
ADD_EXECUTABLE(testConsoleBufChild testConsoleBufChild.cxx)
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})
SET(KWSYS_CXX_TESTS ${KWSYS_CXX_TESTS}
@ -967,6 +971,8 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
${KWSYS_CXX_TESTS}
)
ADD_EXECUTABLE(${KWSYS_NAMESPACE}TestsCxx ${KWSYS_CXX_TEST_SRCS})
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})

View File

@ -4341,18 +4341,35 @@ unsigned char SystemInformationImplementation::GetAPICId()
void SystemInformationImplementation::CPUCountWindows()
{
#if defined(_WIN32)
std::vector<SYSTEM_LOGICAL_PROCESSOR_INFORMATION> ProcInfo;
this->NumberOfPhysicalCPU = 0;
this->NumberOfLogicalCPU = 0;
typedef BOOL(WINAPI * GetLogicalProcessorInformationType)(
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION, PDWORD);
static GetLogicalProcessorInformationType pGetLogicalProcessorInformation =
(GetLogicalProcessorInformationType)GetProcAddress(
GetModuleHandleW(L"kernel32"), "GetLogicalProcessorInformation");
if (!pGetLogicalProcessorInformation) {
// Fallback to approximate implementation on ancient Windows versions.
SYSTEM_INFO info;
ZeroMemory(&info, sizeof(info));
GetSystemInfo(&info);
this->NumberOfPhysicalCPU =
static_cast<unsigned int>(info.dwNumberOfProcessors);
this->NumberOfLogicalCPU = this->NumberOfPhysicalCPU;
return;
}
std::vector<SYSTEM_LOGICAL_PROCESSOR_INFORMATION> ProcInfo;
{
DWORD Length = 0;
DWORD rc = GetLogicalProcessorInformation(NULL, &Length);
DWORD rc = pGetLogicalProcessorInformation(NULL, &Length);
assert(FALSE == rc);
(void)rc; // Silence unused variable warning in Borland C++ 5.81
assert(GetLastError() == ERROR_INSUFFICIENT_BUFFER);
ProcInfo.resize(Length / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION));
rc = GetLogicalProcessorInformation(&ProcInfo[0], &Length);
rc = pGetLogicalProcessorInformation(&ProcInfo[0], &Length);
assert(rc != FALSE);
(void)rc; // Silence unused variable warning in Borland C++ 5.81
}

View File

@ -54,7 +54,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <time.h>
#if defined(_WIN32) && !defined(_MSC_VER) && defined(__GNUC__)
@ -1257,6 +1256,38 @@ bool SystemTools::TestFileAccess(const std::string& filename,
#endif
}
//----------------------------------------------------------------------------
int SystemTools::Stat(const char* path, SystemTools::Stat_t* buf)
{
if (!path) {
errno = EFAULT;
return -1;
}
return SystemTools::Stat(std::string(path), buf);
}
//----------------------------------------------------------------------------
int SystemTools::Stat(const std::string& path, SystemTools::Stat_t* buf)
{
if (path.empty()) {
errno = ENOENT;
return -1;
}
#if defined(_WIN32) && !defined(__CYGWIN__)
// Ideally we should use ConvertToWindowsExtendedPath to support
// long paths, but _wstat64 rejects paths with '?' in them, thinking
// they are wildcards.
std::wstring const& wpath = Encoding::ToWide(path);
#if defined(__BORLANDC__)
return _wstati64(wpath.c_str(), buf);
#else
return _wstat64(wpath.c_str(), buf);
#endif
#else
return stat(path.c_str(), buf);
#endif
}
//----------------------------------------------------------------------------
#ifdef __CYGWIN__
bool SystemTools::PathCygwinToWin32(const char* path, char* win32_path)

View File

@ -13,6 +13,9 @@
#include <@KWSYS_NAMESPACE@/String.hxx>
#include <sys/types.h>
// include sys/stat.h after sys/types.h
#include <sys/stat.h>
#if !defined(_WIN32) || defined(__CYGWIN__)
#include <unistd.h> // For access permissions for use with access()
#endif
@ -324,6 +327,27 @@ public:
TestFilePermissions permissions);
static bool TestFileAccess(const std::string& filename,
TestFilePermissions permissions);
/**
* Cross platform wrapper for stat struct
*/
#if defined(_WIN32) && !defined(__CYGWIN__)
#if defined(__BORLANDC__)
typedef struct stati64 Stat_t;
#else
typedef struct _stat64 Stat_t;
#endif
#else
typedef struct stat Stat_t;
#endif
/**
* Cross platform wrapper for stat system call
*
* On Windows this may not work for paths longer than 250 characters
* due to limitations of the underlying '_wstat64' call.
*/
static int Stat(const char* path, Stat_t* buf);
static int Stat(const std::string& path, Stat_t* buf);
/**
* Converts Cygwin path to Win32 path. Uses dictionary container for

View File

@ -135,6 +135,19 @@ static bool CheckFileOperations()
res = false;
}
kwsys::SystemTools::Stat_t buf;
if (kwsys::SystemTools::Stat(testTxtFile.c_str(), &buf) != 0) {
std::cerr << "Problem with Stat - unable to stat text file: "
<< testTxtFile << std::endl;
res = false;
}
if (kwsys::SystemTools::Stat(testBinFile, &buf) != 0) {
std::cerr << "Problem with Stat - unable to stat bin file: " << testBinFile
<< std::endl;
res = false;
}
if (!kwsys::SystemTools::MakeDirectory(testNewDir)) {
std::cerr << "Problem with MakeDirectory for: " << testNewDir << std::endl;
res = false;