annotate src/clojure/lang/Compile.java @ 10:ef7dbbd6452c

added clojure source goodness
author Robert McIntyre <rlm@mit.edu>
date Sat, 21 Aug 2010 06:25:44 -0400
parents
children
rev   line source
rlm@10 1 /**
rlm@10 2 * Copyright (c) Rich Hickey. All rights reserved.
rlm@10 3 * The use and distribution terms for this software are covered by the
rlm@10 4 * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
rlm@10 5 * which can be found in the file epl-v10.html at the root of this distribution.
rlm@10 6 * By using this software in any fashion, you are agreeing to be bound by
rlm@10 7 * the terms of this license.
rlm@10 8 * You must not remove this notice, or any other, from this software.
rlm@10 9 **/
rlm@10 10
rlm@10 11
rlm@10 12 package clojure.lang;
rlm@10 13
rlm@10 14 import java.io.OutputStreamWriter;
rlm@10 15 import java.io.PrintWriter;
rlm@10 16 import java.io.IOException;
rlm@10 17
rlm@10 18 // Compiles libs and generates class files stored within the directory
rlm@10 19 // named by the Java System property "clojure.compile.path". Arguments are
rlm@10 20 // strings naming the libs to be compiled. The libs and compile-path must
rlm@10 21 // all be within CLASSPATH.
rlm@10 22
rlm@10 23 public class Compile{
rlm@10 24
rlm@10 25 private static final String PATH_PROP = "clojure.compile.path";
rlm@10 26 private static final String REFLECTION_WARNING_PROP = "clojure.compile.warn-on-reflection";
rlm@10 27 private static final Var compile_path = RT.var("clojure.core", "*compile-path*");
rlm@10 28 private static final Var compile = RT.var("clojure.core", "compile");
rlm@10 29 private static final Var warn_on_reflection = RT.var("clojure.core", "*warn-on-reflection*");
rlm@10 30
rlm@10 31 public static void main(String[] args) throws Exception{
rlm@10 32
rlm@10 33 OutputStreamWriter out = (OutputStreamWriter) RT.OUT.deref();
rlm@10 34 PrintWriter err = RT.errPrintWriter();
rlm@10 35 String path = System.getProperty(PATH_PROP);
rlm@10 36 int count = args.length;
rlm@10 37
rlm@10 38 if(path == null)
rlm@10 39 {
rlm@10 40 err.println("ERROR: Must set system property " + PATH_PROP +
rlm@10 41 "\nto the location for compiled .class files." +
rlm@10 42 "\nThis directory must also be on your CLASSPATH.");
rlm@10 43 System.exit(1);
rlm@10 44 }
rlm@10 45
rlm@10 46 boolean warnOnReflection = System.getProperty(REFLECTION_WARNING_PROP, "false").equals("true");
rlm@10 47
rlm@10 48 try
rlm@10 49 {
rlm@10 50 Var.pushThreadBindings(RT.map(compile_path, path, warn_on_reflection, warnOnReflection));
rlm@10 51
rlm@10 52 for(String lib : args)
rlm@10 53 {
rlm@10 54 out.write("Compiling " + lib + " to " + path + "\n");
rlm@10 55 out.flush();
rlm@10 56 compile.invoke(Symbol.intern(lib));
rlm@10 57 }
rlm@10 58 }
rlm@10 59 finally
rlm@10 60 {
rlm@10 61 Var.popThreadBindings();
rlm@10 62 try
rlm@10 63 {
rlm@10 64 out.flush();
rlm@10 65 out.close();
rlm@10 66 }
rlm@10 67 catch(IOException e)
rlm@10 68 {
rlm@10 69 e.printStackTrace(err);
rlm@10 70 }
rlm@10 71 }
rlm@10 72 }
rlm@10 73 }