www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - dub subpckages and how to depend on them internally

reply aliak <something something.com> writes:
Hi, I'm trying to get dub working with subpackages and I just 
can't quite seem to hit the nail on the head. Any help would be 
greatly appreciated.

This is the current setup is like this, and there's a shared 
source folder as well called "common" and "sub2" depends on 
"sub1".

lib
  |-- dub.json
  |-- source/
             | -- sub1/
                      | -- package.d
                      | -- dub.json
             | -- sub2/
                      | -- package.d
                      | -- dub.json
             | -- common/

lib/dub.json
{
     "targetPath": "bin",
     "targetType": "library",
     "dependencies": {
         "lib:sub1": "*",
         "lib:sub2": "*",
     },
     "subPackages": [
         "./source/sub1",
         "./source/sub2"
     ]
}

And then sub1/dub.json and sub2/dub.json:

sub1:
{
     "name": "sub1",
     "targetType": "library",
     "sourcePaths": ["./", "../common"],
     "importPaths": ["./"],
     "targetPath": "../bin"
}

sub2:
{
     "name": "sub2",
     "targetType": "library",
     "dependencies": { "lib:sub1": "*" },
     "sourcePaths": ["./", "../common", "../sub1"],
     "importPaths": ["./"],
     "targetPath": "../bin"
}

So with the current set up, running dub test lib:sub1 works and 
dub test lib:sub2 works.

What doesn't work is if I try "import lib.sub1" from a test 
project. So in test project dub.json I have:

"dependencies": {
   "lib": {
     "path": "../../lib"
   }
}

I get error:

source/app.d(2,8): Error: module `sub1` is in file 'lib/sub1.d' 
which cannot be read. The output from dub shows one of my import 
paths is: import path[6] = ../../lib/source/sub1/. But I guess 
I'm missing something, or doing something wrong.

I also tried:

"dependencies": {
   "lib:sub1": {
     "path": "../../lib"
   }
}

But that gives me the same problem.

Halp!
May 29 2018
next sibling parent reply Martin Tschierschke <mt smartdolphin.de> writes:
On Tuesday, 29 May 2018 at 23:41:59 UTC, aliak wrote:
 Hi, I'm trying to get dub working with subpackages and I just 
 can't quite seem to hit the nail on the head. Any help would be 
 greatly appreciated.

 This is the current setup is like this, and there's a shared 
 source folder as well called "common" and "sub2" depends on 
 "sub1".

 lib
  |-- dub.json
  |-- source/
             | -- sub1/
                      | -- package.d
                      | -- dub.json
             | -- sub2/
                      | -- package.d
                      | -- dub.json
             | -- common/
[...]
 Halp!
I had a similar struggle, may be the version is the missing hint: "dependencies": { "diet-ng": "~>1.4", ...., mylib":{ "versions": "~master", "path": "/home/mt/d/mylib" }, .... } Try to place "versions": "~master", beside your path.
May 31 2018
parent aliak <something something.com> writes:
On Thursday, 31 May 2018 at 12:55:10 UTC, Martin Tschierschke 
wrote:
 I had a similar struggle, may be the version is the missing 
 hint:

 "dependencies": {
     "diet-ng": "~>1.4",
      ....,

      mylib":{
                 "versions": "~master",
                 "path": "/home/mt/d/mylib"
                 },
       ....
 }

 Try to place "versions": "~master", beside your path.
Unfortunately that did not work :(
May 31 2018
prev sibling parent reply Jesse Phillips <Jesse.K.Phillips+D gmail.com> writes:
On Tuesday, 29 May 2018 at 23:41:59 UTC, aliak wrote:
 Hi, I'm trying to get dub working with subpackages and I just 
 can't quite seem to hit the nail on the head. Any help would be 
 greatly appreciated.
Move your sub packages out of source. And each package will have it's own src folder, which you may have.
May 31 2018
parent reply aliak <something something.com> writes:
On Thursday, 31 May 2018 at 13:54:07 UTC, Jesse Phillips wrote:
 On Tuesday, 29 May 2018 at 23:41:59 UTC, aliak wrote:
 Hi, I'm trying to get dub working with subpackages and I just 
 can't quite seem to hit the nail on the head. Any help would 
 be greatly appreciated.
Move your sub packages out of source. And each package will have it's own src folder, which you may have.
Do you mean dub can't have source folder as a top level source directory if you use subpackages? So do I have to do this? root |-- sub1/source |-- sub2/source
May 31 2018
next sibling parent drug <drug2004 bk.ru> writes:
On 31.05.2018 20:56, aliak wrote:
 On Thursday, 31 May 2018 at 13:54:07 UTC, Jesse Phillips wrote:
 On Tuesday, 29 May 2018 at 23:41:59 UTC, aliak wrote:
 Hi, I'm trying to get dub working with subpackages and I just can't 
 quite seem to hit the nail on the head. Any help would be greatly 
 appreciated.
Move your sub packages out of source. And each package will have it's own src folder, which you may have.
Do you mean dub can't have source folder as a top level source directory if you use subpackages? So do I have to do this? root  |-- sub1/source  |-- sub2/source
Yes
May 31 2018
prev sibling parent reply Jesse Phillips <Jesse.K.Phillips+D gmail.com> writes:
On Thursday, 31 May 2018 at 17:56:57 UTC, aliak wrote:
 On Thursday, 31 May 2018 at 13:54:07 UTC, Jesse Phillips wrote:
 On Tuesday, 29 May 2018 at 23:41:59 UTC, aliak wrote:
 Hi, I'm trying to get dub working with subpackages and I just 
 can't quite seem to hit the nail on the head. Any help would 
 be greatly appreciated.
Move your sub packages out of source. And each package will have it's own src folder, which you may have.
Do you mean dub can't have source folder as a top level source directory if you use subpackages? So do I have to do this? root |-- sub1/source |-- sub2/source
Do that. You can have a top level source folder, but this is going to be code separate from your subpackage. The subpackage can depend on this top-level project, or the top-level project can depend on the subpackage.
May 31 2018
parent reply aliak <something something.com> writes:
On Thursday, 31 May 2018 at 20:01:43 UTC, Jesse Phillips wrote:
 On Thursday, 31 May 2018 at 17:56:57 UTC, aliak wrote:
 root
  |-- sub1/source
  |-- sub2/source
Do that. You can have a top level source folder, but this is going to be code separate from your subpackage. The subpackage can depend on this top-level project, or the top-level project can depend on the subpackage.
Ok I tried this as well, but I still get a module `sub1` is in file 'lib/sub1.d' which cannot be read I put up a GH test project with exactly what I'm doing. https://github.com/aliak00/dub-subpackages. There's a "lib" project that has subpackages "liba" and "libb" and there's a test application that tries to use the subpackages in different ways. The exact error for that setup is: source/app.d(4,9): Error: module `liba` is in file 'lib/liba.d' which cannot be read import path[0] = source/ import path[1] = ../lib/liba/source/ import path[2] = ../lib/libb/source/ import path[3] = /usr/local/opt/dmd/include/dlang/dmd Am I missing sourcePaths or something somewhere?
Jun 03 2018
parent reply Jesse Phillips <Jesse.K.Phillips+D gmail.com> writes:
On Sunday, 3 June 2018 at 12:08:44 UTC, aliak wrote:
 The exact error for that setup is:

 source/app.d(4,9): Error: module `liba` is in file 'lib/liba.d' 
 which cannot be read
 import path[0] = source/
 import path[1] = ../lib/liba/source/
 import path[2] = ../lib/libb/source/
 import path[3] = /usr/local/opt/dmd/include/dlang/dmd


 Am I missing sourcePaths or something somewhere?
This is a very complicated answer, so I made a pull request instead: https://github.com/aliak00/dub-subpackages/pull/1 lib/liba/source/suba corrected: lib/liba/source/liba/suba
Jun 03 2018
parent aliak <something something.com> writes:
On Sunday, 3 June 2018 at 15:23:52 UTC, Jesse Phillips wrote:
 On Sunday, 3 June 2018 at 12:08:44 UTC, aliak wrote:
 The exact error for that setup is:

 source/app.d(4,9): Error: module `liba` is in file 
 'lib/liba.d' which cannot be read
 import path[0] = source/
 import path[1] = ../lib/liba/source/
 import path[2] = ../lib/libb/source/
 import path[3] = /usr/local/opt/dmd/include/dlang/dmd


 Am I missing sourcePaths or something somewhere?
This is a very complicated answer, so I made a pull request instead: https://github.com/aliak00/dub-subpackages/pull/1 lib/liba/source/suba corrected: lib/liba/source/liba/suba
Ahhh, I see where I went wrong now. Thanks a lot for the help! And I like the extras you threw in there as well :D Cheers - Ali
Jun 03 2018