RejectedSoftware Forums

Sign up

postBuildCommands runs for each dub build inside

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

"name": "qcore",
"targetName": "qcore",
"targetType": "library",
"targetPath": "bin",
"versions": ["trace"],	
"postBuildCommands-posix": ["./buildExamples.sh"]

buildExamples.sh script:

#!/bin/sh
cd "examples"
echo "Build example 1: "
dub build --config=ex1
echo "Done\n"
echo "Build example 2: "
dub build --config=ex2
echo "Done\n"

and dub configs from examples:

"configurations": [
		{
			"name": "ex1",
			"targetName": "ex1",
			"targetType": "executable",
			"targetPath": "../bin",
			"sourcePaths": ["ex1/"],
			"versions": ["trace"]
		},
		{
			"name": "ex2",
			"targetName": "ex2",
			"targetType": "executable",
			"targetPath": "../bin",
			"sourcePaths": ["ex2/"],
			"versions": ["trace"]
		}
		
	]

When I run "dub build" in main dir i get output like this:

Building qcore ~master configuration "qcore", build type debug.
Running dmd...
Running post-build commands...
Building qcoreexamples ~master configuration "ex1", build type debug.
Compiling using dmd...
Linking...
Running post-build commands...
/bin/bash: ./buildExamples.sh: No such file or directory
Error executing command build: Command failed with exit code 127

Done

Build ex2 example: 
Building qcoreexamples ~master configuration "ex2", build type debug.
Compiling using dmd...
Linking...
Running post-build commands...
/bin/bash: ./buildExamples.sh: No such file or directory
Error executing command build: Command failed with exit code 127

Done

How can I fix this problem?

Thanks.

Re: postBuildCommands runs for each dub build inside

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": ".."}}

Re: postBuildCommands runs for each dub build inside

On Mon, 23 Feb 2015 15:33:58 GMT, Sönke Ludwig wrote:

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

I changed config to subPackages, but defined them in examples separately:
root/dub.json
root/examples/ex1/dub.json
root/examples/ex2/dub.json
and changed main config to

"subPackages": [
	"./examples/ex1/",
	"./examples/ex1/"		
]

when I run "dub build" it goes to infinite loop compiling examples over and over again.

Re: postBuildCommands runs for each dub build inside

On Mon, 23 Feb 2015 15:33:58 GMT, Sönke Ludwig wrote:

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": ".."}}

I understand, but I want to build library and examples with one "dub build". Post build script works great, because you can select what examples you want to build with library. Unfortunately, it doesn't work properly.