www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - dub optional dependency

reply ikod <geller.garry gmail.com> writes:
Hello,

I have dub.json with two configurations:

        "configurations": [
                 {
                         "name": "std",
                         "targetType": "library"
                 },
                 {
                         "name": "vibed",
                         "dependencies": {
                                 "vibe-d": {"version": "~>0.7"}
                         },
                         "targetType": "library",
                         "versions": [
                                 "vibeD"
                         ]
                 }
         ],

So default version is "std", I can build it w/o vibe-d, but dub 
anyway fetch  vibe-d.
I'd like dub fetch vibe-d only when I build with --config vibed.

I know about "optional": true, it prevent dub to fetch vibe-d for 
"std" config, but it also prevent it from fetching for --config 
vibed.

Thanks for any help.
Oct 28 2017
next sibling parent reply evilrat <evilrat666 gmail.com> writes:
On Saturday, 28 October 2017 at 19:23:42 UTC, ikod wrote:
 So default version is "std", I can build it w/o vibe-d, but dub 
 anyway fetch  vibe-d.
 I'd like dub fetch vibe-d only when I build with --config vibed.

 I know about "optional": true, it prevent dub to fetch vibe-d 
 for "std" config, but it also prevent it from fetching for 
 --config vibed.
This is dub design choice, optional requires manual fetching(dub fetch 'package'). I don't see other options, but you can try hack this using 'preBuildCommands' by adding dub fetch. Of course this defeats the purpose. Isn't it possible to put dependencies in specific configuration?
Oct 28 2017
parent reply Mike Parker <aldacron gmail.com> writes:
On Sunday, 29 October 2017 at 01:55:22 UTC, evilrat wrote:

 This is dub design choice, optional requires manual 
 fetching(dub fetch 'package'). I don't see other options, but 
 you can try hack this using 'preBuildCommands' by adding dub 
 fetch. Of course this defeats the purpose.
No, they don't need to be manually fetched. Optional packages are downloaded when they are specified in the dub.selections.json file.
 Isn't it possible to put dependencies in specific configuration?
What the OP wants is to have dependencies in a configuration be downloaded only when the configuration is specified. Currently, dependencies are always downloaded unless they are optional, no matter where they're listed in the file. And optional dependencies are only downloaded when they are specified in dub.selections.json. It would be a nice feature to have.
Oct 28 2017
parent Andre Pany <andre s-e-a-p.de> writes:
On Sunday, 29 October 2017 at 03:26:14 UTC, Mike Parker wrote:
 On Sunday, 29 October 2017 at 01:55:22 UTC, evilrat wrote:

 This is dub design choice, optional requires manual 
 fetching(dub fetch 'package'). I don't see other options, but 
 you can try hack this using 'preBuildCommands' by adding dub 
 fetch. Of course this defeats the purpose.
No, they don't need to be manually fetched. Optional packages are downloaded when they are specified in the dub.selections.json file.
 Isn't it possible to put dependencies in specific 
 configuration?
What the OP wants is to have dependencies in a configuration be downloaded only when the configuration is specified. Currently, dependencies are always downloaded unless they are optional, no matter where they're listed in the file. And optional dependencies are only downloaded when they are specified in dub.selections.json. It would be a nice feature to have.
In my case the eager dependency resolution is a serious problem. In my work environment access to the internet is forbidden for the official build due to software lifecycle requirements. The consequence is that I have to fetch all dependencies into the dub project (--cache = local). In addition every time open source software is used, for each open source software product a process has to be fulfilled. As example I would like to use the unit test framework d-unit. This dub package has for a specific configuration a decency to unit-threaded. The official build will fail as unit-threaded can not be found (no internet access). Including unit-threaded is not an option due to the open source process. Doing this process for the sake of a dub issue is not acceptable. There is an additional dub build option --nodeps. In my opinion this option should solve the problem but it is not working as expected. Maybe to due a bug. I created dub issue 1272 regarding this issue. Kind regards Andre
Oct 29 2017
prev sibling parent Mike Parker <aldacron gmail.com> writes:
On Saturday, 28 October 2017 at 19:23:42 UTC, ikod wrote:

 So default version is "std", I can build it w/o vibe-d, but dub 
 anyway fetch  vibe-d.
 I'd like dub fetch vibe-d only when I build with --config vibed.
As far as I know, that isn't possible. A package is either optional, or it isn't. It certainly would be a useful feature to have. Perhaps create an enhancement request for it if there isn't one already. https://github.com/dlang/dub/issues
Oct 28 2017