1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-16 14:08:35 +08:00

Merge branch 'upstream-KWSys' into update-kwsys

# By KWSys Upstream
* upstream-KWSys:
  KWSys 2020-04-06 (af1f389c)
This commit is contained in:
Brad King
2020-04-06 09:24:42 -04:00
2 changed files with 55 additions and 48 deletions

View File

@@ -498,6 +498,9 @@ public:
bool no_system_path = false); bool no_system_path = false);
}; };
// Do NOT initialize. Default initialization to zero is necessary.
static SystemToolsStatic* SystemToolsStatics;
#ifdef _WIN32 #ifdef _WIN32
std::string SystemToolsStatic::GetCasePathName(std::string const& pathIn) std::string SystemToolsStatic::GetCasePathName(std::string const& pathIn)
{ {
@@ -572,7 +575,7 @@ std::string SystemToolsStatic::GetActualCaseForPathCached(std::string const& p)
{ {
// Check to see if actual case has already been called // Check to see if actual case has already been called
// for this path, and the result is stored in the PathCaseMap // for this path, and the result is stored in the PathCaseMap
auto& pcm = SystemTools::Statics->PathCaseMap; auto& pcm = SystemToolsStatics->PathCaseMap;
{ {
auto itr = pcm.find(p); auto itr = pcm.find(p);
if (itr != pcm.end()) { if (itr != pcm.end()) {
@@ -629,7 +632,7 @@ const char* SystemToolsStatic::GetEnvBuffered(const char* key)
{ {
std::string env; std::string env;
if (SystemTools::GetEnv(key, env)) { if (SystemTools::GetEnv(key, env)) {
std::string& menv = SystemTools::Statics->EnvMap[key]; std::string& menv = SystemToolsStatics->EnvMap[key];
if (menv != env) { if (menv != env) {
menv = std::move(env); menv = std::move(env);
} }
@@ -1453,15 +1456,15 @@ int SystemTools::Stat(const std::string& path, SystemTools::Stat_t* buf)
#ifdef __CYGWIN__ #ifdef __CYGWIN__
bool SystemTools::PathCygwinToWin32(const char* path, char* win32_path) bool SystemTools::PathCygwinToWin32(const char* path, char* win32_path)
{ {
auto itr = SystemTools::Statics->Cyg2Win32Map.find(path); auto itr = SystemToolsStatics->Cyg2Win32Map.find(path);
if (itr != SystemTools::Statics->Cyg2Win32Map.end()) { if (itr != SystemToolsStatics->Cyg2Win32Map.end()) {
strncpy(win32_path, itr->second.c_str(), MAX_PATH); strncpy(win32_path, itr->second.c_str(), MAX_PATH);
} else { } else {
if (cygwin_conv_path(CCP_POSIX_TO_WIN_A, path, win32_path, MAX_PATH) != if (cygwin_conv_path(CCP_POSIX_TO_WIN_A, path, win32_path, MAX_PATH) !=
0) { 0) {
win32_path[0] = 0; win32_path[0] = 0;
} }
SystemTools::Statics->Cyg2Win32Map.insert( SystemToolsStatics->Cyg2Win32Map.insert(
SystemToolsStatic::StringMap::value_type(path, win32_path)); SystemToolsStatic::StringMap::value_type(path, win32_path));
} }
return win32_path[0] != 0; return win32_path[0] != 0;
@@ -3114,16 +3117,14 @@ int SystemTools::ChangeDirectory(const std::string& dir)
return Chdir(dir); return Chdir(dir);
} }
std::string SystemTools::GetCurrentWorkingDirectory(bool collapse) std::string SystemTools::GetCurrentWorkingDirectory()
{ {
char buf[2048]; char buf[2048];
const char* cwd = Getcwd(buf, 2048); const char* cwd = Getcwd(buf, 2048);
std::string path; std::string path;
if (cwd) { if (cwd) {
path = cwd; path = cwd;
} SystemTools::ConvertToUnixSlashes(path);
if (collapse) {
return SystemTools::CollapseFullPath(path);
} }
return path; return path;
} }
@@ -3215,11 +3216,6 @@ bool SystemTools::FindProgramPath(const char* argv0, std::string& pathOut,
return true; return true;
} }
std::string SystemTools::CollapseFullPath(const std::string& in_relative)
{
return SystemTools::CollapseFullPath(in_relative, nullptr);
}
#if KWSYS_SYSTEMTOOLS_USE_TRANSLATION_MAP #if KWSYS_SYSTEMTOOLS_USE_TRANSLATION_MAP
void SystemTools::AddTranslationPath(const std::string& a, void SystemTools::AddTranslationPath(const std::string& a,
const std::string& b) const std::string& b)
@@ -3244,7 +3240,7 @@ void SystemTools::AddTranslationPath(const std::string& a,
path_b += '/'; path_b += '/';
} }
if (!(path_a == path_b)) { if (!(path_a == path_b)) {
SystemTools::Statics->TranslationMap.insert( SystemToolsStatics->TranslationMap.insert(
SystemToolsStatic::StringMap::value_type(std::move(path_a), SystemToolsStatic::StringMap::value_type(std::move(path_a),
std::move(path_b))); std::move(path_b)));
} }
@@ -3274,7 +3270,7 @@ void SystemTools::CheckTranslationPath(std::string& path)
// In case a file was specified we still have to go through this: // In case a file was specified we still have to go through this:
// Now convert any path found in the table back to the one desired: // Now convert any path found in the table back to the one desired:
for (auto const& pair : SystemTools::Statics->TranslationMap) { for (auto const& pair : SystemToolsStatics->TranslationMap) {
// We need to check of the path is a substring of the other path // We need to check of the path is a substring of the other path
if (path.compare(0, pair.first.size(), pair.first) == 0) { if (path.compare(0, pair.first.size(), pair.first) == 0) {
path = path.replace(0, pair.first.size(), pair.second); path = path.replace(0, pair.first.size(), pair.second);
@@ -3309,25 +3305,10 @@ static void SystemToolsAppendComponents(
} }
} }
std::string SystemTools::CollapseFullPath(const std::string& in_path, namespace {
const char* in_base)
{
// Use the current working directory as a base path.
char buf[2048];
const char* res_in_base = in_base;
if (!res_in_base) {
if (const char* cwd = Getcwd(buf, 2048)) {
res_in_base = cwd;
} else {
res_in_base = "";
}
}
return SystemTools::CollapseFullPath(in_path, std::string(res_in_base)); std::string CollapseFullPathImpl(std::string const& in_path,
} std::string const* in_base)
std::string SystemTools::CollapseFullPath(const std::string& in_path,
const std::string& in_base)
{ {
// Collect the output path components. // Collect the output path components.
std::vector<std::string> out_components; std::vector<std::string> out_components;
@@ -3340,8 +3321,15 @@ std::string SystemTools::CollapseFullPath(const std::string& in_path,
// If the input path is relative, start with a base path. // If the input path is relative, start with a base path.
if (path_components[0].empty()) { if (path_components[0].empty()) {
std::vector<std::string> base_components; std::vector<std::string> base_components;
// Use the given base path.
SystemTools::SplitPath(in_base, base_components); if (in_base) {
// Use the given base path.
SystemTools::SplitPath(*in_base, base_components);
} else {
// Use the current working directory as a base path.
std::string cwd = SystemTools::GetCurrentWorkingDirectory();
SystemTools::SplitPath(cwd, base_components);
}
// Append base path components to the output path. // Append base path components to the output path.
out_components.push_back(base_components[0]); out_components.push_back(base_components[0]);
@@ -3374,12 +3362,34 @@ std::string SystemTools::CollapseFullPath(const std::string& in_path,
SystemTools::CheckTranslationPath(newPath); SystemTools::CheckTranslationPath(newPath);
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
newPath = SystemTools::Statics->GetActualCaseForPathCached(newPath); newPath = SystemToolsStatics->GetActualCaseForPathCached(newPath);
SystemTools::ConvertToUnixSlashes(newPath); SystemTools::ConvertToUnixSlashes(newPath);
#endif #endif
// Return the reconstructed path. // Return the reconstructed path.
return newPath; return newPath;
} }
}
std::string SystemTools::CollapseFullPath(std::string const& in_path)
{
return CollapseFullPathImpl(in_path, nullptr);
}
std::string SystemTools::CollapseFullPath(std::string const& in_path,
const char* in_base)
{
if (!in_base) {
return CollapseFullPathImpl(in_path, nullptr);
}
std::string tmp_base = in_base;
return CollapseFullPathImpl(in_path, &tmp_base);
}
std::string SystemTools::CollapseFullPath(std::string const& in_path,
std::string const& in_base)
{
return CollapseFullPathImpl(in_path, &in_base);
}
// compute the relative path from here to there // compute the relative path from here to there
std::string SystemTools::RelativePath(const std::string& local, std::string SystemTools::RelativePath(const std::string& local,
@@ -4601,10 +4611,8 @@ std::string SystemTools::DecodeURL(const std::string& url)
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// These must NOT be initialized. Default initialization to zero is // Do NOT initialize. Default initialization to zero is necessary.
// necessary.
static unsigned int SystemToolsManagerCount; static unsigned int SystemToolsManagerCount;
SystemToolsStatic* SystemTools::Statics;
// SystemToolsManager manages the SystemTools singleton. // SystemToolsManager manages the SystemTools singleton.
// SystemToolsManager should be included in any translation unit // SystemToolsManager should be included in any translation unit
@@ -4647,7 +4655,7 @@ void SystemTools::ClassInitialize()
#endif #endif
// Create statics singleton instance // Create statics singleton instance
SystemTools::Statics = new SystemToolsStatic; SystemToolsStatics = new SystemToolsStatic;
#if KWSYS_SYSTEMTOOLS_USE_TRANSLATION_MAP #if KWSYS_SYSTEMTOOLS_USE_TRANSLATION_MAP
// Add some special translation paths for unix. These are not added // Add some special translation paths for unix. These are not added
@@ -4697,7 +4705,7 @@ void SystemTools::ClassInitialize()
void SystemTools::ClassFinalize() void SystemTools::ClassFinalize()
{ {
delete SystemTools::Statics; delete SystemToolsStatics;
} }
} // namespace KWSYS_NAMESPACE } // namespace KWSYS_NAMESPACE

View File

@@ -411,11 +411,11 @@ public:
* (which defaults to the current working directory). The full path * (which defaults to the current working directory). The full path
* is returned. * is returned.
*/ */
static std::string CollapseFullPath(const std::string& in_relative); static std::string CollapseFullPath(std::string const& in_path);
static std::string CollapseFullPath(const std::string& in_relative, static std::string CollapseFullPath(std::string const& in_path,
const char* in_base); const char* in_base);
static std::string CollapseFullPath(const std::string& in_relative, static std::string CollapseFullPath(std::string const& in_path,
const std::string& in_base); std::string const& in_base);
/** /**
* Get the real path for a given path, removing all symlinks. In * Get the real path for a given path, removing all symlinks. In
@@ -869,7 +869,7 @@ public:
/** /**
* Get current working directory CWD * Get current working directory CWD
*/ */
static std::string GetCurrentWorkingDirectory(bool collapse = true); static std::string GetCurrentWorkingDirectory();
/** /**
* Change directory to the directory specified * Change directory to the directory specified
@@ -981,7 +981,6 @@ private:
return &SystemToolsManagerInstance; return &SystemToolsManagerInstance;
} }
static SystemToolsStatic* Statics;
friend class SystemToolsStatic; friend class SystemToolsStatic;
friend class SystemToolsManager; friend class SystemToolsManager;
}; };