|
@@ -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);
|
|
|
|
|
- if (itr != SystemTools::Statics->Cyg2Win32Map.end()) {
|
|
|
|
|
|
|
+ auto itr = SystemToolsStatics->Cyg2Win32Map.find(path);
|
|
|
|
|
+ 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;
|
|
|
- }
|
|
|
|
|
- if (collapse) {
|
|
|
|
|
- return SystemTools::CollapseFullPath(path);
|
|
|
|
|
|
|
+ SystemTools::ConvertToUnixSlashes(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,
|
|
|
|
|
- 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 = "";
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+namespace {
|
|
|
|
|
|
|
|
- return SystemTools::CollapseFullPath(in_path, std::string(res_in_base));
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-std::string SystemTools::CollapseFullPath(const std::string& in_path,
|
|
|
|
|
- const std::string& in_base)
|
|
|
|
|
|
|
+std::string CollapseFullPathImpl(std::string const& in_path,
|
|
|
|
|
+ std::string const* 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
|
|
|
|
|
-// necessary.
|
|
|
|
|
|
|
+// Do NOT initialize. Default initialization to zero is 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
|