mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-16 14:08:35 +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 };
|
||||
path = basePath.Append(path);
|
||||
}
|
||||
result = cmSystemTools::GetActualCaseForPath(
|
||||
cmSystemTools::GetRealPath(path.String()));
|
||||
result = cmSystemTools::GetRealPath(path.String());
|
||||
};
|
||||
|
||||
std::string realPath;
|
||||
@@ -1420,7 +1419,6 @@ bool HandleRealPathCommand(std::vector<std::string> const& args,
|
||||
std::string oldPolicyPath =
|
||||
cmSystemTools::CollapseFullPath(input, *arguments.BaseDirectory);
|
||||
oldPolicyPath = cmSystemTools::GetRealPath(oldPolicyPath);
|
||||
oldPolicyPath = cmSystemTools::GetActualCaseForPath(oldPolicyPath);
|
||||
if (warnAbout152) {
|
||||
computeNewPath(input, realPath);
|
||||
if (oldPolicyPath != realPath) {
|
||||
|
@@ -1138,6 +1138,29 @@ std::string cmSystemTools::GetRealPathResolvingWindowsSubst(
|
||||
#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()
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
@@ -2703,8 +2726,7 @@ void cmSystemTools::FindCMakeResources(const char* argv0)
|
||||
wchar_t modulepath[_MAX_PATH];
|
||||
::GetModuleFileNameW(nullptr, modulepath, sizeof(modulepath));
|
||||
std::string path = cmsys::Encoding::ToNarrow(modulepath);
|
||||
std::string realPath =
|
||||
cmSystemTools::GetRealPathResolvingWindowsSubst(path, nullptr);
|
||||
std::string realPath = cmSystemTools::GetRealPath(path, nullptr);
|
||||
if (realPath.empty()) {
|
||||
realPath = path;
|
||||
}
|
||||
|
@@ -610,6 +610,8 @@ public:
|
||||
resolve subst drives too. */
|
||||
static std::string GetRealPathResolvingWindowsSubst(
|
||||
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. */
|
||||
static void InitializeLibUV();
|
||||
|
Reference in New Issue
Block a user