moc: Print sterror(errno) when moc can't write the output file

Also prepend a "Error:" label to all strrerror handling locations,
to make it clear where the error starts.

Task-number: QTBUG-101926
Change-Id: I1a781b4c5716636eff4d47a6c8554dcbd51d2697
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 3ba3f322b6b1781cfc1a64be8240b1ae74c36840)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Alexandru Croitor 2023-07-12 10:31:04 +02:00 committed by Qt Cherry-pick Bot
parent b09ff420e4
commit a9e8aa565c

View File

@ -536,7 +536,10 @@ int runMoc(int argc, char **argv)
if (!out)
#endif
{
fprintf(stderr, "moc: Cannot create %s\n", QFile::encodeName(output).constData());
const auto fopen_errno = errno;
fprintf(stderr, "moc: Cannot create %s. Error: %s\n",
QFile::encodeName(output).constData(),
strerror(fopen_errno));
return 1;
}
@ -551,7 +554,7 @@ int runMoc(int argc, char **argv)
#endif
{
const auto fopen_errno = errno;
fprintf(stderr, "moc: Cannot create JSON output file %s. %s\n",
fprintf(stderr, "moc: Cannot create JSON output file %s. Error: %s\n",
QFile::encodeName(jsonOutputFileName).constData(),
strerror(fopen_errno));
}
@ -601,7 +604,7 @@ int runMoc(int argc, char **argv)
#endif
{
const auto fopen_errno = errno;
fprintf(stderr, "moc: Cannot create dep output file '%s'. %s\n",
fprintf(stderr, "moc: Cannot create dep output file '%s'. Error: %s\n",
QFile::encodeName(depOutputFileName).constData(),
strerror(fopen_errno));
}