From 70795c20dd4684cb8c4825aa2daf63626539c5b2 Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Mon, 11 May 2020 18:52:02 +0200 Subject: [PATCH] Generate the lockfile on the fly when missing (#399) --- src/alire/alire-lockfiles.adb | 7 +++++++ src/alire/alire-solutions.ads | 3 ++- src/alr/alr-commands-show.adb | 4 +--- src/alr/alr-commands.adb | 24 ++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/alire/alire-lockfiles.adb b/src/alire/alire-lockfiles.adb index 702889bc..7022f295 100644 --- a/src/alire/alire-lockfiles.adb +++ b/src/alire/alire-lockfiles.adb @@ -1,3 +1,4 @@ +with Ada.Directories; with Ada.Text_IO; with Alire.Directories; @@ -61,6 +62,12 @@ package body Alire.Lockfiles is Close (File); end if; + -- Clean up + + if Ada.Directories.Exists (Filename) then + Ada.Directories.Delete_File (Filename); + end if; + raise; end Write; diff --git a/src/alire/alire-solutions.ads b/src/alire/alire-solutions.ads index a6c45451..8c897fd5 100644 --- a/src/alire/alire-solutions.ads +++ b/src/alire/alire-solutions.ads @@ -57,7 +57,8 @@ package Alire.Solutions is overriding function To_TOML (This : Solution) return TOML.TOML_Value with - Pre => (for all Release of This.Releases => + Pre => not This.Valid or else + (for all Release of This.Releases => Release.Dependencies.Is_Unconditional and then Release.Properties.Is_Unconditional); -- As previous one, but requires releases not to have dynamic expressions diff --git a/src/alr/alr-commands-show.adb b/src/alr/alr-commands-show.adb index c26ed9ce..6e6bc42e 100644 --- a/src/alr/alr-commands-show.adb +++ b/src/alr/alr-commands-show.adb @@ -250,10 +250,8 @@ package body Alr.Commands.Show is when Outside => Reportaise_Wrong_Arguments ("Cannot proceed without a crate name"); - when Broken => + when others => Requires_Valid_Session; - when Bootstrap.Valid_Session_States => - null; end case; end if; diff --git a/src/alr/alr-commands.adb b/src/alr/alr-commands.adb index b38ee54f..8f4bfe63 100644 --- a/src/alr/alr-commands.adb +++ b/src/alr/alr-commands.adb @@ -11,8 +11,10 @@ with Alire; with Alire.Config; with Alire.Features.Index; with Alire.Index; +with Alire.Lockfiles; with Alire.Roots; with Alire.Roots.Check_Valid; +with Alire.Solutions; with Alr.Commands.Build; with Alr.Commands.Clean; @@ -32,6 +34,7 @@ with Alr.Commands.Update; with Alr.Commands.Version; with Alr.Commands.Withing; with Alr.Commands.Setenv; +with Alr.Platform; with Alr.Root; with GNAT.Command_Line.Extra; @@ -424,6 +427,27 @@ package body Alr.Commands is Reportaise_Command_Failed ("Cannot continue with invalid session: " & Checked.Invalid_Reason); end if; + + -- For workspaces created pre-lockfiles, we create one on the fly + + if OS_Lib.Is_Regular_File (Checked.Lock_File) then + return; + end if; + + -- Solve current root dependencies to create the lock file + + Trace.Debug ("Missing lockfile, generating it on the fly..."); + + declare + Solution : constant Alire.Solutions.Solution := + Alire.Solver.Resolve + (Checked.Release.Dependencies (Platform.Properties), + Platform.Properties); + begin + Alire.Lockfiles.Write (Solution, + Platform.Properties, + Checked.Lock_File); + end; end Requires_Valid_Session; -------------------- -- 2.39.5