aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lux-lein/src/leiningen/lux/builder.clj19
-rw-r--r--lux-lein/src/leiningen/lux/packager.clj18
-rw-r--r--lux-lein/src/leiningen/lux/test.clj41
-rw-r--r--lux-lein/src/leiningen/lux/utils.clj16
-rw-r--r--luxc/src/lux/compiler/js.clj14
-rw-r--r--luxc/src/lux/compiler/js/base.clj14
6 files changed, 87 insertions, 35 deletions
diff --git a/lux-lein/src/leiningen/lux/builder.clj b/lux-lein/src/leiningen/lux/builder.clj
index ca9088d4c..65f45b90c 100644
--- a/lux-lein/src/leiningen/lux/builder.clj
+++ b/lux-lein/src/leiningen/lux/builder.clj
@@ -4,10 +4,17 @@
[packager :as &packager])))
(defn build [project]
- (if-let [program-module (get-in project [:lux :program])]
- (when (&utils/run-process (&utils/compile-path project program-module (get project :source-paths (list)))
- nil
- "[BUILD BEGIN]"
- "[BUILD END]")
- (&packager/package project program-module (get project :resource-paths (list))))
+ (if-let [program-modules (get-in project [:lux :program])]
+ (do (when-let [jvm-module (get-in program-modules [:jvm])]
+ (when (&utils/run-process (&utils/compile-path project "jvm" jvm-module (get project :source-paths (list)))
+ nil
+ "[BUILD BEGIN]"
+ "[BUILD END]")
+ (&packager/package project "jvm" jvm-module (get project :resource-paths (list)))))
+ (when-let [js-module (get-in program-modules [:js])]
+ (when (&utils/run-process (&utils/compile-path project "js" js-module (get project :source-paths (list)))
+ nil
+ "[BUILD BEGIN]"
+ "[BUILD END]")
+ (&packager/package project "js" js-module (get project :resource-paths (list))))))
(println "Please provide a program main module in [:lux :program]")))
diff --git a/lux-lein/src/leiningen/lux/packager.clj b/lux-lein/src/leiningen/lux/packager.clj
index 3ac117d15..afb4a82db 100644
--- a/lux-lein/src/leiningen/lux/packager.clj
+++ b/lux-lein/src/leiningen/lux/packager.clj
@@ -123,11 +123,11 @@
(def default-manifest-file (str "." java.io.File/separator "AndroidManifest.xml"))
;; [Resources]
-(defn package
+(defn ^:private package-jvm
"(-> Text (List Text) Null)"
[project module resources-dirs]
(let [output-package-name (get project :jar-name &utils/output-package)
- output-dir (&utils/prepare-path (get-in project [:lux :target] &utils/default-output-dir))
+ output-dir (&utils/prepare-path (get-in project [:lux :target] &utils/default-jvm-output-dir))
output-package (str output-dir java.io.File/separator output-package-name)
!all-jar-files (atom {})
includes-android? (boolean (some #(-> % first (= 'com.google.android/android))
@@ -161,7 +161,7 @@
(.closeEntry)))
nil))
(when (get-in project [:lux :android])
- (let [output-dir-context (new File (get-in project [:lux :target] &utils/default-output-dir))
+ (let [output-dir-context (new File (get-in project [:lux :target] &utils/default-jvm-output-dir))
output-dex "classes.dex"
_ (do (.delete (new File output-dex))
(&utils/run-process (str "dx --dex --output=" output-dex " " output-package-name)
@@ -206,7 +206,13 @@
(&utils/run-process (str "zipalign 4 " output-apk-unaligned-path " " output-apk-path)
nil
"[ZIPALIGN BEGIN]"
- "[ZIPALIGN END]"))
- )
- ]
+ "[ZIPALIGN END]")))]
nil)))))
+
+(defn package
+ "(-> Text Text (List Text) Null)"
+ [project platform module resources-dirs]
+ (case platform
+ "jvm" (package-jvm project module resources-dirs)
+ "js" nil)
+ )
diff --git a/lux-lein/src/leiningen/lux/test.clj b/lux-lein/src/leiningen/lux/test.clj
index 77dc342e7..d3755c1b6 100644
--- a/lux-lein/src/leiningen/lux/test.clj
+++ b/lux-lein/src/leiningen/lux/test.clj
@@ -5,18 +5,31 @@
[packager :as &packager])))
(defn test [project]
- (if-let [tests-module (get-in project [:lux :tests])]
- (when (&utils/run-process (&utils/compile-path project tests-module (concat (:test-paths project) (:source-paths project)))
- nil
- "[BUILD BEGIN]"
- "[BUILD END]")
- (let [java-cmd (get project :java-cmd "java")
- jvm-opts (->> (get project :jvm-opts) (interpose " ") (reduce str ""))
- output-package (str (get-in project [:lux :target] &utils/default-output-dir) "/"
- (get project :jar-name &utils/output-package))]
- (do (&packager/package project tests-module (get project :resource-paths (list)))
- (&utils/run-process (str java-cmd " " jvm-opts " -jar " output-package)
- nil
- "[TEST BEGIN]"
- "[TEST END]"))))
+ (if-let [tests-modules (get-in project [:lux :tests])]
+ (do (when-let [jvm-module (get-in tests-modules [:jvm])]
+ (when (&utils/run-process (&utils/compile-path project "jvm" jvm-module (concat (:test-paths project) (:source-paths project)))
+ nil
+ "[BUILD BEGIN]"
+ "[BUILD END]")
+ (let [java-cmd (get project :java-cmd "java")
+ jvm-opts (->> (get project :jvm-opts) (interpose " ") (reduce str ""))
+ output-package (str (get-in project [:lux :target] &utils/default-jvm-output-dir) "/"
+ (get project :jar-name &utils/output-package))]
+ (do (&packager/package project "jvm" jvm-module (get project :resource-paths (list)))
+ (&utils/run-process (str java-cmd " " jvm-opts " -jar " output-package)
+ nil
+ "[TEST BEGIN]"
+ "[TEST END]")))))
+ (when-let [js-module (get-in tests-modules [:js])]
+ (when (&utils/run-process (&utils/compile-path project "js" js-module (concat (:test-paths project) (:source-paths project)))
+ nil
+ "[BUILD BEGIN]"
+ "[BUILD END]")
+ (let [output-package (str (get-in project [:lux :target] &utils/default-js-output-dir) "/"
+ "program.js")]
+ (do (&packager/package project "js" js-module (get project :resource-paths (list)))
+ (&utils/run-process (str "node " output-package)
+ nil
+ "[TEST BEGIN]"
+ "[TEST END]"))))))
(println "Please provide a test module in [:lux :tests]")))
diff --git a/lux-lein/src/leiningen/lux/utils.clj b/lux-lein/src/leiningen/lux/utils.clj
index a786a4d6d..ae39c37b3 100644
--- a/lux-lein/src/leiningen/lux/utils.clj
+++ b/lux-lein/src/leiningen/lux/utils.clj
@@ -5,7 +5,8 @@
InputStreamReader
BufferedReader)))
-(def ^:const ^String default-output-dir (str "target" java.io.File/separator "jvm"))
+(def ^:const ^String default-jvm-output-dir (str "target" java.io.File/separator "jvm"))
+(def ^:const ^String default-js-output-dir (str "target" java.io.File/separator "js"))
(def ^:const ^String output-package "program.jar")
(def ^:private unit-separator (str (char 31)))
@@ -61,10 +62,17 @@
(str "lux " mode
" " (->> (get project :resource-paths (list)) (interpose unit-separator) (apply str))
" " (->> source-paths (interpose unit-separator) (apply str))
- " " (get-in project [:lux :target] default-output-dir)))
+ " " (get-in project [:lux :target] (cond (.contains mode "jvm")
+ default-jvm-output-dir
+
+ (.contains mode "js")
+ default-js-output-dir
+
+ :else
+ (assert false)))))
(do-template [<name> <mode>]
- (defn <name> [project module source-paths]
+ (defn <name> [project platform module source-paths]
(let [is-stdlib? (= stdlib-id [(get project :group) (get project :name)])
jar-paths (all-jars-in-classloader)
compiler-path (prepare-path (find-compiler-path jar-paths))
@@ -90,7 +98,7 @@
(str (java-command project) " -cp " class-path
" " (lux-command project <mode> source-paths))))
- compile-path (str "release jvm " module)
+ compile-path (str "release " platform " " module)
repl-path "repl"
)
diff --git a/luxc/src/lux/compiler/js.clj b/luxc/src/lux/compiler/js.clj
index 1537bb7de..be405ad33 100644
--- a/luxc/src/lux/compiler/js.clj
+++ b/luxc/src/lux/compiler/js.clj
@@ -131,7 +131,11 @@
(|do [[file-name file-content] (&&io/read-file source-dirs name)
:let [file-hash (hash file-content)
compile-module!! (&&parallel/parallel-compilation (partial compile-module source-dirs))]]
- (&/|eitherL (&&cache/load name)
+ (&/|eitherL (|do [output (&&cache/load name)
+ ^StringBuilder total-buffer &&/get-total-buffer
+ :let [module-code-path (str @&&core/!output-dir java.io.File/separator name java.io.File/separator &&/module-js-name)
+ _ (.append total-buffer ^String (str (slurp module-code-path) "\n"))]]
+ (return output))
(let [compiler-step (&analyser/analyse &optimizer/optimize eval! compile-module!! all-compilers)]
(|do [module-exists? (&a-module/exists? name)]
(if module-exists?
@@ -166,8 +170,12 @@
&&js-cache/load-def-value
&&js-cache/install-all-defs-in-module
&&js-cache/uninstall-all-defs-in-module)
- _ (compile-module source-dirs "lux")]
- (compile-module source-dirs program-module))]
+ _ (compile-module source-dirs "lux")
+ _ (compile-module source-dirs program-module)
+ ^StringBuilder total-buffer &&/get-total-buffer
+ :let [full-program-file (str @&&core/!output-dir java.io.File/separator "program.js")
+ _ (&&core/write-file full-program-file (.getBytes (.toString total-buffer)))]]
+ (return nil))]
(|case (m-action (&/init-state mode (&&/js-host)))
(&/$Right ?state _)
(do (println "Compilation complete!")
diff --git a/luxc/src/lux/compiler/js/base.clj b/luxc/src/lux/compiler/js/base.clj
index 417b35d5a..7f560b87d 100644
--- a/luxc/src/lux/compiler/js/base.clj
+++ b/luxc/src/lux/compiler/js/base.clj
@@ -21,13 +21,16 @@
(deftuple
["interpreter"
- "buffer"])
+ "buffer"
+ "total-buffer"])
(defn js-host []
(&/$Js (&/T [;; "interpreter"
(.getScriptEngine (new NashornScriptEngineFactory))
;; "buffer"
&/$None
+ ;; "total-buffer"
+ (new StringBuilder)
])))
(def ^String module-js-name "module.js")
@@ -44,6 +47,10 @@
(&/$None)
(&/fail-with-loc "[Error] No buffer available."))))
+(def get-total-buffer
+ (|do [host &/js-host]
+ (return (&/get$ $total-buffer host))))
+
(defn run-js! [^String js-code]
(|do [host &/js-host
:let [interpreter ^NashornScriptEngine (&/get$ $interpreter host)]]
@@ -216,12 +223,15 @@
(|do [eval? &/get-eval
module &/get-module-name
^StringBuilder buffer get-buffer
+ ^StringBuilder total-buffer get-total-buffer
+ :let [buffer-code (.toString buffer)
+ _ (.append total-buffer ^String (str buffer-code "\n"))]
:let [_ (when (not eval?)
(let [^String module* (&host/->module-class module)
module-dir (str @&&/!output-dir java.io.File/separator (.replace module* "/" java.io.File/separator))]
(do (.mkdirs (File. module-dir))
(&&/write-file (str module-dir java.io.File/separator module-js-name)
- (.getBytes (.toString buffer))))))]]
+ (.getBytes buffer-code)))))]]
(return nil)))
(defn js-module [module]