Skip to content

Commit

Permalink
Opt_Parse: Transition -j
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoGGuerrier committed Jul 29, 2024
1 parent 6d11f59 commit 2fa744d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 34 deletions.
4 changes: 2 additions & 2 deletions lkql_checker/src/gnatcheck-compiler.adb
Original file line number Diff line number Diff line change
Expand Up @@ -1781,9 +1781,9 @@ package body Gnatcheck.Compiler is
Args (Num_Args) := new String'("--target=codepeer");
end if;

if Process_Num > 1 then
if Arg.Jobs.Get > 1 then
Num_Args := @ + 1;
Args (Num_Args) := new String'("-j" & Image (Process_Num));
Args (Num_Args) := new String'("-j" & Image (Arg.Jobs.Get));
end if;

if Prj /= "" then
Expand Down
16 changes: 16 additions & 0 deletions lkql_checker/src/gnatcheck-options.adb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
with Gnatcheck.Output; use Gnatcheck.Output;

with System.Multiprocessors;

package body Gnatcheck.Options is
procedure Warning (Self : in out Gnatcheck_Error_Handler; Msg : String) is
begin
Expand All @@ -11,4 +13,18 @@ package body Gnatcheck.Options is
Error (Msg);
end Error;

------------------
-- Jobs_Convert --
------------------

function Jobs_Convert (Arg : String) return Natural is
Value : constant Natural := Natural'Value (Arg);
begin
if Value = 0 then
return Natural (System.Multiprocessors.Number_Of_CPUs);
else
return Value;
end if;
end Jobs_Convert;

end Gnatcheck.Options;
19 changes: 11 additions & 8 deletions lkql_checker/src/gnatcheck-options.ads
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,6 @@ package Gnatcheck.Options is
Files_Switch_Used : Boolean := False;
-- True if the files= switch was used

Process_Num : Natural := 1;
-- The maximal number of cores used
-- -jN

J_Specified : Boolean := False;
-- True if the -jN option was given. This is used to distinguish -j0 on a
-- uniprocessor from no -j switch.

----------------------------------------
-- Flags computed from other settings --
----------------------------------------
Expand Down Expand Up @@ -248,6 +240,8 @@ package Gnatcheck.Options is
procedure Warning (Self : in out Gnatcheck_Error_Handler; Msg : String);
procedure Error (Self : in out Gnatcheck_Error_Handler; Msg : String);

function Jobs_Convert (Arg : String) return Natural;

package Arg is
Parser : Argument_Parser := Create_Argument_Parser
(Help => "GNATcheck help",
Expand Down Expand Up @@ -432,6 +426,15 @@ package Gnatcheck.Options is
Default_Val => Null_Unbounded_String,
Help => "do not process sources listed in filename");

package Jobs is new Parse_Option
(Parser => Parser,
Short => "-j",
Name => "Jobs",
Arg_Type => Natural,
Default_Val => 1,
Convert => Jobs_Convert,
Help => "the maximal number of processes");

function Quiet_Mode return Boolean is (Quiet.Get or else Brief.Get);

function Short_Report return Boolean is (Brief.Get or else Short.Get);
Expand Down
24 changes: 0 additions & 24 deletions lkql_checker/src/gnatcheck-projects.adb
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ with GNATCOLL.Traces;

with Rule_Commands; use Rule_Commands;

with System.Multiprocessors;

package body Gnatcheck.Projects is

subtype Unbounded_String is Ada.Strings.Unbounded.Unbounded_String;
Expand Down Expand Up @@ -1118,7 +1116,6 @@ package body Gnatcheck.Projects is
"m? files= a " &
"vP! " & -- project-specific options
"-kp-version= " &
"j! " &
"o= " &
"ox= " &
"l log " &
Expand Down Expand Up @@ -1184,27 +1181,6 @@ package body Gnatcheck.Projects is
end if;
end if;

when 'j' =>
if Full_Switch (Parser => Parser) = "j"
and then not First_Pass
then
begin
J_Specified := True;
Process_Num :=
Natural'Value (Parameter (Parser => Parser));

if Process_Num = 0 then
Process_Num :=
Positive (System.Multiprocessors.Number_Of_CPUs);
end if;
exception
when Constraint_Error =>
Error ("Wrong Parameter of '-j' option: " &
Parameter (Parser => Parser));
raise Parameter_Error;
end;
end if;

when 'l' =>
if not First_Pass then
if Full_Switch (Parser => Parser) = "l" then
Expand Down
1 change: 1 addition & 0 deletions lkql_checker/src/gnatcheck_main.adb
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ procedure Gnatcheck_Main is
File : Ada.Text_IO.File_Type;
Status : Boolean;
Total_Jobs : Natural;
Process_Num : Natural := Arg.Jobs.Get;
begin
-- Compute number of files

Expand Down

0 comments on commit 2fa744d

Please sign in to comment.