PageRenderTime 53ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/src/jvm/clojure/lang/Compile.java

https://github.com/redarma/clojure
Java | 97 lines | 69 code | 15 blank | 13 comment | 5 complexity | c75c1fac683341faeba56168d244244c MD5 | raw file
  1. /**
  2. * Copyright (c) Rich Hickey. All rights reserved.
  3. * The use and distribution terms for this software are covered by the
  4. * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
  5. * which can be found in the file epl-v10.html at the root of this distribution.
  6. * By using this software in any fashion, you are agreeing to be bound by
  7. * the terms of this license.
  8. * You must not remove this notice, or any other, from this software.
  9. **/
  10. package clojure.lang;
  11. import java.io.OutputStreamWriter;
  12. import java.io.PrintWriter;
  13. import java.io.IOException;
  14. import java.util.ArrayList;
  15. import java.util.Enumeration;
  16. import java.util.Map;
  17. // Compiles libs and generates class files stored within the directory
  18. // named by the Java System property "clojure.compile.path". Arguments are
  19. // strings naming the libs to be compiled. The libs and compile-path must
  20. // all be within CLASSPATH.
  21. public class Compile{
  22. private static final String PATH_PROP = "clojure.compile.path";
  23. private static final String REFLECTION_WARNING_PROP = "clojure.compile.warn-on-reflection";
  24. private static final String UNCHECKED_MATH_PROP = "clojure.compile.unchecked-math";
  25. private static final Var compile_path = RT.var("clojure.core", "*compile-path*");
  26. private static final Var compile = RT.var("clojure.core", "compile");
  27. private static final Var warn_on_reflection = RT.var("clojure.core", "*warn-on-reflection*");
  28. private static final Var unchecked_math = RT.var("clojure.core", "*unchecked-math*");
  29. private static final Var compiler_options = RT.var("clojure.core", "*compiler-options*");
  30. public static void main(String[] args) throws IOException{
  31. OutputStreamWriter out = (OutputStreamWriter) RT.OUT.deref();
  32. PrintWriter err = RT.errPrintWriter();
  33. String path = System.getProperty(PATH_PROP);
  34. int count = args.length;
  35. if(path == null)
  36. {
  37. err.println("ERROR: Must set system property " + PATH_PROP +
  38. "\nto the location for compiled .class files." +
  39. "\nThis directory must also be on your CLASSPATH.");
  40. System.exit(1);
  41. }
  42. boolean warnOnReflection = System.getProperty(REFLECTION_WARNING_PROP, "false").equals("true");
  43. boolean uncheckedMath = System.getProperty(UNCHECKED_MATH_PROP, "false").equals("true");
  44. Object compilerOptions = null;
  45. for(Map.Entry e : System.getProperties().entrySet())
  46. {
  47. String name = (String) e.getKey();
  48. String v = (String) e.getValue();
  49. if(name.startsWith("clojure.compiler."))
  50. {
  51. compilerOptions = RT.assoc(compilerOptions
  52. ,RT.keyword(null,name.substring(1 + name.lastIndexOf('.')))
  53. ,RT.readString(v));
  54. }
  55. }
  56. try
  57. {
  58. Var.pushThreadBindings(RT.map(compile_path, path,
  59. warn_on_reflection, warnOnReflection,
  60. unchecked_math, uncheckedMath,
  61. compiler_options, compilerOptions));
  62. for(String lib : args)
  63. {
  64. out.write("Compiling " + lib + " to " + path + "\n");
  65. out.flush();
  66. compile.invoke(Symbol.intern(lib));
  67. }
  68. }
  69. finally
  70. {
  71. Var.popThreadBindings();
  72. try
  73. {
  74. out.flush();
  75. }
  76. catch(IOException e)
  77. {
  78. e.printStackTrace(err);
  79. }
  80. }
  81. }
  82. }