dub sourceFiles

aliak something at something.com
Wed Apr 1 08:52:43 UTC 2020


On Tuesday, 31 March 2020 at 15:23:48 UTC, Anonymouse wrote:
> I have a library package that I split up into subpackages, but 
> I'm having to do mental gymnastics to make it only compile the 
> files I want.
>
> The problem is that even if you specify some `sourceFiles`, it 
> will build everything under the sun inside `sourcePaths`, which 
> defaults to "source" or "src" depending on availability. 
> There's no way to set it to an empty string, or something that 
> doesn't exist.
>
> ```sdl
> name "stuff"
> targetType "library"
>
> subPackage {
>     name "foo"
>
>     sourceFiles \
>         "source/foo.d"
> }
>
> subPackage {
>     name "bar"
>
>     sourceFiles \
>         "source/bar.d" \
>         "source/common.d"
> }
> ```
>
>> $ dub build -v :foo
>> [...]
>> /usr/bin/dmd -Isource source/foo.d source/bar.d source/common.d
>
> Since I didn't specify any `sourcePaths`, it here defaults to 
> "source" and my subpackage only asking for "foo.d" was handed 
> all of the files anyway.
>
> What is the preferred solution here?
>
> 1. Use `excludedSourceFiles` and exclude files not to be 
> compiled. Mental gymnastics needed when you have 12 files (the 
> actual case).
> 2a. Keep source tree in something that isn't named "source" or 
> "src", but keep an empty one around for dub to auto-include 
> nothing from. I kind of want to avoid this.
> 2b. Keep real source files in "source", but declare 
> `sourcePaths` to point to a dummy empty "ignoreme" directory.  
> Crude but technically works.
> 3. Something else? Surely I'm not the first to run into this.
>
> I could set up the subpackages to each have its own directory 
> (2a), but I'd end up with twelve, not including the empty 
> "source" acting as bait for dub.

Maybe this will help you: 
https://github.com/aliak00/dub-subpackages

I think it falls under the something else category. The "lib" 
folder does have a source directory but I'm pretty sure you can 
remove that and it will still work and compile only the sub 
projects you want it to.

But, dub is sometimes a mystery in how it works so shout if the 
above doesn't work!


More information about the Digitalmars-d-learn mailing list