Dear dlang-folk,

one of the tools I always return to is rake (https://ruby.github.io/rake/). For those that do not know it, its a little like make in the
sense that you describe your build as a graph of tasks with dependencies
between them, but in contrast to make the definition is written in
a normal programming language (in this case ruby) with all features of
it.

Dlang is also quite expressive, so I thought why not define the build in Dlang.

The result is mind (https://gitlab.com/gizmomogwai/mind). An example mindfile looks like this:
```
#!/usr/bin/env dub
/+ dub.sdl:
   name "mindfile"
   dependency "mind" version="~master"
   ...further dependencies...
 +/
import mind;
import std.stdio : writeln;
import std.format : format;
import std.range : iota;
import std.algorithm : map;
import std.array : array;
import core.thread.osthread : Thread;
import core.time : msecs;

int main(string[] args)
{
    description("Do all");
    auto all = task("all", null, (t) {});

    for (int i=0; i<1000; ++i)
    {
        auto fileName = "out/file-%s.txt".format(i);
        all.enhance(fileName);
        description(fileName);
        file(fileName, null, (t)
             {
                 Thread.sleep(100.msecs);
                 sh("touch %s".format(t.name));
             },
        );
    }

    return mindMain(args);
}

```

This uses dub's single file feature
(https://dub.pm/advanced_usage#single-file) to get the helper library
and "execution engine" (mind).

The main functions defines a bunch of tasks or file-tasks and finally
forwards to the main function of the library for parallel (if possible)
execution of the tasks.

At the moment this is still in an experimental stage, but has nice
features such as:
- colorized --help (thanks to argparse)
- --tasks to show all defined (and commented tasks)
- parallel execution


I am still trying to find answers to the following questions:
1. Is it somehow possible to get rid of the dub single file scheme, and
   e.g. interpret a full dlang script at runtime?
2. How can the program as is made nicer/shorter? (one could just import
   std, or make use of https://code.dlang.org/packages/scriptlike)?
3. Does this make sense at all, or should we just use make/rake? (dub
   also uses a custom build.d file).


Kind regards,
Christian

Reply via email to