Created
February 3, 2016 15:56
-
-
Save back2dos/de554d549f14e0b9cc0b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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