Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2019-07

Adding Required Packages paths... dynamically

6 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Marcos Douglas B. Santos

Hi,

Imagine a package that has a dependency for another one. However, this dependency has a conditional to exists. So, I cannot add the Required Package by default — I'm talking about ZeosLib.

Then, I used Conditionals (script) for adding ZeosLib paths (-Fu, -Fi) into the paths of the package — amazing work in IDE, by the way.

In Custom Options | Conditionals, I have something like this:
===begin===
if undefined(NOSYNDBZEOS) then
begin
  UnitPath += ';$PkgOutDir(zcore);$PkgOutDir(zdbc);$PkgOutDir(zparsesql);$PkgOutDir(zplain)';
  IncPath += ';$(ProjOutDir);$PkgDir(zcore)\..\..\src';
end;
===end===

And it works. If user add the package into a project, he/she could compile with/without support to ZeosLib, just checking/unchecking some definition into Defines button. Excellent.

However, my only problem occur if user add zcomponent package, which belongs to ZeosLib. If so, I get some hints like this: ```
Note: Duplicate unit "ZVariant" in "mormot_base 1.18", orphaned ppu "<my-path>\zeos\packages\lazarus\lib\zcore\x86_64-win64\ZVariant.ppu" Note: Duplicate unit "ZVariant" in "zcore 7.2.5",
ppu="<my-path>\zeos\packages\lazarus\lib\zcore\x86_64-win64\ZVariant.ppu", source="<my-path>\zeos\src\core\ZVariant.pas"
Note: Duplicate unit "ZVariables" in "mormot_base 1.18", orphaned ppu "<my-path>\zeos\packages\lazarus\lib\zcore\x86_64-win64\ZVariables.ppu" Note: Duplicate unit "ZVariables" in "zcore 7.2.5", ppu="<my-path>\zeos\packages\lazarus\lib\zcore\x86_64-win64\ZVariables.ppu", source="<my-path>\zeos\src\core\ZVariables.pas"
```

What I don't understand is:
Adding ZeosLib into mormot_base package as a dependency (just for testing), I have the same paths as using Conditionals. Then, why the compiler show me these hints when I'm using ZeosLib paths "dynamically" by Conditionals?
What should I do to remove them?

best regards,
Marcos Douglas

Reply by email

Marcos Douglas B. Santos
to Marcos Douglas B. Santos

Maybe adding "dynamically" the Required Package, rather using "dynamically paths" by Conditionals, could fix this? But how to do this?

Just to be more clear, I don't have any "Duplicate units" as compiler is saying! Thanks.

regards,
Marcos Douglas

Reply by email

Tony Whyman
to Marcos Douglas B. Santos

My understanding is that when you add a "required package" what actually happens is that the IDE adds the package unit paths to the list of unit paths for your project, and adds the top level .pas file for the package (which usually has the same name as the package) to the "uses" clause in your project source file. The latter may not happen if an option is set in the package itself.

The result is that the package files get linked into your project. However, if you make the top level .pas file find a conditional reference from the uses clause then the package files only get linked in when the conditional is true.

Of course you also must do the same for any other units from the package that you include in your own unit files i.e. make their use conditional as well.

Marcos Douglas B. Santos wrote 9 lines
Maybe adding "dynamically" the Required Package, rather using "dynamically paths" by Conditionals, could fix this? But how to do this? Just to be more clear, I don't have any "Duplicate units" as compiler is saying! Thanks. regards, Marcos Douglas

Reply by email

Marcos Douglas B. Santos
to Tony Whyman
AM Tony Whyman wrote 7 lines
My understanding is that when you add a "required package" what actually happens is that the IDE adds the package unit paths to the list of unit paths for your project, and adds the top level .pas file for the package (which usually has the same name as the package) to the "uses" clause in your project source file. The latter may not happen if an option is set in the package itself.

I'm not using this option, as we don't need to add all units at the project.

The result is that the package files get linked into your project. However, if you make the top level .pas file find a conditional reference from the uses clause then the package files only get linked in when the conditional is true.

Once the user set some defined (-dNOSYNDBZEOS), the conditional will be always true.
I don't have issues compiling the Package. I can set add/remove the defined and it gets the dependency paths or remove them. Everything works, but only in Package context.

Of course you also must do the same for any other units from the package that you include in your own unit files i.e. make their use conditional as well.

I don't get this part. I'm not including units, but paths:

if undefined(NOSYNDBZEOS) then
begin
  UnitPath += ';$PkgOutDir(zcore);$PkgOutDir(zdbc);$PkgOutDir(zparsesql);$PkgOutDir(zplain)';
  IncPath += ';$PkgDir(zcore)\..\..\src';
end;

And these paths do not have the sources (.pas), only the .ppu files.

If use like this and click on Show Options on the Project, I can see correct paths to use.
if I remove this conditional and add `zcomponent`, which has all these paths, into my package and click on Show Options on the Project, again, I can see the *same* paths.

So, I'm thinking this is something on Lazarus context, before sending to compiler, as the paths looks Ok.

regards,
Marcos Douglas

Reply by email

Mattias Gaertner
to Marcos Douglas B. Santos: Imagine a package that has a dependency for another one. However, this dependency has a…

On Fri, 19 Jul 2019 00:26:49 -0300
"Marcos Douglas B. Santos via lazarus"

Show quoted text 30 lines
Hi, Imagine a package that has a dependency for another one. However, this dependency has a conditional to exists. So, I cannot add the Required Package by default — I'm talking about ZeosLib. Then, I used Conditionals (script) for adding ZeosLib paths (-Fu, -Fi) into the paths of the package — amazing work in IDE, by the way. In Custom Options | Conditionals, I have something like this: ===begin=== if undefined(NOSYNDBZEOS) then begin UnitPath += ';$PkgOutDir(zcore);$PkgOutDir(zdbc);$PkgOutDir(zparsesql);$PkgOutDir(zplain)'; IncPath += ';$(ProjOutDir);$PkgDir(zcore)\..\..\src'; end; ===end=== And it works. If user add the package into a project, he/she could compile with/without support to ZeosLib, just checking/unchecking some definition into Defines button. Excellent. However, my only problem occur if user add zcomponent package, which belongs to ZeosLib. If so, I get some hints like this: ``` Note: Duplicate unit "ZVariant" in "mormot_base 1.18", orphaned ppu "<my-path>\zeos\packages\lazarus\lib\zcore\x86_64-win64\ZVariant.ppu" Note: Duplicate unit "ZVariant" in "zcore 7.2.5", ppu="<my-path>\zeos\packages\lazarus\lib\zcore\x86_64-win64\ZVariant.ppu", source="<my-path>\zeos\src\core\ZVariant.pas"

It means: Two packages reach the same ppu and only one has a source file. Hmm, that should not create a note.
I fixed a check in rev61607, please test with trunk.

Show quoted text 12 lines
Note: Duplicate unit "ZVariables" in "mormot_base 1.18", orphaned ppu "<my-path>\zeos\packages\lazarus\lib\zcore\x86_64-win64\ZVariables.ppu" Note: Duplicate unit "ZVariables" in "zcore 7.2.5", ppu="<my-path>\zeos\packages\lazarus\lib\zcore\x86_64-win64\ZVariables.ppu", source="<my-path>\zeos\src\core\ZVariables.pas" ``` What I don't understand is: Adding ZeosLib into mormot_base package as a dependency (just for testing), I have the same paths as using Conditionals. Then, why the compiler show me these hints when I'm using ZeosLib paths "dynamically" by Conditionals?

These notes come from Lazarus, not fpc.

What should I do to remove them?

Mattias

Reply by email

Marcos Douglas B. Santos
to Mattias Gaertner
AM Mattias Gaertner wrote 39 lines
On Fri, 19 Jul 2019 00:26:49 -0300 "Marcos Douglas B. Santos via lazarus" wrote: > Hi, > > Imagine a package that has a dependency for another one. However, this > dependency has a conditional to exists. So, I cannot add the Required > Package by default — I'm talking about ZeosLib. > > Then, I used Conditionals (script) for adding ZeosLib paths (-Fu, -Fi) > into the paths of the package — amazing work in IDE, by the way. > > In Custom Options | Conditionals, I have something like this: > ===begin=== > if undefined(NOSYNDBZEOS) then > begin > UnitPath += > ';$PkgOutDir(zcore);$PkgOutDir(zdbc);$PkgOutDir(zparsesql);$PkgOutDir(zplain)'; > IncPath += ';$(ProjOutDir);$PkgDir(zcore)\..\..\src'; end; > ===end=== > > And it works. If user add the package into a project, he/she could > compile with/without support to ZeosLib, just checking/unchecking some > definition into Defines button. Excellent. > > However, my only problem occur if user add zcomponent package, which > belongs to ZeosLib. If so, I get some hints like this: > ``` > Note: Duplicate unit "ZVariant" in "mormot_base 1.18", orphaned ppu > "<my-path>\zeos\packages\lazarus\lib\zcore\x86_64-win64\ZVariant.ppu" > Note: Duplicate unit "ZVariant" in "zcore 7.2.5", > ppu="<my-path>\zeos\packages\lazarus\lib\zcore\x86_64-win64\ZVariant.ppu", > source="<my-path>\zeos\src\core\ZVariant.pas" It means: Two packages reach the same ppu and only one has a source file. Hmm, that should not create a note. I fixed a check in rev61607, please test with trunk.

Thanks.
Do you think this is a hack to add packages dynamically, or is it the right way?

regards,
Marcos Douglas

Reply by email