* * *

Author Topic: How do packages work in Lazarus IDE?  (Read 1164 times)

WooBean

  • Jr. Member
  • **
  • Posts: 70
How do packages work in Lazarus IDE?
« on: November 27, 2017, 01:41:24 pm »
Hi to all not willing solving someone's homework! This is not my case.

Investigating Lazarus from source code I tried to find out how packages act in Lazarus IDE. It is not as easy as I expected.
Code of some packages have references to units used by Lazarus (directly from main.pas) and those packages have a way to modify (extend) IDE classes when their Register procedures are called. But, I can not figure out how FPC compiler "knows" that some packages are to be included to Lazarus IDE project. First suspects were *.inc files with modified time of change but they had not any references to packages' units. Where should I look into?

OS: Win 7/64, Lazarus 1.6/32bit, FPC 3.0.0         
« Last Edit: November 27, 2017, 04:56:03 pm by WooBean »
Win7/64, Lazarus 1.8 win64-win64, FPC 3.0.4

howardpc

  • Hero Member
  • *****
  • Posts: 2644
Re: How packages work in Lazarus IDE?
« Reply #1 on: November 27, 2017, 02:05:09 pm »
The FP Compiler does not know or care about packages your Lazarus project uses.
It knows only the information passed to it on the command line when it is invoked.
The packages are managed by the Lazarus IDE, and it uses the metadata in the package file(s) to pass the correct information to the compiler.
When you add a package dependency to your project, the IDE adds all needed paths to the project, so compiled units referenced by the package can be found by the compiler (they are added as -Fu command line parameters when the IDE invokes the compiler on your project's source files). There are similar command line parameters added by the IDE for any libraries the package may need.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 4553
    • wiki
Re: How packages work in Lazarus IDE?
« Reply #2 on: November 27, 2017, 02:10:56 pm »
There are a lot of answers...

1) The IDE knows (from the project *.lpi file) which packages are used.
It will add the correct include path to the fpc commandline options when the IDE calls fpc. That is the path to the lib folder (.ppu and .o files).
Before that the IDE will have compiled the packages.
(That does not add anything, it just gives fpc the info where to find stuff)

2) When you add packages to the IDE itself, the ide creates (in your config folder) staticpackages.inc and that is included in lazarus.pp
So all packages appear in the "uses" list, and their "initialization" (section) code will be called.
(This adds the packages)

3) As for register:
Open the project ide/lazarus.lpi, the open a package you want to look at, and codetools will show you what happens ( Alt - Cursor Up )


This is called from the "initialization" section (see the generated file "packagename".pas  // sometimes the name differs.)

The Initializiton call RegisterPackage, and gives a ref to @Register. And that will then be called at a later time.

Some of the called code may be in IDEIntf.
Check if a procedure is virtual. In that case the IDE may have instantiated a subclass, which overwrites the method.
« Last Edit: November 27, 2017, 02:13:12 pm by Martin_fr »

WooBean

  • Jr. Member
  • **
  • Posts: 70
Re: How packages work in Lazarus IDE?
« Reply #3 on: November 27, 2017, 02:28:34 pm »
Big thanks for Marin_fr reply!
Also thanks for howardpc!

Sometimes tons of wiki documentation are not as helpful as a word of smart people.
Win7/64, Lazarus 1.8 win64-win64, FPC 3.0.4

WooBean

  • Jr. Member
  • **
  • Posts: 70
Re: How do packages work in Lazarus IDE? <SOLVED>
« Reply #4 on: November 27, 2017, 05:11:33 pm »
I tried to use guidances sent by Martin_fr and ...

ad 1) - ok, but it does not explain how lazarus.pp project could somehow refer to installed packages;
ad 2) - there is staticpackages.inc file (all my computer searched and found finally at C:\Users\me\AppData\Local\).
ad 3) - this question must wait until I know how a source code of packages becomes accesible for Lazarus project (lazarus.pp file).

My lack of knowledge  still persists, but we have a progress. More thanks to Martin_fr!

OS: Win 7/64, Lazarus 1.6/32bit, FPC 3.0.0
« Last Edit: November 27, 2017, 05:35:38 pm by WooBean »
Win7/64, Lazarus 1.8 win64-win64, FPC 3.0.4

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 4553
    • wiki
Re: How do packages work in Lazarus IDE?
« Reply #5 on: November 27, 2017, 05:21:32 pm »
In your config folder: (OS dependent)
~/.lazarus/staticpackages.inc
C:\Users\martin\AppData\Local\lazarus\staticpackages.inc

and in lazarus.pp {$I staticpackages.inc}

--------------
This is generally how packages work.

Adding them to the project.lpi, means the IDE adds them to the searchpath when compiling.

In your own project, you would then add some unit from the package to your uses clause.
In the IDE this is the same, only via staticpackages.inc



taazz

  • Hero Member
  • *****
  • Posts: 5023
Re: How do packages work in Lazarus IDE?
« Reply #6 on: November 27, 2017, 05:31:52 pm »
I tried to use guidances sent by Martin_fr and ...

ad 1) - ok, but it does not explain how lazarus.pp project could somehow refer to installed packages;
why? what you want to know exactly? in sort lazarus.pp does not have to refer to installed packages the installed packages have an initialization section that registers their components and property editors with the IDE.
ad 2) - there is no staticpackages.inc file (all my computer searched). It may be valid in some newer or older Lazarus versions;
Yes there is, it has all known packages (not only installed) and it is in the lazarus config directory which is OS /installation specific. For example in my installation it exists in the folder d:\lazarus\1.4.4\cfg and in the folder D:\lazarus\1.6.4\cfg, in most windows installations is in the folder C:\users\<username>\appdata\roaming\lazarus\ or something along those lines on linux/bsd I'm guessing in  a hidden folder in the users home directory something along the lines of ~/.lazarus. You probably have not searched thoroughly enough or you used the half A$$ed explorer search which only indexes known file extensions try opening a command prompt go to c:\ and type "dir staticpackag*.* /s" (with out quotes) and wait for the results.

ad 3) - this question must wait until I know how a source code of packages becomes accesible for Lazarus project (lazarus.pp file).
You have to add the package in your project's required section once there the IDE will be able to use in the compilation process. If you do not add in the required section it does not matter if the IDE knows about the package or not your application will never be able to access its code/units.

Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 4553
    • wiki
Re: How do packages work in Lazarus IDE?
« Reply #7 on: November 27, 2017, 05:59:31 pm »
in sort lazarus.pp does not have to refer to installed packages the installed packages have an initialization section that registers their components and property editors with the IDE.
initialization sections are only executed, if the unit is used somewhere. So the IDE code must use them. (and it does)
Quote
there is no staticpackages.inc
Yes there is, it has all known packages (not only installed) and it is in the lazarus config directory which is OS /installation specific.
staticpackages.inc  has only installed (and dependencies)
packagefiles.xml has ALL packages

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus