Skip to content

Instantly share code, notes, and snippets.

@esnya
Last active August 29, 2015 14:19
Show Gist options
  • Save esnya/a655420fbdb6609a5bf1 to your computer and use it in GitHub Desktop.
Save esnya/a655420fbdb6609a5bf1 to your computer and use it in GitHub Desktop.
ディレクトリ下のD言語ソースコードを全てコンパイルして指定した場所に設置する何か
module publish;
import std.algorithm;
import std.file;
import std.range;
import std.stdio;
import std.parallelism;
import std.path;
import std.process;
import std.typecons;
void pipe(S, D, I)(S src, D dst, I id) {
src.byLine().each!((line) {
dst.lock();
scope(exit) dst.unlock();
dst.writeln(id, "> ", line);
})();
}
auto pipeTask(I, C, P)(I id, C cmd, P pipes) {
writeln(id, "> ", cmd.join(" "));
pipes.stdout.task!pipe(stdout, id).executeInNewThread();
pipes.stderr.task!pipe(stderr, id).executeInNewThread();
auto code = pipes.pid.wait();
(code ? stderr : stdout).writeln(id, "> Done (", code, ')');
return code;
}
void main(string[] args) {
auto dst = (args.length > 1) ? args[1] : "/usr/local/bin";
auto src = (args.length > 2) ? args[2] : ".";
src.dirEntries(SpanMode.shallow)
.filter!`a.isFile`()
.map!`a.name`()
.filter!`a.endsWith(".d")`()
.map!(a => tuple(a.baseName(".d"), ["dmd", "-release", "-O", "-inline", "-od" ~ tempDir, "-of" ~ buildPath(dst, a.baseName(".d")), a]))()
.map!(a => tuple(a[0], a[1], a[1].pipeProcess(Redirect.stdout | Redirect.stderr)))()
.each!(a => task!pipeTask(a.expand).executeInNewThread())();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment