aboutsummaryrefslogtreecommitdiff
path: root/lux-lein/src/leiningen/luxc/utils.clj
diff options
context:
space:
mode:
authorEduardo Julian2016-12-01 11:00:44 -0400
committerEduardo Julian2016-12-01 11:00:44 -0400
commit7f66c54f4c9753b94dbf46ec50b8b16549daf324 (patch)
tree1b5b896cfba870a66a99a03315b09df842eb5737 /lux-lein/src/leiningen/luxc/utils.clj
parent9c30546af022f8fe36b73e7e93414257ff28ee75 (diff)
- Collected the Lux compiler's repo, the Standard Library's, the Leiningen plugin's and the Emacs mode's into a big monorepo, to keep development unified.
Diffstat (limited to '')
-rw-r--r--lux-lein/src/leiningen/luxc/utils.clj97
1 files changed, 97 insertions, 0 deletions
diff --git a/lux-lein/src/leiningen/luxc/utils.clj b/lux-lein/src/leiningen/luxc/utils.clj
new file mode 100644
index 000000000..bae02d365
--- /dev/null
+++ b/lux-lein/src/leiningen/luxc/utils.clj
@@ -0,0 +1,97 @@
+;; Copyright (c) Eduardo Julian. All rights reserved.
+;; This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
+;; If a copy of the MPL was not distributed with this file,
+;; You can obtain one at http://mozilla.org/MPL/2.0/.
+
+(ns leiningen.luxc.utils
+ (:refer-clojure :exclude [compile])
+ (:require [leiningen.core.classpath :as classpath])
+ (:import (java.io File
+ InputStreamReader
+ BufferedReader)))
+
+(def ^:const ^String output-dir "target/jvm")
+(def ^:const ^String output-package "program.jar")
+
+(def ^:private unit-separator (str (char 31)))
+
+(def ^:private vm-options "-server -Xms2048m -Xmx2048m -XX:+OptimizeStringConcat")
+
+(defn compile-path [project module source-paths]
+ (let [output-dir (get-in project [:lux :target] output-dir)
+ jar-paths (->> ^java.net.URLClassLoader (ClassLoader/getSystemClassLoader)
+ (.getURLs)
+ (map #(.getFile ^java.net.URL %))
+ (filter #(.endsWith ^String % ".jar")))
+ compiler-path (some (fn [^:private path]
+ (if (.contains path "com/github/luxlang/luxc-jvm")
+ path
+ nil))
+ jar-paths)
+ stdlib-path (some (fn [^:private path]
+ (if (.contains path "com/github/luxlang/lux-stdlib")
+ path
+ nil))
+ jar-paths)
+ deps-paths (filter (fn [^:private path]
+ (or (.contains path "org/ow2/asm/asm-all")
+ (.contains path "org/clojure/core.match")
+ (.contains path "org/clojure/clojure")))
+ jar-paths)
+ sdk-path (get-in project [:lux :android :sdk])
+ android-path (str sdk-path "/platforms/android-" (get-in project [:lux :android :version]) "/android.jar")
+ deps-paths (if (.exists (new File android-path))
+ (cons android-path deps-paths)
+ deps-paths)]
+ (let [class-path (->> (classpath/get-classpath project)
+ (filter #(.endsWith % ".jar"))
+ (concat deps-paths)
+ (list* stdlib-path)
+ (interpose java.io.File/pathSeparator)
+ (reduce str ""))
+ java-cmd (get project :java-cmd "java")
+ jvm-opts (->> (get project :jvm-opts) (interpose " ") (reduce str ""))]
+ (str java-cmd " " jvm-opts " " vm-options " -cp " (str compiler-path ":" class-path)
+ " lux release " module
+ " " (->> (get project :resource-paths (list)) (interpose unit-separator) (apply str))
+ " " (->> source-paths (interpose unit-separator) (apply str))
+ " " output-dir))))
+
+(defn repl-path [project source-paths]
+ (let [jar-paths (->> ^java.net.URLClassLoader (ClassLoader/getSystemClassLoader)
+ (.getURLs)
+ (map #(.getFile ^java.net.URL %))
+ (filter #(.endsWith ^String % ".jar")))
+ compiler-path (some (fn [^:private path]
+ (if (.contains path "com/github/luxlang/luxc-jvm")
+ path
+ nil))
+ jar-paths)
+ deps-paths (filter (fn [^:private path]
+ (or (.contains path "org/ow2/asm/asm-all")
+ (.contains path "org/clojure/core.match")
+ (.contains path "org/clojure/clojure")))
+ jar-paths)]
+ (let [class-path (->> (classpath/get-classpath project) (filter #(.endsWith % ".jar")) (concat deps-paths) (interpose ":") (reduce str ""))
+ java-cmd (get project :java-cmd "java")
+ jvm-opts (->> (get project :jvm-opts) (interpose " ") (reduce str ""))]
+ (str java-cmd " " jvm-opts " " vm-options " -cp " (str compiler-path ":" class-path)
+ " lux repl " (->> source-paths (interpose unit-separator) (apply str))))))
+
+(defn run-process [command working-directory pre post]
+ (let [process (.exec (Runtime/getRuntime) command nil working-directory)]
+ (with-open [std-out (->> process .getInputStream (new InputStreamReader) (new BufferedReader))
+ std-err (->> process .getErrorStream (new InputStreamReader) (new BufferedReader))]
+ (println pre)
+ (loop [line (.readLine std-out)]
+ (when line
+ (println line)
+ (recur (.readLine std-out))))
+ (loop [had-error? false
+ line (.readLine std-err)]
+ (if line
+ (do (println line)
+ (recur true (.readLine std-err)))
+ (when had-error?
+ (System/exit 1))))
+ (println post))))