summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorKyle Edwards <kyle.edwards@kitware.com>2018-12-05 20:27:08 (GMT)
committerKyle Edwards <kyle.edwards@kitware.com>2018-12-06 15:11:51 (GMT)
commit98a39be6cfb7b229ff78f7045c6d5bcd6b6c7509 (patch)
tree1f9810b45b6d79710d89457d2db530cf5be24613 /Source
parent81bea69bd1d52977c3782d26560f34563394f487 (diff)
downloadCMake-98a39be6cfb7b229ff78f7045c6d5bcd6b6c7509.zip
CMake-98a39be6cfb7b229ff78f7045c6d5bcd6b6c7509.tar.gz
CMake-98a39be6cfb7b229ff78f7045c6d5bcd6b6c7509.tar.bz2
file: Add READ_SYMLINK sub-command
Diffstat (limited to 'Source')
-rw-r--r--Source/cmFileCommand.cxx30
-rw-r--r--Source/cmFileCommand.h1
2 files changed, 31 insertions, 0 deletions
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx
index 73ff5a1..7fc717d 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);
@@ -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,