Skip to content

Instantly share code, notes, and snippets.

@back2dos
Last active December 19, 2015 13:48
Show Gist options
  • Save back2dos/5964415 to your computer and use it in GitHub Desktop.
Save back2dos/5964415 to your computer and use it in GitHub Desktop.
Store build information in metadata.
package ;
import haxe.rtti.Meta;
typedef BuildInfo = {
date: Date,
}
class Build {
static public var info(get, null):BuildInfo;
static function get_info() {
if (info == null) {
var meta = Meta.getType(Build);
info = {
date: Date.fromTime(meta.date[0])
}
}
return info;
}
#if macro
static public function storeInfo() {
switch haxe.macro.Context.getType('Build') {
case TInst(cl, _):
var cl = cl.get();
var m = cl.meta;
if (m.has('info'))
m.remove('info');
m.add('date', [macro $v{Date.now().getTime()}], cl.pos);
default: throw 'assert';
}
}
#end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment