view 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
line wrap: on
line source
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 **/
12 package clojure.lang;
14 import java.io.OutputStreamWriter;
15 import java.io.PrintWriter;
16 import java.io.IOException;
18 // Compiles libs and generates class files stored within the directory
19 // named by the Java System property "clojure.compile.path". Arguments are
20 // strings naming the libs to be compiled. The libs and compile-path must
21 // all be within CLASSPATH.
23 public class Compile{
25 private static final String PATH_PROP = "clojure.compile.path";
26 private static final String REFLECTION_WARNING_PROP = "clojure.compile.warn-on-reflection";
27 private static final Var compile_path = RT.var("clojure.core", "*compile-path*");
28 private static final Var compile = RT.var("clojure.core", "compile");
29 private static final Var warn_on_reflection = RT.var("clojure.core", "*warn-on-reflection*");
31 public static void main(String[] args) throws Exception{
33 OutputStreamWriter out = (OutputStreamWriter) RT.OUT.deref();
34 PrintWriter err = RT.errPrintWriter();
35 String path = System.getProperty(PATH_PROP);
36 int count = args.length;
38 if(path == null)
39 {
40 err.println("ERROR: Must set system property " + PATH_PROP +
41 "\nto the location for compiled .class files." +
42 "\nThis directory must also be on your CLASSPATH.");
43 System.exit(1);
44 }
46 boolean warnOnReflection = System.getProperty(REFLECTION_WARNING_PROP, "false").equals("true");
48 try
49 {
50 Var.pushThreadBindings(RT.map(compile_path, path, warn_on_reflection, warnOnReflection));
52 for(String lib : args)
53 {
54 out.write("Compiling " + lib + " to " + path + "\n");
55 out.flush();
56 compile.invoke(Symbol.intern(lib));
57 }
58 }
59 finally
60 {
61 Var.popThreadBindings();
62 try
63 {
64 out.flush();
65 out.close();
66 }
67 catch(IOException e)
68 {
69 e.printStackTrace(err);
70 }
71 }
72 }
73 }