Reloaded for dub

FG via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Fri Feb 20 10:59:54 PST 2015


On 2015-02-20 at 15:00, Kingsley wrote:
> Just thought I would share this in case anyone else finds it useful. I wrote a tiny utility that detects changes to D files and then rebuilds and re-executes the main binary using dub.

I see two problems:

1. It doesn't sleep for a few seconds after detecting that a file has changed, so when you upload several changed source files, recompilation may start before all of them are updated and either fail or produce something strange.

2. It works like this:

     if (changed) { kill(projectName); build() && run(projectName); sleep(); }

As a result, if the compilation fails, no application will be running. Probably a better approach would be to have the application copied to a different place and run from there. Then the loop would look like this (I also added an extra unittest run before the running application is replaced):

     if (changed) { sleep(); build() && test() && kill(dest) && copy(projectName, dest) && run(dest); sleep(); }

In this approach your program is almost always running. You only have to figure out how to provide `dest`. Perhaps via command line arguments where you provide a path (or just a directory).


More information about the Digitalmars-d-announce mailing list