dub subpckages and how to depend on them internally

aliak something at something.com
Tue May 29 23:41:59 UTC 2018


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!


More information about the Digitalmars-d mailing list