Skip to content

Commit

Permalink
- Fix cases where executable and crate name differ.
Browse files Browse the repository at this point in the history
- Add --executable argument for crates without field or with various
  executables.
  • Loading branch information
mgrojo committed Mar 16, 2024
1 parent 6c94c3d commit 22355e9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion alire.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "alr2appimage"
description = "Tool to create an AppImage executable from an Alire crate"
version = "0.9.2"
version = "0.9.3"
website = "https://github.com/mgrojo/alr2appimage"
long-description = """
There are two prerequisites for your project to work with this tool:
Expand Down
30 changes: 24 additions & 6 deletions src/alr2appimage.adb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ procedure Alr2AppImage is

use Parse_Args;

Abort_Error : exception;

procedure Report_Failure (Message : String) is
begin
Put_Line (File => Standard_Error, Item => Message);
Expand Down Expand Up @@ -44,6 +46,10 @@ begin
"icon", 'i',
Usage => "Specify the icon file for the AppImage");

AP.Add_Option (Make_String_Option (""),
"executable", 'e',
Usage => "Specify the executable for the AppImage (without path)");

AP.Set_Prologue ("Makes an AppImage from your Alire crate.");

AP.Parse_Command_Line;
Expand All @@ -68,16 +74,28 @@ begin
:= Alire_TOML.Read_String_List ("executables");
Icon : constant String := AP.String_Value ("icon");
Name : constant String := Alire_TOML.Read_Field ("name");

function Get_Executable return String
is
begin
if AP.String_Value ("executable") /= "" then
return AP.String_Value ("executable");
elsif Ada.Containers."=" (Executable_List.Length, 0) then
Report_Failure ("Error: the field 'executables' in 'alire.toml' is empty"
& " and no executable was provided on the command line.");
raise Abort_Error;
else
return Executable_List.Element (Positive'First);
end if;
end Get_Executable;

Executable : constant String := Get_Executable;
begin
if Ada.Containers."=" (Executable_List.Length, 0) then
Report_Failure ("Error: the field 'executables' in 'alire.toml' is empty");
return;
end if;

Desktop_File.Write
(Name => Name,
Comment => Alire_TOML.Read_Field ("description"),
Exec => Executable_List.Element (Positive'First),
Exec => Executable,
Icon => Ada.Directories.Base_Name (Icon),
Terminal => AP.Boolean_Value ("terminal"),
Tags => Alire_TOML.Read_String_List ("tags"));
Expand All @@ -103,7 +121,7 @@ begin
end if;

Runner.Run_Linuxdeploy (App_Dir => App_Dir,
Executable => Executable_List.Element (Positive'First),
Executable => Executable,
Icon_File => Ada.Directories.Simple_Name (Icon),
Success => Success);

Expand Down
2 changes: 1 addition & 1 deletion src/desktop_file.adb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ package body Desktop_File is

Desktop_File : File_Type;
begin
Create (File => Desktop_File, Name => Name & ".desktop");
Create (File => Desktop_File, Name => Exec & ".desktop");

Put_Line (Desktop_File, "[Desktop Entry]");

Expand Down

0 comments on commit 22355e9

Please sign in to comment.