ImportAll.hx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright (C)2005-2018 Haxe Foundation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. */
  22. import haxe.macro.Context;
  23. class ImportAll {
  24. static function isSysTarget() {
  25. return Context.defined("neko") || Context.defined("php") || Context.defined("cpp") ||
  26. Context.defined("jvm") || Context.defined("python") ||
  27. Context.defined("lua") || Context.defined("hl") || Context.defined("eval");
  28. }
  29. public static function run( ?pack ) {
  30. if( pack == null ) {
  31. pack = "";
  32. haxe.macro.Compiler.define("doc_gen");
  33. }
  34. switch( pack ) {
  35. case "php":
  36. if( !Context.defined("php") ) return;
  37. case "neko":
  38. if( !Context.defined("neko") ) return;
  39. case "js":
  40. if( !Context.defined("js") ) return;
  41. case "cpp":
  42. if( !Context.defined("cpp") ) return;
  43. case "flash":
  44. if( !Context.defined("flash9") ) return;
  45. case "mt","mtwin":
  46. return;
  47. case "sys":
  48. if(!isSysTarget()) return;
  49. case "sys.thread":
  50. if ( !Context.defined("target.threaded") ) return;
  51. case "java" | "jvm":
  52. if( !Context.defined("jvm") ) return;
  53. case "python":
  54. if ( !Context.defined("python") ) return;
  55. case "hl":
  56. if( !Context.defined("hl") ) return;
  57. case "lua":
  58. if( !Context.defined("lua") ) return;
  59. case "eval":
  60. if( !Context.defined("eval") ) return;
  61. case "ssl":
  62. if (!Context.defined("neko") && !Context.defined("cpp")) return;
  63. case "tools", "build-tool", "jar-tool": return;
  64. }
  65. Context.onAfterInitMacros(() -> {
  66. for( p in Context.getClassPath() ) {
  67. if( p == "/" || p == "" )
  68. continue;
  69. // skip if we have a classpath to haxe
  70. if( pack.length == 0 && sys.FileSystem.exists(p+"std") )
  71. continue;
  72. var p = p + pack.split(".").join("/");
  73. if( StringTools.endsWith(p,"/") )
  74. p = p.substr(0,-1);
  75. if( !sys.FileSystem.exists(p) || !sys.FileSystem.isDirectory(p) )
  76. continue;
  77. for( file in sys.FileSystem.readDirectory(p) ) {
  78. if( file == ".svn" || file == "_std" )
  79. continue;
  80. var full = (pack == "") ? file : pack + "." + file;
  81. if( StringTools.endsWith(file, ".hx") && file.substr(0, file.length - 3).indexOf(".") < 0 ) {
  82. var cl = full.substr(0, full.length - 3);
  83. switch( cl ) {
  84. case "ImportAll", "neko.db.MacroManager": continue;
  85. case "haxe.TimerQueue": if( Context.defined("neko") || Context.defined("php") || Context.defined("cpp") ) continue;
  86. case "Sys": if(!isSysTarget()) continue;
  87. case "haxe.web.Request": if( !(Context.defined("neko") || Context.defined("php") || Context.defined("js")) ) continue;
  88. case "haxe.macro.ExampleJSGenerator","haxe.macro.Context", "haxe.macro.Compiler": if( !Context.defined("eval") ) continue;
  89. case "haxe.remoting.SocketWrapper": if( !Context.defined("flash") ) continue;
  90. case "haxe.remoting.SyncSocketConnection": if( !(Context.defined("neko") || Context.defined("php") || Context.defined("cpp")) ) continue;
  91. case "neko.vm.Ui" | "sys.db.Sqlite" | "sys.db.Mysql" if ( Context.defined("interp") ): continue;
  92. case "haxe.atomic.AtomicBool" if(!Context.defined("target.atomics")): continue;
  93. case "haxe.atomic.AtomicInt" if(!Context.defined("target.atomics")): continue;
  94. case "haxe.atomic.AtomicObject" if(!Context.defined("target.atomics") || Context.defined("js") || Context.defined("cpp")): continue;
  95. }
  96. Context.getModule(cl);
  97. } else if( sys.FileSystem.isDirectory(p + "/" + file) )
  98. run(full);
  99. }
  100. }
  101. });
  102. }
  103. }