Plugin.hx 2.0 KB

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