On Mon, 23 Feb 2015 10:08:05 GMT, Oleh wrote:
Hello.
I have a problem with postBuildCommands. it runs for every "dub build" inside the script that I passed to this parameter. I'm trying to build library and a few executables after, that are using this library (like examples).
Here is my main dub configuration
(...)
I'd generally recommend to not run DUB as a pre/post command as that might cause strange effects in certain situations or in the future. Better tell the user to run ./buildExamples.sh
manually instead of running dub build
.
But the way to fix the concrete issue is to use separate (sub) packages for the examples instead of configurations:
{
"name": "qcore",
"targetName": "qcore",
"targetType": "library",
"targetPath": "bin",
"versions": ["trace"],
"postBuildCommands-posix": ["./buildExamples.sh"],
"subPackages": [
{
"name": "ex1",
"dependencies": {"qcore": "*"}
"targetName": "ex1",
"targetType": "executable",
"targetPath": "../bin",
"sourcePaths": ["ex1/"],
"versions": ["trace"]
},
{
"name": "ex2",
"dependencies": {"qcore": "*"}
"targetName": "ex2",
"targetType": "executable",
"targetPath": "../bin",
"sourcePaths": ["ex2/"],
"versions": ["trace"]
}
]
}
To build an example, you'd then run dub build qcore:ex1
, or shorter: dub build :ex1
Configurations are just variations of how to build the same build target, which means that in your original case there actually were only the two example executables, but no "library" configuration at all. Sub packages on the other hand are used to define separate build targets.
Alternatively, if you want to keep the main dub.json small and clean, you could put a separate dub.json into the "ex1/" and "ex2/" folders and build those with cd ex1 && dub build
or dub build --root=ex1
. The dependencies field would then have to look like this: "dependencies": {"qcore": {"path": ".."}}