mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-20 04:24:36 +08:00
cmSystemTools: Implement GetRealPath on Windows
Use `cm::PathResolver`'s `RealPath` variant to normalize paths, look up their on-disk case, and resolve symlinks, but without resolving `subst` drives on Windows. Fixes: #17206
This commit is contained in:
@@ -1409,8 +1409,7 @@ bool HandleRealPathCommand(std::vector<std::string> const& args,
|
|||||||
auto basePath = cmCMakePath{ *arguments.BaseDirectory };
|
auto basePath = cmCMakePath{ *arguments.BaseDirectory };
|
||||||
path = basePath.Append(path);
|
path = basePath.Append(path);
|
||||||
}
|
}
|
||||||
result = cmSystemTools::GetActualCaseForPath(
|
result = cmSystemTools::GetRealPath(path.String());
|
||||||
cmSystemTools::GetRealPath(path.String()));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string realPath;
|
std::string realPath;
|
||||||
@@ -1420,7 +1419,6 @@ bool HandleRealPathCommand(std::vector<std::string> const& args,
|
|||||||
std::string oldPolicyPath =
|
std::string oldPolicyPath =
|
||||||
cmSystemTools::CollapseFullPath(input, *arguments.BaseDirectory);
|
cmSystemTools::CollapseFullPath(input, *arguments.BaseDirectory);
|
||||||
oldPolicyPath = cmSystemTools::GetRealPath(oldPolicyPath);
|
oldPolicyPath = cmSystemTools::GetRealPath(oldPolicyPath);
|
||||||
oldPolicyPath = cmSystemTools::GetActualCaseForPath(oldPolicyPath);
|
|
||||||
if (warnAbout152) {
|
if (warnAbout152) {
|
||||||
computeNewPath(input, realPath);
|
computeNewPath(input, realPath);
|
||||||
if (oldPolicyPath != realPath) {
|
if (oldPolicyPath != realPath) {
|
||||||
|
@@ -1138,6 +1138,29 @@ std::string cmSystemTools::GetRealPathResolvingWindowsSubst(
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string cmSystemTools::GetRealPath(const std::string& path,
|
||||||
|
std::string* errorMessage)
|
||||||
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
|
std::string resolved_path;
|
||||||
|
using namespace cm::PathResolver;
|
||||||
|
// IWYU pragma: no_forward_declare cm::PathResolver::Policies::RealPath
|
||||||
|
static const Resolver<Policies::RealPath> resolver(RealOS);
|
||||||
|
cmsys::Status status = resolver.Resolve(path, resolved_path);
|
||||||
|
if (!status) {
|
||||||
|
if (errorMessage) {
|
||||||
|
*errorMessage = status.GetString();
|
||||||
|
resolved_path.clear();
|
||||||
|
} else {
|
||||||
|
resolved_path = path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resolved_path;
|
||||||
|
#else
|
||||||
|
return cmsys::SystemTools::GetRealPath(path, errorMessage);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void cmSystemTools::InitializeLibUV()
|
void cmSystemTools::InitializeLibUV()
|
||||||
{
|
{
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
@@ -2703,8 +2726,7 @@ void cmSystemTools::FindCMakeResources(const char* argv0)
|
|||||||
wchar_t modulepath[_MAX_PATH];
|
wchar_t modulepath[_MAX_PATH];
|
||||||
::GetModuleFileNameW(nullptr, modulepath, sizeof(modulepath));
|
::GetModuleFileNameW(nullptr, modulepath, sizeof(modulepath));
|
||||||
std::string path = cmsys::Encoding::ToNarrow(modulepath);
|
std::string path = cmsys::Encoding::ToNarrow(modulepath);
|
||||||
std::string realPath =
|
std::string realPath = cmSystemTools::GetRealPath(path, nullptr);
|
||||||
cmSystemTools::GetRealPathResolvingWindowsSubst(path, nullptr);
|
|
||||||
if (realPath.empty()) {
|
if (realPath.empty()) {
|
||||||
realPath = path;
|
realPath = path;
|
||||||
}
|
}
|
||||||
|
@@ -610,6 +610,8 @@ public:
|
|||||||
resolve subst drives too. */
|
resolve subst drives too. */
|
||||||
static std::string GetRealPathResolvingWindowsSubst(
|
static std::string GetRealPathResolvingWindowsSubst(
|
||||||
const std::string& path, std::string* errorMessage = nullptr);
|
const std::string& path, std::string* errorMessage = nullptr);
|
||||||
|
static std::string GetRealPath(const std::string& path,
|
||||||
|
std::string* errorMessage = nullptr);
|
||||||
|
|
||||||
/** Perform one-time initialization of libuv. */
|
/** Perform one-time initialization of libuv. */
|
||||||
static void InitializeLibUV();
|
static void InitializeLibUV();
|
||||||
|
Reference in New Issue
Block a user