www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Does dub support generating source files?

reply Bastiaan Veelo <Bastiaan Veelo.net> writes:
Hi,

One of my source files (epparser.d) should be generated by 
calling rdmd on another soure file (make.d) and therefore should 
depend on changes in make.d and an additional module 
(epgrammar.d). An include path to Pegged is required for 
compilation. epparser.d should be part of the main project, but 
make.d and epgrammar.d should not. I have tried using a dub 
subpackage for this with preBuildCommands ("cd ./subpackage && 
dub run") in the main project, but that doesn't update epparser.d 
when epgrammar.d changes (oddly enough; is does update when 
subpackage targetType is "library", but it must be "executable"). 
epparser.d should not be generated unnecessarily.

I could script a custom preBuildCommand that checks modification 
dates and supplies the Pegged include path explicitly but that 
seems hackish and non-portable and typically something that the 
build system should do.

Can dub do this or is this a thing for reggae? It must work on 
Windows though.

Thanks!
Jan 06 2018
parent reply rikki cattermole <rikki cattermole.co.nz> writes:
On 06/01/2018 1:23 PM, Bastiaan Veelo wrote:
 Hi,
 
 One of my source files (epparser.d) should be generated by calling rdmd 
 on another soure file (make.d) and therefore should depend on changes in 
 make.d and an additional module (epgrammar.d). An include path to Pegged 
 is required for compilation. epparser.d should be part of the main 
 project, but make.d and epgrammar.d should not. I have tried using a dub 
 subpackage for this with preBuildCommands ("cd ./subpackage && dub run") 
 in the main project, but that doesn't update epparser.d when epgrammar.d 
 changes (oddly enough; is does update when subpackage targetType is 
 "library", but it must be "executable"). epparser.d should not be 
 generated unnecessarily.
 
 I could script a custom preBuildCommand that checks modification dates 
 and supplies the Pegged include path explicitly but that seems hackish 
 and non-portable and typically something that the build system should do.
 
 Can dub do this or is this a thing for reggae? It must work on Windows 
 though.
 
 Thanks!
See: https://github.com/Abscissa/gen-package-version
Jan 06 2018
next sibling parent Bastiaan Veelo <Bastiaan Veelo.net> writes:
On Saturday, 6 January 2018 at 13:40:54 UTC, rikki cattermole 
wrote:
 On 06/01/2018 1:23 PM, Bastiaan Veelo wrote:
 Can dub do this or is this a thing for reggae? It must work on 
 Windows though.
 
 Thanks!
See: https://github.com/Abscissa/gen-package-version
That seems to be a good tip, thanks. I'll need to study what's going on there.
Jan 06 2018
prev sibling parent Bastiaan Veelo <Bastiaan Veelo.net> writes:
On Saturday, 6 January 2018 at 13:40:54 UTC, rikki cattermole 
wrote:
 On 06/01/2018 1:23 PM, Bastiaan Veelo wrote:
 I could script a custom preBuildCommand that checks 
 modification dates and supplies the Pegged include path 
 explicitly but that seems hackish and non-portable and 
 typically something that the build system should do.
See: https://github.com/Abscissa/gen-package-version
If I read this correctly, it basically takes the script route (rdmd) somewhat like the above [1], but taking care to stay portable by inquiring dub. I should be able to make this work, but I wish dub supported adding simple make rules... [1] https://github.com/Abscissa/gen-package-version/blob/515138077fb78af5c4154f13990cee23e54ed9e7/src/genPackageVersion/genDModule.d#L60
Jan 06 2018