Autogen: Abbreviate file paths in messages

This introduces the `cmQtAutoGenerator::MessagePath` method, that abbreviates
paths by placing a
 - "SRC:" prefix in place of the project source directory
 - "BIN:" prefix in place of the project binary directory

The method is used in `AUTO{MOC,UIC,RCC}` when paths are displayed in
messages.  This makes the messages generated by `AUTO{MOC,UIC,RCC}` shorter
and improves their readability.
This commit is contained in:
Sebastian Holtermann
2019-09-09 17:04:51 +02:00
parent 51676cf655
commit f9e5441eb4
6 changed files with 264 additions and 210 deletions

View File

@@ -1410,6 +1410,11 @@ bool cmQtAutoGenInitializer::SetupWriteRccInfo()
for (Qrc const& qrc : this->Rcc.Qrcs) { for (Qrc const& qrc : this->Rcc.Qrcs) {
InfoWriter ofs(qrc.InfoFile); InfoWriter ofs(qrc.InfoFile);
if (ofs) { if (ofs) {
// Utility lambdas
auto MfDef = [this](const char* key) {
return this->Makefile->GetSafeDefinition(key);
};
// Write // Write
ofs.Write("# Configurations\n"); ofs.Write("# Configurations\n");
ofs.Write("ARCC_MULTI_CONFIG", this->MultiConfig ? "TRUE" : "FALSE"); ofs.Write("ARCC_MULTI_CONFIG", this->MultiConfig ? "TRUE" : "FALSE");
@@ -1419,6 +1424,8 @@ bool cmQtAutoGenInitializer::SetupWriteRccInfo()
ofs.WriteConfig("ARCC_SETTINGS_FILE", qrc.ConfigSettingsFile); ofs.WriteConfig("ARCC_SETTINGS_FILE", qrc.ConfigSettingsFile);
ofs.Write("# Directories\n"); ofs.Write("# Directories\n");
ofs.Write("ARCC_CMAKE_SOURCE_DIR", MfDef("CMAKE_SOURCE_DIR"));
ofs.Write("ARCC_CMAKE_BINARY_DIR", MfDef("CMAKE_BINARY_DIR"));
ofs.Write("ARCC_BUILD_DIR", this->Dir.Build); ofs.Write("ARCC_BUILD_DIR", this->Dir.Build);
ofs.Write("ARCC_INCLUDE_DIR", this->Dir.Include); ofs.Write("ARCC_INCLUDE_DIR", this->Dir.Include);
ofs.WriteConfig("ARCC_INCLUDE_DIR", this->Dir.ConfigInclude); ofs.WriteConfig("ARCC_INCLUDE_DIR", this->Dir.ConfigInclude);

View File

@@ -93,32 +93,18 @@ void cmQtAutoGenerator::Logger::Warning(GenT genType,
} }
} }
void cmQtAutoGenerator::Logger::WarningFile(GenT genType,
cm::string_view filename,
cm::string_view message) const
{
Warning(genType, cmStrCat(" ", Quoted(filename), '\n', message));
}
void cmQtAutoGenerator::Logger::Error(GenT genType, void cmQtAutoGenerator::Logger::Error(GenT genType,
cm::string_view message) const cm::string_view message) const
{ {
std::string msg = std::string msg =
cmStrCat(HeadLine(cmStrCat(GeneratorName(genType), " error")), message, cmStrCat('\n', HeadLine(cmStrCat(GeneratorName(genType), " error")),
cmHasSuffix(message, '\n') ? "\n" : "\n\n"); message, cmHasSuffix(message, '\n') ? "\n" : "\n\n");
{ {
std::lock_guard<std::mutex> lock(Mutex_); std::lock_guard<std::mutex> lock(Mutex_);
cmSystemTools::Stderr(msg); cmSystemTools::Stderr(msg);
} }
} }
void cmQtAutoGenerator::Logger::ErrorFile(GenT genType,
cm::string_view filename,
cm::string_view message) const
{
Error(genType, cmStrCat(" ", Quoted(filename), '\n', message));
}
void cmQtAutoGenerator::Logger::ErrorCommand( void cmQtAutoGenerator::Logger::ErrorCommand(
GenT genType, cm::string_view message, GenT genType, cm::string_view message,
std::vector<std::string> const& command, std::string const& output) const std::vector<std::string> const& command, std::string const& output) const
@@ -286,3 +272,16 @@ std::string cmQtAutoGenerator::SettingsFind(std::string const& content,
} }
return std::string(); return std::string();
} }
std::string cmQtAutoGenerator::MessagePath(cm::string_view path) const
{
std::string res;
if (cmHasPrefix(path, ProjectDirs().Source)) {
res = cmStrCat("SRC:", path.substr(ProjectDirs().Source.size()));
} else if (cmHasPrefix(path, ProjectDirs().Binary)) {
res = cmStrCat("BIN:", path.substr(ProjectDirs().Binary.size()));
} else {
res = std::string(path);
}
return cmQtAutoGen::Quoted(res);
}

View File

@@ -23,9 +23,7 @@ class cmQtAutoGenerator : public cmQtAutoGen
public: public:
// -- Types // -- Types
/** /** Thread safe logger. */
* Thread safe logger
*/
class Logger class Logger
{ {
public: public:
@@ -45,12 +43,8 @@ public:
void Info(GenT genType, cm::string_view message) const; void Info(GenT genType, cm::string_view message) const;
// -- Log warning // -- Log warning
void Warning(GenT genType, cm::string_view message) const; void Warning(GenT genType, cm::string_view message) const;
void WarningFile(GenT genType, cm::string_view filename,
cm::string_view message) const;
// -- Log error // -- Log error
void Error(GenT genType, cm::string_view message) const; void Error(GenT genType, cm::string_view message) const;
void ErrorFile(GenT genType, cm::string_view filename,
cm::string_view message) const;
void ErrorCommand(GenT genType, cm::string_view message, void ErrorCommand(GenT genType, cm::string_view message,
std::vector<std::string> const& command, std::vector<std::string> const& command,
std::string const& output) const; std::string const& output) const;
@@ -64,6 +58,15 @@ public:
bool ColorOutput_ = false; bool ColorOutput_ = false;
}; };
/** Project directories. */
struct ProjectDirsT
{
std::string Source;
std::string Binary;
std::string CurrentSource;
std::string CurrentBinary;
};
// -- File system methods // -- File system methods
static bool MakeParentDirectory(std::string const& filename); static bool MakeParentDirectory(std::string const& filename);
static bool FileRead(std::string& content, std::string const& filename, static bool FileRead(std::string& content, std::string const& filename,
@@ -91,13 +94,18 @@ public:
std::string const& InfoDir() const { return InfoDir_; } std::string const& InfoDir() const { return InfoDir_; }
std::string const& InfoConfig() const { return InfoConfig_; } std::string const& InfoConfig() const { return InfoConfig_; }
// -- Directories
ProjectDirsT const& ProjectDirs() const { return ProjectDirs_; }
// -- Utility // -- Utility
static std::string SettingsFind(std::string const& content, const char* key); static std::string SettingsFind(std::string const& content, const char* key);
std::string MessagePath(cm::string_view path) const;
protected: protected:
// -- Abstract processing interface // -- Abstract processing interface
virtual bool Init(cmMakefile* makefile) = 0; virtual bool Init(cmMakefile* makefile) = 0;
virtual bool Process() = 0; virtual bool Process() = 0;
ProjectDirsT& ProjectDirsRef() { return ProjectDirs_; }
private: private:
// -- Info settings // -- Info settings
@@ -105,6 +113,8 @@ private:
cmFileTime InfoFileTime_; cmFileTime InfoFileTime_;
std::string InfoDir_; std::string InfoDir_;
std::string InfoConfig_; std::string InfoConfig_;
// -- Directories
ProjectDirsT ProjectDirs_;
}; };
#endif #endif

View File

@@ -234,13 +234,6 @@ void cmQtAutoMocUic::JobT::LogError(GenT genType,
Gen()->Log().Error(genType, message); Gen()->Log().Error(genType, message);
} }
void cmQtAutoMocUic::JobT::LogFileError(GenT genType, cm::string_view filename,
cm::string_view message) const
{
Gen()->AbortError();
Gen()->Log().ErrorFile(genType, filename, message);
}
void cmQtAutoMocUic::JobT::LogCommandError( void cmQtAutoMocUic::JobT::LogCommandError(
GenT genType, cm::string_view message, GenT genType, cm::string_view message,
std::vector<std::string> const& command, std::string const& output) const std::vector<std::string> const& command, std::string const& output) const
@@ -265,6 +258,7 @@ bool cmQtAutoMocUic::JobT::RunProcess(GenT genType,
info.empty() || cmHasSuffix(info, '\n') ? "" : "\n", info.empty() || cmHasSuffix(info, '\n') ? "" : "\n",
QuotedCommand(command), '\n')); QuotedCommand(command), '\n'));
} }
// Run command
return cmWorkerPool::JobT::RunProcess(result, command, return cmWorkerPool::JobT::RunProcess(result, command,
BaseConst().AutogenBuildDir); BaseConst().AutogenBuildDir);
} }
@@ -279,7 +273,6 @@ void cmQtAutoMocUic::JobMocPredefsT::Process()
if (!Update(reason.get())) { if (!Update(reason.get())) {
return; return;
} }
std::string const& predefsFileRel = MocConst().PredefsFileRel;
std::string const& predefsFileAbs = MocConst().PredefsFileAbs; std::string const& predefsFileAbs = MocConst().PredefsFileAbs;
{ {
cmWorkerPool::ProcessResultT result; cmWorkerPool::ProcessResultT result;
@@ -296,7 +289,7 @@ void cmQtAutoMocUic::JobMocPredefsT::Process()
if (!RunProcess(GenT::MOC, result, cmd, reason.get())) { if (!RunProcess(GenT::MOC, result, cmd, reason.get())) {
LogCommandError(GenT::MOC, LogCommandError(GenT::MOC,
cmStrCat("The content generation command for ", cmStrCat("The content generation command for ",
Quoted(predefsFileRel), " failed.\n", MessagePath(predefsFileAbs), " failed.\n",
result.ErrorMessage), result.ErrorMessage),
cmd, result.StdOut); cmd, result.StdOut);
return; return;
@@ -306,19 +299,20 @@ void cmQtAutoMocUic::JobMocPredefsT::Process()
// (Re)write predefs file only on demand // (Re)write predefs file only on demand
if (cmQtAutoGenerator::FileDiffers(predefsFileAbs, result.StdOut)) { if (cmQtAutoGenerator::FileDiffers(predefsFileAbs, result.StdOut)) {
if (!cmQtAutoGenerator::FileWrite(predefsFileAbs, result.StdOut)) { if (!cmQtAutoGenerator::FileWrite(predefsFileAbs, result.StdOut)) {
LogFileError(GenT::MOC, predefsFileAbs, LogError(
cmStrCat("Writing ", Quoted(predefsFileRel), " failed.")); GenT::MOC,
cmStrCat("Writing ", MessagePath(predefsFileAbs), " failed."));
return; return;
} }
} else { } else {
// Touch to update the time stamp // Touch to update the time stamp
if (Log().Verbose()) { if (Log().Verbose()) {
Log().Info(GenT::MOC, "Touching " + Quoted(predefsFileRel)); Log().Info(GenT::MOC, "Touching " + MessagePath(predefsFileAbs));
} }
if (!cmSystemTools::Touch(predefsFileAbs, false)) { if (!cmSystemTools::Touch(predefsFileAbs, false)) {
LogFileError( LogError(
GenT::MOC, predefsFileAbs, GenT::MOC,
cmStrCat("Touching ", Quoted(predefsFileAbs), " failed.")); cmStrCat("Touching ", MessagePath(predefsFileAbs), " failed."));
return; return;
} }
} }
@@ -326,7 +320,9 @@ void cmQtAutoMocUic::JobMocPredefsT::Process()
// Read file time afterwards // Read file time afterwards
if (!MocEval().PredefsTime.Load(predefsFileAbs)) { if (!MocEval().PredefsTime.Load(predefsFileAbs)) {
LogFileError(GenT::MOC, predefsFileAbs, "File time reading failed."); LogError(GenT::MOC,
cmStrCat("Reading the file time of ", MessagePath(predefsFileAbs),
" failed."));
return; return;
} }
} }
@@ -336,7 +332,7 @@ bool cmQtAutoMocUic::JobMocPredefsT::Update(std::string* reason) const
// Test if the file exists // Test if the file exists
if (!MocEval().PredefsTime.Load(MocConst().PredefsFileAbs)) { if (!MocEval().PredefsTime.Load(MocConst().PredefsFileAbs)) {
if (reason != nullptr) { if (reason != nullptr) {
*reason = cmStrCat("Generating ", Quoted(MocConst().PredefsFileRel), *reason = cmStrCat("Generating ", MessagePath(MocConst().PredefsFileAbs),
", because it doesn't exist."); ", because it doesn't exist.");
} }
return true; return true;
@@ -345,7 +341,7 @@ bool cmQtAutoMocUic::JobMocPredefsT::Update(std::string* reason) const
// Test if the settings changed // Test if the settings changed
if (MocConst().SettingsChanged) { if (MocConst().SettingsChanged) {
if (reason != nullptr) { if (reason != nullptr) {
*reason = cmStrCat("Generating ", Quoted(MocConst().PredefsFileRel), *reason = cmStrCat("Generating ", MessagePath(MocConst().PredefsFileAbs),
", because the moc settings changed."); ", because the moc settings changed.");
} }
return true; return true;
@@ -358,8 +354,9 @@ bool cmQtAutoMocUic::JobMocPredefsT::Update(std::string* reason) const
if (execTime.Load(exec)) { if (execTime.Load(exec)) {
if (MocEval().PredefsTime.Older(execTime)) { if (MocEval().PredefsTime.Older(execTime)) {
if (reason != nullptr) { if (reason != nullptr) {
*reason = cmStrCat("Generating ", Quoted(MocConst().PredefsFileRel), *reason =
" because it is older than ", Quoted(exec), '.'); cmStrCat("Generating ", MessagePath(MocConst().PredefsFileAbs),
" because it is older than ", MessagePath(exec), '.');
} }
return true; return true;
} }
@@ -376,19 +373,21 @@ bool cmQtAutoMocUic::JobParseT::ReadFile()
std::string const& fileName = FileHandle->FileName; std::string const& fileName = FileHandle->FileName;
// Write info // Write info
if (Log().Verbose()) { if (Log().Verbose()) {
Log().Info(GenT::GEN, "Parsing " + Quoted(fileName)); Log().Info(GenT::GEN, cmStrCat("Parsing ", MessagePath(fileName)));
} }
// Read file content // Read file content
{ {
std::string error; std::string error;
if (!cmQtAutoGenerator::FileRead(Content, fileName, &error)) { if (!cmQtAutoGenerator::FileRead(Content, fileName, &error)) {
LogFileError(GenT::GEN, fileName, "Could not read the file: " + error); LogError(
GenT::GEN,
cmStrCat("Could not read ", MessagePath(fileName), ".\n", error));
return false; return false;
} }
} }
// Warn if empty // Warn if empty
if (Content.empty()) { if (Content.empty()) {
Log().WarningFile(GenT::GEN, fileName, "The file is empty."); Log().Warning(GenT::GEN, cmStrCat(MessagePath(fileName), " is empty."));
return false; return false;
} }
return true; return true;
@@ -557,7 +556,7 @@ std::string cmQtAutoMocUic::JobEvalCacheT::MessageSearchLocations() const
res.reserve(512); res.reserve(512);
for (std::string const& path : SearchLocations) { for (std::string const& path : SearchLocations) {
res += " "; res += " ";
res += Quoted(path); res += MessagePath(path);
res += '\n'; res += '\n';
} }
return res; return res;
@@ -645,9 +644,9 @@ bool cmQtAutoMocUic::JobEvalCacheMocT::EvalSource(
if (!sourceIncludesDotMoc && !parseData.Macro.empty() && if (!sourceIncludesDotMoc && !parseData.Macro.empty() &&
!(relaxedMode && sourceIncludesMocUnderscore)) { !(relaxedMode && sourceIncludesMocUnderscore)) {
LogError(GenT::MOC, LogError(GenT::MOC,
cmStrCat(sourceFile.FileName, "\ncontains a ", cmStrCat(MessagePath(sourceFile.FileName), "\ncontains a ",
Quoted(parseData.Macro), " macro, but does not include ", Quoted(parseData.Macro), " macro, but does not include ",
Quoted(sourceBase + ".moc"), MessagePath(sourceBase + ".moc"),
"!\nConsider to\n - add #include \"", sourceBase, "!\nConsider to\n - add #include \"", sourceBase,
".moc\"\n - enable SKIP_AUTOMOC for this file")); ".moc\"\n - enable SKIP_AUTOMOC for this file"));
return false; return false;
@@ -660,8 +659,8 @@ bool cmQtAutoMocUic::JobEvalCacheMocT::EvalSource(
std::string const headerBase = cmStrCat(incKey.Dir, incKey.Base); std::string const headerBase = cmStrCat(incKey.Dir, incKey.Base);
if (!FindIncludedHeader(headerHandle, sourceDirPrefix, headerBase)) { if (!FindIncludedHeader(headerHandle, sourceDirPrefix, headerBase)) {
LogError(GenT::MOC, LogError(GenT::MOC,
cmStrCat(Quoted(sourceFile.FileName), cmStrCat(MessagePath(sourceFile.FileName),
"\nincludes the moc file ", Quoted(incKey.Key), "\nincludes the moc file ", MessagePath(incKey.Key),
",\nbut a header ", MessageHeader(headerBase), ",\nbut a header ", MessageHeader(headerBase),
"\ncould not be found " "\ncould not be found "
"in the following directories\n", "in the following directories\n",
@@ -681,12 +680,12 @@ bool cmQtAutoMocUic::JobEvalCacheMocT::EvalSource(
// Issue a warning // Issue a warning
Log().Warning( Log().Warning(
GenT::MOC, GenT::MOC,
cmStrCat(sourceFile.FileName, "\ncontains a ", Quoted(parseData.Macro), cmStrCat(MessagePath(sourceFile.FileName), "\ncontains a ",
" macro, but does not include ", Quoted(sourceBase + ".moc"), Quoted(parseData.Macro), " macro, but does not include ",
".\nInstead it includes ", Quoted(incKey.Key), MessagePath(sourceBase + ".moc"), ".\nInstead it includes ",
".\nRunning moc on the source\n ", MessagePath(incKey.Key), ".\nRunning moc on the source\n ",
Quoted(sourceFile.FileName), "!\nBetter include ", MessagePath(sourceFile.FileName), "!\nBetter include ",
Quoted(sourceBase + ".moc"), MessagePath(sourceBase + ".moc"),
" for compatibility with regular mode.\n", " for compatibility with regular mode.\n",
"This is a CMAKE_AUTOMOC_RELAXED_MODE warning.\n")); "This is a CMAKE_AUTOMOC_RELAXED_MODE warning.\n"));
@@ -729,8 +728,8 @@ bool cmQtAutoMocUic::JobEvalCacheMocT::EvalSource(
LogError( LogError(
GenT::MOC, GenT::MOC,
cmStrCat( cmStrCat(
Quoted(sourceFile.FileName), "\nincludes the moc file ", MessagePath(sourceFile.FileName), "\nincludes the moc file ",
Quoted(incKey.Key), MessagePath(incKey.Key),
",\nwhich seems to be the moc file from a different source " ",\nwhich seems to be the moc file from a different source "
"file.\nCMAKE_AUTOMOC_RELAXED_MODE:\nAlso a matching header ", "file.\nCMAKE_AUTOMOC_RELAXED_MODE:\nAlso a matching header ",
MessageHeader(headerBase), MessageHeader(headerBase),
@@ -747,23 +746,23 @@ bool cmQtAutoMocUic::JobEvalCacheMocT::EvalSource(
if (ownMoc && parseData.Macro.empty()) { if (ownMoc && parseData.Macro.empty()) {
Log().Warning( Log().Warning(
GenT::MOC, GenT::MOC,
cmStrCat(sourceFile.FileName, "\nincludes the moc file ", cmStrCat(MessagePath(sourceFile.FileName),
Quoted(incKey.Key), ", but does not contain a\n", "\nincludes the moc file ", MessagePath(incKey.Key),
MocConst().MacrosString(), ", but does not contain a\n", MocConst().MacrosString(),
" macro.\nRunning moc on the header\n ", " macro.\nRunning moc on the header\n ",
Quoted(headerHandle->FileName), "!\nBetter include ", MessagePath(headerHandle->FileName), "!\nBetter include ",
Quoted("moc_" + incKey.Base + ".cpp"), MessagePath("moc_" + incKey.Base + ".cpp"),
" for a compatibility with regular mode.\n", " for a compatibility with regular mode.\n",
"This is a CMAKE_AUTOMOC_RELAXED_MODE warning.\n")); "This is a CMAKE_AUTOMOC_RELAXED_MODE warning.\n"));
} else { } else {
Log().Warning( Log().Warning(
GenT::MOC, GenT::MOC,
cmStrCat(sourceFile.FileName, "\nincludes the moc file ", cmStrCat(MessagePath(sourceFile.FileName),
Quoted(incKey.Key), " instead of ", "\nincludes the moc file ", MessagePath(incKey.Key),
Quoted("moc_" + incKey.Base + ".cpp"), " instead of ", MessagePath("moc_" + incKey.Base + ".cpp"),
".\nRunning moc on the header\n ", ".\nRunning moc on the header\n ",
Quoted(headerHandle->FileName), "!\nBetter include ", MessagePath(headerHandle->FileName), "!\nBetter include ",
Quoted("moc_" + incKey.Base + ".cpp"), MessagePath("moc_" + incKey.Base + ".cpp"),
" for compatibility with regular mode.\n", " for compatibility with regular mode.\n",
"This is a CMAKE_AUTOMOC_RELAXED_MODE warning.\n")); "This is a CMAKE_AUTOMOC_RELAXED_MODE warning.\n"));
} }
@@ -781,19 +780,21 @@ bool cmQtAutoMocUic::JobEvalCacheMocT::EvalSource(
if (!ownMoc) { if (!ownMoc) {
// Don't allow <BASE>.moc include other than own in regular mode // Don't allow <BASE>.moc include other than own in regular mode
LogError(GenT::MOC, LogError(GenT::MOC,
cmStrCat(sourceFile.FileName, "\nincludes the moc file ", cmStrCat(MessagePath(sourceFile.FileName),
Quoted(incKey.Key), "\nincludes the moc file ", MessagePath(incKey.Key),
",\nwhich seems to be the moc file from a different " ",\nwhich seems to be the moc file from a different "
"source file.\nThis is not supported. Include ", "source file.\nThis is not supported. Include ",
Quoted(sourceBase + ".moc"), MessagePath(sourceBase + ".moc"),
" to run moc on this source file.")); " to run moc on this source file."));
return false; return false;
} }
// Accept but issue a warning if moc isn't required // Accept but issue a warning if moc isn't required
if (parseData.Macro.empty()) { if (parseData.Macro.empty()) {
Log().Warning(GenT::MOC, Log().Warning(GenT::MOC,
cmStrCat(sourceFile.FileName, "\nincludes the moc file ", cmStrCat(MessagePath(sourceFile.FileName),
Quoted(incKey.Key), ", but does not contain a ", "\nincludes the moc file ",
MessagePath(incKey.Key),
", but does not contain a ",
MocConst().MacrosString(), " macro.")); MocConst().MacrosString(), " macro."));
} }
// Create mapping // Create mapping
@@ -880,18 +881,19 @@ bool cmQtAutoMocUic::JobEvalCacheMocT::RegisterIncluded(
// Check if the output file would be generated from different source files // Check if the output file would be generated from different source files
if (handle->SourceFile != sourceFileHandle) { if (handle->SourceFile != sourceFileHandle) {
std::string files = std::string files =
cmStrCat(" ", Quoted(includerFileHandle->FileName), '\n'); cmStrCat(" ", MessagePath(includerFileHandle->FileName), '\n');
for (auto const& item : handle->IncluderFiles) { for (auto const& item : handle->IncluderFiles) {
files += cmStrCat(" ", Quoted(item->FileName), '\n'); files += cmStrCat(" ", MessagePath(item->FileName), '\n');
} }
LogError( LogError(
GenT::MOC, GenT::MOC,
cmStrCat("The source files\n", files, cmStrCat("The source files\n", files,
"contain the same include string ", Quoted(includeString), "contain the same include string ",
MessagePath(includeString),
", but\nthe moc file would be generated from different " ", but\nthe moc file would be generated from different "
"source files\n ", "source files\n ",
Quoted(sourceFileHandle->FileName), " and\n ", MessagePath(sourceFileHandle->FileName), " and\n ",
Quoted(handle->SourceFile->FileName), MessagePath(handle->SourceFile->FileName),
".\nConsider to\n" ".\nConsider to\n"
" - not include the \"moc_<NAME>.cpp\" file\n" " - not include the \"moc_<NAME>.cpp\" file\n"
" - add a directory prefix to a \"<NAME>.moc\" include " " - add a directory prefix to a \"<NAME>.moc\" include "
@@ -938,7 +940,7 @@ void cmQtAutoMocUic::JobEvalCacheMocT::RegisterMapping(
std::string cmQtAutoMocUic::JobEvalCacheMocT::MessageHeader( std::string cmQtAutoMocUic::JobEvalCacheMocT::MessageHeader(
cm::string_view headerBase) const cm::string_view headerBase) const
{ {
return Quoted(cmStrCat( return MessagePath(cmStrCat(
headerBase, ".{", cmJoin(this->BaseConst().HeaderExtensions, ","), '}')); headerBase, ".{", cmJoin(this->BaseConst().HeaderExtensions, ","), '}'));
} }
@@ -976,9 +978,9 @@ bool cmQtAutoMocUic::JobEvalCacheUicT::EvalFile(
UiName = cmStrCat(incKey.Base, ".ui"); UiName = cmStrCat(incKey.Base, ".ui");
if (!FindIncludedUi(sourceDirPrefix, incKey.Dir)) { if (!FindIncludedUi(sourceDirPrefix, incKey.Dir)) {
LogError(GenT::UIC, LogError(GenT::UIC,
cmStrCat(sourceFile.FileName, "\nincludes the uic file ", cmStrCat(MessagePath(sourceFile.FileName),
Quoted(incKey.Key), ",\nbut the user interface file ", "\nincludes the uic file ", MessagePath(incKey.Key),
Quoted(UiName), ",\nbut the user interface file ", MessagePath(UiName),
"\ncould not be found in the following directories\n", "\ncould not be found in the following directories\n",
MessageSearchLocations())); MessageSearchLocations()));
return false; return false;
@@ -1060,9 +1062,9 @@ bool cmQtAutoMocUic::JobEvalCacheUicT::RegisterMapping(
if (handle->SourceFile != UiFileHandle) { if (handle->SourceFile != UiFileHandle) {
// The output file already gets generated - from a different .ui file! // The output file already gets generated - from a different .ui file!
std::string files = std::string files =
cmStrCat(" ", Quoted(includerFileHandle->FileName), '\n'); cmStrCat(" ", MessagePath(includerFileHandle->FileName), '\n');
for (auto const& item : handle->IncluderFiles) { for (auto const& item : handle->IncluderFiles) {
files += cmStrCat(" ", Quoted(item->FileName), '\n'); files += cmStrCat(" ", MessagePath(item->FileName), '\n');
} }
LogError( LogError(
GenT::UIC, GenT::UIC,
@@ -1071,8 +1073,8 @@ bool cmQtAutoMocUic::JobEvalCacheUicT::RegisterMapping(
Quoted(includeString), Quoted(includeString),
", but\nthe uic file would be generated from different " ", but\nthe uic file would be generated from different "
"user interface files\n ", "user interface files\n ",
Quoted(UiFileHandle->FileName), " and\n ", MessagePath(UiFileHandle->FileName), " and\n ",
Quoted(handle->SourceFile->FileName), MessagePath(handle->SourceFile->FileName),
".\nConsider to\n" ".\nConsider to\n"
" - add a directory prefix to a \"ui_<NAME>.h\" include " " - add a directory prefix to a \"ui_<NAME>.h\" include "
"(e.g \"sub/ui_<NAME>.h\")\n" "(e.g \"sub/ui_<NAME>.h\")\n"
@@ -1168,8 +1170,8 @@ bool cmQtAutoMocUic::JobProbeDepsMocT::Probe(MappingT const& mapping,
if (!outputFileTime.Load(outputFile)) { if (!outputFileTime.Load(outputFile)) {
if (reason != nullptr) { if (reason != nullptr) {
*reason = *reason =
cmStrCat("Generating ", Quoted(outputFile), cmStrCat("Generating ", MessagePath(outputFile),
", because it doesn't exist, from ", Quoted(sourceFile)); ", because it doesn't exist, from ", MessagePath(sourceFile));
} }
return true; return true;
} }
@@ -1177,9 +1179,9 @@ bool cmQtAutoMocUic::JobProbeDepsMocT::Probe(MappingT const& mapping,
// Test if any setting changed // Test if any setting changed
if (MocConst().SettingsChanged) { if (MocConst().SettingsChanged) {
if (reason != nullptr) { if (reason != nullptr) {
*reason = cmStrCat("Generating ", Quoted(outputFile), *reason = cmStrCat("Generating ", MessagePath(outputFile),
", because the uic settings changed, from ", ", because the uic settings changed, from ",
Quoted(sourceFile)); MessagePath(sourceFile));
} }
return true; return true;
} }
@@ -1187,9 +1189,9 @@ bool cmQtAutoMocUic::JobProbeDepsMocT::Probe(MappingT const& mapping,
// Test if the source file is newer // Test if the source file is newer
if (outputFileTime.Older(mapping.SourceFile->FileTime)) { if (outputFileTime.Older(mapping.SourceFile->FileTime)) {
if (reason != nullptr) { if (reason != nullptr) {
*reason = cmStrCat("Generating ", Quoted(outputFile), *reason = cmStrCat("Generating ", MessagePath(outputFile),
", because it's older than its source file, from ", ", because it's older than its source file, from ",
Quoted(sourceFile)); MessagePath(sourceFile));
} }
return true; return true;
} }
@@ -1198,9 +1200,10 @@ bool cmQtAutoMocUic::JobProbeDepsMocT::Probe(MappingT const& mapping,
if (!MocConst().PredefsFileAbs.empty()) { if (!MocConst().PredefsFileAbs.empty()) {
if (outputFileTime.Older(MocEval().PredefsTime)) { if (outputFileTime.Older(MocEval().PredefsTime)) {
if (reason != nullptr) { if (reason != nullptr) {
*reason = cmStrCat( *reason = cmStrCat("Generating ", MessagePath(outputFile),
"Generating ", Quoted(outputFile), ", because it's older than ", ", because it's older than ",
Quoted(MocConst().PredefsFileAbs), ", from ", Quoted(sourceFile)); MessagePath(MocConst().PredefsFileAbs), ", from ",
MessagePath(sourceFile));
} }
return true; return true;
} }
@@ -1209,9 +1212,9 @@ bool cmQtAutoMocUic::JobProbeDepsMocT::Probe(MappingT const& mapping,
// Test if the moc executable is newer // Test if the moc executable is newer
if (outputFileTime.Older(MocConst().ExecutableTime)) { if (outputFileTime.Older(MocConst().ExecutableTime)) {
if (reason != nullptr) { if (reason != nullptr) {
*reason = cmStrCat("Generating ", Quoted(outputFile), *reason = cmStrCat("Generating ", MessagePath(outputFile),
", because it's older than the moc executable, from ", ", because it's older than the moc executable, from ",
Quoted(sourceFile)); MessagePath(sourceFile));
} }
return true; return true;
} }
@@ -1224,17 +1227,19 @@ bool cmQtAutoMocUic::JobProbeDepsMocT::Probe(MappingT const& mapping,
// Find dependency file // Find dependency file
auto const depMatch = FindDependency(sourceDir, dep); auto const depMatch = FindDependency(sourceDir, dep);
if (depMatch.first.empty()) { if (depMatch.first.empty()) {
Log().WarningFile(GenT::MOC, sourceFile, Log().Warning(GenT::MOC,
"Could not find dependency file " + Quoted(dep)); cmStrCat(MessagePath(sourceFile), " depends on ",
MessagePath(dep),
" but the file does not exist."));
continue; continue;
} }
// Test if dependency file is older // Test if dependency file is older
if (outputFileTime.Older(depMatch.second)) { if (outputFileTime.Older(depMatch.second)) {
if (reason != nullptr) { if (reason != nullptr) {
*reason = *reason = cmStrCat("Generating ", MessagePath(outputFile),
cmStrCat("Generating ", Quoted(outputFile), ", because it's older than its dependency file ",
", because it's older than its dependency file ", MessagePath(depMatch.first), ", from ",
Quoted(depMatch.first), ", from ", Quoted(sourceFile)); MessagePath(sourceFile));
} }
return true; return true;
} }
@@ -1297,8 +1302,8 @@ bool cmQtAutoMocUic::JobProbeDepsUicT::Probe(MappingT const& mapping,
if (!outputFileTime.Load(outputFile)) { if (!outputFileTime.Load(outputFile)) {
if (reason != nullptr) { if (reason != nullptr) {
*reason = *reason =
cmStrCat("Generating ", Quoted(outputFile), cmStrCat("Generating ", MessagePath(outputFile),
", because it doesn't exist, from ", Quoted(sourceFile)); ", because it doesn't exist, from ", MessagePath(sourceFile));
} }
return true; return true;
} }
@@ -1306,9 +1311,9 @@ bool cmQtAutoMocUic::JobProbeDepsUicT::Probe(MappingT const& mapping,
// Test if the uic settings changed // Test if the uic settings changed
if (UicConst().SettingsChanged) { if (UicConst().SettingsChanged) {
if (reason != nullptr) { if (reason != nullptr) {
*reason = cmStrCat("Generating ", Quoted(outputFile), *reason = cmStrCat("Generating ", MessagePath(outputFile),
", because the uic settings changed, from ", ", because the uic settings changed, from ",
Quoted(sourceFile)); MessagePath(sourceFile));
} }
return true; return true;
} }
@@ -1316,9 +1321,9 @@ bool cmQtAutoMocUic::JobProbeDepsUicT::Probe(MappingT const& mapping,
// Test if the source file is newer // Test if the source file is newer
if (outputFileTime.Older(mapping.SourceFile->FileTime)) { if (outputFileTime.Older(mapping.SourceFile->FileTime)) {
if (reason != nullptr) { if (reason != nullptr) {
*reason = cmStrCat("Generating ", Quoted(outputFile), *reason = cmStrCat("Generating ", MessagePath(outputFile),
" because it's older than the source file ", " because it's older than the source file ",
Quoted(sourceFile)); MessagePath(sourceFile));
} }
return true; return true;
} }
@@ -1326,9 +1331,9 @@ bool cmQtAutoMocUic::JobProbeDepsUicT::Probe(MappingT const& mapping,
// Test if the uic executable is newer // Test if the uic executable is newer
if (outputFileTime.Older(UicConst().ExecutableTime)) { if (outputFileTime.Older(UicConst().ExecutableTime)) {
if (reason != nullptr) { if (reason != nullptr) {
*reason = cmStrCat("Generating ", Quoted(outputFile), *reason = cmStrCat("Generating ", MessagePath(outputFile),
", because it's older than the uic executable, from ", ", because it's older than the uic executable, from ",
Quoted(sourceFile)); MessagePath(sourceFile));
} }
return true; return true;
} }
@@ -1344,7 +1349,9 @@ void cmQtAutoMocUic::JobProbeDepsFinishT::Process()
auto createDirs = [this](GenT genType, StringSet const& dirSet) { auto createDirs = [this](GenT genType, StringSet const& dirSet) {
for (std::string const& dirName : dirSet) { for (std::string const& dirName : dirSet) {
if (!cmSystemTools::MakeDirectory(dirName)) { if (!cmSystemTools::MakeDirectory(dirName)) {
this->LogFileError(genType, dirName, "Could not create directory."); this->LogError(
genType,
cmStrCat("Creating directory ", MessagePath(dirName), " failed."));
return; return;
} }
} }
@@ -1402,13 +1409,13 @@ void cmQtAutoMocUic::JobCompileMocT::Process()
if (!Mapping->IncluderFiles.empty()) { if (!Mapping->IncluderFiles.empty()) {
includers = "included by\n"; includers = "included by\n";
for (auto const& item : Mapping->IncluderFiles) { for (auto const& item : Mapping->IncluderFiles) {
includers += cmStrCat(" ", Quoted(item->FileName), '\n'); includers += cmStrCat(" ", MessagePath(item->FileName), '\n');
} }
} }
LogCommandError(GenT::MOC, LogCommandError(GenT::MOC,
cmStrCat("The moc process failed to compile\n ", cmStrCat("The moc process failed to compile\n ",
Quoted(sourceFile), "\ninto\n ", MessagePath(sourceFile), "\ninto\n ",
Quoted(outputFile), '\n', includers, MessagePath(outputFile), '\n', includers,
result.ErrorMessage), result.ErrorMessage),
cmd, result.StdOut); cmd, result.StdOut);
} }
@@ -1446,13 +1453,13 @@ void cmQtAutoMocUic::JobCompileUicT::Process()
// Uic command failed // Uic command failed
std::string includers; std::string includers;
for (auto const& item : Mapping->IncluderFiles) { for (auto const& item : Mapping->IncluderFiles) {
includers += cmStrCat(" ", Quoted(item->FileName), '\n'); includers += cmStrCat(" ", MessagePath(item->FileName), '\n');
} }
LogCommandError(GenT::UIC, LogCommandError(GenT::UIC,
cmStrCat("The uic process failed to compile\n ", cmStrCat("The uic process failed to compile\n ",
Quoted(sourceFile), "\ninto\n ", MessagePath(sourceFile), "\ninto\n ",
Quoted(outputFile), "\nincluded by\n", includers, MessagePath(outputFile), "\nincluded by\n",
result.ErrorMessage), includers, result.ErrorMessage),
cmd, result.StdOut); cmd, result.StdOut);
} }
} }
@@ -1480,20 +1487,24 @@ void cmQtAutoMocUic::JobMocsCompilationT::Process()
if (cmQtAutoGenerator::FileDiffers(compAbs, content)) { if (cmQtAutoGenerator::FileDiffers(compAbs, content)) {
// Actually write mocs compilation file // Actually write mocs compilation file
if (Log().Verbose()) { if (Log().Verbose()) {
Log().Info(GenT::MOC, "Generating MOC compilation " + compAbs); Log().Info(GenT::MOC,
"Generating MOC compilation " + MessagePath(compAbs));
} }
if (!FileWrite(compAbs, content)) { if (!FileWrite(compAbs, content)) {
LogFileError(GenT::MOC, compAbs, LogError(GenT::MOC,
"mocs compilation file writing failed."); cmStrCat("Writing MOC compilation ", MessagePath(compAbs),
" failed."));
} }
} else if (MocEval().CompUpdated) { } else if (MocEval().CompUpdated) {
// Only touch mocs compilation file // Only touch mocs compilation file
if (Log().Verbose()) { if (Log().Verbose()) {
Log().Info(GenT::MOC, "Touching mocs compilation " + compAbs); Log().Info(GenT::MOC,
"Touching MOC compilation " + MessagePath(compAbs));
} }
if (!cmSystemTools::Touch(compAbs, false)) { if (!cmSystemTools::Touch(compAbs, false)) {
LogFileError(GenT::MOC, compAbs, LogError(GenT::MOC,
"mocs compilation file touching failed."); cmStrCat("Touching MOC compilation ", MessagePath(compAbs),
" failed."));
} }
} }
} }
@@ -1587,10 +1598,10 @@ bool cmQtAutoMocUic::Init(cmMakefile* makefile)
makefile->GetCMakeInstance()->GetHeaderExtensions(); makefile->GetCMakeInstance()->GetHeaderExtensions();
// - Files and directories // - Files and directories
BaseConst_.ProjectSourceDir = InfoGet("AM_CMAKE_SOURCE_DIR"); ProjectDirsRef().Source = InfoGet("AM_CMAKE_SOURCE_DIR");
BaseConst_.ProjectBinaryDir = InfoGet("AM_CMAKE_BINARY_DIR"); ProjectDirsRef().Binary = InfoGet("AM_CMAKE_BINARY_DIR");
BaseConst_.CurrentSourceDir = InfoGet("AM_CMAKE_CURRENT_SOURCE_DIR"); ProjectDirsRef().CurrentSource = InfoGet("AM_CMAKE_CURRENT_SOURCE_DIR");
BaseConst_.CurrentBinaryDir = InfoGet("AM_CMAKE_CURRENT_BINARY_DIR"); ProjectDirsRef().CurrentBinary = InfoGet("AM_CMAKE_CURRENT_BINARY_DIR");
BaseConst_.AutogenBuildDir = InfoGet("AM_BUILD_DIR"); BaseConst_.AutogenBuildDir = InfoGet("AM_BUILD_DIR");
if (BaseConst_.AutogenBuildDir.empty()) { if (BaseConst_.AutogenBuildDir.empty()) {
return LogInfoError("Autogen build directory missing."); return LogInfoError("Autogen build directory missing.");
@@ -1605,7 +1616,7 @@ bool cmQtAutoMocUic::Init(cmMakefile* makefile)
} }
if (!BaseConst_.CMakeExecutableTime.Load(BaseConst_.CMakeExecutable)) { if (!BaseConst_.CMakeExecutableTime.Load(BaseConst_.CMakeExecutable)) {
return LogInfoError(cmStrCat("The CMake executable ", return LogInfoError(cmStrCat("The CMake executable ",
Quoted(BaseConst_.CMakeExecutable), MessagePath(BaseConst_.CMakeExecutable),
" does not exist.")); " does not exist."));
} }
BaseConst_.ParseCacheFile = InfoGetConfig("AM_PARSE_CACHE_FILE"); BaseConst_.ParseCacheFile = InfoGetConfig("AM_PARSE_CACHE_FILE");
@@ -1634,7 +1645,7 @@ bool cmQtAutoMocUic::Init(cmMakefile* makefile)
// Load the executable file time // Load the executable file time
if (!MocConst_.ExecutableTime.Load(MocConst_.Executable)) { if (!MocConst_.ExecutableTime.Load(MocConst_.Executable)) {
return LogInfoError(cmStrCat("The moc executable ", return LogInfoError(cmStrCat("The moc executable ",
Quoted(MocConst_.Executable), MessagePath(MocConst_.Executable),
" does not exist.")); " does not exist."));
} }
for (std::string& sfl : InfoGetList("AM_MOC_SKIP")) { for (std::string& sfl : InfoGetList("AM_MOC_SKIP")) {
@@ -1700,7 +1711,7 @@ bool cmQtAutoMocUic::Init(cmMakefile* makefile)
// Load the executable file time // Load the executable file time
if (!UicConst_.ExecutableTime.Load(UicConst_.Executable)) { if (!UicConst_.ExecutableTime.Load(UicConst_.Executable)) {
return LogInfoError(cmStrCat("The uic executable ", return LogInfoError(cmStrCat("The uic executable ",
Quoted(UicConst_.Executable), MessagePath(UicConst_.Executable),
" does not exist.")); " does not exist."));
} }
for (std::string& sfl : InfoGetList("AM_UIC_SKIP")) { for (std::string& sfl : InfoGetList("AM_UIC_SKIP")) {
@@ -1729,17 +1740,17 @@ bool cmQtAutoMocUic::Init(cmMakefile* makefile)
// - Headers and sources // - Headers and sources
{ {
auto makeSource = auto makeSource = [this, &LogInfoError](
[&LogInfoError](std::string const& fileName, std::string const& fileName,
std::string const& fileFlags) -> SourceFileHandleT { std::string const& fileFlags) -> SourceFileHandleT {
if (fileFlags.size() != 2) { if (fileFlags.size() != 2) {
LogInfoError("Invalid file flags string size"); LogInfoError("Invalid file flags string size");
return SourceFileHandleT(); return SourceFileHandleT();
} }
cmFileTime fileTime; cmFileTime fileTime;
if (!fileTime.Load(fileName)) { if (!fileTime.Load(fileName)) {
LogInfoError("The source file " + cmQtAutoGen::Quoted(fileName) + LogInfoError(cmStrCat("The source file ", this->MessagePath(fileName),
" does not exist."); " does not exist."));
return SourceFileHandleT(); return SourceFileHandleT();
} }
SourceFileHandleT sfh = std::make_shared<SourceFileT>(fileName); SourceFileHandleT sfh = std::make_shared<SourceFileT>(fileName);
@@ -1777,9 +1788,7 @@ bool cmQtAutoMocUic::Init(cmMakefile* makefile)
if (MocConst().Enabled) { if (MocConst().Enabled) {
sfh->BuildPath = std::move(builds[ii]); sfh->BuildPath = std::move(builds[ii]);
if (sfh->BuildPath.empty()) { if (sfh->BuildPath.empty()) {
Log().ErrorFile(GenT::GEN, this->InfoFile(), return LogInfoError("Header file build path is empty");
"Header file build path is empty");
return false;
} }
} }
BaseEval().Headers.emplace(std::move(fileName), std::move(sfh)); BaseEval().Headers.emplace(std::move(fileName), std::move(sfh));
@@ -1817,13 +1826,13 @@ bool cmQtAutoMocUic::Init(cmMakefile* makefile)
// Moc predefs file // Moc predefs file
if (!MocConst_.PredefsCmd.empty()) { if (!MocConst_.PredefsCmd.empty()) {
std::string pathRel;
if (BaseConst_.MultiConfig) { if (BaseConst_.MultiConfig) {
MocConst_.PredefsFileRel = pathRel = cmStrCat("moc_predefs_", InfoConfig(), ".h");
cmStrCat("moc_predefs_", InfoConfig(), ".h");
} else { } else {
MocConst_.PredefsFileRel = "moc_predefs.h"; pathRel = "moc_predefs.h";
} }
MocConst_.PredefsFileAbs = AbsoluteBuildPath(MocConst().PredefsFileRel); MocConst_.PredefsFileAbs = AbsoluteBuildPath(pathRel);
} }
// Compose moc includes list // Compose moc includes list
@@ -1887,7 +1896,7 @@ void cmQtAutoMocUic::CreateParseJobs(SourceFileMapT const& sourceMap)
std::string cmQtAutoMocUic::CollapseFullPathTS(std::string const& path) const std::string cmQtAutoMocUic::CollapseFullPathTS(std::string const& path) const
{ {
std::lock_guard<std::mutex> guard(CMakeLibMutex_); std::lock_guard<std::mutex> guard(CMakeLibMutex_);
return cmSystemTools::CollapseFullPath(path, BaseConst().CurrentSourceDir); return cmSystemTools::CollapseFullPath(path, ProjectDirs().CurrentSource);
} }
void cmQtAutoMocUic::InitJobs() void cmQtAutoMocUic::InitJobs()
@@ -2016,7 +2025,9 @@ bool cmQtAutoMocUic::SettingsFileWrite()
// Only write if any setting changed // Only write if any setting changed
if (MocConst().SettingsChanged || UicConst().SettingsChanged) { if (MocConst().SettingsChanged || UicConst().SettingsChanged) {
if (Log().Verbose()) { if (Log().Verbose()) {
Log().Info(GenT::GEN, "Writing settings file " + Quoted(SettingsFile_)); Log().Info(
GenT::GEN,
cmStrCat("Writing settings file ", MessagePath(SettingsFile_)));
} }
// Compose settings file content // Compose settings file content
std::string content; std::string content;
@@ -2033,8 +2044,9 @@ bool cmQtAutoMocUic::SettingsFileWrite()
// Write settings file // Write settings file
std::string error; std::string error;
if (!cmQtAutoGenerator::FileWrite(SettingsFile_, content, &error)) { if (!cmQtAutoGenerator::FileWrite(SettingsFile_, content, &error)) {
Log().ErrorFile(GenT::GEN, SettingsFile_, Log().Error(GenT::GEN,
"Settings file writing failed. " + error); cmStrCat("Writing the settings file ",
MessagePath(SettingsFile_), " failed.\n", error));
// Remove old settings file to trigger a full rebuild on the next run // Remove old settings file to trigger a full rebuild on the next run
cmSystemTools::RemoveFile(SettingsFile_); cmSystemTools::RemoveFile(SettingsFile_);
return false; return false;
@@ -2074,12 +2086,14 @@ bool cmQtAutoMocUic::ParseCacheWrite()
if (BaseEval().ParseCacheChanged) { if (BaseEval().ParseCacheChanged) {
if (Log().Verbose()) { if (Log().Verbose()) {
Log().Info(GenT::GEN, Log().Info(GenT::GEN,
"Writing parse cache file " + cmStrCat("Writing the parse cache file ",
Quoted(BaseConst().ParseCacheFile)); MessagePath(BaseConst().ParseCacheFile)));
} }
if (!BaseEval().ParseCache.WriteToFile(BaseConst().ParseCacheFile)) { if (!BaseEval().ParseCache.WriteToFile(BaseConst().ParseCacheFile)) {
Log().ErrorFile(GenT::GEN, BaseConst().ParseCacheFile, Log().Error(GenT::GEN,
"Parse cache file writing failed."); cmStrCat("Writing the parse cache file ",
MessagePath(BaseConst().ParseCacheFile),
" failed."));
return false; return false;
} }
} }
@@ -2090,8 +2104,10 @@ bool cmQtAutoMocUic::CreateDirectories()
{ {
// Create AUTOGEN include directory // Create AUTOGEN include directory
if (!cmSystemTools::MakeDirectory(BaseConst().AutogenIncludeDir)) { if (!cmSystemTools::MakeDirectory(BaseConst().AutogenIncludeDir)) {
Log().ErrorFile(GenT::GEN, BaseConst().AutogenIncludeDir, Log().Error(GenT::GEN,
"Could not create directory."); cmStrCat("Creating the AUTOGEN include directory ",
MessagePath(BaseConst().AutogenIncludeDir),
" failed."));
return false; return false;
} }
return true; return true;

View File

@@ -169,10 +169,6 @@ public:
bool MultiConfig = false; bool MultiConfig = false;
unsigned int QtVersionMajor = 4; unsigned int QtVersionMajor = 4;
// - Directories // - Directories
std::string ProjectSourceDir;
std::string ProjectBinaryDir;
std::string CurrentSourceDir;
std::string CurrentBinaryDir;
std::string AutogenBuildDir; std::string AutogenBuildDir;
std::string AutogenIncludeDir; std::string AutogenIncludeDir;
// - Files // - Files
@@ -218,7 +214,6 @@ public:
cmFileTime ExecutableTime; cmFileTime ExecutableTime;
std::string Executable; std::string Executable;
std::string CompFileAbs; std::string CompFileAbs;
std::string PredefsFileRel;
std::string PredefsFileAbs; std::string PredefsFileAbs;
std::unordered_set<std::string> SkipList; std::unordered_set<std::string> SkipList;
std::vector<std::string> IncludePaths; std::vector<std::string> IncludePaths;
@@ -313,10 +308,13 @@ public:
UicSettingsT const& UicConst() const { return Gen()->UicConst(); } UicSettingsT const& UicConst() const { return Gen()->UicConst(); }
UicEvalT& UicEval() const { return Gen()->UicEval(); } UicEvalT& UicEval() const { return Gen()->UicEval(); }
// -- Error logging with automatic abort // -- Logging
std::string MessagePath(cm::string_view path) const
{
return Gen()->MessagePath(path);
}
// - Error logging with automatic abort
void LogError(GenT genType, cm::string_view message) const; void LogError(GenT genType, cm::string_view message) const;
void LogFileError(GenT genType, cm::string_view filename,
cm::string_view message) const;
void LogCommandError(GenT genType, cm::string_view message, void LogCommandError(GenT genType, cm::string_view message,
std::vector<std::string> const& command, std::vector<std::string> const& command,
std::string const& output) const; std::string const& output) const;

View File

@@ -16,7 +16,6 @@
#include <algorithm> #include <algorithm>
cmQtAutoRcc::cmQtAutoRcc() = default; cmQtAutoRcc::cmQtAutoRcc() = default;
cmQtAutoRcc::~cmQtAutoRcc() = default; cmQtAutoRcc::~cmQtAutoRcc() = default;
bool cmQtAutoRcc::Init(cmMakefile* makefile) bool cmQtAutoRcc::Init(cmMakefile* makefile)
@@ -41,8 +40,8 @@ bool cmQtAutoRcc::Init(cmMakefile* makefile)
return cmExpandedList(InfoGetConfig(key)); return cmExpandedList(InfoGetConfig(key));
}; };
auto LogInfoError = [this](cm::string_view msg) -> bool { auto LogInfoError = [this](cm::string_view msg) -> bool {
this->Log().Error(GenT::RCC, this->Log().Error(
cmStrCat("In ", Quoted(this->InfoFile()), ":\n", msg)); GenT::RCC, cmStrCat("In ", MessagePath(this->InfoFile()), ":\n", msg));
return false; return false;
}; };
@@ -56,6 +55,8 @@ bool cmQtAutoRcc::Init(cmMakefile* makefile)
MultiConfig_ = makefile->IsOn("ARCC_MULTI_CONFIG"); MultiConfig_ = makefile->IsOn("ARCC_MULTI_CONFIG");
// - Directories // - Directories
ProjectDirsRef().Source = InfoGet("ARCC_CMAKE_SOURCE_DIR");
ProjectDirsRef().Binary = InfoGet("ARCC_CMAKE_BINARY_DIR");
AutogenBuildDir_ = InfoGet("ARCC_BUILD_DIR"); AutogenBuildDir_ = InfoGet("ARCC_BUILD_DIR");
if (AutogenBuildDir_.empty()) { if (AutogenBuildDir_.empty()) {
return LogInfoError("Build directory empty."); return LogInfoError("Build directory empty.");
@@ -69,8 +70,8 @@ bool cmQtAutoRcc::Init(cmMakefile* makefile)
// - Rcc executable // - Rcc executable
RccExecutable_ = InfoGet("ARCC_RCC_EXECUTABLE"); RccExecutable_ = InfoGet("ARCC_RCC_EXECUTABLE");
if (!RccExecutableTime_.Load(RccExecutable_)) { if (!RccExecutableTime_.Load(RccExecutable_)) {
return LogInfoError(cmStrCat("The rcc executable ", Quoted(RccExecutable_), return LogInfoError(cmStrCat(
" does not exist.")); "The rcc executable ", MessagePath(RccExecutable_), " does not exist."));
} }
RccListOptions_ = InfoGetList("ARCC_RCC_LIST_OPTIONS"); RccListOptions_ = InfoGetList("ARCC_RCC_LIST_OPTIONS");
@@ -185,8 +186,9 @@ bool cmQtAutoRcc::SettingsFileRead()
if (!cmSystemTools::FileExists(SettingsFile_, true)) { if (!cmSystemTools::FileExists(SettingsFile_, true)) {
// Touch the settings file to make sure it exists // Touch the settings file to make sure it exists
if (!cmSystemTools::Touch(SettingsFile_, true)) { if (!cmSystemTools::Touch(SettingsFile_, true)) {
Log().ErrorFile(GenT::RCC, SettingsFile_, Log().Error(GenT::RCC,
"Settings file creation failed."); cmStrCat("Touching the settings file ",
MessagePath(SettingsFile_), " failed."));
return false; return false;
} }
} }
@@ -196,7 +198,9 @@ bool cmQtAutoRcc::SettingsFileRead()
// Make sure the lock file exists // Make sure the lock file exists
if (!cmSystemTools::FileExists(LockFile_, true)) { if (!cmSystemTools::FileExists(LockFile_, true)) {
if (!cmSystemTools::Touch(LockFile_, true)) { if (!cmSystemTools::Touch(LockFile_, true)) {
Log().ErrorFile(GenT::RCC, LockFile_, "Lock file creation failed."); Log().Error(GenT::RCC,
cmStrCat("Touching the lock file ", MessagePath(LockFile_),
" failed."));
return false; return false;
} }
} }
@@ -204,8 +208,9 @@ bool cmQtAutoRcc::SettingsFileRead()
cmFileLockResult lockResult = cmFileLockResult lockResult =
LockFileLock_.Lock(LockFile_, static_cast<unsigned long>(-1)); LockFileLock_.Lock(LockFile_, static_cast<unsigned long>(-1));
if (!lockResult.IsOk()) { if (!lockResult.IsOk()) {
Log().ErrorFile(GenT::RCC, LockFile_, Log().Error(GenT::RCC,
"File lock failed: " + lockResult.GetOutputMessage()); cmStrCat("Locking of the lock file ", MessagePath(LockFile_),
" failed.\n", lockResult.GetOutputMessage()));
return false; return false;
} }
} }
@@ -221,8 +226,10 @@ bool cmQtAutoRcc::SettingsFileRead()
if (SettingsChanged_) { if (SettingsChanged_) {
std::string error; std::string error;
if (!FileWrite(SettingsFile_, "", &error)) { if (!FileWrite(SettingsFile_, "", &error)) {
Log().ErrorFile(GenT::RCC, SettingsFile_, Log().Error(GenT::RCC,
"Settings file clearing failed. " + error); cmStrCat("Clearing of the settings file ",
MessagePath(SettingsFile_), " failed.\n",
error));
return false; return false;
} }
} }
@@ -239,14 +246,16 @@ bool cmQtAutoRcc::SettingsFileWrite()
// Only write if any setting changed // Only write if any setting changed
if (SettingsChanged_) { if (SettingsChanged_) {
if (Log().Verbose()) { if (Log().Verbose()) {
Log().Info(GenT::RCC, "Writing settings file " + Quoted(SettingsFile_)); Log().Info(GenT::RCC,
"Writing settings file " + MessagePath(SettingsFile_));
} }
// Write settings file // Write settings file
std::string content = cmStrCat("rcc:", SettingsString_, '\n'); std::string content = cmStrCat("rcc:", SettingsString_, '\n');
std::string error; std::string error;
if (!FileWrite(SettingsFile_, content, &error)) { if (!FileWrite(SettingsFile_, content, &error)) {
Log().ErrorFile(GenT::RCC, SettingsFile_, Log().Error(GenT::RCC,
"Settings file writing failed. " + error); cmStrCat("Writing of the settings file ",
MessagePath(SettingsFile_), " failed.\n", error));
// Remove old settings file to trigger a full rebuild on the next run // Remove old settings file to trigger a full rebuild on the next run
cmSystemTools::RemoveFile(SettingsFile_); cmSystemTools::RemoveFile(SettingsFile_);
return false; return false;
@@ -263,17 +272,18 @@ bool cmQtAutoRcc::TestQrcRccFiles(bool& generate)
{ {
// Test if the rcc input file exists // Test if the rcc input file exists
if (!QrcFileTime_.Load(QrcFile_)) { if (!QrcFileTime_.Load(QrcFile_)) {
Log().ErrorFile( Log().Error(GenT::RCC,
GenT::RCC, QrcFile_, cmStrCat("The resources file ", MessagePath(QrcFile_),
cmStrCat("The resources file ", Quoted(QrcFile_), " does not exist")); " does not exist"));
return false; return false;
} }
// Test if the rcc output file exists // Test if the rcc output file exists
if (!RccFileTime_.Load(RccFileOutput_)) { if (!RccFileTime_.Load(RccFileOutput_)) {
if (Log().Verbose()) { if (Log().Verbose()) {
Reason = cmStrCat("Generating ", Quoted(RccFileOutput_), Reason =
", because it doesn't exist, from ", Quoted(QrcFile_)); cmStrCat("Generating ", MessagePath(RccFileOutput_),
", because it doesn't exist, from ", MessagePath(QrcFile_));
} }
generate = true; generate = true;
return true; return true;
@@ -282,9 +292,9 @@ bool cmQtAutoRcc::TestQrcRccFiles(bool& generate)
// Test if the settings changed // Test if the settings changed
if (SettingsChanged_) { if (SettingsChanged_) {
if (Log().Verbose()) { if (Log().Verbose()) {
Reason = cmStrCat("Generating ", Quoted(RccFileOutput_), Reason = cmStrCat("Generating ", MessagePath(RccFileOutput_),
", because the rcc settings changed, from ", ", because the rcc settings changed, from ",
Quoted(QrcFile_)); MessagePath(QrcFile_));
} }
generate = true; generate = true;
return true; return true;
@@ -293,9 +303,9 @@ bool cmQtAutoRcc::TestQrcRccFiles(bool& generate)
// Test if the rcc output file is older than the .qrc file // Test if the rcc output file is older than the .qrc file
if (RccFileTime_.Older(QrcFileTime_)) { if (RccFileTime_.Older(QrcFileTime_)) {
if (Log().Verbose()) { if (Log().Verbose()) {
Reason = cmStrCat("Generating ", Quoted(RccFileOutput_), Reason = cmStrCat("Generating ", MessagePath(RccFileOutput_),
", because it is older than ", Quoted(QrcFile_), ", because it is older than ", MessagePath(QrcFile_),
", from ", Quoted(QrcFile_)); ", from ", MessagePath(QrcFile_));
} }
generate = true; generate = true;
return true; return true;
@@ -304,9 +314,9 @@ bool cmQtAutoRcc::TestQrcRccFiles(bool& generate)
// Test if the rcc output file is older than the rcc executable // Test if the rcc output file is older than the rcc executable
if (RccFileTime_.Older(RccExecutableTime_)) { if (RccFileTime_.Older(RccExecutableTime_)) {
if (Log().Verbose()) { if (Log().Verbose()) {
Reason = cmStrCat("Generating ", Quoted(RccFileOutput_), Reason = cmStrCat("Generating ", MessagePath(RccFileOutput_),
", because it is older than the rcc executable, from ", ", because it is older than the rcc executable, from ",
Quoted(QrcFile_)); MessagePath(QrcFile_));
} }
generate = true; generate = true;
return true; return true;
@@ -322,7 +332,9 @@ bool cmQtAutoRcc::TestResources(bool& generate)
std::string error; std::string error;
RccLister const lister(RccExecutable_, RccListOptions_); RccLister const lister(RccExecutable_, RccListOptions_);
if (!lister.list(QrcFile_, Inputs_, error, Log().Verbose())) { if (!lister.list(QrcFile_, Inputs_, error, Log().Verbose())) {
Log().ErrorFile(GenT::RCC, QrcFile_, error); Log().Error(
GenT::RCC,
cmStrCat("Listing of ", MessagePath(QrcFile_), " failed.\n", error));
return false; return false;
} }
} }
@@ -332,17 +344,18 @@ bool cmQtAutoRcc::TestResources(bool& generate)
// Check if the resource file exists // Check if the resource file exists
cmFileTime fileTime; cmFileTime fileTime;
if (!fileTime.Load(resFile)) { if (!fileTime.Load(resFile)) {
Log().ErrorFile(GenT::RCC, QrcFile_, Log().Error(GenT::RCC,
cmStrCat("Could not find the resource file\n ", cmStrCat("The resource file ", MessagePath(resFile),
Quoted(resFile), '\n')); " listed in ", MessagePath(QrcFile_),
" does not exist."));
return false; return false;
} }
// Check if the resource file is newer than the rcc output file // Check if the resource file is newer than the rcc output file
if (RccFileTime_.Older(fileTime)) { if (RccFileTime_.Older(fileTime)) {
if (Log().Verbose()) { if (Log().Verbose()) {
Reason = cmStrCat("Generating ", Quoted(RccFileOutput_), Reason = cmStrCat("Generating ", MessagePath(RccFileOutput_),
", because it is older than ", Quoted(resFile), ", because it is older than ", MessagePath(resFile),
", from ", Quoted(QrcFile_)); ", from ", MessagePath(QrcFile_));
} }
generate = true; generate = true;
break; break;
@@ -357,12 +370,15 @@ bool cmQtAutoRcc::TestInfoFile()
if (RccFileTime_.Older(InfoFileTime())) { if (RccFileTime_.Older(InfoFileTime())) {
if (Log().Verbose()) { if (Log().Verbose()) {
Log().Info(GenT::RCC, Log().Info(GenT::RCC,
cmStrCat("Touching ", Quoted(RccFileOutput_), cmStrCat("Touching ", MessagePath(RccFileOutput_),
" because it is older than ", Quoted(InfoFile()))); " because it is older than ",
MessagePath(InfoFile())));
} }
// Touch build file // Touch build file
if (!cmSystemTools::Touch(RccFileOutput_, false)) { if (!cmSystemTools::Touch(RccFileOutput_, false)) {
Log().ErrorFile(GenT::RCC, RccFileOutput_, "Build file touch failed"); Log().Error(
GenT::RCC,
cmStrCat("Touching ", MessagePath(RccFileOutput_), " failed."));
return false; return false;
} }
BuildFileChanged_ = true; BuildFileChanged_ = true;
@@ -375,8 +391,9 @@ bool cmQtAutoRcc::GenerateRcc()
{ {
// Make parent directory // Make parent directory
if (!MakeParentDirectory(RccFileOutput_)) { if (!MakeParentDirectory(RccFileOutput_)) {
Log().ErrorFile(GenT::RCC, RccFileOutput_, Log().Error(GenT::RCC,
"Could not create parent directory"); cmStrCat("Could not create parent directory of ",
MessagePath(RccFileOutput_)));
return false; return false;
} }
@@ -405,8 +422,8 @@ bool cmQtAutoRcc::GenerateRcc()
// rcc process failed // rcc process failed
Log().ErrorCommand(GenT::RCC, Log().ErrorCommand(GenT::RCC,
cmStrCat("The rcc process failed to compile\n ", cmStrCat("The rcc process failed to compile\n ",
Quoted(QrcFile_), "\ninto\n ", MessagePath(QrcFile_), "\ninto\n ",
Quoted(RccFileOutput_)), MessagePath(RccFileOutput_)),
cmd, rccStdOut + rccStdErr); cmd, rccStdOut + rccStdErr);
cmSystemTools::RemoveFile(RccFileOutput_); cmSystemTools::RemoveFile(RccFileOutput_);
return false; return false;
@@ -443,22 +460,29 @@ bool cmQtAutoRcc::GenerateWrapper()
if (fileDiffers) { if (fileDiffers) {
// Write new wrapper file // Write new wrapper file
if (Log().Verbose()) { if (Log().Verbose()) {
Log().Info(GenT::RCC, "Generating RCC wrapper file " + RccFilePublic_); Log().Info(GenT::RCC,
cmStrCat("Generating RCC wrapper file ",
MessagePath(RccFilePublic_)));
} }
std::string error; std::string error;
if (!FileWrite(RccFilePublic_, content, &error)) { if (!FileWrite(RccFilePublic_, content, &error)) {
Log().ErrorFile(GenT::RCC, RccFilePublic_, Log().Error(GenT::RCC,
"RCC wrapper file writing failed. " + error); cmStrCat("Generating RCC wrapper file ",
MessagePath(RccFilePublic_), " failed.\n",
error));
return false; return false;
} }
} else if (BuildFileChanged_) { } else if (BuildFileChanged_) {
// Just touch the wrapper file // Just touch the wrapper file
if (Log().Verbose()) { if (Log().Verbose()) {
Log().Info(GenT::RCC, "Touching RCC wrapper file " + RccFilePublic_); Log().Info(
GenT::RCC,
cmStrCat("Touching RCC wrapper file ", MessagePath(RccFilePublic_)));
} }
if (!cmSystemTools::Touch(RccFilePublic_, false)) { if (!cmSystemTools::Touch(RccFilePublic_, false)) {
Log().ErrorFile(GenT::RCC, RccFilePublic_, Log().Error(GenT::RCC,
"RCC wrapper file touch failed."); cmStrCat("Touching RCC wrapper file ",
MessagePath(RccFilePublic_), " failed."));
return false; return false;
} }
} }