Plugin.hx 2.3 KB

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