| 95 | } |
| 96 | |
| 97 | std::pair<std::filesystem::path, std::filesystem::path> |
| 98 | PlatformFileSystem::toSplitPlatformPath(PathId id) { |
| 99 | std::filesystem::path path = toPath(id); |
| 100 | const std::string pathstr = path.string(); |
| 101 | filepath_to_working_directories_cache_t::const_iterator it = |
| 102 | m_filepathToWorkingDirectoriesCache.find(pathstr); |
| 103 | if (it != m_filepathToWorkingDirectoriesCache.end()) { |
| 104 | std::filesystem::path suffix = path.lexically_relative(it->second); |
| 105 | return std::make_pair(it->second, suffix); |
| 106 | } |
| 107 | |
| 108 | int32_t minUpDirs = std::numeric_limits<int32_t>::max(); |
| 109 | std::filesystem::path bestPrefix; |
| 110 | std::filesystem::path bestSuffix; |
| 111 | |
| 112 | for (const Configuration &configuration : m_configurations) { |
| 113 | const std::filesystem::path &prefix = configuration.m_sourceDir; |
| 114 | if (prefix == path) { |
| 115 | bestPrefix = path; |
| 116 | bestSuffix = "."; |
| 117 | minUpDirs = 0; |
| 118 | break; |
| 119 | } else if (prefix.root_path() == path.root_path()) { |
| 120 | std::filesystem::path suffix = path.lexically_relative(prefix); |
| 121 | |
| 122 | int32_t upDirs = 0; |
| 123 | for (const auto &part : suffix) { |
| 124 | if (part == "..") |
| 125 | ++upDirs; |
| 126 | else |
| 127 | break; |
| 128 | } |
| 129 | |
| 130 | if (upDirs < minUpDirs) { |
| 131 | minUpDirs = upDirs; |
| 132 | bestPrefix = prefix; |
| 133 | bestSuffix = suffix; |
| 134 | if (minUpDirs == 0) break; |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | return (minUpDirs == std::numeric_limits<int32_t>::max()) |
| 140 | ? std::make_pair("", path) |
| 141 | : std::make_pair(bestPrefix, bestSuffix); |
| 142 | } |
| 143 | |
| 144 | std::filesystem::path PlatformFileSystem::toPlatformRelPath(PathId id) { |
| 145 | return toSplitPlatformPath(id).second; |