Patchwork [Ada] gnatmake -f -u <main> always invokes the compiler

login
register
mail settings
Submitter Arnaud Charlet
Date June 18, 2010, 8:29 a.m.
Message ID <20100618082924.GA29604@adacore.com>
Download mbox | patch
Permalink /patch/56150/
State New
Headers show

Comments

Arnaud Charlet - June 18, 2010, 8:29 a.m.
As documented, gnatmake -f -u <main> should always invoke the compiler.
This patch ensures that it is aways true, even when the ALI file is
read-only, when the source is in a directory specified with -aL or is
a direct source of an externally built project.

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

2010-06-18  Vincent Celier  <celier@adacore.com>

	* make.adb (Must_Compile): New Boolean global variable
	(Main_On_Command_Line): New Boolean global variable
	(Collect_Arguments_And_Compile): Do compile if Must_Compile is True,
	even when the project is externally built.
	(Start_Compile_If_Possible): Compile in -aL directories if
	Check_Readonly_Files is True. Do compile if Must_Compile is True, even
	when the project is externally built.
	(Gnatmake): Set Must_Compile and Check_Readonly_Files to True when
	invoked with -f -u and one or several mains on the command line.
	(Scan_Make_Arg): Set Main_On_Command_Line to True when at least one main
	is specified on the command line.

Patch

Index: make.adb
===================================================================
--- make.adb	(revision 160959)
+++ make.adb	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1992-2009, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2010, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -202,6 +202,14 @@  package body Make is
    Unique_Compile_All_Projects : Boolean := False;
    --  Set to True if -U is used
 
+   Must_Compile : Boolean := False;
+   --  True if gnatmake is invoked with -f -u and one or several mains on the
+   --  command line.
+
+   Main_On_Command_Line : Boolean := False;
+   --  True if gnatmake is invoked with one or several mains on the command
+   --  line.
+
    RTS_Specified : String_Access := null;
    --  Used to detect multiple --RTS= switches
 
@@ -2243,12 +2251,14 @@  package body Make is
             if Arguments_Project = No_Project then
                Add_Arguments (The_Saved_Gcc_Switches.all);
 
-            elsif not Arguments_Project.Externally_Built then
+            elsif not Arguments_Project.Externally_Built
+              or else Must_Compile
+            then
                --  We get the project directory for the relative path
                --  switches and arguments.
 
-               Arguments_Project := Ultimate_Extending_Project_Of
-                 (Arguments_Project);
+               Arguments_Project :=
+                 Ultimate_Extending_Project_Of (Arguments_Project);
 
                --  If building a dynamic or relocatable library, compile with
                --  PIC option, if it exists.
@@ -2258,7 +2268,6 @@  package body Make is
                then
                   declare
                      PIC : constant String := MLib.Tgt.PIC_Option;
-
                   begin
                      if PIC /= "" then
                         Add_Arguments ((1 => new String'(PIC)));
@@ -2726,7 +2735,9 @@  package body Make is
          --  check for an eventual library project, and use the full path.
 
          if Arguments_Project /= No_Project then
-            if not Arguments_Project.Externally_Built then
+            if not Arguments_Project.Externally_Built
+              or else Must_Compile
+            then
                Prj.Env.Set_Ada_Paths
                  (Arguments_Project,
                   Project_Tree,
@@ -2742,7 +2753,7 @@  package body Make is
 
                   begin
                      if Prj.Library
-                       and then not Prj.Externally_Built
+                       and then (not Prj.Externally_Built or else Must_Compile)
                        and then not Prj.Need_To_Build_Lib
                      then
                         --  Add to the Q all sources of the project that have
@@ -3272,8 +3283,9 @@  package body Make is
                Executable_Obsolete := True;
             end if;
 
-            In_Lib_Dir := Full_Lib_File /= No_File
-              and then In_Ada_Lib_Dir (Full_Lib_File);
+            In_Lib_Dir := not Check_Readonly_Files
+                            and then Full_Lib_File /= No_File
+                            and then In_Ada_Lib_Dir (Full_Lib_File);
 
             --  Since the following requires a system call, we precompute it
             --  when needed.
@@ -3350,6 +3362,7 @@  package body Make is
 
                if Arguments_Project = No_Project
                  or else not Arguments_Project.Externally_Built
+                 or else Must_Compile
                then
                   --  Don't waste any time if we have to recompile anyway
 
@@ -4739,13 +4752,6 @@  package body Make is
          Display_Version ("GNATMAKE", "1995");
       end if;
 
-      if Main_Project /= No_Project
-        and then Main_Project.Externally_Built
-      then
-         Make_Failed
-           ("nothing to do for a main project that is externally built");
-      end if;
-
       if Osint.Number_Of_Files = 0 then
          if Main_Project /= No_Project
            and then Main_Project.Library
@@ -5182,6 +5188,26 @@  package body Make is
          end;
       end if;
 
+      --  The combination of -f -u and one or several mains on the command line
+      --  implies -a.
+
+      if Force_Compilations
+        and then Unique_Compile
+        and then not Unique_Compile_All_Projects
+        and then Main_On_Command_Line
+      then
+         Check_Readonly_Files := True;
+         Must_Compile := True;
+      end if;
+
+      if Main_Project /= No_Project
+        and then not Must_Compile
+        and then Main_Project.Externally_Built
+      then
+         Make_Failed
+           ("nothing to do for a main project that is externally built");
+      end if;
+
       --  Get the target parameters, which are only needed for a couple of
       --  cases in gnatmake. Protect against an exception, such as the case of
       --  system.ads missing from the library, and fail gracefully.
@@ -8219,6 +8245,10 @@  package body Make is
       --  If not a switch it must be a file name
 
       else
+         if And_Save then
+            Main_On_Command_Line := True;
+         end if;
+
          Add_File (Argv);
          Mains.Add_Main (Argv);
       end if;