diff mbox

[Ada] Duplicate projects not detected

Message ID 20140124140531.GA12534@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Jan. 24, 2014, 2:05 p.m. UTC
When the project path specified with environment variables ADA_PROJECT_PATH
or GPR_PROJECT_PATH, or with switch -aP includes a directory where one project
is found, this project may be used incorrectly when imported instead of the
project with a similar name in the directory of the importing project, while
a duplicated project name should have been detected.

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

2014-01-24  Vincent Celier  <celier@adacore.com>

	* prj-env.adb (Find_Project): If cached project path is not in
	project directory, look in current directory first and use cached
	project path only if project is not found in project directory.
diff mbox

Patch

Index: prj-env.adb
===================================================================
--- prj-env.adb	(revision 207026)
+++ prj-env.adb	(working copy)
@@ -2229,20 +2229,21 @@ 
       Directory          : String;
       Path               : out Namet.Path_Name_Type)
    is
+      Result  : String_Access;
+      Has_Dot : Boolean := False;
+      Key     : Name_Id;
+
       File : constant String := Project_File_Name;
       --  Have to do a copy, in case the parameter is Name_Buffer, which we
-      --  modify below
+      --  modify below.
 
-      function Try_Path_Name is new Find_Name_In_Path
-        (Check_Filename => Is_Regular_File);
+      Cached_Path : Namet.Path_Name_Type;
+      --  This should be commented rather than making us guess from the name???
+
+      function Try_Path_Name is new
+        Find_Name_In_Path (Check_Filename => Is_Regular_File);
       --  Find a file in the project search path
 
-      --  Local Declarations
-
-      Result  : String_Access;
-      Has_Dot : Boolean := False;
-      Key     : Name_Id;
-
    --  Start of processing for Find_Project
 
    begin
@@ -2259,13 +2260,8 @@ 
       Name_Len := File'Length;
       Name_Buffer (1 .. Name_Len) := File;
       Key := Name_Find;
-      Path := Projects_Paths.Get (Self.Cache, Key);
+      Cached_Path := Projects_Paths.Get (Self.Cache, Key);
 
-      if Path /= No_Path then
-         Debug_Decrease_Indent;
-         return;
-      end if;
-
       --  Check if File contains an extension (a dot before a
       --  directory separator). If it is the case we do not try project file
       --  with an added extension as it is not possible to have multiple dots
@@ -2283,13 +2279,42 @@ 
 
       if not Is_Absolute_Path (File) then
 
+         --  If we have found project in the cache, check if in the directory
+
+         if Cached_Path /= No_Path then
+            declare
+               Cached : constant String := Get_Name_String (Cached_Path);
+            begin
+               if (not Has_Dot
+                    and then Cached =
+                      GNAT.OS_Lib.Normalize_Pathname
+                        (File & Project_File_Extension,
+                         Directory      => Directory,
+                         Resolve_Links  => Opt.Follow_Links_For_Files,
+                         Case_Sensitive => True))
+                 or else
+                   Cached =
+                     GNAT.OS_Lib.Normalize_Pathname
+                       (File,
+                        Directory      => Directory,
+                        Resolve_Links  => Opt.Follow_Links_For_Files,
+                        Case_Sensitive => True)
+               then
+                  Path := Cached_Path;
+                  Debug_Decrease_Indent;
+                  return;
+               end if;
+            end;
+         end if;
+
          --  First we try <directory>/<file_name>.<extension>
 
          if not Has_Dot then
-            Result := Try_Path_Name
-              (Self,
-               Directory & Directory_Separator &
-               File & Project_File_Extension);
+            Result :=
+              Try_Path_Name
+                (Self,
+                 Directory & Directory_Separator &
+                   File & Project_File_Extension);
          end if;
 
          --  Then we try <directory>/<file_name>
@@ -2300,6 +2325,14 @@ 
          end if;
       end if;
 
+      --  If we found the path in the cache, this is the one
+
+      if Result = null and then Cached_Path /= No_Path then
+         Path := Cached_Path;
+         Debug_Decrease_Indent;
+         return;
+      end if;
+
       --  Then we try <file_name>.<extension>
 
       if Result = null and then not Has_Dot then