2
0
Эх сурвалжийг харах

added macro to setup plugin configuration

ncannasse 6 жил өмнө
parent
commit
ea013c7f2d
2 өөрчлөгдсөн 89 нэмэгдсэн , 25 устгасан
  1. 89 0
      hide/Plugin.hx
  2. 0 25
      plugin.hxml

+ 89 - 0
hide/Plugin.hx

@@ -0,0 +1,89 @@
+package hide;
+#if macro
+import haxe.macro.Compiler in C;
+import haxe.macro.Context;
+#end
+
+class Plugin {
+
+	#if macro
+
+	static var haxelibRoot = sys.io.File.getContent(Sys.getEnv("USERPROFILE")+"/.haxelib");
+	static var EXCLUDES = [
+		"hide",
+
+		"h2d",
+		"h3d",
+		"hxd",
+		"hxsl",
+		"hxbit",
+
+		"haxe",
+		"js",
+		"sys",
+		"hscript",
+		"cdb",
+		"format",
+
+		"HxOverrides",
+		"Math",
+		"EReg",
+		"Lambda",
+		"IntIterator",
+		"Reflect",
+		"Std",
+		"StringBuf",
+		"StringTools",
+		"Sys",
+		"Type",
+		"ValueType",
+		"Xml",		
+	];
+
+	static function getLibraryPath( libName ) {
+		var libPath = haxelibRoot+"/"+libName;
+		var dev = try sys.io.File.getContent(libPath+"/.dev") catch( e : Dynamic ) null;
+		if( dev != null )
+			libPath = dev;
+		else {
+			var cur = try sys.io.File.getContent(libPath+"/.current") catch( e : Dynamic ) null;
+			if( cur == null )
+				throw "Library not installed '"+libName+"'";
+			libPath += "/"+cur.split(".").join(",");
+		}
+		var json = try haxe.Json.parse(sys.io.File.getContent(libPath+"/haxelib.json")) catch( e : Dynamic ) null;
+		if( json != null && json.classPath != null )
+			libPath += "/"+json.classPath;
+		return libPath;
+	}
+
+	static function init() {
+		var hidePath = getLibraryPath("hide");
+		for( f in sys.io.File.getContent(hidePath+"/common.hxml").split("\n") ) {
+			var f = StringTools.trim(f);
+			if( f == "" ) continue;
+			var pl = f.split(" ");
+			var value = pl[1];
+			switch( pl[0] ) {
+			case "-lib":
+				if( value == "heaps" ) continue;
+				if( value == "hxnodejs" ) {
+					// should be set with -cp or will conflict with macro code
+					if( !Context.defined("hxnodejs") ) Context.error("Please add -lib hxnodejs", Context.currentPos());
+					continue;
+				}
+				C.define(value,"1");
+				C.addClassPath(getLibraryPath(value));
+			case "-D":
+				C.define(value,"1");
+			case "-cp":
+				C.addClassPath(hidePath+"/"+value);
+			default:
+			}
+		}		
+		for( e in EXCLUDES )
+			C.exclude(e);
+	}
+	#end
+
+}

+ 0 - 25
plugin.hxml

@@ -1,25 +0,0 @@
-common.hxml
---macro exclude("h3d")
---macro exclude("hxd")
---macro exclude("h2d")
---macro exclude("hxsl")
---macro exclude("hide")
---macro exclude("hscript")
---macro exclude("format")
---macro exclude("haxe")
---macro exclude("js")
---macro exclude("cdb")
---macro exclude("hxbit")
---macro exclude("sys")
-
---macro exclude("EReg")
---macro exclude("Lambda")
---macro exclude("Reflect")
---macro exclude("Std")
---macro exclude("IntIterator")
---macro exclude("StringTools")
---macro exclude("StringBuf")
---macro exclude("Sys")
---macro exclude("Type")
---macro exclude("ValueType")
---macro exclude("Xml")