diff src/rlm/clj.clj @ 0:78a630e650d2

initial import
author Robert McIntyre <rlm@mit.edu>
date Tue, 18 Oct 2011 00:57:08 -0700
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/rlm/clj.clj	Tue Oct 18 00:57:08 2011 -0700
     1.3 @@ -0,0 +1,58 @@
     1.4 +#!/home/r/roBin/env-cool java -cp /home/r/roBin/libs/*:/home/r/roBin/src:/home/r/roBin/rlm-lib/* -Xms1g -Xmx1g clojure.main
     1.5 +
     1.6 +(ns rlm.clj
     1.7 +  (:use [clojure.contrib
     1.8 +	 [duck-streams :only [file-str] ]
     1.9 +	 command-line str-utils shell-out
    1.10 +	 [seq :only [indexed]]]
    1.11 +      [rlm shell-write]))
    1.12 +
    1.13 +(defn clj [& args]
    1.14 +  (with-command-line args 
    1.15 +    "Simple Clojure shebang (#!) lines"
    1.16 +    [[classpath c "java classpath in which this script will run.  rlm is always on the classpath." 
    1.17 +      "/home/r/roBin/libs/*:/home/r/roBin/rlm-lib/*:/home/r/roBin/src"]
    1.18 +     [memory m "how much memory should this stupid jvm be provided? (megabytes)" 1000]
    1.19 +     [garbage g "level of congestion after which the jvm starts garbage collecting (megabytes)"
    1.20 +      "30% of whatever memory is"]
    1.21 +     [libraries l "link in libraries under -Djava.library.path" ""]
    1.22 +     [configure conf "use a file with configureations to defeat shebang line limit don't double define things:) " "/dev/null"]
    1.23 +     target-files]
    1.24 +
    1.25 +    (if (not (= configure "/dev/null"))
    1.26 +      (apply clj (into (re-split #" " (chomp (slurp configure))) target-files)) 
    1.27 +
    1.28 +    (let [
    1.29 +	  adjusted-garbage
    1.30 +	  (if (string? garbage)
    1.31 +	    (int (* 0.3  (Integer. memory)))
    1.32 +	    garbage)]
    1.33 +      
    1.34 +      ;assemble arguments to be passed to java
    1.35 +      (let [java-args
    1.36 +	    (into
    1.37 +	     ["-cp" classpath
    1.38 +	      (str "-Xmn" adjusted-garbage "M")
    1.39 +	      (str "-Xmx" memory "M")
    1.40 +	      (str "-Xms" memory "M")
    1.41 +	      (str "-Djava.library.path=\"" libraries "\"")
    1.42 +	      "clojure.main"]
    1.43 +	     target-files)]
    1.44 +	(let [command  (str "java " (str-join " " java-args))]
    1.45 +	  (println command)
    1.46 +	  (sw command)
    1.47 +	  ))))))
    1.48 +
    1.49 +
    1.50 +
    1.51 +
    1.52 +
    1.53 +(if *command-line-args*
    1.54 +  (let [options #{"-c" "-g" "-m" "-l" "-conf"}
    1.55 +	fuck (split-with (fn [[index element]] (or (odd? index) (options element))) 
    1.56 +		       (indexed *command-line-args*))
    1.57 +	fuck2 (conj (apply vector (map last (first fuck))) (str-join " " (map last (last fuck))))
    1.58 +	]
    1.59 +    (apply clj fuck2)))
    1.60 +
    1.61 +