Recent

Author Topic: Creating a deployable bundle  (Read 1194 times)

Wilko500

  • Full Member
  • ***
  • Posts: 118
Creating a deployable bundle
« on: March 07, 2024, 09:21:21 pm »
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 .

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, FileUtil,
  9.            BaseUnix;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     Button1: TButton;
  17.     procedure Button1Click(Sender: TObject);
  18.   private
  19.  
  20.   public
  21.  
  22.   end;
  23.  
  24. var
  25.   Form1: TForm1;
  26.  
  27. implementation
  28.  
  29. {$R *.lfm}
  30.  
  31. { TForm1 }
  32.  
  33. procedure TForm1.Button1Click(Sender: TObject);
  34. Var ii:                   Boolean;   //Function return value
  35.     i:                    Int32;     //Function return value
  36.     strProjPath:          String;    //eg  "/Volumes/MacHD-SSD-Data/LocBucket/FpLazStuff/TestExtTools/"
  37.     strProjFile:          String;    //eg  "project1"
  38.     strDeploy:            String;    //eg  "Deploy"
  39.     strCopySrc:           String;    //Copy file source
  40.     strCopyDest:          String;    //Copy destination
  41. begin
  42.   ShowMessage('ZZ');
  43.   //Set Deployment folder
  44.   strDeploy:='Deploy';
  45.   //Get ProjPath
  46.   strProjPath:= paramStr(1);
  47.   //Get ProjFile
  48.   strProjFile:= paramStr(2);
  49.   //Create output folder
  50.   If Not DirectoryExists(strProjPath + strDeploy) then
  51.       Begin
  52.       CreateDir( strProjPath +  strDeploy);
  53.   {EndIf}End;
  54.   //Copy bundle into deploy folder
  55.   ii:=CopyDirTree(strProjPath + strProjFile + '.app', strProjPath + strDeploy +'/' + strProjFile + '.app', [cffOverwriteFile]);
  56.   //Now fix the bundle
  57.   strCopySrc:= strProjPath + strProjFile;
  58.   strCopyDest:=  strProjPath + strDeploy + '/' +  strProjFile + '.app' + '/Contents/MacOS/' + strProjFile;
  59.   //ii:=DeleteFile(strCopyDest);
  60.   //ii:=CopyFile( strCopySrc, strCopyDest, [cffOverwriteFile]);
  61.   //And reset permisions
  62.   i:=fpChmod (strCopyDest,&777);
  63.   ShowMessage('Bundle in folder '+ strDeploy + ' fixed sucessfully');
  64. End;
  65.  
  66. end.
  67.  


 
MacBook Pro mid 2015 with OS Monterey 12.7.6
FPC 3.2.3 Lazarus 3.7
FPC 3.2.2 Lazarus 3.4

dbannon

  • Hero Member
  • *****
  • Posts: 3200
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Creating a deployable bundle
« Reply #1 on: March 08, 2024, 03:17:42 am »
Yes, you do need to move the executable into the bundle (and so replace the symlink in the process).

I do so in a bash script that builds the overall package for me.  I suggest you revisit the script you tried to use and show us what it looks like. Its going to be a far simpler process, a one liner in effect, something like -

Code: Bash  [Select][+][-]
  1. cd <appropriate directory>
  2. cp project1 project1.app/Contents/MacOS/.


Davo
Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

 

TinyPortal © 2005-2018