diff --git a/extensions/analysis/bodies b/extensions/analysis/bodies index 853c994c1..5964a1e24 100644 --- a/extensions/analysis/bodies +++ b/extensions/analysis/bodies @@ -83,6 +83,8 @@ is -- This creates a ref-counted object: we must decrease its ref-count -- whether we return normally or through an exception. begin + Libadalang.Project_Provider.Check_Source_Info (Tree); + begin GPR_Impl.Initialize_Context_From_Project (Result, Tree, Project, EH_Int, With_Trivia, Tab_Stop); diff --git a/extensions/src/libadalang-config_pragmas.adb b/extensions/src/libadalang-config_pragmas.adb index 09b0dc5fc..02d6a786c 100644 --- a/extensions/src/libadalang-config_pragmas.adb +++ b/extensions/src/libadalang-config_pragmas.adb @@ -251,7 +251,7 @@ package body Libadalang.Config_Pragmas is begin return Import_From_Project (Context, - (Kind => GPR2_Kind, GPR2_Value => Tree.Reference), + (Kind => GPR2_Kind, GPR2_Value => Tree), (Kind => GPR2_Kind, GPR2_Value => View)); end Import_From_Project; diff --git a/extensions/src/libadalang-data_decomposition.adb b/extensions/src/libadalang-data_decomposition.adb index 2408d7a14..41dbee53e 100644 --- a/extensions/src/libadalang-data_decomposition.adb +++ b/extensions/src/libadalang-data_decomposition.adb @@ -14,14 +14,18 @@ with GNATCOLL.Mmap; with GNATCOLL.OS.FS; with GNATCOLL.OS.Process; with GNATCOLL.VFS; +pragma Warnings (Off, "not referenced"); +with GPR2.Build.Source.Sets; +pragma Warnings (On, "not referenced"); with GPR2.Containers; with GPR2.Context; with GPR2.Path_Name; with GPR2.Path_Name.Set; -with Libadalang.Auto_Provider; use Libadalang.Auto_Provider; -with Libadalang.Common; use Libadalang.Common; -with Libadalang.GPR_Utils; use Libadalang.GPR_Utils; +with Libadalang.Auto_Provider; use Libadalang.Auto_Provider; +with Libadalang.Common; use Libadalang.Common; +with Libadalang.GPR_Utils; use Libadalang.GPR_Utils; +with Libadalang.Project_Provider; use Libadalang.Project_Provider; package body Libadalang.Data_Decomposition is @@ -2682,6 +2686,8 @@ package body Libadalang.Data_Decomposition is Args : Argument_List; begin + Check_Source_Info (Tree); + Args.Append ("gprbuild"); Args.Append ("-c"); Args.Append ("-P" & String (Tree.Root_Project.Path_Name.Value)); @@ -2785,6 +2791,8 @@ package body Libadalang.Data_Decomposition is -- Look for JSON files for all Ada sources declare + use type GPR2.Language_Id; + Actual_View : constant GPR2.Project.View.Object := (if View.Is_Defined then View else Tree.Root_Project); Loaded_Subdir : constant GPR2.Filename_Optional := Tree.Subdirs; @@ -2800,7 +2808,8 @@ package body Libadalang.Data_Decomposition is Obj_Dir := V.Object_Directory; if Loaded_Subdir'Length > 0 then - pragma Assert (Obj_Dir.Simple_Name = Loaded_Subdir); + pragma Assert + (V.Is_Runtime or else Obj_Dir.Simple_Name = Loaded_Subdir); Obj_Dir := Obj_Dir.Containing_Directory; end if; if Subdirs'Length > 0 then @@ -2810,7 +2819,7 @@ package body Libadalang.Data_Decomposition is Trace.Trace ("Object directory: " & String (Obj_Dir.Value)); for S of V.Sources loop - if S.Is_Ada then + if S.Language = GPR2.Ada_Language then Trace.Trace ("Processing Ada source: " & String (S.Path_Name.Value)); Repinfo_File := diff --git a/extensions/src/libadalang-gpr_utils.adb b/extensions/src/libadalang-gpr_utils.adb index 3a71365cc..7baf74afd 100644 --- a/extensions/src/libadalang-gpr_utils.adb +++ b/extensions/src/libadalang-gpr_utils.adb @@ -9,14 +9,17 @@ with GNAT.Strings; use GNAT.Strings; with GNATCOLL.Utils; with GNATCOLL.VFS; use GNATCOLL.VFS; +with GPR2.Build.Source; +pragma Warnings (Off, "not referenced"); +with GPR2.Build.Source.Sets; +pragma Warnings (On, "not referenced"); +with GPR2.Build.Unit_Info; with GPR2.Containers; with GPR2.Path_Name; with GPR2.Project.Attribute; with GPR2.Project.Attribute.Set; with GPR2.Project.Attribute_Index; -with GPR2.Project.Source; with GPR2.Project.View.Set; -with GPR2.Unit; package body Libadalang.GPR_Utils is @@ -425,13 +428,12 @@ package body Libadalang.GPR_Utils is when GPR2_Kind => declare - Path : constant GPR2.Path_Name.Object := - GPR2.Path_Name.Create_File - (GPR2.Filename_Type (Filename), GPR2.Path_Name.No_Resolution); - File : constant GPR2.Project.Source.Object := - View.GPR2_Value.Source (Path); + use type GPR2.Language_Id; + + File : constant GPR2.Build.Source.Object := + View.GPR2_Value.Source (GPR2.Simple_Name (Filename)); begin - return File.Is_Defined and then File.Is_Ada; + return File.Is_Defined and then File.Language = GPR2.Ada_Language; end; end case; end Is_Ada_Source; @@ -511,32 +513,53 @@ package body Libadalang.GPR_Utils is -- instead of using this internal API. declare - procedure Process_Wrapper (Source : GPR2.Project.Source.Object); + procedure Process_Wrapper (Source : GPR2.Build.Source.Object); -- Call ``Process`` on all units in ``Source`` + function Unit_Name (U : GPR2.Build.Unit_Info.Object) return String + is (String (U.Name) + & (if U.Kind in GPR2.S_Separate + then "." & String (U.Separate_Name) + else "")); + --------------------- -- Process_Wrapper -- --------------------- - procedure Process_Wrapper (Source : GPR2.Project.Source.Object) is + procedure Process_Wrapper (Source : GPR2.Build.Source.Object) is Filename : constant String := String (Source.Path_Name.Value); begin + if not Source.Has_Units then + return; + end if; + for U of Source.Units loop - Process.all - (Unit_Name => String (U.Name), - Unit_Part => (if U.Kind in GPR2.Unit.Spec_Kind - then Unit_Spec - else Unit_Body), - Filename => Filename); + + -- TODO (eng/gpr/gpr-issues#227) GPR2 cannot find the name + -- of some units. Discard them since we cannot do anything + -- useful with them, and they may cause trouble later on + -- (conflicting sources for the same empty unit name). + + declare + N : constant String := Unit_Name (U); + begin + if N /= "" then + Process.all + (Unit_Name => N, + Unit_Part => (if U.Kind in GPR2.S_Spec + then Unit_Spec + else Unit_Body), + Filename => Filename); + end if; + end; end loop; end Process_Wrapper; begin if Recursive then - Tree.GPR2_Value.For_Each_Source - (View => View.GPR2_Value, - Action => Process_Wrapper'Access, - Language => GPR2.Ada_Language, - Externally_Built => True); + for V of View.GPR2_Value.Closure (Include_Self => True) loop + Iterate_Ada_Units + (Tree, (GPR2_Kind, V), Process, Recursive => False); + end loop; else for S of View.GPR2_Value.Sources loop Process_Wrapper (S); @@ -590,15 +613,19 @@ package body Libadalang.GPR_Utils is -- Also process compiler switches for all Ada sources - for Source of Indexes (Self, Switches) loop - declare - Filename : constant String := Source.To_String; - begin - if Is_Ada_Source (Tree, Self, Filename) then - Process_Switches (Self, Switches, Filename); - end if; - end; - end loop; + declare + Index_List : constant XString_Array := Indexes (Self, Switches); + begin + for Source of Index_List loop + declare + Filename : constant String := Source.To_String; + begin + if Is_Ada_Source (Tree, Self, Filename) then + Process_Switches (Self, Switches, Filename); + end if; + end; + end loop; + end; end Process_View; ---------------------- diff --git a/extensions/src/libadalang-gpr_utils.ads b/extensions/src/libadalang-gpr_utils.ads index 95125af0d..451d67353 100644 --- a/extensions/src/libadalang-gpr_utils.ads +++ b/extensions/src/libadalang-gpr_utils.ads @@ -29,8 +29,7 @@ private package Libadalang.GPR_Utils is type Any_Tree (Kind : Project_Kind := Project_Kind'First) is record case Kind is when GPR1_Kind => GPR1_Value : GPR1.Project_Tree_Access; - when GPR2_Kind => - GPR2_Value : access constant GPR2.Project.Tree.Object; + when GPR2_Kind => GPR2_Value : GPR2.Project.Tree.Object; end case; end record; diff --git a/extensions/src/libadalang-helpers.adb b/extensions/src/libadalang-helpers.adb index 32899ee09..bc2e00afc 100644 --- a/extensions/src/libadalang-helpers.adb +++ b/extensions/src/libadalang-helpers.adb @@ -19,10 +19,7 @@ with GNAT.Traceback.Symbolic; with GNATCOLL.File_Paths; with GNATCOLL.Strings; use GNATCOLL.Strings; with GNATCOLL.VFS; use GNATCOLL.VFS; -with GPR2.Containers; -with GPR2.Context; -with GPR2.Path_Name; -with GPR2.Project.Configuration; +with GPR2.Options; with GPR2.Project.View; with GPR2.Project.View.Set; @@ -510,8 +507,7 @@ package body Libadalang.Helpers is if Use_GPR2 then App_Ctx.Provider := - (Kind => GPR2_Project_File, - GPR2_Project => GPR2_Project.Reference); + (Kind => GPR2_Project_File, GPR2_Project => GPR2_Project); else App_Ctx.Provider := (Kind => Project_File, Project => Project); @@ -823,8 +819,8 @@ package body Libadalang.Helpers is Target, RTS, Config_File : String := ""; Project : in out GPR2.Project.Tree.Object) is - Ctx : GPR2.Context.Object; - Error : Boolean := False; + Options : GPR2.Options.Object; + Error : Boolean := False; procedure Set_Scenario_Var (Name, Value : String); -- Set the given scenario variable in ``Ctx`` @@ -835,7 +831,7 @@ package body Libadalang.Helpers is procedure Set_Scenario_Var (Name, Value : String) is begin - Ctx.Include (GPR2.Name_Type (Name), Value); + Options.Add_Switch (GPR2.Options.X, Name & "=" & Value); end Set_Scenario_Var; begin @@ -845,42 +841,28 @@ package body Libadalang.Helpers is Iterate_Scenario_Vars (Scenario_Vars, Set_Scenario_Var'Access); -- Load the project tree with either a config file (if given) or the - -- requested target/runtime , and beware of loading errors + -- requested target/runtime, and beware of loading errors - declare - PF : constant GPR2.Path_Name.Object := - GPR2.Path_Name.Create_File - (GPR2.Filename_Type (Project_File), GPR2.Path_Name.No_Resolution); - RTS_Map : GPR2.Containers.Lang_Value_Map; begin - if Config_File = "" then - if RTS /= "" then - RTS_Map.Include (GPR2.Ada_Language, RTS); + Options.Add_Switch (GPR2.Options.P, Project_File); + + if Config_File /= "" then + if Target /= "" or else RTS /= "" then + Abort_App + ("--config not allowed if --target or --RTS are passed"); end if; - Project.Load_Autoconf - (Filename => PF, - Context => Ctx, - Target => GPR2.Optional_Name_Type (Target), - Language_Runtimes => RTS_Map); + Options.Add_Switch (GPR2.Options.Config, Config_File); + end if; - elsif Target /= "" or else RTS /= "" then - Abort_App ("--config not allowed if --target or --RTS are passed"); + if Target /= "" then + Options.Add_Switch (GPR2.Options.Target, Target); + end if; - else - declare - F : constant GPR2.Path_Name.Object := - GPR2.Path_Name.Create_File (GPR2.Filename_Type (Config_File)); - Config : constant GPR2.Project.Configuration.Object := - GPR2.Project.Configuration.Load (F); - begin - Project.Load - (Filename => PF, - Context => Ctx, - Config => Config); - end; + if RTS /= "" then + Options.Add_Switch (GPR2.Options.RTS, RTS); end if; - Project.Update_Sources (With_Runtime => True); + Error := not Project.Load (Options); exception when Exc : GPR2.Project_Error => Error := True; @@ -888,14 +870,17 @@ package body Libadalang.Helpers is ("Loading failed: " & Exception_Message (Exc)); end; + Error := Error or else not Update_Sources (Project); + -- Whether the project loaded successfully or not, print messages since -- they may contain warnings. If there was an error, abort the App. + Error := Error or else Project.Log_Messages.Has_Error; Project.Log_Messages.Output_Messages (Information => False, Warning => True, Error => True); - if Error or else Project.Log_Messages.Has_Error then + if Error then Abort_App; end if; diff --git a/extensions/src/libadalang-helpers.ads b/extensions/src/libadalang-helpers.ads index 0525f13db..0d8ba6bf3 100644 --- a/extensions/src/libadalang-helpers.ads +++ b/extensions/src/libadalang-helpers.ads @@ -89,7 +89,7 @@ package Libadalang.Helpers is when Auto_Dir => Dirs, Found_Files : String_Vectors.Vector; when GPR2_Project_File => - GPR2_Project : access GPR2.Project.Tree.Object; + GPR2_Project : GPR2.Project.Tree.Object; end case; end record; diff --git a/extensions/src/libadalang-preprocessing.adb b/extensions/src/libadalang-preprocessing.adb index b721461e6..0ab179122 100644 --- a/extensions/src/libadalang-preprocessing.adb +++ b/extensions/src/libadalang-preprocessing.adb @@ -19,10 +19,11 @@ with GNATCOLL.Strings; use GNATCOLL.Strings; with Langkit_Support.Slocs; use Langkit_Support.Slocs; with Langkit_Support.Text; use Langkit_Support.Text; -with Libadalang.Common; use Libadalang.Common; -with Libadalang.GPR_Utils; use Libadalang.GPR_Utils; -with Libadalang.PP_Impl; use Libadalang.PP_Impl; -with Libadalang.PP_Lexer; use Libadalang.PP_Lexer; +with Libadalang.Common; use Libadalang.Common; +with Libadalang.GPR_Utils; use Libadalang.GPR_Utils; +with Libadalang.PP_Impl; use Libadalang.PP_Impl; +with Libadalang.PP_Lexer; use Libadalang.PP_Lexer; +with Libadalang.Project_Provider; use Libadalang.Project_Provider; package body Libadalang.Preprocessing is @@ -730,11 +731,11 @@ package body Libadalang.Preprocessing is Default_Config : out File_Config; File_Configs : out File_Config_Maps.Map) is begin + Check_Source_Info (Tree); + Extract_Preprocessor_Data_From_Project - (Tree => (Kind => GPR2_Kind, - GPR2_Value => Tree'Unrestricted_Access), - View => (Kind => GPR2_Kind, - GPR2_Value => Project), + (Tree => (Kind => GPR2_Kind, GPR2_Value => Tree), + View => (Kind => GPR2_Kind, GPR2_Value => Project), Default_Config => Default_Config, File_Configs => File_Configs); end Extract_Preprocessor_Data_From_Project; diff --git a/extensions/src/libadalang-project_provider.adb b/extensions/src/libadalang-project_provider.adb index 9ff32ebdf..229f440a8 100644 --- a/extensions/src/libadalang-project_provider.adb +++ b/extensions/src/libadalang-project_provider.adb @@ -12,8 +12,11 @@ with GNAT.Task_Lock; with GNATCOLL.Strings; use GNATCOLL.Strings; with GNATCOLL.VFS; use GNATCOLL.VFS; -with GPR2.Project.Unit_Info; -with GPR2.Unit; +with GPR2.Build.Compilation_Unit; +pragma Warnings (Off, "not referenced"); +with GPR2.Build.Source.Sets; +pragma Warnings (On, "not referenced"); +with GPR2.Log; with Libadalang.GPR_Utils; use Libadalang.GPR_Utils; with Libadalang.Implementation; use Libadalang.Implementation; @@ -42,7 +45,7 @@ package body Libadalang.Project_Provider is GPR1_Env : Prj.Project_Environment_Access; GPR1_Is_Project_Owner : Boolean; when GPR2_Kind => - GPR2_Tree : access GPR2.Project.Tree.Object; + GPR2_Tree : GPR2.Project.Tree.Object; end case; end record; @@ -201,9 +204,15 @@ package body Libadalang.Project_Provider is Unit_File : constant access US.Unbounded_String := (case Part is when Unit_Spec => FFU.Spec_File'Access, - when Unit_Body => FFU.Body_File'Access); + when Unit_Body => FFU.Body_File'Access); begin - pragma Assert (Unit_File.all = US.Null_Unbounded_String); + -- TODO (eng/gpr/gpr-issues#227) Once this bug is resolved, assert that + -- Unit_File.all is empty. + + if Unit_File.all /= US.Null_Unbounded_String then + return; + end if; + Unit_File.all := (if File = "" then US.Null_Unbounded_String @@ -366,8 +375,7 @@ package body Libadalang.Project_Provider is GPR1_Is_Project_Owner => False); when GPR2_Kind => - Data := - (Kind => GPR2_Kind, GPR2_Tree => Tree.GPR2_Value.Reference); + Data := (Kind => GPR2_Kind, GPR2_Tree => Tree.GPR2_Value); end case; Provider.Projects := Views; return LAL.Create_Unit_Provider_Reference (Provider); @@ -498,6 +506,16 @@ package body Libadalang.Project_Provider is Trace.Decrease_Indent; end if; + -- For GPR2, make sure that all projects are namespace roots + + if Tree.Kind = GPR2_Kind then + for Item of Partition loop + for P of Item.Projects loop + pragma Assert (P.GPR2_Value.Is_Namespace_Root); + end loop; + end loop; + end if; + -- The partition is ready: turn each part into a unit provider and -- return the list. @@ -570,6 +588,18 @@ package body Libadalang.Project_Provider is "selected project is aggregate and has more than one sub-project"; end if; + -- Make sure we have a namespace root for GPR2, as only these can be + -- queried for units. If needed, take the first namespace root: all + -- namespace roots could do, as they all give access to the same sources + -- for the requested closure. + + if Tree.Kind = GPR2_Kind + and then not Actual_View.GPR2_Value.Is_Namespace_Root + then + Actual_View.GPR2_Value := + Actual_View.GPR2_Value.Namespace_Roots.First_Element; + end if; + declare Views : View_Vectors.Vector; begin @@ -718,78 +748,51 @@ package body Libadalang.Project_Provider is when GPR2_Kind => declare - procedure Set (SUI : GPR2.Unit.Source_Unit_Identifier); + procedure Set (SUI : GPR2.Build.Compilation_Unit.Unit_Location); -- Set ``Filename`` and ``PLE_Root_Index`` from ``SUI``'s - function Lookup (View : GPR2.Project.View.Object) return Boolean; - -- If ``View`` contains the requested unit, return ``True`` and - -- set ``Filename`` to the corresponding filename. Return - -- ``False`` otherwise. - Unit_Name : constant GPR2.Name_Type := GPR2.Name_Type (Str_Name); --------- -- Set -- --------- - procedure Set (SUI : GPR2.Unit.Source_Unit_Identifier) is + procedure Set (SUI : GPR2.Build.Compilation_Unit.Unit_Location) is use type GPR2.Unit_Index; begin -- GPR2 sets the CU index to 0 when there is no "at N" clause -- in the project file. This is equivalont to "at 1", which is -- what we need here since PLE_Root_Index is a Positive. - Filename := US.To_Unbounded_String (SUI.Source.Value); + Filename := US.To_Unbounded_String (String (SUI.Source.Value)); PLE_Root_Index := (if SUI.Index = 0 then 1 else Positive (SUI.Index)); end Set; - - ------------ - -- Lookup -- - ------------ - - function Lookup (View : GPR2.Project.View.Object) return Boolean is - Unit : constant GPR2.Project.Unit_Info.Object := - View.Unit (Unit_Name); - begin - if Unit.Is_Defined then - case Kind is - when Unit_Specification => - if Unit.Has_Spec then - Set (Unit.Spec); - return True; - end if; - when Unit_Body => - if Unit.Has_Body then - Set (Unit.Main_Body); - return True; - end if; - end case; - end if; - - return False; - end Lookup; - - Tree : GPR2.Project.Tree.Object renames - Provider.Data.GPR2_Tree.all; begin - -- Look for all the requested unit in the closure of all the - -- projects that this provider handles. + -- Look for the requested unit in all the projects that this + -- provider handles. for View of Provider.Projects loop - for V of Closure (View.GPR2_Value) loop - if Lookup (V) then - return; + declare + Unit : constant GPR2.Build.Compilation_Unit.Object := + View.GPR2_Value.Unit (Unit_Name); + begin + if Unit.Is_Defined then + case Kind is + when Unit_Specification => + if Unit.Has_Part (GPR2.S_Spec) then + Set (Unit.Spec); + return; + end if; + when Unit_Body => + if Unit.Has_Part (GPR2.S_Body) then + Set (Unit.Main_Body); + return; + end if; + end case; end if; - end loop; + end; end loop; - - -- Also look in the runtime project, if any - - if Tree.Has_Runtime_Project and then Lookup (Tree.Runtime_Project) - then - return; - end if; end; end case; @@ -1085,9 +1088,11 @@ package body Libadalang.Project_Provider is when Default => -- Go through all projects except externally built ones + -- except the runtime. for V of Closure (View) loop - if not V.Is_Externally_Built then + if not V.Is_Externally_Built and then not V.Is_Runtime + then Include (V); end if; end loop; @@ -1104,7 +1109,10 @@ package body Libadalang.Project_Provider is -- Go through the whole project sub tree for V of Closure (View) loop - Include (V); + if Mode = Whole_Project_With_Runtime or else not V.Is_Runtime + then + Include (V); + end if; end loop; end case; end Process; @@ -1124,7 +1132,7 @@ package body Libadalang.Project_Provider is end Include; begin - -- Include sources from all the requested projects themselves + -- Include sources from all the requested projects if Projects.Is_Empty then Process (Tree.Root_Project); @@ -1134,14 +1142,6 @@ package body Libadalang.Project_Provider is end loop; end if; - -- Only then, if requested, get runtime sources: they are common to all - -- subprojects. - - if Mode = Whole_Project_With_Runtime and then Tree.Has_Runtime_Project - then - Include (Tree.Runtime_Project); - end if; - -- Return the sorted list of source files. Sorting gets the output -- deterministic and thus helps reproducibility. @@ -1150,6 +1150,46 @@ package body Libadalang.Project_Provider is end return; end Source_Files; + ----------------------- + -- Check_Source_Info -- + ----------------------- + + procedure Check_Source_Info (Tree : GPR2.Project.Tree.Object) is + function Is_Empty_Aggregate + (View : GPR2.Project.View.Object) return Boolean + is (View.Kind in GPR2.Aggregate_Kind and then View.Aggregated.Is_Empty); + begin + -- There is one case where it is actually expected that there is no + -- runtime: an aggregate project with no aggregated projects. + + if not Tree.Has_Runtime_Project + and then not Is_Empty_Aggregate (Tree.Root_Project) + then + raise Runtime_Missing_Error; + end if; + + if Tree.Source_Option not in GPR2.Source_Info_Option then + raise Source_Info_Missing_Error; + end if; + end Check_Source_Info; + + -------------------- + -- Update_Sources -- + -------------------- + + function Update_Sources (Tree : GPR2.Project.Tree.Object) return Boolean is + Messages : GPR2.Log.Object; + begin + return Result : Boolean do + Tree.Update_Sources (Messages => Messages); + Result := not Messages.Has_Error; + Messages.Output_Messages + (Information => False, + Warning => True, + Error => True); + end return; + end Update_Sources; + ----------------------------------- -- Create_Project_Unit_Providers -- ----------------------------------- @@ -1158,10 +1198,14 @@ package body Libadalang.Project_Provider is (Tree : GPR2.Project.Tree.Object) return GPR2_Provider_And_Projects_Array_Access is - Result : Any_Provider_And_Projects_Array_Access := - Create_Project_Unit_Providers - ((Kind => GPR2_Kind, GPR2_Value => Tree.Reference)); + Result : Any_Provider_And_Projects_Array_Access; begin + Check_Source_Info (Tree); + + Result := + Create_Project_Unit_Providers + ((Kind => GPR2_Kind, GPR2_Value => Tree)); + -- Convert Result (GPR library agnostic data structure) into the return -- type (GPR2-specific data structure). @@ -1196,9 +1240,11 @@ package body Libadalang.Project_Provider is is Dummy : Project_Unit_Provider_Access; begin + Check_Source_Info (Tree); + return Result : LAL.Unit_Provider_Reference do Create_Project_Unit_Provider - (Tree => (Kind => GPR2_Kind, GPR2_Value => Tree.Reference), + (Tree => (Kind => GPR2_Kind, GPR2_Value => Tree), View => (Kind => GPR2_Kind, GPR2_Value => Project), Provider => Dummy, Provider_Ref => Result); @@ -1257,7 +1303,7 @@ package body Libadalang.Project_Provider is return String is begin return Default_Charset_From_Project - (Tree => (Kind => GPR2_Kind, GPR2_Value => Tree'Unrestricted_Access), + (Tree => (Kind => GPR2_Kind, GPR2_Value => Tree), View => (Kind => GPR2_Kind, GPR2_Value => Project)); end Default_Charset_From_Project; diff --git a/extensions/src/libadalang-project_provider.ads b/extensions/src/libadalang-project_provider.ads index 144aaa575..ebe39916d 100644 --- a/extensions/src/libadalang-project_provider.ads +++ b/extensions/src/libadalang-project_provider.ads @@ -142,6 +142,32 @@ package Libadalang.Project_Provider is -- to allow experiments, it is totally unsupported and the API is very -- likely to change in the future. + Runtime_Missing_Error : exception; + -- Exception raised by the ``Create_Project_Unit_Provider[s]`` functions + -- when passed a project that does not have the runtime project loaded. + -- + -- In order to load the runtime project, pass ``With_Runtime => True`` to + -- the relevant project loading procedure (in ``GPR2.Project.Tree``). + + Source_Info_Missing_Error : exception; + -- Exception raised by the ``Create_Project_Unit_Provider[s]`` functions + -- when passed a project that does not contain the necessary source + -- information. + -- + -- In order to load the source infomation necessary for unit providers to + -- work correctly, use ``GPR2.Projects.Tree.Update_Sources`` or the + -- ``Update_Sources`` shortcut below. + + procedure Check_Source_Info (Tree : GPR2.Project.Tree.Object); + -- Raise ``Runtime_Missing_Error` if ``Tree`` does not have a runtime + -- project loaded. Raise ``Source_Missing_Info_Error`` if it does not have + -- source information loaded. + + function Update_Sources (Tree : GPR2.Project.Tree.Object) return Boolean; + -- Call ``GPR2.Project.Tree.Update_Sources``, print potential + -- warnings/errors. Return ``True`` if there was no error, ``False`` + -- otherwise. + type GPR2_Provider_And_Projects is record Provider : LAL.Unit_Provider_Reference; Projects : GPR2.Project.View.Vector.Object; @@ -171,9 +197,8 @@ package Libadalang.Project_Provider is -- providers, and it is up to callers to deallocate ``Tree`` itself. function Create_Project_Unit_Provider - (Tree : GPR2.Project.Tree.Object; - Project : GPR2.Project.View.Object := - GPR2.Project.View.Undefined) + (Tree : GPR2.Project.Tree.Object; + Project : GPR2.Project.View.Object := GPR2.Project.View.Undefined) return LAL.Unit_Provider_Reference; -- Likewise, but create only one unit provider. -- diff --git a/testsuite/tests/ada_api/config_pragmas/projects.adb b/testsuite/tests/ada_api/config_pragmas/projects.adb index df4d56195..d316676a4 100644 --- a/testsuite/tests/ada_api/config_pragmas/projects.adb +++ b/testsuite/tests/ada_api/config_pragmas/projects.adb @@ -6,15 +6,15 @@ with Ada.Text_IO; use Ada.Text_IO; with GNATCOLL.Projects; use GNATCOLL.Projects; with GNATCOLL.VFS; use GNATCOLL.VFS; -with GPR2.Context; -with GPR2.Path_Name; +with GPR2.Options; with GPR2.Project.Tree; with GPR2.Project.View; with Langkit_Support.Text; use Langkit_Support.Text; -with Libadalang.Analysis; use Libadalang.Analysis; -with Libadalang.Config_Pragmas; use Libadalang.Config_Pragmas; +with Libadalang.Analysis; use Libadalang.Analysis; +with Libadalang.Config_Pragmas; use Libadalang.Config_Pragmas; +with Libadalang.Project_Provider; use Libadalang.Project_Provider; procedure Projects is @@ -78,15 +78,17 @@ procedure Projects is -- Make sure we get the same mapping when loading from a GPR2 project declare + Options : GPR2.Options.Object; Tree : GPR2.Project.Tree.Object; View : GPR2.Project.View.Object := GPR2.Project.View.Undefined; GPR2_Mapping : Config_Pragmas_Mapping; begin - Tree.Load_Autoconf - (Filename => GPR2.Path_Name.Create_File - (GPR2.Filename_Type (Root_Project), - GPR2.Path_Name.No_Resolution), - Context => GPR2.Context.Empty); + Options.Add_Switch (GPR2.Options.P, Root_Project); + if not Tree.Load (Options, With_Runtime => True) + or else not Update_Sources (Tree) + then + raise Program_Error; + end if; if Project /= "" then for V of Tree.Ordered_Views loop if To_Lower (String (V.Name)) = To_Lower (Project) then diff --git a/testsuite/tests/ada_api/gpr2_context/main.adb b/testsuite/tests/ada_api/gpr2_context/main.adb index d6a30eeee..0d8f677ad 100644 --- a/testsuite/tests/ada_api/gpr2_context/main.adb +++ b/testsuite/tests/ada_api/gpr2_context/main.adb @@ -2,7 +2,7 @@ with Ada.Characters.Handling; use Ada.Characters.Handling; with Ada.Exceptions; use Ada.Exceptions; with Ada.Text_IO; use Ada.Text_IO; -with GPR2.Context; +with GPR2.Options; with GPR2.Path_Name; with GPR2.Project.Tree; with GPR2.Project.View; @@ -38,25 +38,27 @@ procedure Main is With_Trivia : Boolean := True; Tab_Stop : Positive := 8) is - Tree : GPR2.Project.Tree.Object; - Prj : GPR2.Project.View.Object; - Ctx : Analysis_Context; - U : Analysis_Unit; - N : Basic_Decl; + Options : GPR2.Options.Object; + Tree : GPR2.Project.Tree.Object; + Prj : GPR2.Project.View.Object; + Ctx : Analysis_Context; + U : Analysis_Unit; + N : Basic_Decl; begin Put_Line ("== " & Label & " =="); New_Line; -- Load the requested tree and fetch the requested project (if any) - Tree.Load_Autoconf - (Filename => GPR2.Path_Name.Create_File - (GPR2.Filename_Type (Root_Project)), - Context => GPR2.Context.Empty); - if Tree.Has_Messages then + Options.Add_Switch (GPR2.Options.P, Root_Project); + if not Tree.Load (Options) then + raise Program_Error; + elsif Tree.Has_Messages then Tree.Log_Messages.Output_Messages (Information => False); end if; - Tree.Update_Sources (With_Runtime => True); + if not Update_Sources (Tree) then + raise Program_Error; + end if; if Project /= "" then declare Root : constant GPR2.Project.View.Object := Tree.Root_Project; diff --git a/testsuite/tests/ada_api/gpr2_project_partition/basic/main.adb b/testsuite/tests/ada_api/gpr2_project_partition/basic/main.adb index 303ce2156..09ac3e151 100644 --- a/testsuite/tests/ada_api/gpr2_project_partition/basic/main.adb +++ b/testsuite/tests/ada_api/gpr2_project_partition/basic/main.adb @@ -4,8 +4,7 @@ with Ada.Text_IO; use Ada.Text_IO; with GNATCOLL.Traces; -with GPR2.Context; -with GPR2.Path_Name; +with GPR2.Options; with GPR2.Project.Tree; with Libadalang.Analysis; use Libadalang.Analysis; @@ -19,15 +18,19 @@ procedure Main is type Context_Array is array (Positive range <>) of Analysis_Context; - Tree : GPR2.Project.Tree.Object; - PAPs : GPR2_Provider_And_Projects_Array_Access; + Options : GPR2.Options.Object; + Tree : GPR2.Project.Tree.Object; + PAPs : GPR2_Provider_And_Projects_Array_Access; begin GNATCOLL.Traces.Parse_Config ("LIBADALANG.PROJECT_PROVIDER=yes"); Put_Line ("Loading the project:"); - Tree.Load_Autoconf - (Filename => GPR2.Path_Name.Create_File ("ap1.gpr"), - Context => GPR2.Context.Empty); + Options.Add_Switch (GPR2.Options.P, "ap1.gpr"); + if not Tree.Load (Options, With_Runtime => True) + or else not Update_Sources (Tree) + then + raise Program_Error; + end if; PAPs := Create_Project_Unit_Providers (Tree); declare diff --git a/testsuite/tests/ada_api/gpr2_project_partition/c_units/main.adb b/testsuite/tests/ada_api/gpr2_project_partition/c_units/main.adb index fcde2aff7..3fe5583e0 100644 --- a/testsuite/tests/ada_api/gpr2_project_partition/c_units/main.adb +++ b/testsuite/tests/ada_api/gpr2_project_partition/c_units/main.adb @@ -2,20 +2,23 @@ with Ada.Text_IO; use Ada.Text_IO; -with GPR2.Context; -with GPR2.Path_Name; +with GPR2.Options; with GPR2.Project.Tree; with Libadalang.Project_Provider; use Libadalang.Project_Provider; procedure Main is - Tree : GPR2.Project.Tree.Object; - PAPs : GPR2_Provider_And_Projects_Array_Access; + Options : GPR2.Options.Object; + Tree : GPR2.Project.Tree.Object; + PAPs : GPR2_Provider_And_Projects_Array_Access; begin Put_Line ("Loading the project:"); - Tree.Load_Autoconf - (Filename => GPR2.Path_Name.Create_File ("ap.gpr"), - Context => GPR2.Context.Empty); + Options.Add_Switch (GPR2.Options.P, "ap.gpr"); + if not Tree.Load (Options, With_Runtime => True) + or else not Update_Sources (Tree) + then + raise Program_Error; + end if; PAPs := Create_Project_Unit_Providers (Tree); for I in PAPs'Range loop Put (" *"); diff --git a/testsuite/tests/ada_api/gpr2_project_partition/empty/main.adb b/testsuite/tests/ada_api/gpr2_project_partition/empty/main.adb index 22cb2ee9e..b552f7823 100644 --- a/testsuite/tests/ada_api/gpr2_project_partition/empty/main.adb +++ b/testsuite/tests/ada_api/gpr2_project_partition/empty/main.adb @@ -2,20 +2,23 @@ with Ada.Text_IO; use Ada.Text_IO; -with GPR2.Context; -with GPR2.Path_Name; +with GPR2.Options; with GPR2.Project.Tree; with Libadalang.Project_Provider; use Libadalang.Project_Provider; procedure Main is - Tree : GPR2.Project.Tree.Object; - PAPs : GPR2_Provider_And_Projects_Array_Access; + Options : GPR2.Options.Object; + Tree : GPR2.Project.Tree.Object; + PAPs : GPR2_Provider_And_Projects_Array_Access; begin Put_Line ("Loading the project:"); - Tree.Load_Autoconf - (Filename => GPR2.Path_Name.Create_File ("ap.gpr"), - Context => GPR2.Context.Empty); + Options.Add_Switch (GPR2.Options.P, "ap.gpr"); + if not Tree.Load (Options, With_Runtime => True) + or else not Update_Sources (Tree) + then + raise Program_Error; + end if; PAPs := Create_Project_Unit_Providers (Tree); for I in PAPs'Range loop Put (" *"); diff --git a/testsuite/tests/ada_api/gpr2_project_partition/empty/test.out b/testsuite/tests/ada_api/gpr2_project_partition/empty/test.out index 03720c467..bad8cd19a 100644 --- a/testsuite/tests/ada_api/gpr2_project_partition/empty/test.out +++ b/testsuite/tests/ada_api/gpr2_project_partition/empty/test.out @@ -1,3 +1,4 @@ Loading the project: +ap.gpr: warning: no language for the projects tree: configuration skipped * Done. diff --git a/testsuite/tests/ada_api/gpr2_project_unit_provider/main.adb b/testsuite/tests/ada_api/gpr2_project_unit_provider/main.adb index 8e8b43d1d..247fa8292 100644 --- a/testsuite/tests/ada_api/gpr2_project_unit_provider/main.adb +++ b/testsuite/tests/ada_api/gpr2_project_unit_provider/main.adb @@ -6,8 +6,7 @@ with Ada.Characters.Handling; use Ada.Characters.Handling; with Ada.Exceptions; with Ada.Text_IO; use Ada.Text_IO; -with GPR2.Context; -with GPR2.Path_Name; +with GPR2.Options; with GPR2.Project.Tree; with GPR2.Project.View; @@ -33,16 +32,19 @@ procedure Main is function Load_Project (File : String; Project : String := "") return Unit_Provider_Reference is - View : GPR2.Project.View.Object; + Options : GPR2.Options.Object; + View : GPR2.Project.View.Object; begin Put_Line ("Loading " & File & "..."); if Project'Length > 0 then Put_Line (" Targetting subproject " & Project); end if; - Tree.Load_Autoconf - (Filename => GPR2.Path_Name.Create_File (GPR2.Filename_Type (File)), - Context => GPR2.Context.Empty); - Tree.Update_Sources (With_Runtime => True); + Options.Add_Switch (GPR2.Options.P, File); + if not Tree.Load (Options, With_Runtime => True) + or else not Update_Sources (Tree) + then + raise Program_Error; + end if; if Project'Length > 0 then for V of Tree.Ordered_Views loop if To_Lower (String (V.Name)) = To_Lower (Project) then diff --git a/testsuite/tests/ada_api/gpr2_project_unit_provider_invalid/main.adb b/testsuite/tests/ada_api/gpr2_project_unit_provider_invalid/main.adb index d201128a6..4ee755ee1 100644 --- a/testsuite/tests/ada_api/gpr2_project_unit_provider_invalid/main.adb +++ b/testsuite/tests/ada_api/gpr2_project_unit_provider_invalid/main.adb @@ -2,8 +2,7 @@ with Ada.Exceptions; use Ada.Exceptions; with Ada.Strings.Wide_Wide_Unbounded; use Ada.Strings.Wide_Wide_Unbounded; with Ada.Text_IO; use Ada.Text_IO; -with GPR2.Context; -with GPR2.Path_Name; +with GPR2.Options; with GPR2.Project.Tree; with Langkit_Support.Diagnostics; use Langkit_Support.Diagnostics; @@ -29,10 +28,14 @@ procedure Main is ------------------ function Load_Project (File : String) return Unit_Provider_Reference is + Options : GPR2.Options.Object; begin - Tree.Load_Autoconf - (Filename => GPR2.Path_Name.Create_File (GPR2.Filename_Type (File)), - Context => GPR2.Context.Empty); + Options.Add_Switch (GPR2.Options.P, File); + if not Tree.Load (Options, With_Runtime => True) + or else not Update_Sources (Tree) + then + raise Program_Error; + end if; return Create_Project_Unit_Provider (Tree, Tree.Root_Project); end Load_Project; diff --git a/testsuite/tests/ada_api/gpr_default_charset/main.adb b/testsuite/tests/ada_api/gpr_default_charset/main.adb index bf7563814..3e68553da 100644 --- a/testsuite/tests/ada_api/gpr_default_charset/main.adb +++ b/testsuite/tests/ada_api/gpr_default_charset/main.adb @@ -5,8 +5,7 @@ with Ada.Text_IO; use Ada.Text_IO; with GNATCOLL.Projects; use GNATCOLL.Projects; with GNATCOLL.VFS; use GNATCOLL.VFS; -with GPR2.Context; -with GPR2.Path_Name; +with GPR2.Options; with GPR2.Project.Tree; with Libadalang.Project_Provider; use Libadalang.Project_Provider; @@ -37,12 +36,15 @@ procedure Main is end; declare - Tree : GPR2.Project.Tree.Object; + Options : GPR2.Options.Object; + Tree : GPR2.Project.Tree.Object; begin - Tree.Load_Autoconf - (Filename => GPR2.Path_Name.Create_File - (GPR2.Filename_Type (project)), - Context => GPR2.Context.Empty); + Options.Add_Switch (GPR2.Options.P, Project); + if not Tree.Load (Options, With_Runtime => True) + or else not Update_Sources (Tree) + then + raise Program_Error; + end if; Put_Line ("GPR2: " & Default_Charset_From_Project (Tree)); end; diff --git a/testsuite/tests/ada_api/source_files/main.adb b/testsuite/tests/ada_api/source_files/main.adb index 37a8d3c82..d25f0c059 100644 --- a/testsuite/tests/ada_api/source_files/main.adb +++ b/testsuite/tests/ada_api/source_files/main.adb @@ -8,8 +8,8 @@ with Ada.Text_IO; use Ada.Text_IO; with GNATCOLL.Projects; use GNATCOLL.Projects; with GNATCOLL.VFS; use GNATCOLL.VFS; -with GPR2.Context; -with GPR2.Path_Name; +with GPR2.Log; +with GPR2.Options; with GPR2.Project.Tree; with GPR2.Project.View.Set; @@ -24,6 +24,7 @@ procedure Main is Tree : Project_Tree_Access; GPR2_Tree : GPR2.Project.Tree.Object; + Log : GPR2.Log.Object; type Project_Name_Array is array (Positive range <>) of Unbounded_String; @@ -67,15 +68,18 @@ procedure Main is ---------- procedure Load (Filename : String) is + Options : GPR2.Options.Object; begin Initialize (Env); Tree := new Project_Tree; Tree.Load (Create (+Filename), Env); - GPR2_Tree.Load_Autoconf - (Filename => GPR2.Path_Name.Create_File - (GPR2.Filename_Type (Filename), - GPR2.Path_Name.No_Resolution), - Context => GPR2.Context.Empty); + + Options.Add_Switch (GPR2.Options.P, Filename); + if not GPR2_Tree.Load (Options, With_Runtime => True) + or else not Update_Sources (GPR2_Tree) + then + raise Program_Error; + end if; end Load; ------------ @@ -134,11 +138,26 @@ procedure Main is use type Filename_Vectors.Vector; Has_Runtime : Boolean := False; - GPR1_Sources : constant Filename_Vectors.Vector := + GPR1_Sources : Filename_Vectors.Vector := Source_Files (Tree.all, Mode, GPR1_Prjs); GPR2_Sources : constant Filename_Vectors.Vector := Source_Files (GPR2_Tree, Mode, GPR2_Prjs); begin + -- Remove the "memtrack.adb" runtime unit from GPR1 sources: it is + -- not supposed to be there, but we have no hope to get this fixed + -- at this point. + + for I in reverse 1 .. GPR1_Sources.Last_Index loop + declare + Simple_Name : constant String := + Ada.Directories.Simple_Name (To_String (GPR1_Sources (I))); + begin + if Simple_Name = "memtrack.adb" then + GPR1_Sources.Delete (I); + end if; + end; + end loop; + for F of GPR1_Sources loop declare Simple_Name : constant String := @@ -156,6 +175,14 @@ procedure Main is end if; if GPR1_Sources /= GPR2_Sources then + Put_Line ("With GPR1:"); + for F of GPR1_Sources loop + Put_Line (" " & To_String (F)); + end loop; + Put_Line ("With GPR2:"); + for F of GPR2_Sources loop + Put_Line (" " & To_String (F)); + end loop; raise Program_Error with "got different sources with GPR2"; end if; end; diff --git a/testsuite/tests/dda/project_json/main.adb b/testsuite/tests/dda/project_json/main.adb index b18afc034..8023eec06 100644 --- a/testsuite/tests/dda/project_json/main.adb +++ b/testsuite/tests/dda/project_json/main.adb @@ -5,8 +5,7 @@ with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with Ada.Text_IO; use Ada.Text_IO; with GNATCOLL.Traces; -with GPR2.Context; -with GPR2.Path_Name; +with GPR2.Options; with GPR2.Project.Tree; with GPR2.Project.View; @@ -18,18 +17,17 @@ with Libadalang.Project_Provider; use Libadalang.Project_Provider; procedure Main is - Ctx : Analysis_Context; - Tree : GPR2.Project.Tree.Object; - View : GPR2.Project.View.Object; Repinfo : Repinfo_Collection; function "+" (S : String) return Unbounded_String renames To_Unbounded_String; procedure Load_Project - (Filename : String; - Var_Name : GPR2.Optional_Name_Type := ""; - Var_Value : GPR2.Value_Type := ""; + (Tree : in out GPR2.Project.Tree.Object; + View : out GPR2.Project.View.Object; + Filename : String; + Var_Name : String := ""; + Var_Value : String := ""; Subdirs : String := ""; Subproject : String := ""); -- Load in ``Tree`` the project file ``Filename` with the given settings @@ -39,7 +37,10 @@ procedure Main is -- Set ``View`` to ``Undefined`` if ``Subproject`` is the empty string, and -- to the view with the corresponding name otherwise. - procedure Check (Sources : Filename_Array); + procedure Check + (Tree : GPR2.Project.Tree.Object; + View : GPR2.Project.View.Object; + Sources : Filename_Array); -- Load all Ada sources files denoted by the filenames in ``Sources`` and -- lookup type information for the (only expected) type declaration they -- contain. @@ -49,24 +50,32 @@ procedure Main is ------------------ procedure Load_Project - (Filename : String; - Var_Name : GPR2.Optional_Name_Type := ""; - Var_Value : GPR2.Value_Type := ""; + (Tree : in out GPR2.Project.Tree.Object; + View : out GPR2.Project.View.Object; + Filename : String; + Var_Name : String := ""; + Var_Value : String := ""; Subdirs : String := ""; Subproject : String := "") is - Context : GPR2.Context.Object; + Options : GPR2.Options.Object; begin + Options.Add_Switch (GPR2.Options.P, Filename); + if Subdirs /= "" then + Options.Add_Switch (GPR2.Options.Subdirs, Subdirs); + end if; if Var_Name'Length > 0 then - Context.Insert (Var_Name, Var_Value); + Options.Add_Switch (GPR2.Options.X, Var_Name & "=" & Var_Value); end if; - Tree.Load_Autoconf - (Filename => GPR2.Path_Name.Create_File - (Name => GPR2.Filename_Type (Filename), - Directory => GPR2.Path_Name.No_Resolution), - Context => Context, - Subdirs => GPR2.Optional_Name_Type (Subdirs)); + if not Tree.Load + (Options, + With_Runtime => True, + Absent_Dir_Error => GPR2.No_Error) + or else not Update_Sources (Tree) + then + raise Program_Error; + end if; View := GPR2.Project.View.Undefined; if Subproject'Length > 0 then @@ -80,16 +89,19 @@ procedure Main is "cannot find " & Subproject & " in " & Filename; end if; end if; - - Ctx := Create_Context - (Unit_Provider => Create_Project_Unit_Provider (Tree, View)); end Load_Project; ----------- -- Check -- ----------- - procedure Check (Sources : Filename_Array) is + procedure Check + (Tree : GPR2.Project.Tree.Object; + View : GPR2.Project.View.Object; + Sources : Filename_Array) + is + Ctx : constant Analysis_Context := Create_Context + (Unit_Provider => Create_Project_Unit_Provider (Tree, View)); U : Analysis_Unit; T : Base_Type_Decl; T_Info : Type_Representation; @@ -126,9 +138,14 @@ begin Put_Line ("== Simple =="); New_Line; - Load_Project ("simple.gpr"); - Repinfo := Load_From_Project (Tree, View); - Check ((1 => +"src/simple/simple.ads")); + declare + Tree : GPR2.Project.Tree.Object; + View : GPR2.Project.View.Object; + begin + Load_Project (Tree, View, "simple.gpr"); + Repinfo := Load_From_Project (Tree, View); + Check (Tree, View, (1 => +"src/simple/simple.ads")); + end; New_Line; -- Make sure Load_From_Project honors its View formal: it is not supposed @@ -136,11 +153,18 @@ begin Put_Line ("== Tree =="); New_Line; - Load_Project ("tree_root.gpr", Subproject => "tree_child"); - Repinfo := Load_From_Project (Tree, View); - Check - ((+"src/tree_root/tree_root.ads", - +"src/tree_child/tree_child.ads")); + declare + Tree : GPR2.Project.Tree.Object; + View : GPR2.Project.View.Object; + begin + Load_Project (Tree, View, "tree_root.gpr", Subproject => "tree_child"); + Repinfo := Load_From_Project (Tree, View); + Check + (Tree, + View, + (+"src/tree_root/tree_root.ads", + +"src/tree_child/tree_child.ads")); + end; New_Line; -- Make sure Load_From_Project correctly procesess a project loaded with @@ -149,9 +173,14 @@ begin Put_Line ("== Subdirs =="); New_Line; - Load_Project ("simple.gpr", Subdirs => "somesubdirs"); - Repinfo := Load_From_Project (Tree, View, Subdirs => "othersubdirs"); - Check ((1 => +"src/simple/simple.ads")); + declare + Tree : GPR2.Project.Tree.Object; + View : GPR2.Project.View.Object; + begin + Load_Project (Tree, View, "simple.gpr", Subdirs => "somesubdirs"); + Repinfo := Load_From_Project (Tree, View, Subdirs => "othersubdirs"); + Check (Tree, View, (1 => +"src/simple/simple.ads")); + end; New_Line; -- Make sure Load_From_Project passes expected external variables to @@ -160,9 +189,15 @@ begin Put_Line ("== With vars =="); New_Line; - Load_Project ("with_var.gpr", Var_Name => "MY_VAR", Var_Value => "foo"); - Repinfo := Load_From_Project (Tree, View); - Check ((1 => +"src/with_var/with_var.ads")); + declare + Tree : GPR2.Project.Tree.Object; + View : GPR2.Project.View.Object; + begin + Load_Project + (Tree, View, "with_var.gpr", Var_Name => "MY_VAR", Var_Value => "foo"); + Repinfo := Load_From_Project (Tree, View); + Check (Tree, View, (1 => +"src/with_var/with_var.ads")); + end; New_Line; Put_Line ("Done."); diff --git a/testsuite/tests/prep/errors/main.adb b/testsuite/tests/prep/errors/main.adb index 327a3e461..e672b475a 100644 --- a/testsuite/tests/prep/errors/main.adb +++ b/testsuite/tests/prep/errors/main.adb @@ -1,11 +1,10 @@ with Ada.Text_IO; use Ada.Text_IO; -with GPR2.Context; -with GPR2.Path_Name; +with GPR2.Options; with GPR2.Project.Tree; -with Libadalang.Analysis; use Libadalang.Analysis; -with Libadalang.Preprocessing; use Libadalang.Preprocessing; +with Libadalang.Analysis; use Libadalang.Analysis; +with Libadalang.Project_Provider; use Libadalang.Project_Provider; procedure Main is @@ -53,12 +52,15 @@ procedure Main is -- Create a context from the example project - Tree : GPR2.Project.Tree.Object; + Options : GPR2.Options.Object; + Tree : GPR2.Project.Tree.Object; begin - Tree.Load_Autoconf - (Filename => GPR2.Path_Name.Create_File - ("p.gpr", GPR2.Path_Name.No_Resolution), - Context => GPR2.Context.Empty); + Options.Add_Switch (GPR2.Options.P, "p.gpr"); + if not Tree.Load (Options, With_Runtime => True) + or else not Update_Sources (Tree) + then + raise Program_Error; + end if; Ctx := Create_Context_From_Project (Tree); -- As a sanity check, first make sure that preprocessing is active diff --git a/testsuite/tests/prep/projects/main.adb b/testsuite/tests/prep/projects/main.adb index d27c3c1be..ac8a4387b 100644 --- a/testsuite/tests/prep/projects/main.adb +++ b/testsuite/tests/prep/projects/main.adb @@ -5,13 +5,14 @@ with Ada.Text_IO; use Ada.Text_IO; with GNATCOLL.Projects; use GNATCOLL.Projects; with GNATCOLL.VFS; use GNATCOLL.VFS; -with GPR2.Context; -with GPR2.Path_Name; +with GPR2.Options; with GPR2.Project.Tree; with GPR2.Project.View; with Langkit_Support.Errors; use Langkit_Support.Errors; -with Libadalang.Preprocessing; use Libadalang.Preprocessing; + +with Libadalang.Preprocessing; use Libadalang.Preprocessing; +with Libadalang.Project_Provider; use Libadalang.Project_Provider; procedure Main is @@ -35,6 +36,7 @@ procedure Main is Tree : Project_Tree; Project : Project_Type; + Options : GPR2.Options.Object; GPR2_Tree : GPR2.Project.Tree.Object; GPR2_View : GPR2.Project.View.Object; begin @@ -46,12 +48,12 @@ procedure Main is Initialize (Env); Tree.Load (Create (+Filename)); - GPR2_Tree.Load_Autoconf - (Filename => GPR2.Path_Name.Create_File - (GPR2.Filename_Type (Filename), - GPR2.Path_Name.No_Resolution), - Context => GPR2.Context.Empty); - GPR2_Tree.Update_Sources (With_Runtime => True); + Options.Add_Switch (GPR2.Options.P, Filename); + if not GPR2_Tree.Load (Options, With_Runtime => True) + or else not Update_Sources (GPR2_Tree) + then + raise Program_Error; + end if; -- Run the extraction on all the requested subprojects