|
| 1 | +package linc; |
| 2 | + |
| 3 | +import haxe.io.Path; |
| 4 | +import haxe.macro.Expr; |
| 5 | +import haxe.macro.Context; |
| 6 | + |
| 7 | +using haxe.macro.PositionTools; |
| 8 | + |
| 9 | + |
| 10 | +class Linc { |
| 11 | + |
| 12 | + /** Adds a private internal inline static variable called __touch, |
| 13 | + which sets the value to the current time so that builds are always |
| 14 | + updated by the code, and native changes are dragged in automatically (except for header only changes) */ |
| 15 | + macro public static function touch() : Array<Field> { |
| 16 | + |
| 17 | + var _fields = Context.getBuildFields(); |
| 18 | + |
| 19 | + _fields.push({ |
| 20 | + name: '__touch', pos: Context.currentPos(), |
| 21 | + doc: null, meta: [], access: [APrivate, AStatic, AInline], |
| 22 | + kind: FVar(macro : String, macro $v{ Std.string(Date.now().getTime()) }), |
| 23 | + }); |
| 24 | + |
| 25 | + return _fields; |
| 26 | + |
| 27 | + } //touch |
| 28 | + |
| 29 | + /** Adds a @:buildXml meta node with a linc <set> and an <import> tag. |
| 30 | + The set is named LINC_${_lib}_PATH, and points to the root folder of the library. |
| 31 | + That path is calculated from the calling file using the optional _relative_root, default ../ |
| 32 | + This means that somelib/ is the root. |
| 33 | + somelib/somelib/Somelib.hx is the calling file. |
| 34 | + LINC_SOMELIB_PATH is set to somelib/ |
| 35 | + ${LINC_SOMELIB_PATH}/linc/linc_${_lib}.xml is added directly. */ |
| 36 | + macro public static function xml(_lib:String, _relative_root:String='../'):Array<Field> { |
| 37 | + |
| 38 | + var _pos = Context.currentPos(); |
| 39 | + var _pos_info = _pos.getInfos(); |
| 40 | + var _class = Context.getLocalClass(); |
| 41 | + |
| 42 | + var _source_path = Path.directory(_pos_info.file); |
| 43 | + if( !Path.isAbsolute(_source_path) ) { |
| 44 | + _source_path = Path.join([Sys.getCwd(), _source_path]); |
| 45 | + } |
| 46 | + |
| 47 | + _source_path = Path.normalize(_source_path); |
| 48 | + |
| 49 | + var _linc_lib_path = Path.normalize(Path.join([_source_path, _relative_root])); |
| 50 | + var _linc_include_path = Path.normalize(Path.join([ _linc_lib_path, './linc/linc_${_lib}.xml' ])); |
| 51 | + var _linc_lib_var = 'LINC_${_lib.toUpperCase()}_PATH'; |
| 52 | + |
| 53 | + var _define = '<set name="$_linc_lib_var" value="$_linc_lib_path/"/>'; |
| 54 | + var _import_path = '$${$_linc_lib_var}linc/linc_${_lib}.xml'; |
| 55 | + var _import = '<include name="$_import_path" />'; |
| 56 | + |
| 57 | + _class.get().meta.add(":buildXml", [{ expr:EConst( CString( '$_define\n$_import' ) ), pos:_pos }], _pos ); |
| 58 | + |
| 59 | + return Context.getBuildFields(); |
| 60 | + |
| 61 | + } //xml |
| 62 | + |
| 63 | +} //Linc |
0 commit comments