Skip to content

Instantly share code, notes, and snippets.

@back2dos
Created February 3, 2016 15:56
Show Gist options
  • Select an option

  • Save back2dos/de554d549f14e0b9cc0b to your computer and use it in GitHub Desktop.

Select an option

Save back2dos/de554d549f14e0b9cc0b to your computer and use it in GitHub Desktop.
class Build {
macro static public function getEnv(s:String)
return macro $v{Sys.getEnv(s)};
macro static public function exec(cmd:String, ?args:Array<String>) {
var p = new sys.io.Process(cmd, args),
pos = haxe.macro.Context.currentPos();
return
switch p.exitCode() {
case 0:
var value =
switch p.stdout.readAll().toString() {
case '': p.stderr.readAll().toString();//sometimes output goes to stderr, particularly for --help and --version type of invocations
case v: v;
}
macro @:pos(pos) $v{value};
case v:
haxe.macro.Context.fatalError('Command $cmd exited with $v because ${p.stderr.readAll().toString()}', pos);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment