summaryrefslogtreecommitdiff
path: root/Source/cmQtAutoGenerator.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2018-04-04 15:21:48 +0000
committerKitware Robot <kwrobot@kitware.com>2018-04-04 11:21:54 -0400
commit49ea1bb243e8e2995bb3012a0b0ca226db845e3e (patch)
tree7ff9eef5c73ed18814a377d080977666421cfd6b /Source/cmQtAutoGenerator.cxx
parent6425ceb46cdb44396922819dcc56f919214cd85d (diff)
parentb11e2c80b1e45fc12151c8392707d88b508191ca (diff)
downloadcmake-49ea1bb243e8e2995bb3012a0b0ca226db845e3e.tar.gz
Merge topic 'autogen-protect-cmsys-calls'
b11e2c80b1 Autogen: Print moc/uic/rcc output to stdout 1d2c9d8c6d Autogen: Use std::istreambuf_iterator for file so string reading ccc38fa509 Autogen: Protected calls to cmFilePathChecksum 719b24c872 Autogen: Protected calls to cmQtAutoGen::SubDirPrefix 9a73615815 Autogen: Protected calls to cmSystemTools::GetFilenameWithoutLastExtension 65203ce407 Autogen: Protected calls to cmSystemTools::Split/JoinPath 14a86c9ea7 Autogen: Protected calls to cmSystemTools::CollapseCombinedPath Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !1918
Diffstat (limited to 'Source/cmQtAutoGenerator.cxx')
-rw-r--r--Source/cmQtAutoGenerator.cxx111
1 files changed, 90 insertions, 21 deletions
diff --git a/Source/cmQtAutoGenerator.cxx b/Source/cmQtAutoGenerator.cxx
index 5c35d76421..bf184d85e6 100644
--- a/Source/cmQtAutoGenerator.cxx
+++ b/Source/cmQtAutoGenerator.cxx
@@ -146,19 +146,93 @@ void cmQtAutoGenerator::Logger::ErrorCommand(
}
}
-std::string cmQtAutoGenerator::FileSystem::RealPath(
+std::string cmQtAutoGenerator::FileSystem::GetRealPath(
std::string const& filename)
{
std::lock_guard<std::mutex> lock(Mutex_);
return cmSystemTools::GetRealPath(filename);
}
+std::string cmQtAutoGenerator::FileSystem::CollapseCombinedPath(
+ std::string const& dir, std::string const& file)
+{
+ std::lock_guard<std::mutex> lock(Mutex_);
+ return cmSystemTools::CollapseCombinedPath(dir, file);
+}
+
+void cmQtAutoGenerator::FileSystem::SplitPath(
+ const std::string& p, std::vector<std::string>& components,
+ bool expand_home_dir)
+{
+ std::lock_guard<std::mutex> lock(Mutex_);
+ cmSystemTools::SplitPath(p, components, expand_home_dir);
+}
+
+std::string cmQtAutoGenerator::FileSystem::JoinPath(
+ const std::vector<std::string>& components)
+{
+ std::lock_guard<std::mutex> lock(Mutex_);
+ return cmSystemTools::JoinPath(components);
+}
+
+std::string cmQtAutoGenerator::FileSystem::JoinPath(
+ std::vector<std::string>::const_iterator first,
+ std::vector<std::string>::const_iterator last)
+{
+ std::lock_guard<std::mutex> lock(Mutex_);
+ return cmSystemTools::JoinPath(first, last);
+}
+
+std::string cmQtAutoGenerator::FileSystem::GetFilenameWithoutLastExtension(
+ const std::string& filename)
+{
+ std::lock_guard<std::mutex> lock(Mutex_);
+ return cmSystemTools::GetFilenameWithoutLastExtension(filename);
+}
+
+std::string cmQtAutoGenerator::FileSystem::SubDirPrefix(
+ std::string const& filename)
+{
+ std::lock_guard<std::mutex> lock(Mutex_);
+ return cmQtAutoGen::SubDirPrefix(filename);
+}
+
+void cmQtAutoGenerator::FileSystem::setupFilePathChecksum(
+ std::string const& currentSrcDir, std::string const& currentBinDir,
+ std::string const& projectSrcDir, std::string const& projectBinDir)
+{
+ std::lock_guard<std::mutex> lock(Mutex_);
+ FilePathChecksum_.setupParentDirs(currentSrcDir, currentBinDir,
+ projectSrcDir, projectBinDir);
+}
+
+std::string cmQtAutoGenerator::FileSystem::GetFilePathChecksum(
+ std::string const& filename)
+{
+ std::lock_guard<std::mutex> lock(Mutex_);
+ return FilePathChecksum_.getPart(filename);
+}
+
bool cmQtAutoGenerator::FileSystem::FileExists(std::string const& filename)
{
std::lock_guard<std::mutex> lock(Mutex_);
return cmSystemTools::FileExists(filename);
}
+bool cmQtAutoGenerator::FileSystem::FileExists(std::string const& filename,
+ bool isFile)
+{
+ std::lock_guard<std::mutex> lock(Mutex_);
+ return cmSystemTools::FileExists(filename, isFile);
+}
+
+unsigned long cmQtAutoGenerator::FileSystem::FileLength(
+ std::string const& filename)
+{
+ std::lock_guard<std::mutex> lock(Mutex_);
+ return cmSystemTools::FileLength(filename);
+}
+
bool cmQtAutoGenerator::FileSystem::FileIsOlderThan(
std::string const& buildFile, std::string const& sourceFile,
std::string* error)
@@ -188,35 +262,30 @@ bool cmQtAutoGenerator::FileSystem::FileRead(std::string& content,
std::string* error)
{
bool success = false;
- {
- std::lock_guard<std::mutex> lock(Mutex_);
- if (cmSystemTools::FileExists(filename, true)) {
- std::size_t const length = cmSystemTools::FileLength(filename);
+ if (FileExists(filename, true)) {
+ unsigned long const length = FileLength(filename);
+ {
+ std::lock_guard<std::mutex> lock(Mutex_);
cmsys::ifstream ifs(filename.c_str(), (std::ios::in | std::ios::binary));
if (ifs) {
- if (length > 0) {
- content.resize(length);
- ifs.read(&content.front(), content.size());
- if (ifs) {
- success = true;
- } else {
- content.clear();
- if (error != nullptr) {
- error->append("Reading from the file failed.");
- }
- }
+ content.reserve(length);
+ content.assign(std::istreambuf_iterator<char>{ ifs },
+ std::istreambuf_iterator<char>{});
+ if (ifs) {
+ success = true;
} else {
- // Readable but empty file
content.clear();
- success = true;
+ if (error != nullptr) {
+ error->append("Reading from the file failed.");
+ }
}
} else if (error != nullptr) {
error->append("Opening the file for reading failed.");
}
- } else if (error != nullptr) {
- error->append(
- "The file does not exist, is not readable or is a directory.");
}
+ } else if (error != nullptr) {
+ error->append(
+ "The file does not exist, is not readable or is a directory.");
}
return success;
}