Skip to content

Commit 44f8b40

Browse files
committed
Merge branch 'topic/warnings_as_errors' into 'master'
Add the "-W/--warnings-as-errors" flag to GNATcheck Closes #232 See merge request eng/libadalang/langkit-query-language!328
2 parents ca66efd + e2b082b commit 44f8b40

File tree

14 files changed

+227
-305
lines changed

14 files changed

+227
-305
lines changed

lkql_checker/doc/gnatcheck_rm/using_gnatcheck.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,12 @@ The following switches control the general ``gnatcheck`` behavior
270270
Verbose mode; ``gnatcheck`` generates version information and then
271271
a trace of sources being processed.
272272

273+
.. index:: -W
274+
275+
``-W, --warnings-as-errors``
276+
Treat warnings raised by GNATcheck as errors, ensuring an erroneous return
277+
code.
278+
273279
.. index:: -o
274280

275281
``-o report_file``

lkql_checker/src/gnatcheck-options.ads

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,6 @@ package Gnatcheck.Options is
9494
KP_Version : GNAT.OS_Lib.String_Access;
9595
-- If set, the relevant GNAT version to check when running gnatkp.
9696

97-
type Warning_Modes is
98-
(Quiet, -- all warnings are suppressed
99-
Short,
100-
Normal,
101-
Full);
102-
103-
Warning_Mode : Warning_Modes := Normal;
104-
-- Specifies the warning message level
105-
-- '-w(q|s|n|f)
106-
10797
Log_Mode : Boolean := False;
10898
-- Create the log file and duplicate in this file all the messages
10999
-- generated by a tool.
@@ -466,6 +456,12 @@ package Gnatcheck.Options is
466456
Help => "emit a 'rules.lkql' file containing the rules "
467457
& "configuration");
468458

459+
package Warnings_As_Errors is new Parse_Flag
460+
(Parser => Parser,
461+
Long => "--warnings-as-errors",
462+
Short => "-W",
463+
Help => "Treat warning messages as errors");
464+
469465
function Quiet_Mode return Boolean is (Quiet.Get or else Brief.Get);
470466

471467
function Short_Report return Boolean is (Brief.Get or else Short.Get);

lkql_checker/src/gnatcheck-output.adb

Lines changed: 137 additions & 234 deletions
Large diffs are not rendered by default.

lkql_checker/src/gnatcheck-output.ads

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ package Gnatcheck.Output is
1818
Custom_XML_Report_File : Boolean := False;
1919
-- Undicate if custom name is specified for text or XML output file
2020

21+
Error_From_Warning : Boolean;
22+
-- Whether a warning message has been emitted while "warnings as errors"
23+
-- mode is enabled. This ensure the return code of GNATcheck is not 0.
24+
2125
procedure Print_Version_Info (Released_At : Positive);
2226
-- Prints into Stderr the tool version information in the following format:
2327
--
@@ -43,39 +47,19 @@ package Gnatcheck.Output is
4347
procedure Error_No_Tool_Name (Message : String);
4448
-- Sends into Stderr the error message with no tool name prefix
4549

46-
procedure Error_In_Tty (Message : String);
47-
-- Same as ``Error`` but send the message only if Stderr is a TTY. Also,
48-
-- ``Message`` is not added to the stderr log file.
50+
procedure Warning (Message : String);
51+
-- Same as ``Error``
52+
53+
procedure Info (Message : String);
54+
-- Sends Message into Stderr (with no tool name prefix).
4955

50-
procedure SLOC_Error
51-
(Message : String;
52-
SLOC : String);
53-
-- Sends to Stderr the error message in the following format:
54-
-- 'SLOC:Tool_Name:Message', where SLOC is the GNAT-style source location.
56+
procedure Info_No_EOL (Message : String);
57+
-- The same as ``Info``, but does not output a (platform-specific) EOL
58+
-- character(s) after ``Message``.
5559

56-
procedure Warning (Message : String);
57-
-- Same as Error, but do nothing if Warning_Mode = Quiet.
58-
59-
procedure Info
60-
(Message : String;
61-
Line_Len : Natural := 0;
62-
Spacing : Natural := 0);
63-
-- Sends Message as a separate line(s) into Stderr (with no tool name
64-
-- prefix). If Line_Len is set to some positive value, it is treated as a
65-
-- maximal length of the text to be placed into one output line, and if the
66-
-- length of Message exceeds Line_Len, this procedure tries to split
67-
-- Message treating spaces as word separators and prints the rest of the
68-
-- Message on the next line(s). Each continuation line starts from Spacing
69-
-- number of space characters. Message can be split only on borders of
70-
-- words.
71-
72-
procedure Info_No_EOL
73-
(Message : String;
74-
Line_Len : Natural := 0;
75-
Spacing : Natural := 0);
76-
-- The same as Info, but does not "close" the last line being printed out,
77-
-- that is, the last line does not contain a (platform-specific) EOL
78-
-- character(s).
60+
procedure Info_In_Tty (Message : String);
61+
-- Same as ``Info`` but send the message only if Stderr is a TTY. Also,
62+
-- ``Message`` is not added to the current ``Log_File``.
7963

8064
Indent_String : constant String := " ";
8165
-- Used as indentation element in various output

lkql_checker/src/gnatcheck-projects.adb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,13 +1212,14 @@ package body Gnatcheck.Projects is
12121212
Individual_Rules_Set := True;
12131213
end case;
12141214
if not Rules_Depreciation_Emitted then
1215-
Error_In_Tty
1215+
Info_In_Tty
12161216
("The '-rules' section is now deprecated. You should only " &
12171217
"use the '--rule' and '--rule-file' command-line options.");
1218-
Error_In_Tty
1218+
Info_In_Tty
12191219
("You can use the '--emit-lkql-rule-file' flag to " &
12201220
"automatically translate your rule configuration to the " &
12211221
"new LKQL format.");
1222+
Rules_Depreciation_Emitted := True;
12221223
end if;
12231224
end loop;
12241225
end Process_Sections;

lkql_checker/src/gnatcheck-rules-rule_table.adb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,9 +1052,9 @@ package body Gnatcheck.Rules.Rule_Table is
10521052
then To_String (Instance.Defined_At)
10531053
else "command line") & Diag_Defined_At);
10541054
if not Instance_Help_Emitted then
1055-
Warning
1055+
Info
10561056
("if you want to pass multiple parameters to a rule you " &
1057-
"should use the comma separated notation: e.g. " &
1057+
"should use the comma separated notation: e.g. " &
10581058
"+RMy_Rule:Param1,Param2");
10591059
Instance_Help_Emitted := True;
10601060
end if;

lkql_checker/src/gnatcheck-rules.adb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2804,11 +2804,9 @@ package body Gnatcheck.Rules is
28042804
procedure Print_Rule_Help (Rule : Rule_Info) is
28052805
begin
28062806
Info
2807-
(Message =>
2808-
" " & Rule_Name (Rule) & " - " &
2809-
To_String (Rule.Help_Info) & " - " &
2810-
Rule.Remediation_Level'Img,
2811-
Line_Len => 0, Spacing => 0);
2807+
(" " & Rule_Name (Rule) & " - " &
2808+
To_String (Rule.Help_Info) & " - " &
2809+
Rule.Remediation_Level'Img);
28122810
end Print_Rule_Help;
28132811

28142812
---------------------------------------

lkql_checker/src/gnatcheck_main.adb

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -604,22 +604,25 @@ begin
604604
Gnatcheck.Rules.Rule_Table.Clean_Up;
605605
Close_Log_File;
606606

607-
OS_Exit (if Tool_Failures /= 0 or else Detected_Internal_Error /= 0
608-
then E_Error
609-
elsif Missing_Rule_File_Detected then E_Missing_Rule_File
610-
elsif Bad_Rule_Detected then E_Missing_Rule
611-
elsif Rule_Option_Problem_Detected then E_Bad_Rules
612-
elsif Missing_File_Detected then E_Missing_Source
613-
614-
-- If we are here, no problem with gnatcheck execution or rule
615-
-- option or missing file definition is detected, so we can trust
616-
-- gnatcheck results.
617-
618-
elsif (Detected_Non_Exempted_Violations > 0
619-
or else Detected_Compiler_Error > 0)
620-
and then not Arg.Brief_Mode
621-
then E_Violation
622-
else E_Success);
607+
OS_Exit
608+
(if Tool_Failures /= 0
609+
or else Detected_Internal_Error /= 0
610+
or else Error_From_Warning
611+
then E_Error
612+
elsif Missing_Rule_File_Detected then E_Missing_Rule_File
613+
elsif Bad_Rule_Detected then E_Missing_Rule
614+
elsif Rule_Option_Problem_Detected then E_Bad_Rules
615+
elsif Missing_File_Detected then E_Missing_Source
616+
617+
-- If we are here, no problem with gnatcheck execution or rule
618+
-- option or missing file definition is detected, so we can trust
619+
-- gnatcheck results.
620+
621+
elsif (Detected_Non_Exempted_Violations > 0
622+
or else Detected_Compiler_Error > 0)
623+
and then not Arg.Brief_Mode
624+
then E_Violation
625+
else E_Success);
623626

624627
exception
625628
when Parameter_Error =>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
gnatcheck: The '-rules' section is now deprecated. You should only use the '--rule' and '--rule-file' command-line options.
2-
gnatcheck: You can use the '--emit-lkql-rule-file' flag to automatically translate your rule configuration to the new LKQL format.
1+
The '-rules' section is now deprecated. You should only use the '--rule' and '--rule-file' command-line options.
2+
You can use the '--emit-lkql-rule-file' flag to automatically translate your rule configuration to the new LKQL format.
33
main.adb:3:04: goto statement
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
procedure Main is
2+
begin
3+
goto lbl; -- FLAG (2)
4+
<<lbl>>
5+
end Main;

0 commit comments

Comments
 (0)