Plugin.hx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package hide;
  2. #if macro
  3. import haxe.macro.Compiler in C;
  4. import haxe.macro.Context;
  5. #end
  6. class Plugin {
  7. #if macro
  8. static var haxelibRoot = sys.io.File.getContent(Sys.getEnv("USERPROFILE")+"/.haxelib");
  9. static var EXCLUDES = [
  10. "hide",
  11. "hrt",
  12. "h2d",
  13. "h3d",
  14. "hxd",
  15. "hxsl",
  16. "hxbit",
  17. "haxe",
  18. "js",
  19. "sys",
  20. "hscript",
  21. "cdb",
  22. "format",
  23. "domkit",
  24. "HxOverrides",
  25. "Math",
  26. "EReg",
  27. "Lambda",
  28. "IntIterator",
  29. "Reflect",
  30. "Std",
  31. "StringBuf",
  32. "StringTools",
  33. "DateTools",
  34. "Sys",
  35. "_Sys",
  36. "Type",
  37. "ValueType",
  38. "Xml",
  39. "_Xml",
  40. ];
  41. static function getLibraryPath( libName ) {
  42. var libPath = haxelibRoot+"/"+libName;
  43. var dev = try StringTools.trim(sys.io.File.getContent(libPath+"/.dev")) catch( e : Dynamic ) null;
  44. if( dev != null )
  45. libPath = dev;
  46. else {
  47. var cur = try StringTools.trim(sys.io.File.getContent(libPath+"/.current")) catch( e : Dynamic ) null;
  48. if( cur == null )
  49. throw "Library not installed '"+libName+"'";
  50. libPath += "/"+cur.split(".").join(",");
  51. }
  52. var json = try haxe.Json.parse(sys.io.File.getContent(libPath+"/haxelib.json")) catch( e : Dynamic ) null;
  53. if( json != null && json.classPath != null )
  54. libPath += "/"+json.classPath;
  55. return libPath;
  56. }
  57. static function init() {
  58. var hidePath = getLibraryPath("hide");
  59. for( f in sys.io.File.getContent(hidePath+"/common.hxml").split("\n") ) {
  60. var f = StringTools.trim(f);
  61. if( f == "" ) continue;
  62. var pl = f.split(" ");
  63. var value = pl[1];
  64. switch( pl[0] ) {
  65. case "-lib":
  66. if( value == "heaps" ) continue;
  67. if( value == "hxnodejs" ) {
  68. // should be set with -cp or will conflict with macro code
  69. if( !Context.defined("hxnodejs") ) Context.error("Please add -lib hxnodejs", Context.currentPos());
  70. continue;
  71. }
  72. C.define(value,"1");
  73. C.addClassPath(getLibraryPath(value));
  74. case "-D":
  75. C.define(value,"1");
  76. case "-cp":
  77. C.addClassPath(hidePath+"/"+value);
  78. default:
  79. }
  80. }
  81. for( e in EXCLUDES )
  82. C.exclude(e);
  83. }
  84. #end
  85. }