aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lux/compiler.clj5
-rw-r--r--src/lux/compiler/host.clj4
-rw-r--r--src/lux/packager/program.clj29
3 files changed, 31 insertions, 7 deletions
diff --git a/src/lux/compiler.clj b/src/lux/compiler.clj
index fa9527282..885344e37 100644
--- a/src/lux/compiler.clj
+++ b/src/lux/compiler.clj
@@ -538,7 +538,10 @@
(defn ^:private init! []
(reset! !source->last-line {})
- (.mkdirs (java.io.File. &&/output-dir)))
+ (.mkdirs (java.io.File. &&/output-dir))
+ (doto (.getDeclaredMethod java.net.URLClassLoader "addURL" (into-array [java.net.URL]))
+ (.setAccessible true)
+ (.invoke (ClassLoader/getSystemClassLoader) (to-array [(-> (new java.io.File "./resources") .toURI .toURL)]))))
;; [Resources]
(defn compile-program [mode program-module]
diff --git a/src/lux/compiler/host.clj b/src/lux/compiler/host.clj
index 32e15637f..ebac433f2 100644
--- a/src/lux/compiler/host.clj
+++ b/src/lux/compiler/host.clj
@@ -1134,7 +1134,7 @@
(.visitTypeInsn Opcodes/ANEWARRAY "java/lang/Object") ;; V
(.visitInsn Opcodes/DUP) ;; VV
(.visitLdcInsn (int 0)) ;; VVI
- (.visitLdcInsn &/$Nil) ;; VVIT
+ (.visitLdcInsn (->> #'&/$Nil meta ::&/idx)) ;; VVIT
(&&/wrap-long)
(.visitInsn Opcodes/AASTORE) ;; V
(.visitInsn Opcodes/DUP) ;; VV
@@ -1180,7 +1180,7 @@
(.visitTypeInsn Opcodes/ANEWARRAY "java/lang/Object") ;; I2V
(.visitInsn Opcodes/DUP) ;; I2VV
(.visitLdcInsn (int 0)) ;; I2VVI
- (.visitLdcInsn &/$Cons) ;; I2VVIT
+ (.visitLdcInsn (->> #'&/$Cons meta ::&/idx)) ;; I2VVIT
(&&/wrap-long)
(.visitInsn Opcodes/AASTORE) ;; I2V
(.visitInsn Opcodes/DUP_X1) ;; IV2V
diff --git a/src/lux/packager/program.clj b/src/lux/packager/program.clj
index 02a082101..f01212b70 100644
--- a/src/lux/packager/program.clj
+++ b/src/lux/packager/program.clj
@@ -30,10 +30,11 @@
"(-> Text Manifest)"
(doto (new Manifest)
(-> .getMainAttributes (doto (.put Attributes$Name/MAIN_CLASS (str (&host/->module-class module) "._"))
- (.put Attributes$Name/MANIFEST_VERSION "1.0")))))
+ (.put Attributes$Name/MANIFEST_VERSION "1.0")
+ (.put Attributes$Name/CLASS_PATH "resources/")))))
(defn ^:private write-class! [^String path ^File file ^JarOutputStream out]
- "(-> Text File JarOutputStream Unit)"
+ "(-> Text File JarOutputStream Null)"
(with-open [in (new BufferedInputStream (new FileInputStream file))]
(let [buffer (byte-array buffer-size)]
(doto out
@@ -48,7 +49,7 @@
(let [output-dir-size (inc (.length &&/output-dir))]
(defn ^:private write-module! [^File file ^JarOutputStream out]
- "(-> File JarOutputStream Unit)"
+ "(-> File JarOutputStream Null)"
(let [module-name (.substring (.getPath file) output-dir-size)
inner-files (.listFiles file)
inner-modules (filter #(.isDirectory ^File %) inner-files)
@@ -58,6 +59,25 @@
(doseq [$module inner-modules]
(write-module! $module out)))))
+(let [resources-path "resources"]
+ (defn ^:private write-resources! [^JarOutputStream out]
+ "(-> JarOutputStream Null)"
+ (let [resources-dir (new File resources-path)]
+ (if (.exists resources-dir)
+ (doseq [res (.listFiles resources-dir)]
+ (with-open [in (->> res (new FileInputStream) (new BufferedInputStream))]
+ (let [buffer (byte-array buffer-size)]
+ (doto out
+ (.putNextEntry (new JarEntry (str resources-path "/" (.getName res))))
+ (-> (.write buffer 0 bytes-read)
+ (->> (when (not= -1 bytes-read))
+ (loop [bytes-read (.read in buffer)])))
+ (.flush)
+ (.closeEntry)
+ ))
+ ))
+ nil))))
+
(defn ^:private fetch-available-jars []
(->> ^java.net.URLClassLoader (ClassLoader/getSystemClassLoader)
(.getURLs)
@@ -101,10 +121,11 @@
;; [Resources]
(defn package [module]
- "(-> Text (,))"
+ "(-> Text Null)"
(with-open [out (new JarOutputStream (->> &&/output-package (new File) (new FileOutputStream)) (manifest module))]
(doseq [$group (.listFiles (new File &&/output-dir))]
(write-module! $group out))
+ (write-resources! out)
(->> (fetch-available-jars)
(filter #(and (not (.endsWith ^String % "luxc.jar"))
(not (.endsWith ^String % "tools.nrepl-0.2.3.jar"))