|
@@ -270,87 +270,18 @@ class Compiler {
|
|
|
@param paths An Array of package, module or sub-type dot paths to keep.
|
|
|
@param recursive If true, recurses into sub-packages for package paths.
|
|
|
**/
|
|
|
- public static function keep(?path : String, ?paths : Array<String>, ?recursive:Bool = true)
|
|
|
- {
|
|
|
+ public static function keep(?path : String, ?paths : Array<String>, ?recursive:Bool = true) {
|
|
|
if (null == paths)
|
|
|
paths = [];
|
|
|
if (null != path)
|
|
|
paths.push(path);
|
|
|
for (path in paths) {
|
|
|
- var found:Bool = false;
|
|
|
- var moduleFirstCharacter:String = ((path.indexOf(".") < 0)?path:path.substring(path.lastIndexOf(".")+1)).charAt(0);
|
|
|
- var startsWithUpperCase:Bool = (moduleFirstCharacter == moduleFirstCharacter.toUpperCase());//needed because FileSystem is not case sensitive
|
|
|
- var moduleRoot = (path.indexOf(".") < 0)?"":path.substring(0, path.lastIndexOf("."));
|
|
|
- var moduleRootFirstCharacter:String = ((moduleRoot.indexOf(".") < 0)?moduleRoot:moduleRoot.substring(moduleRoot.lastIndexOf(".")+1)).charAt(0);
|
|
|
- var rootStartsWithUpperCase:Bool = (moduleRootFirstCharacter == moduleRootFirstCharacter.toUpperCase());//needed because FileSystem is not case sensitive
|
|
|
- for ( classPath in Context.getClassPath() ) {
|
|
|
- var moduleRootPath = (moduleRoot == "")?"":(classPath + moduleRoot.split(".").join("/") + ".hx");
|
|
|
- var fullPath = classPath + path.split(".").join("/");
|
|
|
- var isValidModule:Bool = startsWithUpperCase && sys.FileSystem.exists(fullPath + ".hx");
|
|
|
- var isValidSubType:Bool = !isValidModule && moduleRootPath != "" && rootStartsWithUpperCase && sys.FileSystem.exists(moduleRootPath);
|
|
|
- var isValidDirectory:Bool = !isValidSubType && sys.FileSystem.exists(fullPath) && sys.FileSystem.isDirectory(fullPath);
|
|
|
- if ( !isValidDirectory && !isValidModule && !isValidSubType)
|
|
|
- continue;
|
|
|
- else
|
|
|
- found = true;
|
|
|
-
|
|
|
- if(isValidDirectory) {
|
|
|
- for( file in sys.FileSystem.readDirectory(fullPath) ) {
|
|
|
- if( StringTools.endsWith(file, ".hx") ) {
|
|
|
- var module = path + "." + file.substr(0, file.length - 3);
|
|
|
- keepModule(module);
|
|
|
- } else if( recursive && sys.FileSystem.isDirectory(fullPath + "/" + file) )
|
|
|
- keep(path + "." + file, true);
|
|
|
- }
|
|
|
- } else if(isValidModule){
|
|
|
- keepModule(path);
|
|
|
- } else if(isValidSubType){
|
|
|
- keepSubType(path);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (!found)
|
|
|
- Context.warning("file or directory not found, can't keep: "+path, Context.currentPos());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private static function keepSubType( path : String )
|
|
|
- {
|
|
|
- var module = path.substring(0, path.lastIndexOf("."));
|
|
|
- var typeName = path.substring(path.lastIndexOf(".") + 1);
|
|
|
- var subType:Type.BaseType = null;
|
|
|
- for (type in Context.getModule(module)) {
|
|
|
- switch(type) {
|
|
|
- case TInst(_.get() => cls, _) if (cls.name == typeName):
|
|
|
- subType = cls;
|
|
|
- break;
|
|
|
- case TEnum(_.get() => en, _) if (en.name == typeName):
|
|
|
- subType = en;
|
|
|
- break;
|
|
|
- default:
|
|
|
- //
|
|
|
- }
|
|
|
+ addGlobalMetadata(path, "@:keep", recursive, true, true);
|
|
|
}
|
|
|
-
|
|
|
- if (subType == null)
|
|
|
- Context.warning('Cannot keep $path: type not found or is not a class or enum', Context.currentPos());
|
|
|
- else
|
|
|
- subType.meta.add(":keep", [], subType.pos);
|
|
|
}
|
|
|
|
|
|
- private static function keepModule( path : String )
|
|
|
- {
|
|
|
- var types = Context.getModule(path);
|
|
|
- for (type in types) {
|
|
|
- switch(type) {
|
|
|
- case TInst(_.get() => cls, _) if (!cls.kind.match(KAbstractImpl(_))):
|
|
|
- cls.meta.add(":keep", [], cls.pos);
|
|
|
- case TEnum(_.get() => en, _):
|
|
|
- en.meta.add(":keep", [], en.pos);
|
|
|
- default:
|
|
|
- //
|
|
|
- }
|
|
|
- }
|
|
|
+ public static function addGlobalMetadata(pathFilter:String, meta:String, ?recursive:Bool = true, ?toTypes:Bool = true, ?toFields:Bool = false) {
|
|
|
+ untyped load("add_global_metadata",5)(untyped pathFilter.__s, meta.__s, recursive, toTypes, toFields);
|
|
|
}
|
|
|
|
|
|
/**
|