Last active
December 22, 2015 11:19
-
-
Save back2dos/6465183 to your computer and use it in GitHub Desktop.
Compile only classes belonging to a given module
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
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