Skip to content

Instantly share code, notes, and snippets.

@back2dos
Last active December 22, 2015 11:19
Show Gist options
  • Save back2dos/6465183 to your computer and use it in GitHub Desktop.
Save back2dos/6465183 to your computer and use it in GitHub Desktop.
Compile only classes belonging to a given module
package ;
import haxe.macro.Type;
import haxe.macro.Expr;
import haxe.macro.Context;
class Module {
static function build(?module:String) {
function isIncluded(meta:MetaAccess)
return
(module == null && !meta.has(':module'))
||
Lambda.exists(meta.get(), function (m) return switch m {
case {
name: ':module',
params: []
} if (module == null): true;
case {
name: ':module',
params: [{ expr: EConst(CString(m))}]
} if (module == m): true;
default: false;
});
function checkType(b:BaseType) {
if (!isIncluded(b.meta)) {
Context.warning('excluding ' + b.name, b.pos);
b.exclude();
}
}
Context.onGenerate(function (types:Array<Type>) {
for (t in types) switch t {
case TInst(b, _): checkType(b.get());
case TEnum(b, _): checkType(b.get());
default:
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment