Lazarus/FPC = 3.0/3.3.1 on macOS Monterey 12.7.2
As a beginner using Lazarus on MacOS I have found the process of deploying my complied bundle(s) somewhat frustrating. Bundle is created but cannot be moved without copying the executable into the bundle to replace the bundles link. I know that the (one) solution is to use Finder to draw the executable into the bundle and voila the bundle can be moved. But I don't like Finder, I think its clumsy and not intuitive. How hard can it be to create an external tool to fix the bundle? So I have wanted to explore and understand the external tool facility in Lazarus so I created a tool.
I had tried to doing this with a shell script but could not get that to work, probably my lack of understanding of shell scripts, and have not tried other approached like LazXproj. I wanted something simple and easy.
It has been an interesting and helpful learning process for me. One of the most interesting issues was that after I had "fixed" the bundle in my working folder the next compile completed without error but did not load the compiled code but an earlier version. To resolve this it was necessary to delete the .app folder.
I included my code as it might help other beginners. At present it does not contain error checking, on todo list. I used a form as that helped me with development and testing, it could just as well have been a console app. My approach was to create a copy of the bundle in a "Deploy" folder and do the fit there thus preventing the issues with subsequent compiles. When development gets to an appropriate point I run the External tool and copy the "Deploy" bundle to wherever .
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, FileUtil,
BaseUnix;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
Var ii: Boolean; //Function return value
i: Int32; //Function return value
strProjPath: String; //eg "/Volumes/MacHD-SSD-Data/LocBucket/FpLazStuff/TestExtTools/"
strProjFile: String; //eg "project1"
strDeploy: String; //eg "Deploy"
strCopySrc: String; //Copy file source
strCopyDest: String; //Copy destination
begin
ShowMessage('ZZ');
//Set Deployment folder
strDeploy:='Deploy';
//Get ProjPath
strProjPath:= paramStr(1);
//Get ProjFile
strProjFile:= paramStr(2);
//Create output folder
If Not DirectoryExists(strProjPath + strDeploy) then
Begin
CreateDir( strProjPath + strDeploy);
{EndIf}End;
//Copy bundle into deploy folder
ii:=CopyDirTree(strProjPath + strProjFile + '.app', strProjPath + strDeploy +'/' + strProjFile + '.app', [cffOverwriteFile]);
//Now fix the bundle
strCopySrc:= strProjPath + strProjFile;
strCopyDest:= strProjPath + strDeploy + '/' + strProjFile + '.app' + '/Contents/MacOS/' + strProjFile;
//ii:=DeleteFile(strCopyDest);
//ii:=CopyFile( strCopySrc, strCopyDest, [cffOverwriteFile]);
//And reset permisions
i:=fpChmod (strCopyDest,&777);
ShowMessage('Bundle in folder '+ strDeploy + ' fixed sucessfully');
End;
end.