diff mbox

[Ada] File not found for unit in multi-unit source

Message ID 20100622064744.GA18419@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet June 22, 2010, 6:47 a.m. UTC
When several units are specified in a multi-unit source, the Project
Manager may fail to recognize the source file for some of the units.
This patch ensures that if a multi-unit source is found, it will be used
for all units sharing this source.

The following project file should be built successfully if all sources
(main.adb, pkg.ads, pkg.adb and pkg_separates.adb) are found:

project Test_Ada is
   for Main use ("main.adb");

   package Naming is
      for Body ("PKG.SEP_1") use "pkg_separates.adb" at 1;
      for Body ("PKG.SEP_2") use "pkg_separates.adb" at 2;
   end Naming;
end Test_Ada;

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

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

	* prj-nmsc.adb (Find_Sources): When a source from a multi-unit file is
	found, check if it's path has aready been found, whatever its index.
diff mbox

Patch

Index: prj-nmsc.adb
===================================================================
--- prj-nmsc.adb	(revision 161088)
+++ prj-nmsc.adb	(working copy)
@@ -57,8 +57,14 @@  package body Prj.Nmsc is
       Listed   : Boolean := False;
       Found    : Boolean := False;
    end record;
+
    No_Name_Location : constant Name_Location :=
-     (No_File, No_Location, No_Source, False, False);
+                        (Name     => No_File,
+                         Location => No_Location,
+                         Source   => No_Source,
+                         Listed   => False,
+                         Found    => False);
+
    package Source_Names_Htable is new GNAT.Dynamic_HTables.Simple_HTable
      (Header_Num => Header_Num,
       Element    => Name_Location,
@@ -66,11 +72,10 @@  package body Prj.Nmsc is
       Key        => File_Name_Type,
       Hash       => Hash,
       Equal      => "=");
-   --  Information about file names found in string list attribute
-   --  (Source_Files or Source_List_File).
-   --  Except is set to True if source is a naming exception in the project.
-   --  This is used to check that all referenced files were indeed found on the
-   --  disk.
+   --  File name information found in string list attribute (Source_Files or
+   --  Source_List_File). Except is set to True if source is a naming exception
+   --  in the project. Used to check that all referenced files were indeed
+   --  found on the disk.
 
    type Unit_Exception is record
       Name : Name_Id;  --  ??? duplicates the key
@@ -6405,6 +6410,8 @@  package body Prj.Nmsc is
       declare
          Source : Source_Id;
          Iter   : Source_Iterator;
+         Found  : Boolean := False;
+         Path   : Path_Information;
 
       begin
          Iter := For_Each_Source (Data.Tree, Project.Project);
@@ -6416,16 +6423,22 @@  package body Prj.Nmsc is
               and then Source.Path = No_Path_Information
             then
                if Source.Unit /= No_Unit_Index then
+                  Found := False;
 
                   --  For multi-unit source files, source_id gets duplicated
                   --  once for every unit. Only the first source_id got its
-                  --  full path set. So if it isn't set for that first one,
-                  --  the file wasn't found. Otherwise we need to update for
-                  --  units after the first one.
+                  --  full path set.
 
-                  if Source.Index = 0
-                    or else Source.Index = 1
-                  then
+                  if Source.Index /= 0 then
+                     Path := Files_Htable.Get
+                       (Data.File_To_Source, Source.File).Path;
+
+                     if Path /= No_Path_Information then
+                        Found := True;
+                     end if;
+                  end if;
+
+                  if not Found then
                      Error_Msg_Name_1 := Name_Id (Source.Display_File);
                      Error_Msg_Name_2 := Name_Id (Source.Unit.Name);
                      Error_Msg
@@ -6434,8 +6447,7 @@  package body Prj.Nmsc is
                         No_Location, Project.Project);
 
                   else
-                     Source.Path := Files_Htable.Get
-                       (Data.File_To_Source, Source.File).Path;
+                     Source.Path := Path;
 
                      if Current_Verbosity = High then
                         if Source.Path /= No_Path_Information then
@@ -6443,7 +6455,7 @@  package body Prj.Nmsc is
                                        & Get_Name_String (Source.File)
                                        & " at" & Source.Index'Img
                                        & " to "
-                                       & Get_Name_String (Source.Path.Name));
+                                       & Get_Name_String (Path.Name));
                         end if;
                      end if;
                   end if;