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

Function HandleRealPathCommand

Source/cmFileCommand.cxx:1294–1404  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1292}
1293
1294bool HandleRealPathCommand(std::vector<std::string> const& args,
1295 cmExecutionStatus& status)
1296{
1297 if (args.size() < 3) {
1298 status.SetError("REAL_PATH requires a path and an output variable");
1299 return false;
1300 }
1301
1302 struct Arguments : public ArgumentParser::ParseResult
1303 {
1304 cm::optional<std::string> BaseDirectory;
1305 bool ExpandTilde = false;
1306 };
1307 static auto const parser =
1308 cmArgumentParser<Arguments>{}
1309 .Bind("BASE_DIRECTORY"_s, &Arguments::BaseDirectory)
1310 .Bind("EXPAND_TILDE"_s, &Arguments::ExpandTilde);
1311
1312 std::vector<std::string> unparsedArguments;
1313 auto arguments =
1314 parser.Parse(cmMakeRange(args).advance(3), &unparsedArguments);
1315
1316 if (!unparsedArguments.empty()) {
1317 status.SetError("REAL_PATH called with unexpected arguments");
1318 return false;
1319 }
1320 if (arguments.MaybeReportError(status.GetMakefile())) {
1321 return true;
1322 }
1323
1324 if (!arguments.BaseDirectory) {
1325 arguments.BaseDirectory = status.GetMakefile().GetCurrentSourceDirectory();
1326 }
1327
1328 auto input = args[1];
1329 if (arguments.ExpandTilde && !input.empty()) {
1330 if (input[0] == '~' && (input.length() == 1 || input[1] == '/')) {
1331 std::string home;
1332 if (
1333#if defined(_WIN32) && !defined(__CYGWIN__)
1334 cmSystemTools::GetEnv("USERPROFILE", home) ||
1335#endif
1336 cmSystemTools::GetEnv("HOME", home)) {
1337 input.replace(0, 1, home);
1338 }
1339 }
1340 }
1341
1342 bool warnAbout152 = false;
1343 bool use152New = true;
1344 cmPolicies::PolicyStatus policyStatus =
1345 status.GetMakefile().GetPolicyStatus(cmPolicies::CMP0152);
1346 switch (policyStatus) {
1347 case cmPolicies::NEW:
1348 break;
1349 case cmPolicies::WARN:
1350 use152New = false;
1351 warnAbout152 = true;

Callers

nothing calls this directly

Calls 15

cmMakeRangeFunction · 0.85
GetRealPathFunction · 0.85
MaybeReportErrorMethod · 0.80
lengthMethod · 0.80
IsRelativeMethod · 0.80
cmStrCatFunction · 0.70
FileExistsFunction · 0.50
sizeMethod · 0.45
SetErrorMethod · 0.45
BindMethod · 0.45
ParseMethod · 0.45
advanceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…