Browse Source

cmSystemTools: Add ToNormalizedPathOnDisk helper

`CollapseFullPath` currently accesses the filesystem on Windows to
convert the path to the (upper/lower) case it has on disk.  Not all call
sites need this, so we'd eventually like to remove the behavior.  Add a
wrapper for call sites to express that they need to match the case of
on-disk paths.

Issue: #20214
Brad King 1 year ago
parent
commit
2503b43b6c
2 changed files with 9 additions and 0 deletions
  1. 7 0
      Source/cmSystemTools.cxx
  2. 2 0
      Source/cmSystemTools.h

+ 7 - 0
Source/cmSystemTools.cxx

@@ -1628,6 +1628,13 @@ std::vector<std::string> cmSystemTools::SplitEnvPath(std::string const& value)
   return paths;
 }
 
+std::string cmSystemTools::ToNormalizedPathOnDisk(std::string p)
+{
+  p = cmSystemTools::CollapseFullPath(p);
+  cmSystemTools::ConvertToUnixSlashes(p);
+  return p;
+}
+
 #ifndef CMAKE_BOOTSTRAP
 bool cmSystemTools::UnsetEnv(const char* value)
 {

+ 2 - 0
Source/cmSystemTools.h

@@ -401,6 +401,8 @@ public:
   static cm::optional<std::string> GetEnvVar(std::string const& var);
   static std::vector<std::string> SplitEnvPath(std::string const& value);
 
+  static std::string ToNormalizedPathOnDisk(std::string p);
+
 #ifndef CMAKE_BOOTSTRAP
   /** Remove an environment variable */
   static bool UnsetEnv(const char* value);