diff options
author | Brad King <brad.king@kitware.com> | 2018-12-10 13:21:33 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2018-12-10 13:21:40 (GMT) |
commit | 0bfe96a8c35aae2744efad664444ac5a963d74d3 (patch) | |
tree | 01274134ad4e168667e9deff248e77cc619459e6 /Source | |
parent | e1db7aac307e85154c1abd91afbdf61b65780caf (diff) | |
parent | 31840e363f61c10770a3d22467396c05e7d3d422 (diff) | |
download | CMake-0bfe96a8c35aae2744efad664444ac5a963d74d3.zip CMake-0bfe96a8c35aae2744efad664444ac5a963d74d3.tar.gz CMake-0bfe96a8c35aae2744efad664444ac5a963d74d3.tar.bz2 |
Merge topic 'file-read_symlink'
31840e363f file: Fix formatting of error in SIZE sub-command
98a39be6cf file: Add READ_SYMLINK sub-command
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2705
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmFileCommand.cxx | 32 | ||||
-rw-r--r-- | Source/cmFileCommand.h | 1 |
2 files changed, 32 insertions, 1 deletions
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index 73ff5a1..fb8e8d3 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -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); @@ -3627,7 +3630,7 @@ bool cmFileCommand::HandleSizeCommand(std::vector<std::string> const& args) if (!cmSystemTools::FileExists(filename, true)) { std::ostringstream e; - e << "SIZE requested of path that is not readable " << filename; + e << "SIZE requested of path that is not readable:\n " << filename; this->SetError(e.str()); return false; } @@ -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; +} diff --git a/Source/cmFileCommand.h b/Source/cmFileCommand.h index 01e007d..fe05c98 100644 --- a/Source/cmFileCommand.h +++ b/Source/cmFileCommand.h @@ -60,6 +60,7 @@ protected: bool HandleGenerateCommand(std::vector<std::string> const& args); bool HandleLockCommand(std::vector<std::string> const& args); bool HandleSizeCommand(std::vector<std::string> const& args); + bool HandleReadSymlinkCommand(std::vector<std::string> const& args); private: void AddEvaluationFile(const std::string& inputName, |