Fix: Make all settingsgen 'warnings' fatal. (#10766)

Compilation should stop If settingsgen fails to complete properly.
This commit is contained in:
PeterN 2023-05-05 09:22:03 +01:00 committed by GitHub
parent a7d3c79d79
commit bda754ec83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 10 deletions

View File

@ -29,7 +29,7 @@
*/ */
void NORETURN FatalErrorI(const std::string &msg) void NORETURN FatalErrorI(const std::string &msg)
{ {
fprintf(stderr, "FATAL: %s\n", msg.c_str()); fprintf(stderr, "settingsgen: FATAL: %s\n", msg.c_str());
exit(1); exit(1);
} }
@ -66,7 +66,7 @@ public:
void Write(FILE *out_fp) const void Write(FILE *out_fp) const
{ {
if (fwrite(this->data, 1, this->size, out_fp) != this->size) { if (fwrite(this->data, 1, this->size, out_fp) != this->size) {
fprintf(stderr, "Error: Cannot write output\n"); FatalError("Cannot write output");
} }
} }
@ -323,8 +323,7 @@ static void DumpSections(IniLoadFile *ifile)
IniItem *template_item = templates_grp->GetItem(grp->name, false); // Find template value. IniItem *template_item = templates_grp->GetItem(grp->name, false); // Find template value.
if (template_item == nullptr || !template_item->value.has_value()) { if (template_item == nullptr || !template_item->value.has_value()) {
fprintf(stderr, "settingsgen: Warning: Cannot find template %s\n", grp->name.c_str()); FatalError("Cannot find template {}", grp->name);
continue;
} }
DumpLine(template_item, grp, default_grp, _stored_output); DumpLine(template_item, grp, default_grp, _stored_output);
@ -348,8 +347,7 @@ static void CopyFile(const char *fname, FILE *out_fp)
FILE *in_fp = fopen(fname, "r"); FILE *in_fp = fopen(fname, "r");
if (in_fp == nullptr) { if (in_fp == nullptr) {
fprintf(stderr, "settingsgen: Warning: Cannot open file %s for copying\n", fname); FatalError("Cannot open file {} for copying", fname);
return;
} }
char buffer[4096]; char buffer[4096];
@ -357,8 +355,7 @@ static void CopyFile(const char *fname, FILE *out_fp)
do { do {
length = fread(buffer, 1, lengthof(buffer), in_fp); length = fread(buffer, 1, lengthof(buffer), in_fp);
if (fwrite(buffer, 1, length, out_fp) != length) { if (fwrite(buffer, 1, length, out_fp) != length) {
fprintf(stderr, "Error: Cannot copy file\n"); FatalError("Cannot copy file");
break;
} }
} while (length == lengthof(buffer)); } while (length == lengthof(buffer));
@ -507,8 +504,7 @@ int CDECL main(int argc, char *argv[])
FILE *fp = fopen(tmp_output, "w"); FILE *fp = fopen(tmp_output, "w");
if (fp == nullptr) { if (fp == nullptr) {
fprintf(stderr, "settingsgen: Warning: Cannot open file %s\n", tmp_output); FatalError("Cannot open file {}", tmp_output);
return 1;
} }
CopyFile(before_file, fp); CopyFile(before_file, fp);
_stored_output.Write(fp); _stored_output.Write(fp);