mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-05 21:31:08 -06:00
Autogen: Add lock file to AUTORCC commands
By using a per .qrc lock file in AUTORCC, the same `cmake -E cmake_autorcc ...` command can be called concurrently.
This commit is contained in:
@@ -588,8 +588,13 @@ void cmQtAutoGenInitializer::InitCustomTargets()
|
|||||||
if (!qrc.Unique) {
|
if (!qrc.Unique) {
|
||||||
base += qrc.PathChecksum;
|
base += qrc.PathChecksum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qrc.LockFile = base;
|
||||||
|
qrc.LockFile += ".lock";
|
||||||
|
|
||||||
qrc.InfoFile = base;
|
qrc.InfoFile = base;
|
||||||
qrc.InfoFile += "Info.cmake";
|
qrc.InfoFile += "Info.cmake";
|
||||||
|
|
||||||
qrc.SettingsFile = base;
|
qrc.SettingsFile = base;
|
||||||
qrc.SettingsFile += "Settings.txt";
|
qrc.SettingsFile += "Settings.txt";
|
||||||
}
|
}
|
||||||
@@ -1043,6 +1048,7 @@ void cmQtAutoGenInitializer::SetupCustomTargets()
|
|||||||
CWrite("ARCC_RCC_LIST_OPTIONS", cmJoin(this->RccListOptions, ";"));
|
CWrite("ARCC_RCC_LIST_OPTIONS", cmJoin(this->RccListOptions, ";"));
|
||||||
|
|
||||||
ofs << "# Rcc job\n";
|
ofs << "# Rcc job\n";
|
||||||
|
CWrite("ARCC_LOCK_FILE", qrc.LockFile);
|
||||||
CWrite("ARCC_SOURCE", qrc.QrcFile);
|
CWrite("ARCC_SOURCE", qrc.QrcFile);
|
||||||
CWrite("ARCC_OUTPUT_CHECKSUM", qrc.PathChecksum);
|
CWrite("ARCC_OUTPUT_CHECKSUM", qrc.PathChecksum);
|
||||||
CWrite("ARCC_OUTPUT_NAME",
|
CWrite("ARCC_OUTPUT_NAME",
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
std::string LockFile;
|
||||||
std::string QrcFile;
|
std::string QrcFile;
|
||||||
std::string QrcName;
|
std::string QrcName;
|
||||||
std::string PathChecksum;
|
std::string PathChecksum;
|
||||||
|
|||||||
@@ -367,10 +367,11 @@ bool cmQtAutoGenerator::FileSystem::FileRemove(std::string const& filename)
|
|||||||
return cmSystemTools::RemoveFile(filename);
|
return cmSystemTools::RemoveFile(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cmQtAutoGenerator::FileSystem::Touch(std::string const& filename)
|
bool cmQtAutoGenerator::FileSystem::Touch(std::string const& filename,
|
||||||
|
bool create)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(Mutex_);
|
std::lock_guard<std::mutex> lock(Mutex_);
|
||||||
return cmSystemTools::Touch(filename, false);
|
return cmSystemTools::Touch(filename, create);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cmQtAutoGenerator::FileSystem::MakeDirectory(std::string const& dirname)
|
bool cmQtAutoGenerator::FileSystem::MakeDirectory(std::string const& dirname)
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ public:
|
|||||||
bool FileDiffers(std::string const& filename, std::string const& content);
|
bool FileDiffers(std::string const& filename, std::string const& content);
|
||||||
|
|
||||||
bool FileRemove(std::string const& filename);
|
bool FileRemove(std::string const& filename);
|
||||||
bool Touch(std::string const& filename);
|
bool Touch(std::string const& filename, bool create = false);
|
||||||
|
|
||||||
// -- Directory access
|
// -- Directory access
|
||||||
bool MakeDirectory(std::string const& dirname);
|
bool MakeDirectory(std::string const& dirname);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include "cmAlgorithms.h"
|
#include "cmAlgorithms.h"
|
||||||
#include "cmCryptoHash.h"
|
#include "cmCryptoHash.h"
|
||||||
|
#include "cmFileLockResult.h"
|
||||||
#include "cmMakefile.h"
|
#include "cmMakefile.h"
|
||||||
#include "cmSystemTools.h"
|
#include "cmSystemTools.h"
|
||||||
#include "cmUVHandlePtr.h"
|
#include "cmUVHandlePtr.h"
|
||||||
@@ -89,6 +90,7 @@ bool cmQtAutoGeneratorRcc::Init(cmMakefile* makefile)
|
|||||||
RccListOptions_ = InfoGetList("ARCC_RCC_LIST_OPTIONS");
|
RccListOptions_ = InfoGetList("ARCC_RCC_LIST_OPTIONS");
|
||||||
|
|
||||||
// - Job
|
// - Job
|
||||||
|
LockFile_ = InfoGet("ARCC_LOCK_FILE");
|
||||||
QrcFile_ = InfoGet("ARCC_SOURCE");
|
QrcFile_ = InfoGet("ARCC_SOURCE");
|
||||||
QrcFileName_ = cmSystemTools::GetFilenameName(QrcFile_);
|
QrcFileName_ = cmSystemTools::GetFilenameName(QrcFile_);
|
||||||
QrcFileDir_ = cmSystemTools::GetFilenamePath(QrcFile_);
|
QrcFileDir_ = cmSystemTools::GetFilenamePath(QrcFile_);
|
||||||
@@ -101,6 +103,10 @@ bool cmQtAutoGeneratorRcc::Init(cmMakefile* makefile)
|
|||||||
SettingsFile_ = InfoGetConfig("ARCC_SETTINGS_FILE");
|
SettingsFile_ = InfoGetConfig("ARCC_SETTINGS_FILE");
|
||||||
|
|
||||||
// - Validity checks
|
// - Validity checks
|
||||||
|
if (LockFile_.empty()) {
|
||||||
|
Log().ErrorFile(GeneratorT::RCC, InfoFile(), "Lock file name missing");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (SettingsFile_.empty()) {
|
if (SettingsFile_.empty()) {
|
||||||
Log().ErrorFile(GeneratorT::RCC, InfoFile(), "Settings file name missing");
|
Log().ErrorFile(GeneratorT::RCC, InfoFile(), "Settings file name missing");
|
||||||
return false;
|
return false;
|
||||||
@@ -170,8 +176,11 @@ void cmQtAutoGeneratorRcc::PollStage()
|
|||||||
switch (Stage_) {
|
switch (Stage_) {
|
||||||
// -- Initialize
|
// -- Initialize
|
||||||
case StageT::SETTINGS_READ:
|
case StageT::SETTINGS_READ:
|
||||||
SettingsFileRead();
|
if (SettingsFileRead()) {
|
||||||
SetStage(StageT::TEST_QRC_RCC_FILES);
|
SetStage(StageT::TEST_QRC_RCC_FILES);
|
||||||
|
} else {
|
||||||
|
SetStage(StageT::FINISH);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// -- Change detection
|
// -- Change detection
|
||||||
@@ -252,7 +261,7 @@ std::string cmQtAutoGeneratorRcc::MultiConfigOutput() const
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmQtAutoGeneratorRcc::SettingsFileRead()
|
bool cmQtAutoGeneratorRcc::SettingsFileRead()
|
||||||
{
|
{
|
||||||
// Compose current settings strings
|
// Compose current settings strings
|
||||||
{
|
{
|
||||||
@@ -278,21 +287,51 @@ void cmQtAutoGeneratorRcc::SettingsFileRead()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make sure the settings file exists
|
||||||
|
if (!FileSys().FileExists(SettingsFile_, true)) {
|
||||||
|
// Touch the settings file to make sure it exists
|
||||||
|
FileSys().Touch(SettingsFile_, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lock the lock file
|
||||||
|
{
|
||||||
|
// Make sure the lock file exists
|
||||||
|
if (!FileSys().FileExists(LockFile_, true)) {
|
||||||
|
if (!FileSys().Touch(LockFile_, true)) {
|
||||||
|
Log().ErrorFile(GeneratorT::RCC, LockFile_,
|
||||||
|
"Lock file creation failed");
|
||||||
|
Error_ = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Lock the lock file
|
||||||
|
cmFileLockResult lockResult =
|
||||||
|
LockFileLock_.Lock(LockFile_, static_cast<unsigned long>(-1));
|
||||||
|
if (!lockResult.IsOk()) {
|
||||||
|
Log().ErrorFile(GeneratorT::RCC, LockFile_,
|
||||||
|
"File lock failed: " + lockResult.GetOutputMessage());
|
||||||
|
Error_ = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Read old settings
|
// Read old settings
|
||||||
{
|
{
|
||||||
std::string content;
|
std::string content;
|
||||||
if (FileSys().FileRead(content, SettingsFile_)) {
|
if (FileSys().FileRead(content, SettingsFile_)) {
|
||||||
SettingsChanged_ = (SettingsString_ != SettingsFind(content, "rcc"));
|
SettingsChanged_ = (SettingsString_ != SettingsFind(content, "rcc"));
|
||||||
// In case any setting changed remove the old settings file.
|
// In case any setting changed clear the old settings file.
|
||||||
// This triggers a full rebuild on the next run if the current
|
// This triggers a full rebuild on the next run if the current
|
||||||
// build is aborted before writing the current settings in the end.
|
// build is aborted before writing the current settings in the end.
|
||||||
if (SettingsChanged_) {
|
if (SettingsChanged_) {
|
||||||
FileSys().FileRemove(SettingsFile_);
|
FileSys().FileWrite(GeneratorT::RCC, SettingsFile_, "");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
SettingsChanged_ = true;
|
SettingsChanged_ = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmQtAutoGeneratorRcc::SettingsFileWrite()
|
void cmQtAutoGeneratorRcc::SettingsFileWrite()
|
||||||
@@ -315,6 +354,9 @@ void cmQtAutoGeneratorRcc::SettingsFileWrite()
|
|||||||
Error_ = true;
|
Error_ = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unlock the lock file
|
||||||
|
LockFileLock_.Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cmQtAutoGeneratorRcc::TestQrcRccFiles()
|
bool cmQtAutoGeneratorRcc::TestQrcRccFiles()
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include "cmConfigure.h" // IWYU pragma: keep
|
#include "cmConfigure.h" // IWYU pragma: keep
|
||||||
|
|
||||||
|
#include "cmFileLock.h"
|
||||||
#include "cmQtAutoGenerator.h"
|
#include "cmQtAutoGenerator.h"
|
||||||
#include "cm_uv.h"
|
#include "cm_uv.h"
|
||||||
|
|
||||||
@@ -48,7 +49,7 @@ private:
|
|||||||
void PollStage();
|
void PollStage();
|
||||||
void SetStage(StageT stage);
|
void SetStage(StageT stage);
|
||||||
// -- Settings file
|
// -- Settings file
|
||||||
void SettingsFileRead();
|
bool SettingsFileRead();
|
||||||
void SettingsFileWrite();
|
void SettingsFileWrite();
|
||||||
// -- Tests
|
// -- Tests
|
||||||
bool TestQrcRccFiles();
|
bool TestQrcRccFiles();
|
||||||
@@ -77,6 +78,8 @@ private:
|
|||||||
std::string RccExecutable_;
|
std::string RccExecutable_;
|
||||||
std::vector<std::string> RccListOptions_;
|
std::vector<std::string> RccListOptions_;
|
||||||
// -- Job
|
// -- Job
|
||||||
|
std::string LockFile_;
|
||||||
|
cmFileLock LockFileLock_;
|
||||||
std::string QrcFile_;
|
std::string QrcFile_;
|
||||||
std::string QrcFileName_;
|
std::string QrcFileName_;
|
||||||
std::string QrcFileDir_;
|
std::string QrcFileDir_;
|
||||||
|
|||||||
Reference in New Issue
Block a user