Commit cd8bfe35 by Emmanuel Briot Committed by Arnaud Charlet

makeutl.adb (Complete_Mains): add support for specs with no suffix on the command line.

2011-08-04  Emmanuel Briot  <briot@adacore.com>

	* makeutl.adb (Complete_Mains): add support for specs with no suffix on
	the command line.

From-SVN: r177363
parent 7db29ea7
2011-08-04 Emmanuel Briot <briot@adacore.com> 2011-08-04 Emmanuel Briot <briot@adacore.com>
* makeutl.adb (Complete_Mains): add support for specs with no suffix on
the command line.
2011-08-04 Emmanuel Briot <briot@adacore.com>
* make.adb, makeutl.adb (Complete_Mains): if a main specified on the * make.adb, makeutl.adb (Complete_Mains): if a main specified on the
command line is not a file name, also check whether it could be a unit command line is not a file name, also check whether it could be a unit
name. name.
......
...@@ -1288,6 +1288,12 @@ package body Makeutl is ...@@ -1288,6 +1288,12 @@ package body Makeutl is
Source : Prj.Source_Id); Source : Prj.Source_Id);
-- Add all units from the same file as the multi-unit Source. -- Add all units from the same file as the multi-unit Source.
function Find_File_Add_Extension
(Tree : Project_Tree_Ref;
Root_Project : Project_Id;
Base_Main : String) return Prj.Source_Id;
-- Search for Main in the project, adding body or spec extensions.
---------------------------- ----------------------------
-- Add_Multi_Unit_Sources -- -- Add_Multi_Unit_Sources --
---------------------------- ----------------------------
...@@ -1334,6 +1340,78 @@ package body Makeutl is ...@@ -1334,6 +1340,78 @@ package body Makeutl is
end loop; end loop;
end Add_Multi_Unit_Sources; end Add_Multi_Unit_Sources;
-----------------------------
-- Find_File_Add_Extension --
-----------------------------
function Find_File_Add_Extension
(Tree : Project_Tree_Ref;
Root_Project : Project_Id;
Base_Main : String) return Prj.Source_Id
is
Spec_Source : Prj.Source_Id := No_Source;
Source : Prj.Source_Id := No_Source;
Project : Project_Id := Root_Project;
Iter : Source_Iterator;
Suffix : File_Name_Type;
begin
while Source = No_Source
and then Project /= No_Project
loop
Iter := For_Each_Source (Tree, Project);
loop
Source := Prj.Element (Iter);
exit when Source = No_Source;
if Source.Kind = Impl then
Get_Name_String (Source.File);
if Name_Len > Base_Main'Length
and then Name_Buffer (1 .. Base_Main'Length) = Base_Main
then
Suffix :=
Source.Language.Config.Naming_Data.Body_Suffix;
exit when Suffix /= No_File and then
Name_Buffer (Base_Main'Length + 1 .. Name_Len) =
Get_Name_String (Suffix);
end if;
elsif Source.Kind = Spec then
-- A spec needs to be taken into account unless there is
-- also a body. So we delay the decision for them.
Get_Name_String (Source.File);
if Name_Len > Base_Main'Length
and then Name_Buffer (1 .. Base_Main'Length) = Base_Main
then
Suffix :=
Source.Language.Config.Naming_Data.Spec_Suffix;
if Suffix /= No_File
and then
Name_Buffer (Base_Main'Length + 1 .. Name_Len) =
Get_Name_String (Suffix)
then
Spec_Source := Source;
end if;
end if;
end if;
Next (Iter);
end loop;
Project := Project.Extends;
end loop;
if Source = No_Source then
Source := Spec_Source;
end if;
return Source;
end Find_File_Add_Extension;
----------------- -----------------
-- Do_Complete -- -- Do_Complete --
----------------- -----------------
...@@ -1354,10 +1432,9 @@ package body Makeutl is ...@@ -1354,10 +1432,9 @@ package body Makeutl is
File : Main_Info := Names.Table (J); File : Main_Info := Names.Table (J);
Main_Id : File_Name_Type := File.File; Main_Id : File_Name_Type := File.File;
Main : constant String := Get_Name_String (Main_Id); Main : constant String := Get_Name_String (Main_Id);
Base : constant String := Base_Name (Main);
Source : Prj.Source_Id := No_Source; Source : Prj.Source_Id := No_Source;
Suffix : File_Name_Type; Is_Absolute : Boolean := False;
Iter : Source_Iterator;
Is_Absolute : Boolean := False;
begin begin
if Base /= Main then if Base /= Main then
...@@ -1379,9 +1456,7 @@ package body Makeutl is ...@@ -1379,9 +1456,7 @@ package body Makeutl is
end if; end if;
-- If no project or tree was specified for the main, it -- If no project or tree was specified for the main, it
-- came from the command line. In this case, it needs to -- came from the command line.
-- belong to the root project.
-- Note that the assignments below will not modify inside -- Note that the assignments below will not modify inside
-- the table itself. -- the table itself.
...@@ -1413,64 +1488,19 @@ package body Makeutl is ...@@ -1413,64 +1488,19 @@ package body Makeutl is
Index => File.Index); Index => File.Index);
if Source = No_Source then if Source = No_Source then
Source := Find_File_Add_Extension
(Tree, File.Project, Get_Name_String (Main_Id));
end if;
-- Now look for the main with a body suffix if Is_Absolute
and then Source /= No_Source
declare and then File_Name_Type (Source.Path.Name) /=
-- Main already has a canonical casing File.File
then
Main : constant String := Debug_Output
Get_Name_String (Main_Id); ("Found a non-matching file",
Project : Project_Id; Name_Id (Source.Path.Display_Name));
Source := No_Source;
begin
Project := File.Project;
while Source = No_Source
and then Project /= No_Project
loop
Iter := For_Each_Source (File.Tree, Project);
loop
Source := Prj.Element (Iter);
exit when Source = No_Source;
-- Only consider bodies
if Source.Kind = Impl then
Get_Name_String (Source.File);
if Name_Len > Main'Length
and then Name_Buffer
(1 .. Main'Length) = Main
then
Suffix :=
Source.Language
.Config.Naming_Data.Body_Suffix;
exit when Suffix /= No_File and then
Name_Buffer
(Main'Length + 1 .. Name_Len) =
Get_Name_String (Suffix);
end if;
end if;
Next (Iter);
end loop;
Project := Project.Extends;
end loop;
end;
else
if Is_Absolute then
if File_Name_Type (Source.Path.Name) /=
File.File
then
Debug_Output
("found a non-matching file",
Name_Id (Source.Path.Display_Name));
Source := No_Source;
end if;
end if;
end if; end if;
if Source = No_Source then if Source = No_Source then
...@@ -1480,6 +1510,7 @@ package body Makeutl is ...@@ -1480,6 +1510,7 @@ package body Makeutl is
Units_Htable.Get Units_Htable.Get
(File.Tree.Units_HT, Name_Id (Main_Id)); (File.Tree.Units_HT, Name_Id (Main_Id));
begin begin
if Unit /= No_Unit_Index then if Unit /= No_Unit_Index then
Source := Unit.File_Names (Impl); Source := Unit.File_Names (Impl);
if Source = No_Source then if Source = No_Source then
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment