How to add and run subPackages in Dub?

947 views Asked by At
Project/
  dub.sdl/
  source/
  examples/
    test/
      source/
        app.d
      dub.sdl

Project/dub.sdl

...
subpackage "./examples/test"
...

Project/examples/test/dub.sdl

name "test"
targetType "executeable"

If I try to execute dub run test if get the following error

Failed to parse package description for test in Project/examples/test.
Failed to find a package named 'test'.

The same happens if I try to execute dub run :test.

2

There are 2 answers

1
rcorre On BEST ANSWER

In the command, you should prefix the subpackage name with the root package name.

dub run rootpackagename:test

It appears you need to specify run (or build or some other command) explicitly).

0
biocyberman On

As of year 2017 with dub version 1.3.0: <rootpackagename> is optional. For example, I was testing jsoniopipe package as following:

# Add dependency which is not found on dub's repo:
git clone https://github.com/schveiguy/iopipe ../iopipe
dub add-local ../iopipe

dub.sdl file:

name "jsoniopipe"
description "JSON parser for iopipe"
authors "Steven Schveighoffer"
copyright "Copyright © 2017, Steven Schveighoffer"
license "boost"
targetType "library"
dependency "iopipe" version="*"
subPackage {
   name "formatjson"
   targetType "executable"
   sourcePaths "examples/formatjson"
   dependency "jsoniopipe" version="*"
}

Content of testjson.json

{
    "name": "myproject",
    "authors": [
        "My Name"
    ],
    "description": "My first project",
    "copyright": "Copyright © 2017, imadev",
    "license": "Boost"
}

Run command:

dub run :formatjson -- ./testjson.json