From 81d8dc864f0afddb81073714b5af3531a15f2894 Mon Sep 17 00:00:00 2001 From: mivirl Date: Sun, 10 Aug 2025 12:21:07 +0000 Subject: [PATCH] Remove original Spawn_Raw Replaced the original call to `Alr.OS_Lib.Spawn_Raw` with a call to `Alire.OS_Lib.Subprocess.Spawn_Raw` to reduce duplication. --- src/alire/alire-os_lib-subprocess.adb | 4 ++-- src/alire/alire-os_lib-subprocess.ads | 3 +++ src/alr/alr-commands-run.adb | 5 ++++- src/alr/alr-commands.adb | 4 +++- src/alr/alr-os_lib.adb | 24 ------------------------ src/alr/alr-os_lib.ads | 7 ------- 6 files changed, 12 insertions(+), 35 deletions(-) diff --git a/src/alire/alire-os_lib-subprocess.adb b/src/alire/alire-os_lib-subprocess.adb index 72d9e057..c5c772bc 100644 --- a/src/alire/alire-os_lib-subprocess.adb +++ b/src/alire/alire-os_lib-subprocess.adb @@ -336,6 +336,7 @@ package body Alire.OS_Lib.Subprocess is is Code : Integer; begin + Trace.Detail ("Spawning: " & Image (Command, Arguments)); declare Full_Path : constant String := @@ -346,8 +347,7 @@ package body Alire.OS_Lib.Subprocess is if Full_Path = "" then Alire.Raise_Checked_Error ("Executable not found in PATH when spawning: " - -- & TTY.Terminal (Command & " " & Arguments)); - & TTY.Terminal (Command)); + & TTY.Terminal (Image (Command, Arguments))); end if; Code := GNAT.OS_Lib.Spawn (Full_Path, Parsed_Arguments.all); diff --git a/src/alire/alire-os_lib-subprocess.ads b/src/alire/alire-os_lib-subprocess.ads index f344081f..c09d762b 100644 --- a/src/alire/alire-os_lib-subprocess.ads +++ b/src/alire/alire-os_lib-subprocess.ads @@ -50,6 +50,9 @@ package Alire.OS_Lib.Subprocess is -- Doesn't capture output but doesn't fail on error either Child_Failed : exception; + -- Used to notify that a subprocess launched by Spawn_Raw completed with + -- non-zero error + procedure Spawn_Raw (Command : String; Arguments : AAA.Strings.Vector); diff --git a/src/alr/alr-commands-run.adb b/src/alr/alr-commands-run.adb index 34277ce6..eb43ffbc 100644 --- a/src/alr/alr-commands-run.adb +++ b/src/alr/alr-commands-run.adb @@ -1,6 +1,7 @@ with Ada.Containers; with Alire.OS_Lib; +with Alire.OS_Lib.Subprocess; with Alire.Platforms.Current; with Alr.Commands.Build; @@ -219,7 +220,9 @@ package body Alr.Commands.Run is else Trace.Detail ("Launching " & Target_Exes.First_Element); Trace.Detail ("..."); - OS_Lib.Spawn_Raw (Target_Exes.First_Element, Cmd.Args.all); + Alire.OS_Lib.Subprocess.Spawn_Raw + (Target_Exes.First_Element, + Alire.OS_Lib.Subprocess.Split_Arguments (Cmd.Args.all)); end if; end; end; diff --git a/src/alr/alr-commands.adb b/src/alr/alr-commands.adb index a7fc8e00..6655158f 100644 --- a/src/alr/alr-commands.adb +++ b/src/alr/alr-commands.adb @@ -16,6 +16,7 @@ with Alire.Formatting; with Alire.Index_On_Disk.Loading; with Alire.Index_On_Disk.Updates; with Alire.Lockfiles; +with Alire.OS_Lib.Subprocess; with Alire.Paths; with Alire.Platforms.Current; with Alire.Root; @@ -641,7 +642,8 @@ package body Alr.Commands is OS_Lib.Bailout (1); end if; - when Child_Failed | Command_Failed | Wrong_Command_Arguments => + when Alire.OS_Lib.Subprocess.Child_Failed | Command_Failed + | Wrong_Command_Arguments => Trace.Detail ("alr " & Sub_Cmd.What_Command & " unsuccessful"); if Alire.Log_Level = Debug then raise; diff --git a/src/alr/alr-os_lib.adb b/src/alr/alr-os_lib.adb index 22107b9a..47701ece 100644 --- a/src/alr/alr-os_lib.adb +++ b/src/alr/alr-os_lib.adb @@ -1,6 +1,3 @@ -with Ada.Exceptions; -with Alire.OS_Lib.Subprocess; - package body Alr.OS_Lib is ------------ @@ -41,25 +38,4 @@ package body Alr.OS_Lib is return False; end if; end Is_Older; - - --------------- - -- Spawn_Raw -- - --------------- - - procedure Spawn_Raw (Command : String; - Arguments : String := "") - is - begin - Trace.Debug ("Spawning " & Command & " " & Arguments); - - begin - Alire.OS_Lib.Subprocess.Spawn_Raw - (Command, - Alire.OS_Lib.Subprocess.Split_Arguments (Arguments)); - exception - when E : Alire.OS_Lib.Subprocess.Child_Failed => - raise Child_Failed with Ada.Exceptions.Exception_Message (E); - end; - end Spawn_Raw; - end Alr.OS_Lib; diff --git a/src/alr/alr-os_lib.ads b/src/alr/alr-os_lib.ads index c57ad1bb..6cd493c9 100644 --- a/src/alr/alr-os_lib.ads +++ b/src/alr/alr-os_lib.ads @@ -19,13 +19,6 @@ package Alr.OS_Lib is (GNAT.OS_Lib."/=" (GNAT.OS_Lib.Locate_Exec_On_Path (File), null)); -- FIXME: memory leak in this call - -- Process spawning - - procedure Spawn_Raw (Command : String; Arguments : String := ""); - -- Direct launch, without any shenanigangs on output, for example for - -- respawning the canonical version. - -- Raises CHILD_FAILED if exit code /= 0. - -- OS PORTABLE FUNCTIONS procedure Bailout (Code : Integer := 0) renames Alire.OS_Lib.Bailout; -- 2.39.5