Skip to content

Commit 5cf8490

Browse files
committed
Migrate the '-cargs' section to Opt_Parse
Also refactor the way arguments are collected when spawning a new GPRbuild process.
1 parent b3e1867 commit 5cf8490

File tree

5 files changed

+69
-80
lines changed

5 files changed

+69
-80
lines changed

lkql_checker/src/gnatcheck-compiler.adb

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,13 +1924,23 @@ package body Gnatcheck.Compiler is
19241924
--------------------
19251925

19261926
function Spawn_GPRbuild (Output_File : String) return Process_Id is
1927+
19271928
Pid : Process_Id;
19281929
GPRbuild : String_Access := Locate_Exec_On_Path (GPRbuild_Exec);
19291930
Prj : constant String := Gnatcheck_Prj.Source_Prj;
19301931
Last_Source : constant SF_Id := Last_Argument_Source;
19311932
Args : Argument_List (1 .. 128 + Integer (Last_Source));
19321933
Num_Args : Integer := 0;
19331934

1935+
procedure Add_Arg (Arg : String);
1936+
-- Add an argument to the local argument list ``Args``.
1937+
1938+
procedure Add_Arg (Arg : String) is
1939+
begin
1940+
Num_Args := @ + 1;
1941+
Args (Num_Args) := new String'(Arg);
1942+
end Add_Arg;
1943+
19341944
use Ada.Strings.Unbounded;
19351945
begin
19361946
if GPRbuild = null then
@@ -1950,51 +1960,67 @@ package body Gnatcheck.Compiler is
19501960
Num_Args := 8;
19511961

19521962
if Target /= Null_Unbounded_String then
1953-
Num_Args := @ + 1;
1954-
Args (Num_Args) := new String'("--target=" & To_String (Target));
1963+
Add_Arg ("--target=" & To_String (Target));
19551964
end if;
19561965

19571966
if Arg.Jobs.Get > 1 then
1958-
Num_Args := @ + 1;
1959-
Args (Num_Args) := new String'("-j" & Image (Arg.Jobs.Get));
1967+
Add_Arg ("-j" & Image (Arg.Jobs.Get));
19601968
end if;
19611969

19621970
if Prj /= "" then
1963-
Num_Args := @ + 1;
1964-
Args (Num_Args) := new String'("-P" & Prj);
1971+
Add_Arg ("-P" & Prj);
19651972
end if;
19661973

19671974
if Arg.Follow_Symbolic_Links.Get then
1968-
Num_Args := @ + 1;
1969-
Args (Num_Args) := new String'("-eL");
1975+
Add_Arg ("-eL");
19701976
end if;
19711977

19721978
-- If files are specified explicitly, only compile these files
19731979

19741980
if (Argument_File_Specified and then not Arg.Transitive_Closure.Get)
19751981
or else Arg.Source_Files_Specified
19761982
then
1977-
Num_Args := @ + 1;
1978-
Args (Num_Args) := new String'("-u");
1983+
Add_Arg ("-u");
19791984

19801985
for SF in First_SF_Id .. Last_Source loop
1981-
Num_Args := @ + 1;
1982-
Args (Num_Args) := new String'(Short_Source_Name (SF));
1986+
Add_Arg (Short_Source_Name (SF));
19831987
end loop;
19841988
else
19851989
if Arg.Transitive_Closure.Get then
1986-
Num_Args := @ + 1;
1987-
Args (Num_Args) := new String'("-U");
1990+
Add_Arg ("-U");
19881991
end if;
19891992

19901993
if not Main_Unit.Is_Empty then
19911994
for MU of Main_Unit loop
1992-
Num_Args := @ + 1;
1993-
Args (Num_Args) := new String'(String (MU));
1995+
Add_Arg (String (MU));
19941996
end loop;
19951997
end if;
19961998
end if;
19971999

2000+
-- Append options specified through the "-cargs" section
2001+
for Option of Arg.Cargs_Section.Get loop
2002+
Add_Arg (To_String (Option));
2003+
end loop;
2004+
2005+
if Analyze_Compiler_Output then
2006+
Add_Arg ("-gnatec=" & Gnatcheck_Config_File.all);
2007+
Add_Arg ("-gnatcU");
2008+
Add_Arg ("-gnatwnA.d");
2009+
2010+
if Use_gnatw_Option then
2011+
Add_Arg (Get_Warning_Option);
2012+
end if;
2013+
2014+
Add_Arg ("-gnatyN");
2015+
2016+
if Use_gnaty_Option then
2017+
for S of Split (Get_Style_Option, ' ') loop
2018+
Add_Arg (S);
2019+
end loop;
2020+
end if;
2021+
end if;
2022+
2023+
-- Add scenario variables to the compiler command
19982024
Append_Variables (Args, Num_Args);
19992025

20002026
if Arg.Debug_Mode.Get then
@@ -2004,17 +2030,13 @@ package body Gnatcheck.Compiler is
20042030
Put (" " & Args (J).all);
20052031
end loop;
20062032

2007-
for S of Compiler_Arg_List.all loop
2008-
Put (" " & S.all);
2009-
end loop;
2010-
20112033
New_Line;
20122034
end if;
20132035

20142036
Pid :=
20152037
Non_Blocking_Spawn
20162038
(GPRbuild.all,
2017-
Args (1 .. Num_Args) & Compiler_Arg_List.all,
2039+
Args (1 .. Num_Args),
20182040
Output_File & ".out",
20192041
Output_File);
20202042
Free (GPRbuild);

lkql_checker/src/gnatcheck-options.adb

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ with Gnatcheck.Output; use Gnatcheck.Output;
44
with Gnatcheck.Projects; use Gnatcheck.Projects;
55
with Gnatcheck.Source_Table; use Gnatcheck.Source_Table;
66

7-
with GNATCOLL.Strings; use GNATCOLL.Strings;
8-
97
with System.Multiprocessors;
108

119
package body Gnatcheck.Options is
@@ -86,6 +84,15 @@ package body Gnatcheck.Options is
8684
end;
8785
end Max_Diagnoses_Convert;
8886

87+
--------------------
88+
-- Is_New_Section --
89+
--------------------
90+
91+
function Is_New_Section (Arg : XString) return Boolean is
92+
begin
93+
return Arg = "-rules" or else Arg = "-cargs";
94+
end Is_New_Section;
95+
8996
--------------------
9097
-- Scan_Arguments --
9198
--------------------
@@ -128,14 +135,6 @@ package body Gnatcheck.Options is
128135

129136
procedure Process_Sections is
130137
begin
131-
-- Processing the 'cargs' section
132-
133-
Goto_Section ("cargs", Parser => Parser);
134-
135-
while Getopt ("*", Parser => Parser) /= ASCII.NUL loop
136-
Store_Compiler_Option (Full_Switch (Parser => Parser));
137-
end loop;
138-
139138
-- Processing the 'rules' section
140139
Goto_Section ("rules", Parser => Parser);
141140

lkql_checker/src/gnatcheck-options.ads

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ with Gnatcheck.Projects;
1717
with Gnatcheck.String_Utilities; use Gnatcheck.String_Utilities;
1818

1919
with GNATCOLL.Opt_Parse; use GNATCOLL.Opt_Parse;
20+
with GNATCOLL.Strings; use GNATCOLL.Strings;
2021

2122
with GPR2.Options;
2223

@@ -203,6 +204,8 @@ package Gnatcheck.Options is
203204
function Project_Verbosity_Convert (Arg : String) return Natural;
204205
function Max_Diagnoses_Convert (Arg : String) return Max_Diagnoses_Count;
205206

207+
function Is_New_Section (Arg : XString) return Boolean;
208+
206209
package Arg is
207210
Parser : Argument_Parser :=
208211
Create_Argument_Parser
@@ -625,6 +628,19 @@ package Gnatcheck.Options is
625628
Short => "-W",
626629
Help => "Treat warning messages as errors");
627630

631+
package Cargs_Section is new
632+
Parse_Option_List
633+
(Parser => Parser,
634+
Long => "-cargs",
635+
Name => "Compiler options",
636+
Accumulate => True,
637+
Arg_Number => Multiple_Args,
638+
Allow_Empty => True,
639+
Arg_Type => Unbounded_String,
640+
List_Stop_Predicate => Is_New_Section,
641+
Help => "options forwarded to the compiler",
642+
Legacy_Long_Form => True);
643+
628644
----------------------
629645
-- Option shortcuts --
630646
----------------------

lkql_checker/src/gnatcheck-projects.adb

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ with Ada.Strings; use Ada.Strings;
1111
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
1212

1313
with GNAT.Directory_Operations;
14-
with GNAT.Regexp; use GNAT.Regexp;
15-
with GNAT.String_Split; use GNAT.String_Split;
16-
with GNAT.Table;
14+
with GNAT.Regexp; use GNAT.Regexp;
1715

1816
with Gnatcheck.Compiler; use Gnatcheck.Compiler;
1917
with Gnatcheck.Diagnoses;
@@ -1108,24 +1106,6 @@ package body Gnatcheck.Projects is
11081106
and then LKQL_Rule_File_Name = Null_Unbounded_String;
11091107
end Is_Rule_Options_Empty;
11101108

1111-
---------------------------
1112-
-- Store_Compiler_Option --
1113-
---------------------------
1114-
1115-
package Compiler_Switches is new
1116-
GNAT.Table
1117-
(Table_Component_Type => String_Access,
1118-
Table_Index_Type => Natural,
1119-
Table_Low_Bound => 1,
1120-
Table_Initial => 20,
1121-
Table_Increment => 100,
1122-
Table_Name => "Compiler options");
1123-
1124-
procedure Store_Compiler_Option (Switch : String) is
1125-
begin
1126-
Compiler_Switches.Append (new String'(Switch));
1127-
end Store_Compiler_Option;
1128-
11291109
----------------------
11301110
-- Check_Parameters --
11311111
----------------------
@@ -1185,24 +1165,6 @@ package body Gnatcheck.Projects is
11851165
or Check_Restrictions
11861166
or Arg.Check_Semantic.Get;
11871167

1188-
if Analyze_Compiler_Output then
1189-
Store_Compiler_Option ("-gnatec=" & Gnatcheck_Config_File.all);
1190-
Store_Compiler_Option ("-gnatcU");
1191-
Store_Compiler_Option ("-gnatwnA.d");
1192-
1193-
if Use_gnatw_Option then
1194-
Store_Compiler_Option (Get_Warning_Option);
1195-
end if;
1196-
1197-
Store_Compiler_Option ("-gnatyN");
1198-
1199-
if Use_gnaty_Option then
1200-
for S of Create (Get_Style_Option, " ") loop
1201-
Store_Compiler_Option (S);
1202-
end loop;
1203-
end if;
1204-
end if;
1205-
12061168
-- If GNATcheck is in KP mode and there is a command line specified KP
12071169
-- version, we have to iterate over all implemented rules to enable
12081170
-- those which match the version.
@@ -1273,13 +1235,6 @@ package body Gnatcheck.Projects is
12731235

12741236
Sources_Left := Total_Sources;
12751237

1276-
-- Save compiler switches computed in Compiler_Arg_List
1277-
1278-
Compiler_Arg_List :=
1279-
new Argument_List'
1280-
(String_List
1281-
(Compiler_Switches.Table (1 .. Compiler_Switches.Last)));
1282-
12831238
<<Processing_Aggregate_Project>>
12841239

12851240
Ada.Directories.Create_Path (Global_Report_Dir.all);

lkql_checker/src/gnatcheck-projects.ads

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,6 @@ package Gnatcheck.Projects is
201201
-- Raises Gnatcheck.Common.Parameter_Error if any of these check fails,
202202
-- stores the name of the configuration project file otherwise.
203203

204-
procedure Store_Compiler_Option (Switch : String);
205-
-- Stores a compiler option as is.
206-
207204
function Is_Specified (My_Project : Arg_Project_Type) return Boolean;
208205
-- Checks if the argument represents a project that corresponds to some
209206
-- project file specified as a tool parameter.

0 commit comments

Comments
 (0)