From 5141543323f91254ae3ecb1e4d351afed5a10aa9 Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Wed, 2 Sep 2020 18:56:56 +0200 Subject: [PATCH] Warn of obsolete metadata and provide some guidance (#506) * Warn the user if old manifest detected Minimal information is shown to reset a workspace; for more details a wiki on the project repo link is printed. * Improve the formatting of outdated index * Don't consider `config.toml` for detection --- src/alire/alire-directories.adb | 47 ++++++++++++++++++++++++++++++++ src/alire/alire-toml_index.adb | 22 +++++++++------ src/alr/alr-commands-version.adb | 3 ++ 3 files changed, 64 insertions(+), 8 deletions(-) diff --git a/src/alire/alire-directories.adb b/src/alire/alire-directories.adb index 5e2132c1..cb6bd0fc 100644 --- a/src/alire/alire-directories.adb +++ b/src/alire/alire-directories.adb @@ -1,5 +1,6 @@ with Ada.Exceptions; with Ada.Numerics.Discrete_Random; +with Ada.Text_IO; with Ada.Unchecked_Deallocation; with Alire.Properties; @@ -7,6 +8,46 @@ with Alire.Roots; package body Alire.Directories is + ------------------------ + -- Report_Deprecation -- + ------------------------ + + procedure Report_Deprecation with No_Return; + -- We give some minimal guidelines about what to do with the metadata + -- changes, and redirect to a wiki page for more details. + + procedure Report_Deprecation is + Old_Manifest : constant String := + Directories.Find_Single_File ("alire", "toml"); + use Ada.Text_IO; -- To bypass any -q or verbosity configuration + begin + New_Line; + Put_Line ("WARNING: Deprecated metadata possibly detected at " + & Old_Manifest); + New_Line; + Put_Line ("Due to recent changes to Alire's way of storing metadata,"); + Put_Line ("you need to reinitialize or migrate the workspace."); + Put_Line + ("Please check here for details on how to migrate your metadata:"); + New_Line; + Put_Line (" https://github.com/alire-project/alire/wiki/" + & "2020-Metadata-format-migration"); + Put_Line (""); + Put_Line ("How to reinitialize, in a nutshell:"); + New_Line; + Put_Line (" - Delete the old manifest file at 'alire/*.toml'"); + Put_Line (" - run one of"); + Put_Line (" $ alr init --in-place --bin "); + Put_Line (" $ alr init --in-place --lib "); + Put_Line (" - Re-add any necessary dependencies using one or more "); + Put_Line (" $ alr with "); + New_Line; + + -- This happens too early during elaboration and otherwise a stack trace + -- is produced, so: + GNAT.OS_Lib.OS_Exit (1); + end Report_Deprecation; + ------------------------ -- Backup_If_Existing -- ------------------------ @@ -92,6 +133,12 @@ package body Alire.Directories is Kind (Possible_Root.Crate_File) = Ordinary_File then return Path; + elsif GNAT.OS_Lib.Is_Directory ("alire") and then + Directories.Find_Single_File ("alire", "toml") /= "" and then + not Utils.Ends_With (Directories.Find_Single_File ("alire", "toml"), + "config.toml") + then + Report_Deprecation; else return Find_Candidate_Folder (Containing_Directory (Path)); end if; diff --git a/src/alire/alire-toml_index.adb b/src/alire/alire-toml_index.adb index 332beff9..acd5e452 100644 --- a/src/alire/alire-toml_index.adb +++ b/src/alire/alire-toml_index.adb @@ -1,6 +1,7 @@ with Ada.Directories; with Alire.Directories; +with Alire.Errors; with Alire.GPR; with Alire.Hashes.SHA512_Impl; pragma Unreferenced (Alire.Hashes.SHA512_Impl); @@ -127,14 +128,19 @@ package body Alire.TOML_Index is & VCSs.Git.Handler.Branch (Index.Index_Directory)); Set_Error (Result, Index.Index_Directory, - "Mismatched branch in checked out community index. " - & "Expected branch '" & Alire.Index.Community_Branch - & "' but found '" - & VCSs.Git.Handler.Branch (Index.Index_Directory) - & "'. If you have updated alr, you may need to reset " - & " the community index with 'alr index --reset-community'. " - & "Note that this operation will delete any local changes to" - & " the community index."); + Errors.Wrap + ("Mismatched branch in checked out community index", + Errors.Wrap + ("Expected branch '" & Alire.Index.Community_Branch + & "' but found '" + & VCSs.Git.Handler.Branch (Index.Index_Directory) + & "'", + Errors.Wrap + ("If you have updated alr, you may need to reset " + & " the community index with" + & " 'alr index --reset-community'", + "Note that this operation will delete any local" + & " changes to the community index.")))); return; end if; diff --git a/src/alr/alr-commands-version.adb b/src/alr/alr-commands-version.adb index 5e2afbbc..afe35585 100644 --- a/src/alr/alr-commands-version.adb +++ b/src/alr/alr-commands-version.adb @@ -1,3 +1,4 @@ +with Alire.Index; with Alire.Properties; with Alire.Roots.Optional; with Alire.Utils.TTY; @@ -68,6 +69,8 @@ package body Alr.Commands.Version is Put (" " & Prop.Image); end loop; New_Line; + Trace.Always ("community index required branch: " + & Alire.Index.Community_Branch); end Execute; ---------------------- -- 2.39.5