www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - dub sourceFiles

reply Anonymouse <zorael gmail.com> writes:
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.
Mar 31 2020
next sibling parent Andre Pany <andre s-e-a-p.de> writes:
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.

 [...]
Vibe-d is using approach 2a. You may have a look here https://github.com/vibe-d/vibe.d Kind regards Andre
Mar 31 2020
prev sibling next sibling parent WebFreak001 <d.forum webfreak.org> writes:
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.

 [...]
how about targetType "none" if you don't have any source in the main package but only subpackages? see https://dub.pm/package-format-sdl.html#sub-packages
Apr 01 2020
prev sibling parent aliak <something something.com> writes:
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!
Apr 01 2020