Patchwork [Ada] gnatmake and invalid mains in attribute Main

login
register
mail settings
Submitter Arnaud Charlet
Date Oct. 4, 2010, 3:08 p.m.
Message ID <20101004150833.GA733@adacore.com>
Download mbox | patch
Permalink /patch/66697/
State New
Headers show

Comments

Arnaud Charlet - Oct. 4, 2010, 3:08 p.m.
gnatmake now fails before attempting compilation if it is not invoked
with mains on the command line, there are no language other than Ada in
attribute Languages of the main project and one of the main specified in
attribute Main of the main project does not exist or is a source of
another project.
The test for this is to invoke "gnatmake -P prj.gpr" on the following
project with only source file main.adb in the directory:

project Prj is
   for Main use ("main.adb", "junk.adb");
end Prj;

This invocation of gnatmake should fail with:

gnatmake: "junk.adb" is not a source of project Prj

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

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

	* make.adb (Gnatmake): When there are no foreign languages declared and
	a main in attribute Main of the main project does not exist or is a
	source of another project, fail immediately before attempting
	compilation.

Patch

Index: make.adb
===================================================================
--- make.adb	(revision 164940)
+++ make.adb	(working copy)
@@ -4468,29 +4468,41 @@  package body Make is
                      --  language, all the Ada mains.
 
                      while Value /= Prj.Nil_String loop
-                        Get_Name_String
-                          (Project_Tree.String_Elements.Table (Value).Value);
-
                         --  To know if a main is an Ada main, get its project.
                         --  It should be the project specified on the command
                         --  line.
 
-                        if (not Foreign_Language) or else
-                            Prj.Env.Project_Of
-                              (Name_Buffer (1 .. Name_Len),
-                               Main_Project,
-                               Project_Tree) =
-                             Main_Project
-                        then
-                           At_Least_One_Main := True;
-                           Osint.Add_File
-                             (Get_Name_String
-                                (Project_Tree.String_Elements.Table
-                                   (Value).Value),
-                              Index =>
-                                Project_Tree.String_Elements.Table
-                                  (Value).Index);
-                        end if;
+                        Get_Name_String
+                          (Project_Tree.String_Elements.Table (Value).Value);
+
+                        declare
+                           Main_Name : constant String :=
+                              Get_Name_String
+                               (Project_Tree.String_Elements.Table
+                                    (Value).Value);
+                           Proj : constant Project_Id :=
+                             Prj.Env.Project_Of
+                              (Main_Name, Main_Project, Project_Tree);
+                        begin
+
+                           if Proj = Main_Project then
+
+                              At_Least_One_Main := True;
+                              Osint.Add_File
+                                (Get_Name_String
+                                   (Project_Tree.String_Elements.Table
+                                      (Value).Value),
+                                 Index =>
+                                   Project_Tree.String_Elements.Table
+                                     (Value).Index);
+
+                           elsif not Foreign_Language then
+                              Make_Failed
+                                ("""" & Main_Name &
+                                 """ is not a source of project " &
+                                 Get_Name_String (Main_Project.Display_Name));
+                           end if;
+                        end;
 
                         Value := Project_Tree.String_Elements.Table
                                    (Value).Next;