Thread overview
Dub importPath and sourcePath variables
Aug 28, 2019
Max
Aug 28, 2019
Andre Pany
Sep 02, 2019
Max
August 28, 2019
Hello,

I am having a problem working with custom build types in Dub.

For my project, when I perform a regular build, all of my source code is contained in ./source or ~/.dub/packages/<package-name>.
However, I want to specify a custom build type (called 'tests') that imports modules from the additional directory ./tests.
Accordingly, my dub.json file is structured as follows:

{
	"name": "q1dcfd",
	"authors": [
		"Tom Reddell", "Viv Bone"
	],
	"description" : "Quasi One Dimensional Compressible Flow Dynamics",
	"copyright"   : "Copyright © 2018, Tom Reddell",
	"license"     : "MIT",
	"targetType"  : "executable",
	"sourceFiles"         : ["$CPD/source/cpp_layer.o", "$CPD/source/libCoolProp.a"],
    "excludedSourceFiles" : ["source/experimental/*"],
	"dependencies": {
        "mir"           : "~>3.2.0",
        "mir-algorithm" : "~>3.4.14",
        "lubeck"        : "~>1.1.2",
		"coolprop"      : "*"
	},
    "buildTypes" : {
        "tests" : {
            "buildOptions"        : ["unittests", "debugMode"],
            "importPaths"         : ["tests/", "source/"],
            "sourcePaths"         : ["tests/", "source/"],
            "excludedSourceFiles" : ["source/experimental/*"]
        }
    }
}

When I manually assign my "importPaths" and "sourcePaths" variables during a "tests" build, I overwrite the values in these variables that have been automatically added due to my dependencies, causing the build to fail.
Is there a way that I can append "tests" to importPaths and sourcePaths, rather than overwriting them completely?

Regards,

Viv

August 28, 2019
On Wednesday, 28 August 2019 at 00:26:24 UTC, Max wrote:
> Hello,
>
> I am having a problem working with custom build types in Dub.
>
> For my project, when I perform a regular build, all of my source code is contained in ./source or ~/.dub/packages/<package-name>.
> However, I want to specify a custom build type (called 'tests') that imports modules from the additional directory ./tests.
> Accordingly, my dub.json file is structured as follows:
>
> {
> 	"name": "q1dcfd",
> 	"authors": [
> 		"Tom Reddell", "Viv Bone"
> 	],
> 	"description" : "Quasi One Dimensional Compressible Flow Dynamics",
> 	"copyright"   : "Copyright © 2018, Tom Reddell",
> 	"license"     : "MIT",
> 	"targetType"  : "executable",
> 	"sourceFiles"         : ["$CPD/source/cpp_layer.o", "$CPD/source/libCoolProp.a"],
>     "excludedSourceFiles" : ["source/experimental/*"],
> 	"dependencies": {
>         "mir"           : "~>3.2.0",
>         "mir-algorithm" : "~>3.4.14",
>         "lubeck"        : "~>1.1.2",
> 		"coolprop"      : "*"
> 	},
>     "buildTypes" : {
>         "tests" : {
>             "buildOptions"        : ["unittests", "debugMode"],
>             "importPaths"         : ["tests/", "source/"],
>             "sourcePaths"         : ["tests/", "source/"],
>             "excludedSourceFiles" : ["source/experimental/*"]
>         }
>     }
> }
>
> When I manually assign my "importPaths" and "sourcePaths" variables during a "tests" build, I overwrite the values in these variables that have been automatically added due to my dependencies, causing the build to fail.
> Is there a way that I can append "tests" to importPaths and sourcePaths, rather than overwriting them completely?
>
> Regards,
>
> Viv

My understanding is that you can use configurations rather than build types.

"configurations": [{
            "name": "debug",
            "targetType": "executable",
            "targetName": "puzz",
            "targetPath": "bin"
        }, {
            "name": "unittest",
            "targetType": "executable",
            "targetName": "unittest",
            "mainSourceFile": "source/cp/app.d"
        }

    ]

Command ```dub build``` will use the first configuration (debug). Command ```dub test``` will automatically use configuration unittest.

Kind regards
Andre


September 02, 2019
Works great, thanks Andre.