Patchwork [Ada] Allow gnatmake switch -j0

login
register
mail settings
Submitter Arnaud Charlet
Date Oct. 12, 2010, 12:23 p.m.
Message ID <20101012122352.GA17345@adacore.com>
Download mbox | patch
Permalink /patch/67548/
State New
Headers show

Comments

Arnaud Charlet - Oct. 12, 2010, 12:23 p.m.
-j0 is now a valid gnatmake switch. It indicates that the maximum number
simultaneous compilation is the number of available processors.
The test is to invoke gnatmake with -j0. Adding the debugging switch -dm
will display the actual maximum of simultaneous compilations.

Tested on x86_64-pc-linux-gnu, committed on trunk

2010-10-12  Vincent Celier  <celier@adacore.com>

	* debug.adb: For gnatmake, document the meaning of -dm
	* make.adb (Gnatmake): If -dm is used, indicate the maximum number of
	simultaneous compilations.
	* switch-m.adb (Scan_Make_Switches): Allow -j0, meaning as many
	simultaneous compilations as the number of processors.

Patch

Index: make.adb
===================================================================
--- make.adb	(revision 165359)
+++ make.adb	(working copy)
@@ -5321,6 +5321,11 @@  package body Make is
          Saved_Maximum_Processes := Maximum_Processes;
       end if;
 
+      if Debug.Debug_Flag_M then
+         Write_Line ("Maximum number of simultaneous compilations =" &
+                     Saved_Maximum_Processes'Img);
+      end if;
+
       --  Allocate as many temporary mapping file names as the maximum number
       --  of compilations processed, for each possible project.
 
Index: debug.adb
===================================================================
--- debug.adb	(revision 165316)
+++ debug.adb	(working copy)
@@ -198,7 +198,7 @@  package body Debug is
    --  dj
    --  dk
    --  dl
-   --  dm
+   --  dm  Display the number of maximum simultaneous compilations
    --  dn  Do not delete temp files created by gnatmake
    --  do
    --  dp  Prints the contents of the Q used by Make.Compile_Sources
Index: switch-m.adb
===================================================================
--- switch-m.adb	(revision 165316)
+++ switch-m.adb	(working copy)
@@ -31,6 +31,8 @@  with Prj;      use Prj;
 with Prj.Env;  use Prj.Env;
 with Table;
 
+with System.Multiprocessors; use System.Multiprocessors;
+
 package body Switch.M is
 
    package Normalized_Switches is new Table.Table
@@ -751,14 +753,22 @@  package body Switch.M is
             Ptr := Ptr + 1;
 
             declare
-               Max_Proc : Pos;
+               Max_Proc : Nat;
             begin
-               Scan_Pos (Switch_Chars, Max, Ptr, Max_Proc, C);
+               Scan_Nat (Switch_Chars, Max, Ptr, Max_Proc, C);
 
                if Ptr <= Max then
                   Bad_Switch (Switch_Chars);
 
                else
+                  if Max_Proc = 0 then
+                     Max_Proc := Nat (Number_Of_CPUs);
+
+                     if Max_Proc = 0 then
+                        Max_Proc := 1;
+                     end if;
+                  end if;
+
                   Maximum_Processes := Positive (Max_Proc);
                end if;
             end;