| 149 | } |
| 150 | |
| 151 | std::string DeterminePrefix(std::string const& filepath, |
| 152 | Json::Value const& data) |
| 153 | { |
| 154 | // First check if an absolute prefix was supplied. |
| 155 | std::string prefix = ToString(data["prefix"]); |
| 156 | if (!prefix.empty()) { |
| 157 | // Ensure that the specified prefix is valid. |
| 158 | if (cmsys::SystemTools::FileIsFullPath(prefix) && |
| 159 | cmsys::SystemTools::FileIsDirectory(prefix)) { |
| 160 | cmSystemTools::ConvertToUnixSlashes(prefix); |
| 161 | return prefix; |
| 162 | } |
| 163 | // The specified absolute prefix is not valid. |
| 164 | return {}; |
| 165 | } |
| 166 | |
| 167 | // Get and validate prefix-relative path. |
| 168 | std::string const& absPath = cmSystemTools::GetFilenamePath(filepath); |
| 169 | std::string relPath = ToString(data["cps_path"]); |
| 170 | cmSystemTools::ConvertToUnixSlashes(relPath); |
| 171 | if (relPath.empty() || !cmHasLiteralPrefix(relPath, "@prefix@")) { |
| 172 | // The relative prefix is not valid. |
| 173 | return {}; |
| 174 | } |
| 175 | if (relPath.size() == 8) { |
| 176 | // The relative path is exactly "@prefix@". |
| 177 | return absPath; |
| 178 | } |
| 179 | if (relPath[8] != '/') { |
| 180 | // The relative prefix is not valid. |
| 181 | return {}; |
| 182 | } |
| 183 | relPath = relPath.substr(8); |
| 184 | |
| 185 | // Get directory portion of the absolute path. |
| 186 | if (ComparePathSuffix(absPath, relPath)) { |
| 187 | return absPath.substr(0, absPath.size() - relPath.size()); |
| 188 | } |
| 189 | |
| 190 | for (auto* const f : { GetRealPath, GetRealDir }) { |
| 191 | std::string const& tmpPath = (*f)(absPath); |
| 192 | if (!cmSystemTools::ComparePath(tmpPath, absPath) && |
| 193 | ComparePathSuffix(tmpPath, relPath)) { |
| 194 | return tmpPath.substr(0, tmpPath.size() - relPath.size()); |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | return {}; |
| 199 | } |
| 200 | |
| 201 | // Extract key name from value iterator as string_view. |
| 202 | cm::string_view IterKey(Json::Value::const_iterator iter) |
no test coverage detected
searching dependent graphs…