From 8b908a6fd71a55e95bb7f2ff5d649424b0fe2c7d Mon Sep 17 00:00:00 2001 From: Fabien Chouteau Date: Thu, 2 Jul 2020 16:10:08 +0200 Subject: [PATCH] implementation of an automatic gpr file with (#458) * First prototype implementation of an automatic gpr file with * Add user query and config option for Auto-gpr-with * Introduce Boolean properties * Alire.Properties.Labeled: check TOML_Kind for labels * auto-gpr-with: add crate entry to disable auto-gpr-with feature * testsuite: allow custom indexes to reference fixtures/crates/ This removes duplication of several sources and archives. * Bump index version to 0.3 for auto-gpr-with feature * auto-gpr-with: do not add default project file for extern crates * Bump alire-index in CI scripts * tests/workflows/auto-gpr-with: rename test crate to avoid conflicts with scripts * Review fixes * tests/get/external-tool-dependency: make the test more robust On Windows when using msys2, the make seen by alr can be different than the one seen from the testsuite scripts. The means that the current way to identify make's version will fail in some cases. This patch introduces a different way to workaround the different version numbers of make. --- doc/catalog-format-spec.md | 7 + doc/user-changes.md | 29 ++++ src/alire/alire-config.ads | 9 +- src/alire/alire-index.ads | 2 +- src/alire/alire-properties-bool.adb | 65 +++++++++ src/alire/alire-properties-bool.ads | 72 ++++++++++ src/alire/alire-properties-from_toml.ads | 4 + src/alire/alire-properties-labeled.adb | 5 + src/alire/alire-releases.adb | 29 +++- src/alire/alire-releases.ads | 2 + src/alire/alire-roots.adb | 29 ++++ src/alire/alire-roots.ads | 15 +++ src/alire/alire-toml_keys.ads | 1 + src/alr/alr-commands-withing.adb | 17 +++ src/alr/alr-utils-auto_gpr_with.adb | 125 ++++++++++++++++++ src/alr/alr-utils-auto_gpr_with.ads | 14 ++ testsuite/drivers/alr.py | 8 ++ testsuite/drivers/helpers.py | 15 --- testsuite/fix-versions.sh | 4 +- testsuite/fixtures/basic_index/index.toml | 2 +- testsuite/fixtures/cases_index/index.toml | 2 +- testsuite/fixtures/checked_index/index.toml | 2 +- testsuite/fixtures/git_index/index.toml | 2 +- testsuite/fixtures/native_index/index.toml | 2 +- testsuite/fixtures/run_index/index.toml | 2 +- testsuite/fixtures/solver_index/index.toml | 2 +- .../local-index/my_index/index/index.toml | 2 +- .../tests/get/build/my_index/index/index.toml | 2 +- .../my_index/crates/noop_1.0.tgz | Bin 436 -> 0 bytes .../my_index/index/index.toml | 2 +- .../my_index/index/ma/main.toml | 2 +- .../get/external-tool-dependency/test.py | 22 +-- .../get/external-tool-dependency/test.yaml | 1 + .../indirect-link/my_index/index/index.toml | 2 +- .../my_index/index/index.toml | 2 +- .../my_index/index/index.toml | 2 +- .../bad-license/my_index/index/index.toml | 2 +- .../index/bad-tag/my_index/index/index.toml | 2 +- .../index/empty-tag/my_index/index/index.toml | 2 +- .../environment/my_index/index/index.toml | 2 +- .../external-available/my_index/index.toml | 2 +- .../my_index/index/index.toml | 2 +- .../my_index/cr/crate_master.toml | 2 +- .../index/external-hint/my_index/index.toml | 2 +- .../index/external-hint/my_index/noop_1.0.tgz | Bin 436 -> 0 bytes testsuite/tests/index/external-hint/test.yaml | 1 + .../my_index/crates/noop_1.0.tgz | Bin 436 -> 0 bytes .../external-msys2/my_index/index/index.toml | 2 +- .../my_index/index/ma/main.toml | 2 +- .../tests/index/external-msys2/test.yaml | 1 + .../my_index/index/index.toml | 2 +- .../my_index/index/index.toml | 2 +- .../index/long-tag/my_index/index/index.toml | 2 +- .../maint-bad-email/my_index/index/index.toml | 2 +- .../maint-bad-login/my_index/index/index.toml | 2 +- .../bad_index_1/index.toml | 2 +- .../bad_index_2/index.toml | 2 +- .../my_index/index/index.toml | 2 +- .../my_index/index/index.toml | 2 +- .../my_index/index/index.toml | 2 +- .../tests/pin/all/my_index/index/index.toml | 2 +- .../pin/change-type/my_index/index/index.toml | 2 +- .../pin/downgrade/my_index/index/index.toml | 2 +- .../crates/libhello_1.0.0/libhello.gpr | 24 ---- .../crates/libhello_1.0.0/src/libhello.ads | 3 - .../my_index/index/index.toml | 2 +- .../tests/pin/pin-dir-with-regular/test.yaml | 1 + .../crates/libhello_1.0.0/libhello.gpr | 24 ---- .../crates/libhello_1.0.0/src/libhello.ads | 3 - .../pin/pin-dir/my_index/index/index.toml | 2 +- testsuite/tests/pin/pin-dir/test.yaml | 1 + .../pin/post-update/my_index/index/index.toml | 2 +- .../unneeded-held/my_index/index/index.toml | 2 +- .../action-test/my_index/index/index.toml | 2 +- .../selective/my_index/index/index.toml | 2 +- .../my_index/updated/index/index.toml | 2 +- .../with/pin-dir/my_index/index/index.toml | 2 +- .../action-command/my_index/index/index.toml | 2 +- .../my_index/index/ex/extern.toml | 11 ++ .../auto-gpr-with/my_index/index/index.toml | 1 + .../my_index/index/li/libhello_nogprwith.toml | 11 ++ .../tests/workflows/auto-gpr-with/test.py | 49 +++++++ .../tests/workflows/auto-gpr-with/test.yaml | 7 + 83 files changed, 575 insertions(+), 129 deletions(-) create mode 100644 src/alire/alire-properties-bool.adb create mode 100644 src/alire/alire-properties-bool.ads create mode 100644 src/alr/alr-utils-auto_gpr_with.adb create mode 100644 src/alr/alr-utils-auto_gpr_with.ads delete mode 100644 testsuite/tests/get/external-tool-dependency/my_index/crates/noop_1.0.tgz delete mode 100644 testsuite/tests/index/external-hint/my_index/noop_1.0.tgz delete mode 100644 testsuite/tests/index/external-msys2/my_index/crates/noop_1.0.tgz delete mode 100644 testsuite/tests/pin/pin-dir-with-regular/my_index/crates/libhello_1.0.0/libhello.gpr delete mode 100644 testsuite/tests/pin/pin-dir-with-regular/my_index/crates/libhello_1.0.0/src/libhello.ads delete mode 100644 testsuite/tests/pin/pin-dir/my_index/crates/libhello_1.0.0/libhello.gpr delete mode 100644 testsuite/tests/pin/pin-dir/my_index/crates/libhello_1.0.0/src/libhello.ads create mode 100644 testsuite/tests/workflows/auto-gpr-with/my_index/index/ex/extern.toml create mode 100644 testsuite/tests/workflows/auto-gpr-with/my_index/index/index.toml create mode 100644 testsuite/tests/workflows/auto-gpr-with/my_index/index/li/libhello_nogprwith.toml create mode 100644 testsuite/tests/workflows/auto-gpr-with/test.py create mode 100644 testsuite/tests/workflows/auto-gpr-with/test.yaml diff --git a/doc/catalog-format-spec.md b/doc/catalog-format-spec.md index 24c7d443..8c651081 100644 --- a/doc/catalog-format-spec.md +++ b/doc/catalog-format-spec.md @@ -350,6 +350,13 @@ entries: # An explicit empty case alternative, which is not mandatory ``` + - `auto-gpr-with`: Boolean value that specifies if the project files of a + crate can be automatically 'withed' by the root project file (default is + true). This feature is meant to simplify the process of using dependencies + in Alire. However, not all project files are supposed to be withed, some can + be extended for instance, in that case a crate can disable the feature by + setting `auto-gpr-with=false`. + ## Release-specific information Each release is materialized as an entry in the top-level object. The key is a diff --git a/doc/user-changes.md b/doc/user-changes.md index aa268796..31bd9d60 100644 --- a/doc/user-changes.md +++ b/doc/user-changes.md @@ -4,6 +4,35 @@ This document is a development diary summarizing changes in `alr` that notably affect the user experience. It is intended as a one-stop point for users to stay on top of `alr` new features. +### Automatically 'with' GPR project files from dependencies + +PR [#458](https://github.com/alire-project/alire/pull/458). + +When adding or removing dependency with `alr with`, a list of `with` statement +for each project files of the dependencies can be automatically added to the +root project file: +``` +-- begin auto-gpr-with -- +-- This section was automatically added by Alire +with "libhello.gpr"; +-- end auto-gpr-with -- + +project Test is +... +``` + +This feature can be permanently enabled or disabled with a local or global +configuration option: +```bash +alr config --global --set auto-gpr-with false +``` + +Crates with project files not compatible with this feature can disable it using +the `auto-gpr-with` entry: +```toml +auto-gpr-with=false +``` + ### Show release-specific dependency sets in solutions PR [#453](https://github.com/alire-project/alire/pull/453). diff --git a/src/alire/alire-config.ads b/src/alire/alire-config.ads index f1bf808b..d05a38aa 100644 --- a/src/alire/alire-config.ads +++ b/src/alire/alire-config.ads @@ -184,7 +184,14 @@ private (+"msys2.install_dir", Cfg_Absolute_Path, +("Directory where Alire will detect and/or install" & - " msys2 system package manager. (Windows only) ")) + " 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.")) + ); end Alire.Config; diff --git a/src/alire/alire-index.ads b/src/alire/alire-index.ads index 965d8131..73be1860 100644 --- a/src/alire/alire-index.ads +++ b/src/alire/alire-index.ads @@ -35,7 +35,7 @@ package Alire.Index is and then Branch_String (Branch_String'Last) /= '-' and then (for some C of Branch_String => C = '-'); - Community_Branch : constant String := "devel-0.2"; + Community_Branch : constant String := "devel-0.3"; -- The branch used for the community index Version : constant Semantic_Versioning.Version := diff --git a/src/alire/alire-properties-bool.adb b/src/alire/alire-properties-bool.adb new file mode 100644 index 00000000..86d38907 --- /dev/null +++ b/src/alire/alire-properties-bool.adb @@ -0,0 +1,65 @@ +package body Alire.Properties.Bool is + + --------------- + -- From_TOML -- + --------------- + + function From_TOML (From : TOML_Adapters.Key_Queue) + return Conditional.Properties + is + Value : TOML.TOML_Value; + Key : constant String := From.Pop (Value); + + ------------------ + -- Key_To_Label -- + ------------------ + + function Key_To_Label (K : String) return Labels is + begin + -- TODO: instead of this inefficient O(n) lookup, have a map. + for L in Labels loop + if Bool.Key (L) = K then + return L; + end if; + end loop; + From.Checked_Error ("Key is not a valid boolean property: " & K); + end Key_To_Label; + + -- For conditional loading, we use specific conditional loaders that + -- only recognize the property being loaded: + + begin + return Props : Conditional.Properties do + declare + Val : constant TOML.TOML_Value := TOML_Adapters.To_Array (Value); + -- We process the same way single values and arrays of values + -- (since they get converted into individual properties). + begin + if Val.Length > 1 then + raise Checked_Error with + "Expected single value for " & Key; + end if; + + if Val.Item (1).Kind /= TOML_Boolean then + raise Checked_Error with "Expected boolean value for " & Key; + end if; + + declare + L : constant Property := New_Property + (Key_To_Label (Key), + Val.Item (1).As_Boolean); + use all type Conditional.Properties; + begin + -- Labeled property is valid and added to the release props. + Props := Props and + Conditional.For_Properties.New_Value (L); + end; + end; + end return; + exception + when E : others => + Log_Exception (E); + raise Checked_Error with "Cannot read valid property from " & Key; + end From_TOML; + +end Alire.Properties.Bool; diff --git a/src/alire/alire-properties-bool.ads b/src/alire/alire-properties-bool.ads new file mode 100644 index 00000000..3e7bc88c --- /dev/null +++ b/src/alire/alire-properties-bool.ads @@ -0,0 +1,72 @@ +with Alire.Conditional; +with Alire.GPR; +with Alire.TOML_Adapters; +with Alire.TOML_Keys; +with Alire.Utils; + +package Alire.Properties.Bool with Preelaborate is + + type Labels is + (Auto_GPR_With + -- Boolean to specify if a crate is compatible with the auto-gpr-with + -- feature. + ); + + type Property is new Properties.Property with private; + + function New_Property (Name : Labels; + V : Boolean) + return Property; + + overriding + function Image (V : Property) return String; + + overriding + function To_YAML (V : Property) return String; + + overriding + function Key (V : Property) return String; + + function Value (V : Property) return Boolean; + + function From_TOML (From : TOML_Adapters.Key_Queue) + return Conditional.Properties; +private + + function Key (L : Labels) return String + is (case L is + when Auto_GPR_With => TOML_Keys.Auto_GPR_With); + + type Property is new Properties.Property with record + Name : Labels; + Value : Boolean; + end record; + + overriding + function To_TOML (V : Property) return TOML.TOML_Value; + + function New_Property (Name : Labels; + V : Boolean) + return Property + is (Name => Name, Value => V); + + overriding + function Image (V : Property) return String + is (Utils.To_Mixed_Case (V.Name'Img) & ": " & V.To_YAML); + + overriding + function To_YAML (V : Property) return String + is (Key (V.Name) & "=" & (if V.Value then "true" else "false")); + + overriding + function To_TOML (V : Property) return TOML.TOML_Value + is (TOML.Create_Boolean (V.Value)); + + overriding + function Key (V : Property) return String + is (Key (V.Name)); + + function Value (V : Property) return Boolean + is (V.Value); + +end Alire.Properties.Bool; diff --git a/src/alire/alire-properties-from_toml.ads b/src/alire/alire-properties-from_toml.ads index 8bc3c51c..8ae5fd50 100644 --- a/src/alire/alire-properties-from_toml.ads +++ b/src/alire/alire-properties-from_toml.ads @@ -5,6 +5,7 @@ with Alire.Properties.Environment; with Alire.Properties.Labeled; with Alire.Properties.Licenses; with Alire.Properties.Scenarios; +with Alire.Properties.Bool; with Alire.TOML_Adapters; package Alire.Properties.From_TOML with Preelaborate is @@ -13,6 +14,7 @@ package Alire.Properties.From_TOML with Preelaborate is type Property_Keys is (Actions, Authors, + Auto_GPR_With, Description, Environment, Executables, @@ -49,6 +51,7 @@ package Alire.Properties.From_TOML with Preelaborate is => Scenarios.From_TOML'Access, Hint => null, -- Only apply to externals Licenses => Properties.Licenses.From_TOML'Access, + Auto_GPR_With => Bool.From_TOML'Access, others => Labeled.From_TOML'Access); -- This loader is used in the [general] crate section @@ -62,6 +65,7 @@ package Alire.Properties.From_TOML with Preelaborate is => Scenarios.From_TOML'Access, Notes => Labeled.From_TOML'Access, Project_Files => Labeled.From_TOML'Access, + Auto_GPR_With => Bool.From_TOML'Access, others => null); -- This loader applies to release sections diff --git a/src/alire/alire-properties-labeled.adb b/src/alire/alire-properties-labeled.adb index ee1f60c3..69b6af9f 100644 --- a/src/alire/alire-properties-labeled.adb +++ b/src/alire/alire-properties-labeled.adb @@ -63,6 +63,11 @@ package body Alire.Properties.Labeled is -- (since they get converted into individual properties). begin for I in 1 .. Val.Length loop + + if Val.Item (I).Kind /= TOML_String then + raise Checked_Error with "Expected String value for " & Key; + end if; + declare L : constant Label := New_Label (Key_To_Label (Key), diff --git a/src/alire/alire-releases.adb b/src/alire/alire-releases.adb index 7286fb84..ef312975 100644 --- a/src/alire/alire-releases.adb +++ b/src/alire/alire-releases.adb @@ -5,6 +5,7 @@ with Alire.Defaults; with Alire.Requisites.Booleans; with Alire.TOML_Load; with Alire.Utils.YAML; +with Alire.Properties.Bool; with GNAT.IO; -- To keep preelaborable @@ -258,6 +259,10 @@ package body Alire.Releases is else Properties), Available => Requisites.Booleans.Always_True); + ------------------------- + -- On_Platform_Actions -- + ------------------------- + function On_Platform_Actions (R : Release; P : Alire.Properties.Vector; Moments : Moment_Array := (others => True)) @@ -380,7 +385,12 @@ package body Alire.Releases is Props_To_Strings (R.All_Properties (P), Project_File); Without : Utils.String_Vector; begin - if With_Paths.Is_Empty then + if With_Paths.Is_Empty + and then + R.Origin.Kind not in Origins.External | Origins.System + then + -- Default project file if no one is specified by the crate. Only if + -- the create is not external nor system. With_Paths.Append (String'((+R.Name) & ".gpr")); end if; @@ -423,6 +433,23 @@ package body Alire.Releases is end return; end Project_Paths; + ------------------- + -- Auto_GPR_With -- + ------------------- + + function Auto_GPR_With (R : Release) return Boolean is + Vect : constant Alire.Properties.Vector := + Conditional.Enumerate (R.Properties).Filter + (Alire.TOML_Keys.Auto_GPR_With); + begin + if not Vect.Is_Empty then + return Alire.Properties.Bool.Property (Vect.First_Element).Value; + else + -- The default is to enable auto-gpr-with + return True; + end if; + end Auto_GPR_With; + ------------------------ -- Labeled_Properties -- ------------------------ diff --git a/src/alire/alire-releases.ads b/src/alire/alire-releases.ads index 48e9dd43..c9ea8c96 100644 --- a/src/alire/alire-releases.ads +++ b/src/alire/alire-releases.ads @@ -245,6 +245,8 @@ package Alire.Releases with Preelaborate is function Tag (R : Release) return Alire.Properties.Vector; + function Auto_GPR_With (R : Release) return Boolean; + procedure Print (R : Release); -- Dump info to console diff --git a/src/alire/alire-roots.adb b/src/alire/alire-roots.adb index 8f46b5be..67c68264 100644 --- a/src/alire/alire-roots.adb +++ b/src/alire/alire-roots.adb @@ -100,4 +100,33 @@ package body Alire.Roots is return Paths; end Project_Paths; + ----------------------- + -- GPR_Project_Files -- + ----------------------- + + function GPR_Project_Files (This : Root; + Exclude_Root : Boolean) + return Utils.String_Set + is + Files : Utils.String_Set; + begin + + -- Add files from every release in the solution + + for Rel of This.Solution.Releases.Including (Release (This)) loop + + if (not Exclude_Root or else Rel.Name /= Release (This).Name) + and then + Rel.Auto_GPR_With + then + for File of Rel.Project_Files + (This.Environment, With_Path => False) + loop + Files.Include (File); + end loop; + end if; + end loop; + return Files; + end GPR_Project_Files; + end Alire.Roots; diff --git a/src/alire/alire-roots.ads b/src/alire/alire-roots.ads index ee0a6552..c48d6690 100644 --- a/src/alire/alire-roots.ads +++ b/src/alire/alire-roots.ads @@ -70,6 +70,14 @@ package Alire.Roots is -- solution in this root. This includes al releases' paths and any linked -- directories. + function GPR_Project_Files (This : Root; + Exclude_Root : Boolean) + return Utils.String_Set with + Pre => This.Is_Valid; + -- Return all the gprbuild project files defined for the solution in this + -- root. If Exclude_Root is True, the project files of the root crate are + -- excluded from the result. + function Release (This : Root) return Releases.Release with Pre => This.Is_Valid; @@ -77,6 +85,10 @@ package Alire.Roots is Pre => This.Is_Valid; -- Returns the solution stored in the lockfile + function Environment (This : Root) return Properties.Vector with + Pre => This.Is_Valid; + -- Properties of the Root + -- files and folders derived from the root path (this obsoletes Alr.Paths) function Working_Folder (This : Root) return Absolute_Path with @@ -155,4 +167,7 @@ private function Working_Folder (This : Root) return Absolute_Path is ((+This.Path) / "alire"); + function Environment (This : Root) return Properties.Vector + is (This.Environment); + end Alire.Roots; diff --git a/src/alire/alire-toml_keys.ads b/src/alire/alire-toml_keys.ads index f78b9755..1ee2d2af 100644 --- a/src/alire/alire-toml_keys.ads +++ b/src/alire/alire-toml_keys.ads @@ -8,6 +8,7 @@ package Alire.TOML_Keys with Preelaborate is Action_Folder : constant String := "directory"; Archive_Name : constant String := "archive-name"; Author : constant String := "authors"; + Auto_GPR_With : constant String := "auto-gpr-with"; Available : constant String := "available"; Compiler : constant String := "compiler"; Depends_On : constant String := "depends-on"; diff --git a/src/alr/alr-commands-withing.adb b/src/alr/alr-commands-withing.adb index 1dd2568b..b4fd35ed 100644 --- a/src/alr/alr-commands-withing.adb +++ b/src/alr/alr-commands-withing.adb @@ -18,6 +18,7 @@ with Alr.Commands.User_Input; with Alr.OS_Lib; with Alr.Platform; with Alr.Root; +with Alr.Utils.Auto_GPR_With; with Semantic_Versioning.Extended; @@ -30,6 +31,21 @@ package body Alr.Commands.Withing is New_Deps : Alire.Conditional.Dependencies; Old_Solution : Alire.Solutions.Solution := Root.Current.Solution); + ------------------- + -- Auto_GPR_With -- + ------------------- + + procedure Auto_GPR_With is + begin + for File of Root.Current.Release.Project_Files + (Root.Current.Environment, With_Path => True) + loop + Utils.Auto_GPR_With.Update + (Alire.Directories."/" (Root.Current.Path, File), + Root.Current.GPR_Project_Files (Exclude_Root => True)); + end loop; + end Auto_GPR_With; + --------- -- Add -- --------- @@ -237,6 +253,7 @@ package body Alr.Commands.Withing is Root => New_Root, Solution => New_Solution); + 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 new file mode 100644 index 00000000..fa1130bf --- /dev/null +++ b/src/alr/alr-utils-auto_gpr_with.adb @@ -0,0 +1,125 @@ +with Ada.Text_IO; use Ada.Text_IO; +with Ada.Directories; + +with Alire.Directories; +with Alire.Utils.User_Input; +with Alire.Config; +with Alire.Config.Edit; + +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.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); + 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 new file mode 100644 index 00000000..55dcc47c --- /dev/null +++ b/src/alr/alr-utils-auto_gpr_with.ads @@ -0,0 +1,14 @@ +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/drivers/alr.py b/testsuite/drivers/alr.py index 4402d27a..e826e144 100644 --- a/testsuite/drivers/alr.py +++ b/testsuite/drivers/alr.py @@ -4,6 +4,7 @@ Helpers to run alr in the testsuite. import os.path +from shutil import copytree from e3.os.process import Run, quote_arg from e3.fs import mkdir from e3.testsuite.driver.classic import ProcessResult @@ -128,6 +129,9 @@ def prepare_indexes(config_dir, working_dir, index_descriptions): in_fixtures = desc.pop('in_fixtures', True) check_type('"in_fixtures"', 'a boolean', in_fixtures, bool) + copy_crates_src = desc.pop('copy_crates_src', False) + check_type('"copy_crates_src"', 'a boolean', copy_crates_src, bool) + priority = desc.pop('priority', 1) check_type('"priority"', 'an integer', priority, int) @@ -140,6 +144,10 @@ def prepare_indexes(config_dir, working_dir, index_descriptions): if in_fixtures else files_dir) + if copy_crates_src: + crates_dir = fixtures_path('crates') + copytree(crates_dir, os.path.join (working_dir, name, 'crates')) + # Finally create the index description in the config directory index_dir = os.path.join(indexes_dir, name) mkdir(index_dir) diff --git a/testsuite/drivers/helpers.py b/testsuite/drivers/helpers.py index 7b38dee9..da571f2f 100644 --- a/testsuite/drivers/helpers.py +++ b/testsuite/drivers/helpers.py @@ -5,21 +5,6 @@ Assorted helpers that are reused by several tests. import os -# Check a file contains a concrete line -def check_line_in(filename, line): - """ - Assert that the `filename` text file contains at least one line that - contains `line`. - """ - with open(filename, 'r') as f: - for l in f: - if l.rstrip() == line: - break - else: - assert False, 'Could not find {} in {}'.format( - repr(line), filename) - - # Return the entries (sorted) under a given folder, both folders and files def contents(dir): assert os.path.exists(dir), "Bad path for enumeration: {}".format(dir) diff --git a/testsuite/fix-versions.sh b/testsuite/fix-versions.sh index 40639a0f..19c75eb6 100755 --- a/testsuite/fix-versions.sh +++ b/testsuite/fix-versions.sh @@ -1,6 +1,6 @@ #!/bin/bash -oldversion=0.1 -newversion=0.2 +oldversion=0.2 +newversion=0.3 find . -type f -name index.toml -exec sed -i "s/$oldversion/$newversion/" {} \; diff --git a/testsuite/fixtures/basic_index/index.toml b/testsuite/fixtures/basic_index/index.toml index 7c969026..319b3b37 100644 --- a/testsuite/fixtures/basic_index/index.toml +++ b/testsuite/fixtures/basic_index/index.toml @@ -1 +1 @@ -version = "0.2" +version = "0.3" diff --git a/testsuite/fixtures/cases_index/index.toml b/testsuite/fixtures/cases_index/index.toml index 7c969026..319b3b37 100644 --- a/testsuite/fixtures/cases_index/index.toml +++ b/testsuite/fixtures/cases_index/index.toml @@ -1 +1 @@ -version = "0.2" +version = "0.3" diff --git a/testsuite/fixtures/checked_index/index.toml b/testsuite/fixtures/checked_index/index.toml index 7c969026..319b3b37 100644 --- a/testsuite/fixtures/checked_index/index.toml +++ b/testsuite/fixtures/checked_index/index.toml @@ -1 +1 @@ -version = "0.2" +version = "0.3" diff --git a/testsuite/fixtures/git_index/index.toml b/testsuite/fixtures/git_index/index.toml index 7c969026..319b3b37 100644 --- a/testsuite/fixtures/git_index/index.toml +++ b/testsuite/fixtures/git_index/index.toml @@ -1 +1 @@ -version = "0.2" +version = "0.3" diff --git a/testsuite/fixtures/native_index/index.toml b/testsuite/fixtures/native_index/index.toml index 7c969026..319b3b37 100644 --- a/testsuite/fixtures/native_index/index.toml +++ b/testsuite/fixtures/native_index/index.toml @@ -1 +1 @@ -version = "0.2" +version = "0.3" diff --git a/testsuite/fixtures/run_index/index.toml b/testsuite/fixtures/run_index/index.toml index 7c969026..319b3b37 100644 --- a/testsuite/fixtures/run_index/index.toml +++ b/testsuite/fixtures/run_index/index.toml @@ -1 +1 @@ -version = "0.2" +version = "0.3" diff --git a/testsuite/fixtures/solver_index/index.toml b/testsuite/fixtures/solver_index/index.toml index 7c969026..319b3b37 100644 --- a/testsuite/fixtures/solver_index/index.toml +++ b/testsuite/fixtures/solver_index/index.toml @@ -1 +1 @@ -version = "0.2" +version = "0.3" diff --git a/testsuite/skels/local-index/my_index/index/index.toml b/testsuite/skels/local-index/my_index/index/index.toml index 7c969026..319b3b37 100644 --- a/testsuite/skels/local-index/my_index/index/index.toml +++ b/testsuite/skels/local-index/my_index/index/index.toml @@ -1 +1 @@ -version = "0.2" +version = "0.3" diff --git a/testsuite/tests/get/build/my_index/index/index.toml b/testsuite/tests/get/build/my_index/index/index.toml index 7c969026..319b3b37 100644 --- a/testsuite/tests/get/build/my_index/index/index.toml +++ b/testsuite/tests/get/build/my_index/index/index.toml @@ -1 +1 @@ -version = "0.2" +version = "0.3" diff --git a/testsuite/tests/get/external-tool-dependency/my_index/crates/noop_1.0.tgz b/testsuite/tests/get/external-tool-dependency/my_index/crates/noop_1.0.tgz deleted file mode 100644 index 56af8b042b6c587603ebe22a143a72d12e798960..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 436 zcmV;l0ZaZLiwFSwq1{~o1MQW|Zi6roMOo)7Mywhsv^)YVvTK`Vn?R7s?&a~5E9$K$as9t$Z8CuLJo=hcmM9$ZZvhUV?Xp}YC+u)H9Q;=p&~ zK*xE$=SLQVXR2q5x~zx-ux3QapW^oEe-yFlzxlY%3U%T&jKR@x_^to3AFTY3hQ|LO z@nhl_UDJSVrmN@ zruxUCb4M>h=NlDv#q8{xi-Wg4E;l#aOw`HDhcR)~JIep9^RGQV#~pA?|6iVeKQ`wd z`~Ug*R7s?&a~5E9$K$as9t$Z8CuLJo=hcmM9$ZZvhUV?Xp}YC+u)H9Q;=p&~ zK*xE$=SLQVXR2q5x~zx-ux3QapW^oEe-yFlzxlY%3U%T&jKR@x_^to3AFTY3hQ|LO z@nhl_UDJSVrmN@ zruxUCb4M>h=NlDv#q8{xi-Wg4E;l#aOw`HDhcR)~JIep9^RGQV#~pA?|6iVeKQ`wd z`~Ug*R7s?&a~5E9$K$as9t$Z8CuLJo=hcmM9$ZZvhUV?Xp}YC+u)H9Q;=p&~ zK*xE$=SLQVXR2q5x~zx-ux3QapW^oEe-yFlzxlY%3U%T&jKR@x_^to3AFTY3hQ|LO z@nhl_UDJSVrmN@ zruxUCb4M>h=NlDv#q8{xi-Wg4E;l#aOw`HDhcR)~JIep9^RGQV#~pA?|6iVeKQ`wd z`~Ug*