Skip to content

Commit 80139b1

Browse files
committed
lc-compile: Add -Werror option
Make lc-compile understand a `-Werror` command-line option, that turns all warnings into errors. This is extremely basic: it doesn't support turning warnings on or off for particular warning types, or any different ways of specifying command-line options (e.g. `-W error` or `--warn error`).
1 parent f1b53da commit 80139b1

3 files changed

Lines changed: 37 additions & 10 deletions

File tree

toolchain/lc-compile/src/main.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ usage(int status)
104104
" --deps changed-order Generate the order the input source files should be\n"
105105
" compiled in, but only if they need recompiling.\n"
106106
" --manifest MANIFEST Filename for generated manifest.\n"
107+
" -Werror Turn all warnings into errors.\n"
107108
" -v, --verbose Output extra debugging information.\n"
108109
" -h, --help Print this message.\n"
109110
" -- Treat all remaining arguments as filenames.\n"
@@ -180,6 +181,15 @@ static void full_main(int argc, char *argv[])
180181
SetManifestOutputFile(argv[++argi]);
181182
continue;
182183
}
184+
/* FIXME This should be expanded to support "-W error",
185+
* "--warn error", "--warn=error", etc. Also options for
186+
* enabling/disabling/errorifying particular warning
187+
* types. */
188+
if (0 == strcmp(opt, "-Werror"))
189+
{
190+
s_is_werror_enabled = 1;
191+
continue;
192+
}
183193
if (0 == strcmp(opt, "-v") || 0 == strcmp(opt, "--verbose"))
184194
{
185195
++s_verbose_level;

toolchain/lc-compile/src/report.c

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ extern int IsDependencyCompile(void);
2828

2929
static int s_error_count;
3030
int s_verbose_level;
31+
int s_is_werror_enabled;
3132

3233
void InitializeReports(void)
3334
{
@@ -162,9 +163,16 @@ static void _Warning(long p_position, const char *p_message)
162163
{
163164
if (IsDependencyCompile())
164165
return;
165-
166-
_PrintPosition(p_position);
167-
fprintf(stderr, "warning: %s\n", p_message);
166+
167+
if (s_is_werror_enabled)
168+
{
169+
_Error(p_position, p_message);
170+
}
171+
else
172+
{
173+
_PrintPosition(p_position);
174+
fprintf(stderr, "warning: %s\n", p_message);
175+
}
168176
}
169177

170178
static void _ErrorS(long p_position, const char *p_message, const char *p_string)
@@ -173,6 +181,7 @@ static void _ErrorS(long p_position, const char *p_message, const char *p_string
173181
GetColumnOfPosition(p_position, &t_column);
174182
GetRowOfPosition(p_position, &t_row);
175183
_PrintPosition(p_position);
184+
fprintf(stderr, "error: ");
176185
fprintf(stderr, p_message, p_string);
177186
fprintf(stderr, "\n");
178187
s_error_count += 1;
@@ -184,13 +193,20 @@ static void _WarningS(long p_position, const char *p_message, const char *p_stri
184193

185194
if (IsDependencyCompile())
186195
return;
187-
188-
GetColumnOfPosition(p_position, &t_column);
189-
GetRowOfPosition(p_position, &t_row);
190-
_PrintPosition(p_position);
191-
fprintf(stderr, "warning: ");
192-
fprintf(stderr, p_message, p_string);
193-
fprintf(stderr, "\n");
196+
197+
if (s_is_werror_enabled)
198+
{
199+
_ErrorS(p_position, p_message, p_string);
200+
}
201+
else
202+
{
203+
GetColumnOfPosition(p_position, &t_column);
204+
GetRowOfPosition(p_position, &t_row);
205+
_PrintPosition(p_position);
206+
fprintf(stderr, "warning: ");
207+
fprintf(stderr, p_message, p_string);
208+
fprintf(stderr, "\n");
209+
}
194210
}
195211

196212
static void _ErrorI(long p_position, const char *p_message, NameRef p_name)

toolchain/lc-compile/src/report.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
extern "C" {
2222
#endif
2323

24+
extern int s_is_werror_enabled;
2425
extern int s_verbose_level;
2526

2627
void InitializeReports(void);

0 commit comments

Comments
 (0)