[Lazarus] Adding Required Packages paths... dynamically

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[Lazarus] Adding Required Packages paths... dynamically

Free Pascal - Lazarus mailing list
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
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Adding Required Packages paths... dynamically

Free Pascal - Lazarus mailing list
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
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Adding Required Packages paths... dynamically

Free Pascal - Lazarus mailing list
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.

On 19/07/2019 14:21, Marcos Douglas B. Santos via lazarus wrote:
> 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
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Adding Required Packages paths... dynamically

Free Pascal - Lazarus mailing list
On Fri, Jul 19, 2019 at 10:30 AM Tony Whyman via lazarus
<[hidden email]> wrote:
>
> 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
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Adding Required Packages paths... dynamically

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
On Fri, 19 Jul 2019 00:26:49 -0300
"Marcos Douglas B. Santos via lazarus" <[hidden email]>
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.


> 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

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Adding Required Packages paths... dynamically

Free Pascal - Lazarus mailing list
On Sat, Jul 20, 2019 at 6:24 AM Mattias Gaertner via lazarus
<[hidden email]> wrote:

>
> On Fri, 19 Jul 2019 00:26:49 -0300
> "Marcos Douglas B. Santos via lazarus" <[hidden email]>
> 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
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus