Recent

Author Topic: How to install Lazarus packages from CLI, or: do I need Lazarus?  (Read 1080 times)

xixixi

  • New Member
  • *
  • Posts: 25
Hi. I need to build a small CLI application that reads an Excel file, changes something, and writes it back to disk.

I was going to use FreePascal and FP Spreadsheet (https://wiki.freepascal.org/FPSpreadsheet).

But there it says that to install it, I need to do it using Lazarus's Package Manager. Is there an alternative way to install this unit (and its dependencies) from the command line?

Otherwise I would be installing the full IDE just for that. I only need the Pascal compiler.

Thanks.

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: How to install Lazarus packages from CLI, or: do I need Lazarus?
« Reply #1 on: January 14, 2023, 04:59:00 pm »
yes, most likely. It's graphic.

it's no big deal, really.
The only true wisdom is knowing you know nothing

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: How to install Lazarus packages from CLI, or: do I need Lazarus?
« Reply #2 on: January 14, 2023, 07:07:04 pm »
Better ask wp.
Change your subjectline (first post) to include the word "fpspreadsheet" and he'll read this thread.

Bart

xixixi

  • New Member
  • *
  • Posts: 25
Re: How to install Lazarus packages from CLI, or: do I need Lazarus?
« Reply #3 on: January 14, 2023, 09:45:20 pm »
FPSpreadsheet is just an example. I already solved it, I downloaded and compiled it (in about 1/2 second, this compiler is FAST), and fortunately it didn't have any external dependency.

My question is more general.

C# has nuget, Nim has nimble, Haskell has cargo, D has dub, Ruby has gem, Lisp has quicklisp...

What's Free Pascal's command line package manager?

I found something called fppkg, but almost all its packages are already in the distribution, so it isn't very useful. FPSpreadsheet wasn't there.

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: How to install Lazarus packages from CLI, or: do I need Lazarus?
« Reply #4 on: January 14, 2023, 10:29:05 pm »
Joost (I think) is working on such a thing for fpc: fppkg.
Not sure wether this will be used by Lazarus.
ATM all packages are statically linked into the IDE.

Bart

dbannon

  • Hero Member
  • *****
  • Posts: 2796
    • tomboy-ng, a rewrite of the classic Tomboy
Re: How to install Lazarus packages from CLI, or: do I need Lazarus?
« Reply #5 on: January 15, 2023, 12:12:31 am »
You can build a project directly with fpc. If its dependent of Lazarus packages, its easy to download the package, build the relevant pascal units and then use them in the fpc command line. No GUI needed in the build process and, obviously, you can build a GUI app this way.

Its a great way to, for example, automate your build process. Probably not that useful during development.

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

PierceNg

  • Sr. Member
  • ****
  • Posts: 373
    • SamadhiWeb
Re: How to install Lazarus packages from CLI, or: do I need Lazarus?
« Reply #6 on: January 15, 2023, 02:27:00 am »
Otherwise I would be installing the full IDE just for that. I only need the Pascal compiler.

The Lazarus code editor is Pascal-aware. E.g. (once the editor knows what files are where) on the statement "MyWorkbook := TsWorkbook.Create;" double click to select the word TsWorkbook, then (for Linux) control-click - the code editor opens another tab with the cursor pointing at the class definition of TsWorkbook.

If you use another editor for Pascal programming, you'll still need to set up that editor to do similar. Which editor do you use?

How to let the Lazarus editor know where to find stuff? See https://wiki.freepascal.org/FPSpreadsheet#Installation, first bullet point:

Quote
Installation
If you only need non-GUI components: in Lazarus: Package/Open Package File, select laz_fpspreadsheet.lpk, click Compile. Now the package is known to Lazarus (and should e.g. show up in Package/Package Links). Now you can add a dependency on laz_fpspreadsheet in your project options and fpspreadsheet to the uses clause of the project units that need to use it.

The lpk file specifies the files that make up the package. Again, if you use another editor, well, firstly is it lpk-aware?

But there it says that to install it, I need to do it using Lazarus's Package Manager. Is there an alternative way to install this unit (and its dependencies) from the command line?

Dunno about installing, but once you set up a Lazarus project for your application, then you could build it from the CLI with the command "lazbuild myproject.lpi".
« Last Edit: January 15, 2023, 02:32:24 am by PierceNg »

xixixi

  • New Member
  • *
  • Posts: 25
Re: How to install Lazarus packages from CLI, or: do I need Lazarus?
« Reply #7 on: January 15, 2023, 02:43:52 pm »
The Lazarus code editor is Pascal-aware. E.g. (once the editor knows what files are where) on the statement "MyWorkbook := TsWorkbook.Create;" double click to select the word TsWorkbook, then (for Linux) control-click - the code editor opens another tab with the cursor pointing at the class definition of TsWorkbook.

I don't need that; the package comes with excellent documentation. I just work with the CHM on the side.

If you use another editor for Pascal programming, you'll still need to set up that editor to do similar. Which editor do you use?

Emacs. It doesn't have very good support for Object Pascal, not to mention Free Pascal dialects, unfortunately.

The lpk file specifies the files that make up the package. Again, if you use another editor, well, firstly is it lpk-aware?

I doubt there is any other program or editor, except Lazarus, that is "lpk-aware".

Dunno about installing, but once you set up a Lazarus project for your application, then you could build it from the CLI with the command "lazbuild myproject.lpi".

In this case, it only took

fpc -Fu<"lazutils" directory> -Fi.. fpspreadsheet
fpc -Fu<"lazutils" directory> -Fi.. fpsallformats


to build all (non-visual) units. The only thing needed from Lazarus were some units (avglvltree and its dependencies).

I'll try lazbuild next time, but I wonder what it will it do, since I tried first compiling the package using the "online package manager" as directed, but then couldn't find the units anywhere... that's when I decided to do everything by hand.

Anyway, if I could only write...

fppkg install fpspreadsheet

or similar to be able to use that library in my non-Lazarus Pascal program, it would be amazing. I guess the majority of people using FP are Lazarus users, so there isn't much interest in non-Lazarus libraries or packages, unfortunately.

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: How to install Lazarus packages from CLI, or: do I need Lazarus?
« Reply #8 on: January 15, 2023, 04:15:45 pm »
yes, you will be Assimilated!

There will be no other IDE's before Yeah!

The only true wisdom is knowing you know nothing

Warfley

  • Hero Member
  • *****
  • Posts: 1499
Re: How to install Lazarus packages from CLI, or: do I need Lazarus?
« Reply #9 on: January 15, 2023, 08:23:51 pm »
First of all, lazarus packages a lot of build logic within it's projects, so to use a package, you need an LPI (lazarus project file) containing the reference to said package. This can then be read by a lazarus instance and if alle the packages are installed, lazarus will call the correct compiler commands (by looking at the build instructions for the package in the lpk and the instructions for the project in the lpi) to build it.

This building is available via the command line tool lazbuiild already shipped (and built) with lazarus. Simply call "lazbuild path/to/lpi". Lazbuild can also install lpk files, what it can't do is search the online package manager and install packages.

For this I wrote a small script a few years ago: https://github.com/Warfley/LazarusPackageManager
This does both give a command line interface for downloading and installing packages into lazarus using lazbuild, while also providing a neat wrapper for building lpis where lpm will read the lpi, detect if any packages from OPM are missing and if so it can download and install them.

Using the docker container it works like that (Using an example project I've built for this some time ago):
Code: Bash  [Select][+][-]
  1. $> git clone https://gitlab.com/Warfley/lazarusgitlabci testproject
  2. $> docker run --rm -v $(realpath testproject):/project lpm:stable lpm build --yes project/FileEncrypter.lpi Windows QTLinux GTKLinux
What this does it creates a new LPM docker container (which is pre packaged with fpc and lazarus and lpm), mounts the project into it, and then compiles the projects build targets Windows, QTLinux, and GTKLinux (see the pdf in the repository on what these build modes are and how they where created).
The project uses the DCPCrypt package which lpm (with --yes) will automatically download from OPM before compiling.
After the container finished, there will be a build folder in the project directory containing the compiled executables.

But of course this is only for existing lazarus projects, you still need lazarus for creating and managing the project and settings in the lpi project file

dbannon

  • Hero Member
  • *****
  • Posts: 2796
    • tomboy-ng, a rewrite of the classic Tomboy
Re: How to install Lazarus packages from CLI, or: do I need Lazarus?
« Reply #10 on: January 15, 2023, 11:33:39 pm »
....
Emacs.
Yeah, emacs user are like that....

In this case, it only took
Code: Pascal  [Select][+][-]
  1. fpc -Fu<"lazutils" directory> -Fi.. fpspreadsheet
  2. fpc -Fu<"lazutils" directory> -Fi.. fpsallformats
to build all (non-visual) units. The only thing needed from Lazarus were some units (avglvltree and its dependencies).
Same model will also build the GUI components, you just need to get the command line right.

I'll try lazbuild next time,
Lazbuild is great if you already have a Lazarus install with all the packages you need but if you want to to do automated builds for quality control, remote builds for eg Debian etc, a pure FPC build is the way to go. Maybe Warfley's script helps the Lazbuild model but the pure FPC is dead easy (and easier to debug) once you have it in place. Easy to turn into a makefile too.

I use a script, https://github.com/tomboy-notes/tomboy-ng/blob/master/buildit.bash  in several types of builds that can download the needed package (kcontrols) build it then build the remainder of the project, then link all, including kontrols into binaries. This is used on remote machines, where I have no opportunity to do things like install packages in lazarus. Debian, Ubuntu PPA, packman.

But I also use a lazbuild based script, https://github.com/tomboy-notes/tomboy-ng/blob/master/package/package.bash on a specially setup VM where I build and package to make debs, rpms, windows executable for i386, x86_64, RaspPi for direct distribution. The difference is that I control that VM, its convenient for me to configure Lazarus to be workable with lazbuild.

But I do agree, it would be useful to have a command line tool that would install a package in a Lazarus install. I might look at Warfley's script....

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

Warfley

  • Hero Member
  • *****
  • Posts: 1499
Re: How to install Lazarus packages from CLI, or: do I need Lazarus?
« Reply #11 on: January 16, 2023, 01:16:44 am »
I'd be careful with just including the directories for packages. This approach only works with simple packages that only provide units and no configuration. An lpk can contain much more. For example an lpk can contain specific compiler or linker options, custom user defines, pre and post build scripts or even a complete custom build script (e.g. a makefile).

So while this will probably work for the very most packages, not using lazarus (or lazbuild) can result in all kinds of problems from simply not being able to compile the package at all, to some weird behavior because some custom defines are missing.

What can be done there is to take a package and turn it into a makefile with lazbuild:
Code: Bash  [Select][+][-]
  1. $> lazbuild --create-makefile path/to/lpk

You should then be able to include that makefile into your makefiles. This way you can safely use lazarus packages without relying on lazarus directly.

 

TinyPortal © 2005-2018