2
0

ImportAll.hx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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("java") || Context.defined("python") ||
  27. Context.defined("lua") || Context.defined("hl") || Context.defined("eval"); // TODO: have to add cs here, SPOD gets in the way at the moment
  28. }
  29. public static function run( ?pack ) {
  30. if( pack == null ) {
  31. pack = "";
  32. haxe.macro.Compiler.define("doc_gen");
  33. }
  34. if (Context.defined("interp")) {
  35. haxe.macro.Compiler.define("macro");
  36. }
  37. switch( pack ) {
  38. case "php":
  39. if( !Context.defined("php") ) return;
  40. case "neko":
  41. if( !Context.defined("neko") ) return;
  42. case "js":
  43. if( !Context.defined("js") ) return;
  44. case "cpp":
  45. if( !Context.defined("cpp") ) return;
  46. case "flash":
  47. if( !Context.defined("flash9") ) return;
  48. case "mt","mtwin":
  49. return;
  50. case "sys":
  51. if(!isSysTarget()) return;
  52. case "sys.thread":
  53. if ( !Context.defined("target.threaded") ) return;
  54. case "java":
  55. if( !Context.defined("java") ) return;
  56. case "jvm":
  57. if( !Context.defined("jvm") ) return;
  58. case "cs":
  59. if( !Context.defined("cs") ) return;
  60. case "python":
  61. if ( !Context.defined("python") ) return;
  62. case "hl":
  63. if( !Context.defined("hl") ) return;
  64. case "lua":
  65. if( !Context.defined("lua") ) return;
  66. case "eval":
  67. if( !Context.defined("eval") ) return;
  68. case "ssl":
  69. if (!Context.defined("neko") && !Context.defined("cpp")) return;
  70. case "tools", "build-tool", "jar-tool": return;
  71. }
  72. for( p in Context.getClassPath() ) {
  73. if( p == "/" )
  74. continue;
  75. // skip if we have a classpath to haxe
  76. if( pack.length == 0 && sys.FileSystem.exists(p+"std") )
  77. continue;
  78. var p = p + pack.split(".").join("/");
  79. if( StringTools.endsWith(p,"/") )
  80. p = p.substr(0,-1);
  81. if( !sys.FileSystem.exists(p) || !sys.FileSystem.isDirectory(p) )
  82. continue;
  83. for( file in sys.FileSystem.readDirectory(p) ) {
  84. if( file == ".svn" || file == "_std" )
  85. continue;
  86. var full = (pack == "") ? file : pack + "." + file;
  87. if( StringTools.endsWith(file, ".hx") && file.substr(0, file.length - 3).indexOf(".") < 0 ) {
  88. var cl = full.substr(0, full.length - 3);
  89. switch( cl ) {
  90. case "ImportAll", "neko.db.MacroManager": continue;
  91. case "haxe.TimerQueue": if( Context.defined("neko") || Context.defined("php") || Context.defined("cpp") ) continue;
  92. case "Sys": if(!isSysTarget()) continue;
  93. case "haxe.web.Request": if( !(Context.defined("neko") || Context.defined("php") || Context.defined("js")) ) continue;
  94. case "haxe.macro.ExampleJSGenerator","haxe.macro.Context", "haxe.macro.Compiler": if( !Context.defined("eval") ) continue;
  95. case "haxe.remoting.SocketWrapper": if( !Context.defined("flash") ) continue;
  96. case "haxe.remoting.SyncSocketConnection": if( !(Context.defined("neko") || Context.defined("php") || Context.defined("cpp")) ) continue;
  97. case "neko.vm.Ui" | "sys.db.Sqlite" | "sys.db.Mysql" if ( Context.defined("interp") ): continue;
  98. case "sys.db.Sqlite" | "sys.db.Mysql" | "cs.db.AdoNet" if ( Context.defined("cs") ): continue;
  99. }
  100. Context.getModule(cl);
  101. } else if( sys.FileSystem.isDirectory(p + "/" + file) )
  102. run(full);
  103. }
  104. }
  105. }
  106. }