MCPcopy Create free account
hub / github.com/Kitware/CMake / DeterminePrefix

Function DeterminePrefix

Source/cmPackageInfoReader.cxx:151–199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

149}
150
151std::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.
202cm::string_view IterKey(Json::Value::const_iterator iter)

Callers 1

ReadMethod · 0.85

Calls 6

cmHasLiteralPrefixFunction · 0.85
ComparePathSuffixFunction · 0.85
ToStringFunction · 0.70
emptyMethod · 0.45
sizeMethod · 0.45
substrMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…