-
-
Save sonygod/7545381 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
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
One way to tackle this is do decorate all classes with different metadata.
Something like this:
@:module('a')
class A {
}
@:module('b')
class B {
}
class X {
}
And then you will need something like this:
https://gist.github.com/back2dos/6465183
And then you would compile with
--macro Module.build();
to getanything that is not part of some module (that would include the std
lib and
X
) and then--macro Module.build('a');
and--macro Module.build('b');
And you must be sure to load them in the right order of course. Cyclic
dependencies will probably break your neck. And you'll need to
@:expose stuff in the gist, along the lines of Caue's snippet.
Regards,
Juraj