dub sourceFiles

Anonymouse zorael at gmail.com
Tue Mar 31 15:23:48 UTC 2020


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.


More information about the Digitalmars-d-learn mailing list