mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-04 13:19:51 -05:00
file: Add READ_SYMLINK sub-command
This commit is contained in:
@@ -180,6 +180,9 @@ bool cmFileCommand::InitialPass(std::vector<std::string> const& args,
|
||||
if (subCommand == "SIZE") {
|
||||
return this->HandleSizeCommand(args);
|
||||
}
|
||||
if (subCommand == "READ_SYMLINK") {
|
||||
return this->HandleReadSymlinkCommand(args);
|
||||
}
|
||||
|
||||
std::string e = "does not recognize sub-command " + subCommand;
|
||||
this->SetError(e);
|
||||
@@ -3638,3 +3641,30 @@ bool cmFileCommand::HandleSizeCommand(std::vector<std::string> const& args)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cmFileCommand::HandleReadSymlinkCommand(
|
||||
std::vector<std::string> const& args)
|
||||
{
|
||||
if (args.size() != 3) {
|
||||
std::ostringstream e;
|
||||
e << args[0] << " requires a file name and output variable";
|
||||
this->SetError(e.str());
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string& filename = args[1];
|
||||
const std::string& outputVariable = args[2];
|
||||
|
||||
std::string result;
|
||||
if (!cmSystemTools::ReadSymlink(filename, result)) {
|
||||
std::ostringstream e;
|
||||
e << "READ_SYMLINK requested of path that is not a symlink:\n "
|
||||
<< filename;
|
||||
this->SetError(e.str());
|
||||
return false;
|
||||
}
|
||||
|
||||
this->Makefile->AddDefinition(outputVariable, result.c_str());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user