From cfb08816a55006c87c20fa66f36b3dbabbbb4519 Mon Sep 17 00:00:00 2001 From: Fabien Chouteau Date: Sat, 22 May 2021 11:26:58 +0200 Subject: [PATCH] Crate Configuration: add options to control the generators (#740) * Crate Configuration: add options to control the generators * Move the auto-gpr-with feature to the crate configuration * Fix review comments --- doc/catalog-format-spec.md | 24 ++++ doc/user-changes.md | 8 ++ src/alire/alire-config-edit.ads | 6 - src/alire/alire-crate_configuration.adb | 54 ++++++-- src/alire/alire-crate_configuration.ads | 12 +- src/alire/alire-properties-configurations.adb | 76 ++++++++++- src/alire/alire-properties-configurations.ads | 67 ++++++--- src/alire/alire-utils.ads | 3 +- src/alr/alr-commands-init.adb | 17 +++ src/alr/alr-commands-withing.adb | 19 --- src/alr/alr-utils-auto_gpr_with.adb | 127 ------------------ src/alr/alr-utils-auto_gpr_with.ads | 14 -- .../my_index/hello_src/hello_world.gpr | 6 + .../my_index/hello_src/src/main.adb | 6 + .../he/hello_world/hello_world-0.1.0.toml | 16 +++ .../gen_control/my_index/index/index.toml | 1 + .../libcrate_config-1.0.0.toml | 22 +++ .../libcrate_config_src/libcrate_config.gpr | 8 ++ .../my_index/libcrate_config_src/src/plop.adb | 22 +++ .../my_index/libcrate_config_src/src/plop.ads | 3 + .../tests/crate_config/gen_control/test.py | 35 +++++ .../tests/crate_config/gen_control/test.yaml | 4 + .../with/auto-gpr-with/gpr_in_subdir/test.py | 5 +- .../tests/workflows/init-options/test.py | 6 + 24 files changed, 347 insertions(+), 214 deletions(-) delete mode 100644 src/alr/alr-utils-auto_gpr_with.adb delete mode 100644 src/alr/alr-utils-auto_gpr_with.ads create mode 100644 testsuite/tests/crate_config/gen_control/my_index/hello_src/hello_world.gpr create mode 100644 testsuite/tests/crate_config/gen_control/my_index/hello_src/src/main.adb create mode 100644 testsuite/tests/crate_config/gen_control/my_index/index/he/hello_world/hello_world-0.1.0.toml create mode 100644 testsuite/tests/crate_config/gen_control/my_index/index/index.toml create mode 100644 testsuite/tests/crate_config/gen_control/my_index/index/li/libcrate_config/libcrate_config-1.0.0.toml create mode 100644 testsuite/tests/crate_config/gen_control/my_index/libcrate_config_src/libcrate_config.gpr create mode 100644 testsuite/tests/crate_config/gen_control/my_index/libcrate_config_src/src/plop.adb create mode 100644 testsuite/tests/crate_config/gen_control/my_index/libcrate_config_src/src/plop.ads create mode 100644 testsuite/tests/crate_config/gen_control/test.py create mode 100644 testsuite/tests/crate_config/gen_control/test.yaml diff --git a/doc/catalog-format-spec.md b/doc/catalog-format-spec.md index 069a9ce3..8775e95c 100644 --- a/doc/catalog-format-spec.md +++ b/doc/catalog-format-spec.md @@ -425,6 +425,30 @@ static, i.e. they cannot depend on the context. notes = "Experimental version" ``` + - `configuration` optional table to control crate configuration code + generators: + + For more information on crate configuration, see [Using crate + configuration](#using-crate-configuration). + + - `disabled`: Completely disable configuration code generation for the + crate (default: `false`) + + - `output_dir`: Path to the directory where the configuration code will + be generated, relative to the crate root (default: `config`). + + - `generate_ada`: Enable generation of Ada configuration (default: + `true`). + + - `generate_gpr`: Enable generation of GPR file configuration (default: + `true`). + + - `generate_c`: Enable generation of C configuration (default: `true`). + + - `auto_gpr_with`: Enabled generation of list of withed project in the + GPR file configuration (default: `true`). + + - `configuration.variables` optional table of crate configuration variable definitions. diff --git a/doc/user-changes.md b/doc/user-changes.md index 1e17892a..14245ecc 100644 --- a/doc/user-changes.md +++ b/doc/user-changes.md @@ -6,6 +6,14 @@ stay on top of `alr` new features. ## Release `1.1` +### Automatic GPR 'with' now in crate configuration + +PR [#740](https://github.com/alire-project/alire/pull/740). + +When adding or removing dependency with `alr with`, the list of `with` +statement for each project files of the dependencies is now automatically added +to the GPR crate configuration file instead of the root project file. + ### Git remotes for pinned releases PR [#715](https://github.com/alire-project/alire/pull/715) diff --git a/src/alire/alire-config-edit.ads b/src/alire/alire-config-edit.ads index 1dd345e5..66944653 100644 --- a/src/alire/alire-config-edit.ads +++ b/src/alire/alire-config-edit.ads @@ -120,12 +120,6 @@ private +("Directory where Alire will detect and/or install" & " msys2 system package manager. (Windows only)")), - (+"auto-gpr-with", - Cfg_Bool, - +("If true, Alire will automatically add/edit a list of 'with' " & - "statements in the root GPR project file based on the " & - "dependencies of the crate.")), - (+Keys.Update_Manually, Cfg_Bool, +("If true, Alire will not attempt to update dependencies even after " diff --git a/src/alire/alire-crate_configuration.adb b/src/alire/alire-crate_configuration.adb index 814bf9da..4551da18 100644 --- a/src/alire/alire-crate_configuration.adb +++ b/src/alire/alire-crate_configuration.adb @@ -55,6 +55,22 @@ package body Alire.Crate_Configuration is use Alire.Origins; Solution : constant Solutions.Solution := Root.Solution; + + function Get_Config_Entry (Rel : Releases.Release) return Config_Entry is + begin + for Prop of Rel.On_Platform_Properties (Root.Environment, + Config_Entry'Tag) + loop + return Config_Entry (Prop); + end loop; + + -- No Config_Entry found, return the default Config_Entry + declare + Ret : Config_Entry; + begin + return Ret; + end; + end Get_Config_Entry; begin if not Solution.Is_Complete then @@ -69,22 +85,36 @@ package body Alire.Crate_Configuration is if Rel.Origin.Kind /= Alire.Origins.External then declare + Ent : constant Config_Entry := Get_Config_Entry (Rel); + Conf_Dir : constant Absolute_Path := - Root.Release_Base (Rel.Name) / "config"; + Root.Release_Base (Rel.Name) / Ent.Output_Dir; begin - Ada.Directories.Create_Path (Conf_Dir); - - This.Generate_Ada_Config - (Rel.Name, Conf_Dir / (+Rel.Name & "_config.ads")); - - This.Generate_GPR_Config - (Rel.Name, - Conf_Dir / (+Rel.Name & "_config.gpr"), - Root.Direct_Withs (Rel)); - This.Generate_C_Config - (Rel.Name, Conf_Dir / (+Rel.Name & "_config.h")); + if not Ent.Disabled then + Ada.Directories.Create_Path (Conf_Dir); + + if Ent.Generate_Ada then + This.Generate_Ada_Config + (Rel.Name, Conf_Dir / (+Rel.Name & "_config.ads")); + end if; + + if Ent.Generate_GPR then + This.Generate_GPR_Config + (Rel.Name, + Conf_Dir / (+Rel.Name & "_config.gpr"), + (if Ent.Auto_GPR_With + then Root.Direct_Withs (Rel) + else Alire.Utils.Empty_Set)); + end if; + + if Ent.Generate_C then + This.Generate_C_Config + (Rel.Name, Conf_Dir / (+Rel.Name & "_config.h")); + end if; + end if; end; + end if; end loop; end Generate_Config_Files; diff --git a/src/alire/alire-crate_configuration.ads b/src/alire/alire-crate_configuration.ads index d162c414..4cef7e72 100644 --- a/src/alire/alire-crate_configuration.ads +++ b/src/alire/alire-crate_configuration.ads @@ -47,13 +47,13 @@ private -- Use default value for unset variable, raise Checked_Error if a variable -- has no default value. - procedure Load_Definitions (This : in out Global_Config; - Root : in out Roots.Root; - Crate : Crate_Name); + procedure Load_Definitions (This : in out Global_Config; + Root : in out Roots.Root; + Crate : Crate_Name); - procedure Load_Settings (This : in out Global_Config; - Root : in out Roots.Root; - Crate : Crate_Name); + procedure Load_Settings (This : in out Global_Config; + Root : in out Roots.Root; + Crate : Crate_Name); procedure Generate_Ada_Config (This : Global_Config; Crate : Crate_Name; diff --git a/src/alire/alire-properties-configurations.adb b/src/alire/alire-properties-configurations.adb index fb37643c..a03fa2bb 100644 --- a/src/alire/alire-properties-configurations.adb +++ b/src/alire/alire-properties-configurations.adb @@ -164,6 +164,23 @@ package body Alire.Properties.Configurations is Image (This.Int_Last)) ); + ------------- + -- To_TOML -- + ------------- + + overriding + function To_TOML (This : Config_Entry) return TOML.TOML_Value is + Table : constant TOML.TOML_Value := TOML.Create_Table; + begin + Table.Set ("output_dir", Create_String (This.Output_Dir)); + Table.Set ("disabled", Create_Boolean (This.Disabled)); + Table.Set ("generate_ada", Create_Boolean (This.Gen_Ada)); + Table.Set ("generate_gpr", Create_Boolean (This.Gen_GPR)); + Table.Set ("generate_c", Create_Boolean (This.Gen_C)); + Table.Set ("auto_gpr_with", Create_Boolean (This.Auto_GPR_With)); + return Table; + end To_TOML; + ----------- -- Image -- ----------- @@ -796,9 +813,10 @@ package body Alire.Properties.Configurations is (TOML_Keys.Configuration, TOML_Table), TOML_Keys.Configuration); + Ent : Config_Entry; begin return Props : Conditional.Properties do - while True loop + loop declare Val : TOML_Value; Key : constant String := Config.Pop (Val); @@ -810,22 +828,68 @@ package body Alire.Properties.Configurations is if Key = Utils.Tail (TOML_Keys.Config_Vars, '.') then Nested := Definitions_From_TOML (From.Descend (Key, Val, "variables")); + elsif Key = Utils.Tail (TOML_Keys.Config_Values, '.') then Nested := Assignments_From_TOML (From.Descend (Key, Val, "settings")); + + elsif Key = "output_dir" then + if Val.Kind = TOML_String then + Ent.Output_Dir := Val.As_Unbounded_String; + else + Raise_Checked_Error ("invalid value for: " & Key & + "(string expected)"); + end if; + + elsif Key = "generate_ada" then + if Val.Kind = TOML_Boolean then + Ent.Gen_Ada := Val.As_Boolean; + else + Raise_Checked_Error ("invalid value for: " & Key & + "(boolean expected)"); + end if; + + elsif Key = "generate_gpr" then + if Val.Kind = TOML_Boolean then + Ent.Gen_GPR := Val.As_Boolean; + else + Raise_Checked_Error ("invalid value for: " & Key & + "(Boolean expected)"); + end if; + + elsif Key = "generate_c" then + if Val.Kind = TOML_Boolean then + Ent.Gen_C := Val.As_Boolean; + else + Raise_Checked_Error ("invalid value for: " & Key & + "(Boolean expected)"); + end if; + + elsif Key = "auto_gpr_with" then + if Val.Kind = TOML_Boolean then + Ent.Auto_GPR_With := Val.As_Boolean; + else + Raise_Checked_Error ("invalid value for: " & Key & + "(Boolean expected)"); + end if; + + elsif Key = "disabled" then + if Val.Kind = TOML_Boolean then + Ent.Disabled := Val.As_Boolean; + else + Raise_Checked_Error ("invalid value for: " & Key & + "(Boolean expected)"); + end if; + else Raise_Checked_Error ("Unknown configuration entry: " & Key); end if; - Props.Append (Nested); end; end loop; - if Props.Is_Empty then - Props := Conditional.New_Property - (Config_Entry'(Property with null record)); - end if; + Props.Append (Conditional.For_Properties.New_Value (Ent)); end return; end Config_Entry_From_TOML; diff --git a/src/alire/alire-properties-configurations.ads b/src/alire/alire-properties-configurations.ads index 272579ee..08c82026 100644 --- a/src/alire/alire-properties-configurations.ads +++ b/src/alire/alire-properties-configurations.ads @@ -35,9 +35,16 @@ package Alire.Properties.Configurations with Preelaborate is -- type of property, but also the children tables as same-level properties -- (top-level, or under a case). - type Config_Entry is new Properties.Property with null record; + type Config_Entry is new Properties.Property with private; -- This property is the [configuration] itself + function Output_Dir (This : Config_Entry) return Relative_Path; + function Generate_Ada (This : Config_Entry) return Boolean; + function Generate_GPR (This : Config_Entry) return Boolean; + function Generate_C (This : Config_Entry) return Boolean; + function Auto_GPR_With (This : Config_Entry) return Boolean; + function Disabled (This : Config_Entry) return Boolean; + type Config_Type_Definition (<>) is new Properties.Property with private; -- [configuration.variables] @@ -89,6 +96,44 @@ package Alire.Properties.Configurations with Preelaborate is private + type Config_Entry is new Properties.Property with record + Output_Dir : Ada.Strings.Unbounded.Unbounded_String := +"config"; + Gen_Ada : Boolean := True; + Gen_GPR : Boolean := True; + Gen_C : Boolean := True; + Auto_GPR_With : Boolean := True; + Disabled : Boolean := False; + end record; + + overriding + function Key (This : Config_Entry) return String + is (TOML_Keys.Configuration); + + overriding + function To_TOML (This : Config_Entry) return TOML.TOML_Value; + + overriding + function Image (This : Config_Entry) return String + is ("Configuration: no modifiers"); + -- In the future, we may have other settings here + + overriding + function To_YAML (This : Config_Entry) return String + is ("Configuration: no modifiers"); + + function Output_Dir (This : Config_Entry) return Relative_Path + is (Relative_Path (+This.Output_Dir)); + function Generate_Ada (This : Config_Entry) return Boolean + is (This.Gen_Ada); + function Generate_GPR (This : Config_Entry) return Boolean + is (This.Gen_GPR); + function Generate_C (This : Config_Entry) return Boolean + is (This.Gen_C); + function Auto_GPR_With (This : Config_Entry) return Boolean + is (This.Auto_GPR_With); + function Disabled (This : Config_Entry) return Boolean + is (This.Disabled); + type Config_Type_Kind is (Real, Int, Enum, Str, Bool); subtype Config_Integer is TOML.Any_Integer; @@ -140,24 +185,4 @@ private overriding function To_YAML (This : Config_Value_Assignment) return String; - -- top-level configuration -- - - overriding - function Key (This : Config_Entry) return String - is (TOML_Keys.Configuration); - - overriding - function To_TOML (This : Config_Entry) return TOML.TOML_Value - is (TOML.Create_Table); - -- Empty for now - - overriding - function Image (This : Config_Entry) return String - is ("Configuration: no modifiers"); - -- In the future, we may have other settings here - - overriding - function To_YAML (This : Config_Entry) return String - is ("Configuration: no modifiers"); - end Alire.Properties.Configurations; diff --git a/src/alire/alire-utils.ads b/src/alire/alire-utils.ads index 616db500..66846fa1 100644 --- a/src/alire/alire-utils.ads +++ b/src/alire/alire-utils.ads @@ -126,7 +126,8 @@ package Alire.Utils with Preelaborate is -- Convert between two vector types package String_Sets is new Ada.Containers.Indefinite_Ordered_Sets (String); - type String_Set is new String_Sets.Set with null record; + subtype String_Set is String_Sets.Set; + Empty_Set : String_Set renames String_Sets.Empty_Set; -------------------- -- String_Vectors -- diff --git a/src/alr/alr-commands-init.adb b/src/alr/alr-commands-init.adb index 531b0451..893df23b 100644 --- a/src/alr/alr-commands-init.adb +++ b/src/alr/alr-commands-init.adb @@ -46,6 +46,7 @@ package body Alr.Commands.Init is then Get_Current_Dir else Create (+Name, Normalize => True)); Src_Directory : constant Virtual_File := Directory / "src"; + Config_Directory : constant Virtual_File := Directory / "config"; File : TIO.File_Type; @@ -104,13 +105,28 @@ package body Alr.Commands.Init is procedure Generate_Project_File is Filename : constant String := +Full_Name (Directory / (+Lower_Name & ".gpr")); + + Config_Filename : constant String := + +Full_Name (Config_Directory / (+Lower_Name & "_config.gpr")); begin -- Use more than 80 colums for more readable strings pragma Style_Checks ("M200"); + + -- Config project file + if not Create (Config_Filename) then + Trace.Warning ("Cannot create '" & Config_Filename & "'"); + return; + end if; + Put_Line ("project " & Mixed_Name & "_Config is"); + TIO.Put (File, "end " & Mixed_Name & "_Config;"); + TIO.Close (File); + + -- Main project file if not Create (Filename) then Trace.Warning ("Cannot create '" & Filename & "'"); return; end if; + Put_Line ("with ""config/" & Lower_Name & "_config.gpr"";"); Put_Line ("project " & Mixed_Name & " is"); Put_New_Line; if For_Library then @@ -362,6 +378,7 @@ package body Alr.Commands.Init is .Make_Dir; if not Cmd.No_Skel then + Config_Directory.Make_Dir; Generate_Project_File; Src_Directory.Make_Dir; if For_Library then diff --git a/src/alr/alr-commands-withing.adb b/src/alr/alr-commands-withing.adb index 56b4458e..a107621f 100644 --- a/src/alr/alr-commands-withing.adb +++ b/src/alr/alr-commands-withing.adb @@ -8,7 +8,6 @@ with Alire.Dependencies.Diffs; with Alire.Index; with Alire.Manifest; with Alire.Milestones; -with Alire.OS_Lib; with Alire.Releases; with Alire.Roots.Optional; with Alire.Solutions; @@ -19,7 +18,6 @@ with Alire.Utils.User_Input; with Alr.Commands.User_Input; with Alr.OS_Lib; with Alr.Platform; -with Alr.Utils.Auto_GPR_With; with Semantic_Versioning.Extended; @@ -35,21 +33,6 @@ package body Alr.Commands.Withing is New_Deps : Alire.Conditional.Dependencies; Old_Solution : Alire.Solutions.Solution); - ------------------- - -- Auto_GPR_With -- - ------------------- - - procedure Auto_GPR_With (Cmd : in out Command) is - begin - for File of Cmd.Root.Release.Project_Files - (Cmd.Root.Environment, With_Path => True) - loop - Utils.Auto_GPR_With.Update - (Alire.OS_Lib."/" (Cmd.Root.Path, File), - Cmd.Root.Direct_Withs (Cmd.Root.Release)); - end loop; - end Auto_GPR_With; - --------- -- Add -- --------- @@ -354,8 +337,6 @@ package body Alr.Commands.Withing is Cmd.Set (New_Root); Cmd.Root.Set (Solution => New_Solution); Cmd.Root.Deploy_Dependencies; - - Cmd.Auto_GPR_With; end; end Replace_Current; diff --git a/src/alr/alr-utils-auto_gpr_with.adb b/src/alr/alr-utils-auto_gpr_with.adb deleted file mode 100644 index 6a09ffd7..00000000 --- a/src/alr/alr-utils-auto_gpr_with.adb +++ /dev/null @@ -1,127 +0,0 @@ -with Ada.Text_IO; use Ada.Text_IO; -with Ada.Directories; - -with Alire.Directories; -with Alire.Utils.User_Input; -with Alire.Config.Edit; -with Alire.Paths; - -package body Alr.Utils.Auto_GPR_With is - - Begin_Line : constant String := "-- begin auto-gpr-with --"; - End_Line : constant String := "-- end auto-gpr-with --"; - - ---------------- - -- Query_User -- - ---------------- - - function Query_User return Boolean is - use Alire.Utils.User_Input; - use Alire.Config; - - Result : Boolean; - begin - -- First check if user already configured the auto-gpr-with policy - if Defined ("auto-gpr-with") then - - Result := Get ("auto-gpr-with", False); - - if Result then - Trace.Info ("Auto-gpr-with enabled by configuration."); - else - Trace.Info ("Auto-gpr-with disabled by configuration."); - end if; - - return Result; - end if; - - -- If not, ask the user - Result := Query - (Question => "Do you want Alire to automatically update your project" & - " file with the new dependency solution?", - Valid => (Yes | No => True, others => False), - Default => Yes) = Yes; - - -- Offer to save this choice in configuration - if Query - (Question => "Do you want Alire to remember this choice?", - Valid => (Yes | No => True, others => False), - Default => No) = Yes - then - Edit.Set (Alire.Config.Edit.Filepath (Global), "auto-gpr-with", - (if Result then "true" else "false")); - end if; - - if not Result then - Trace.Detail ("Auto-gpr-with rejected by user."); - end if; - - return Result; - end Query_User; - - ------------ - -- Update -- - ------------ - - procedure Update (GPR_File : Alire.Absolute_Path; - Withs : Alire.Utils.String_Set) - is - In_File : Ada.Text_IO.File_Type; - Out_File : Ada.Text_IO.File_Type; - Tmp : Alire.Directories.Temp_File; - - Skip : Boolean := False; - begin - - if not Query_User then - return; - end if; - - Open (In_File, Ada.Text_IO.In_File, GPR_File); - Create (Out_File, Ada.Text_IO.Out_File, Tmp.Filename); - - -- First add the new auto-with section to the output file, if any - if not Withs.Is_Empty then - Put_Line (Out_File, Begin_Line); - Put_Line (Out_File, - "-- This section was automatically added by Alire"); - for File of Withs loop - Put_Line (Out_File, "with """ & File & """;"); - end loop; - Put_Line (Out_File, End_Line); - end if; - - -- Copy the content of the project file except the auto-with section, - -- if any. - loop - exit when End_Of_File (In_File); - - declare - In_Line : constant String := Get_Line (In_File); - begin - - if In_Line = Begin_Line then - Skip := True; - end if; - - if Skip then - Trace.Debug ("Autowith skip: " & In_Line); - if In_Line = End_Line then - Skip := False; - end if; - else - Put_Line (Out_File, In_Line); - end if; - end; - end loop; - - Close (In_File); - Close (Out_File); - - Alire.Directories.Backup_If_Existing - (GPR_File, - Base_Dir => Alire.Paths.Working_Folder_Inside_Root); - Ada.Directories.Copy_File (Tmp.Filename, GPR_File); - end Update; - -end Alr.Utils.Auto_GPR_With; diff --git a/src/alr/alr-utils-auto_gpr_with.ads b/src/alr/alr-utils-auto_gpr_with.ads deleted file mode 100644 index 55dcc47c..00000000 --- a/src/alr/alr-utils-auto_gpr_with.ads +++ /dev/null @@ -1,14 +0,0 @@ -with Alire.Utils; -with Alire; - -package Alr.Utils.Auto_GPR_With is - - procedure Update (GPR_File : Alire.Absolute_Path; - Withs : Alire.Utils.String_Set); - -- Update the list of with statement in project file. - -- - -- This is done in a specific section of the project file guarded by tokens - -- in comments. The previous list of "auto-withs" is completely removed and - -- replaced by the one provided in the Withs String_Set. - -end Alr.Utils.Auto_GPR_With; diff --git a/testsuite/tests/crate_config/gen_control/my_index/hello_src/hello_world.gpr b/testsuite/tests/crate_config/gen_control/my_index/hello_src/hello_world.gpr new file mode 100644 index 00000000..5a092227 --- /dev/null +++ b/testsuite/tests/crate_config/gen_control/my_index/hello_src/hello_world.gpr @@ -0,0 +1,6 @@ +with "libcrate_config.gpr"; + +project Hello_World is + for Source_Dirs use ("src"); + for Main use ("main.adb"); +end Hello_World; diff --git a/testsuite/tests/crate_config/gen_control/my_index/hello_src/src/main.adb b/testsuite/tests/crate_config/gen_control/my_index/hello_src/src/main.adb new file mode 100644 index 00000000..12cfabfb --- /dev/null +++ b/testsuite/tests/crate_config/gen_control/my_index/hello_src/src/main.adb @@ -0,0 +1,6 @@ +with Plop; + +procedure Main is +begin + Plop.Print; +end Main; diff --git a/testsuite/tests/crate_config/gen_control/my_index/index/he/hello_world/hello_world-0.1.0.toml b/testsuite/tests/crate_config/gen_control/my_index/index/he/hello_world/hello_world-0.1.0.toml new file mode 100644 index 00000000..296c2b96 --- /dev/null +++ b/testsuite/tests/crate_config/gen_control/my_index/index/he/hello_world/hello_world-0.1.0.toml @@ -0,0 +1,16 @@ +description = "\"Hello, world!\" demonstration project" +name = "hello_world" +version = "0.1.0" +licenses = "GPL-3.0-only" +maintainers = ["example@example.com"] +maintainers-logins = ["mylogin"] +executables=['main'] + +[origin] +url = "file:../../../hello_src" + +[[depends-on]] +libcrate_config = "*" + +[configuration] +disabled = true diff --git a/testsuite/tests/crate_config/gen_control/my_index/index/index.toml b/testsuite/tests/crate_config/gen_control/my_index/index/index.toml new file mode 100644 index 00000000..346c93fc --- /dev/null +++ b/testsuite/tests/crate_config/gen_control/my_index/index/index.toml @@ -0,0 +1 @@ +version = "1.0" diff --git a/testsuite/tests/crate_config/gen_control/my_index/index/li/libcrate_config/libcrate_config-1.0.0.toml b/testsuite/tests/crate_config/gen_control/my_index/index/li/libcrate_config/libcrate_config-1.0.0.toml new file mode 100644 index 00000000..c368ecd0 --- /dev/null +++ b/testsuite/tests/crate_config/gen_control/my_index/index/li/libcrate_config/libcrate_config-1.0.0.toml @@ -0,0 +1,22 @@ +description = "crate config demonstration project" +name = "libcrate_config" +version = "1.0.0" +licenses = "GPL-3.0-only" +maintainers = ["example@example.com"] +maintainers-logins = ["mylogin"] + +[origin] +url = "file:../../../libcrate_config_src" + +[configuration] +output_dir = "plop_config" +generate_c = false +generate_gpr = false + +[configuration.variables] +Var_Bool = {type="Boolean", default=true} +Var_String = {type="String", default="Test string."} +Var_Int = {type="Integer", first=-42, last=42, default=-1} +Var_Real = {type="Real", first=-42.0, last=42.0, default=-1.0} +Var_Enum = {type="Enum", values=["A", "B", "C"], default="B"} + diff --git a/testsuite/tests/crate_config/gen_control/my_index/libcrate_config_src/libcrate_config.gpr b/testsuite/tests/crate_config/gen_control/my_index/libcrate_config_src/libcrate_config.gpr new file mode 100644 index 00000000..124ef472 --- /dev/null +++ b/testsuite/tests/crate_config/gen_control/my_index/libcrate_config_src/libcrate_config.gpr @@ -0,0 +1,8 @@ +project Libcrate_Config is + for Source_Dirs use ("src", "config"); + for Languages use ("Ada"); + for Library_Name use "crate_config"; + for Library_Kind use "static"; + for Source_Dirs use ("src", "plop_config"); + +end Libcrate_Config; diff --git a/testsuite/tests/crate_config/gen_control/my_index/libcrate_config_src/src/plop.adb b/testsuite/tests/crate_config/gen_control/my_index/libcrate_config_src/src/plop.adb new file mode 100644 index 00000000..a8234644 --- /dev/null +++ b/testsuite/tests/crate_config/gen_control/my_index/libcrate_config_src/src/plop.adb @@ -0,0 +1,22 @@ +with Ada.Text_IO; use Ada.Text_IO; + +with Libcrate_Config_Config; use Libcrate_Config_Config; + +package body Plop is + + type My_Int_Type is range Var_Int_First .. Var_Int_Last; + My_Int : constant My_Int_Type := Var_Int; + + type My_Real_Type is digits 10 range Var_Real_First .. Var_Real_Last; + My_Real : constant My_Real_Type := Var_Real; + + procedure Print is + begin + Put_Line ("Ada -> Var_Bool: " & Libcrate_Config_Config.Var_Bool'Img); + Put_Line ("Ada -> Var_String: '" & Libcrate_Config_Config.Var_String & "'"); + Put_Line ("Ada -> Var_Int: " & My_Int'Img); + Put_Line ("Ada -> Var_Real: " & My_Real'Img); + Put_Line ("Ada -> Var_Enum: " & Libcrate_Config_Config.Var_Enum'Img); + end Print; + +end Plop; diff --git a/testsuite/tests/crate_config/gen_control/my_index/libcrate_config_src/src/plop.ads b/testsuite/tests/crate_config/gen_control/my_index/libcrate_config_src/src/plop.ads new file mode 100644 index 00000000..17a1e218 --- /dev/null +++ b/testsuite/tests/crate_config/gen_control/my_index/libcrate_config_src/src/plop.ads @@ -0,0 +1,3 @@ +package Plop is + procedure Print; +end Plop; diff --git a/testsuite/tests/crate_config/gen_control/test.py b/testsuite/tests/crate_config/gen_control/test.py new file mode 100644 index 00000000..8c12fb9b --- /dev/null +++ b/testsuite/tests/crate_config/gen_control/test.py @@ -0,0 +1,35 @@ +""" +Test basic crate configuration +""" + +from drivers.alr import run_alr +from drivers.asserts import assert_eq +from drivers.helpers import contents + +import os + +# Get and check post fetch action +run_alr('get', 'hello_world', quiet=False, debug=True) +os.chdir("hello_world_0.1.0_filesystem/") + +run_alr('build', quiet=False, debug=True) +p = run_alr('run') +assert_eq("Ada -> Var_Bool: TRUE\n" + "Ada -> Var_String: 'Test string.'\n" + "Ada -> Var_Int: -1\n" + "Ada -> Var_Real: -1.000000000E+00\n" + "Ada -> Var_Enum: B\n", + p.out) + +assert not os.path.isdir('config'), "config should not be created for root project" + +for top, dirs, files in os.walk('./'): + for nm in files: + path = os.path.join(top, nm) + if 'plop_config' in path: + assert not path.endswith('.h'), "C header should not be generated" + assert not path.endswith('.gpr'), "GPR should not be generated" + +print(p.out) + +print('SUCCESS') diff --git a/testsuite/tests/crate_config/gen_control/test.yaml b/testsuite/tests/crate_config/gen_control/test.yaml new file mode 100644 index 00000000..0a859639 --- /dev/null +++ b/testsuite/tests/crate_config/gen_control/test.yaml @@ -0,0 +1,4 @@ +driver: python-script +indexes: + my_index: + in_fixtures: false diff --git a/testsuite/tests/with/auto-gpr-with/gpr_in_subdir/test.py b/testsuite/tests/with/auto-gpr-with/gpr_in_subdir/test.py index 6709abf7..33a88b19 100644 --- a/testsuite/tests/with/auto-gpr-with/gpr_in_subdir/test.py +++ b/testsuite/tests/with/auto-gpr-with/gpr_in_subdir/test.py @@ -20,10 +20,11 @@ os.chdir(glob('myhello*')[0]) run_alr('with', 'libhello') run_alr('with', 'gpr_in_subdir') -check_line_in('myhello.gpr', 'with "libhello.gpr";') +check_line_in('config/myhello_config.gpr', 'with "libhello.gpr";') # When the crate declares a project file: `dir1/dir2/dir3/prj.gpr`, the with # statement has to be `with "prj.gpr"`. Without the sub-dirs because # GPR_PROJECT_PATH is already set with dirs that contain the project file. -check_line_in('myhello.gpr', 'with "gpr_in_subdir.gpr";') +check_line_in('config/myhello_config.gpr', 'with "gpr_in_subdir.gpr";') + print('SUCCESS') diff --git a/testsuite/tests/workflows/init-options/test.py b/testsuite/tests/workflows/init-options/test.py index 06e1ec4c..5ee8eb1a 100644 --- a/testsuite/tests/workflows/init-options/test.py +++ b/testsuite/tests/workflows/init-options/test.py @@ -21,6 +21,8 @@ compare(contents('xxx'), ['xxx/.gitignore', 'xxx/alire', 'xxx/alire.lock', 'xxx/alire.toml', + 'xxx/config', + 'xxx/config/xxx_config.gpr', 'xxx/src', 'xxx/src/xxx.adb', 'xxx/xxx.gpr']) @@ -33,6 +35,8 @@ compare(contents('aaa'), ['aaa/.gitignore', 'aaa/alire', 'aaa/alire.lock', 'aaa/alire.toml', + 'aaa/config', + 'aaa/config/aaa_config.gpr', 'aaa/src', 'aaa/src/aaa.adb']) @@ -69,6 +73,8 @@ compare(contents('.'), ['./.gitignore', './alire', './alire.lock', './alire.toml', + './config', + './config/zzz_config.gpr', './src', './src/zzz.adb', './zzz.gpr']) -- 2.39.5