aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Julian2016-10-30 00:30:43 -0400
committerEduardo Julian2016-10-30 00:30:43 -0400
commit8d7472544db3e0b1cccb0660fa5715cec7e559b0 (patch)
tree3a1494f3e15dac57d6c01f5271e267e07d1a0feb
parent2dfc64d30a6220866a80e1a9c77910df0b177a06 (diff)
- Moved the packaging of Lux programs from the compiler to the Leiningen plugin.
-rw-r--r--src/lux/compiler.clj6
-rw-r--r--src/lux/compiler/base.clj3
-rw-r--r--src/lux/packager/program.clj145
3 files changed, 3 insertions, 151 deletions
diff --git a/src/lux/compiler.clj b/src/lux/compiler.clj
index 56574f8b1..44584e801 100644
--- a/src/lux/compiler.clj
+++ b/src/lux/compiler.clj
@@ -30,8 +30,7 @@
[lambda :as &&lambda]
[module :as &&module]
[io :as &&io]
- [parallel :as &&parallel])
- [lux.packager.program :as &packager-program])
+ [parallel :as &&parallel]))
(:import (org.objectweb.asm Opcodes
Label
ClassWriter
@@ -269,8 +268,7 @@
(|case (m-action (&/init-state mode))
(&/$Right ?state _)
(do (println "Compilation complete!")
- (&&cache/clean ?state)
- (&packager-program/package program-module resources-dir))
+ (&&cache/clean ?state))
(&/$Left ?message)
(assert false ?message)))))
diff --git a/src/lux/compiler/base.clj b/src/lux/compiler/base.clj
index 9eec050e9..499bc2644 100644
--- a/src/lux/compiler/base.clj
+++ b/src/lux/compiler/base.clj
@@ -26,8 +26,7 @@
(java.lang.reflect Field)))
;; [Constants]
-(def ^:const ^String output-dir "target/jvm")
-(def ^:const ^String output-package (str output-dir "/" "program.jar"))
+5
(def ^:const ^String function-class "lux/Function")
(def ^:const ^String lux-utils-class "lux/LuxRT")
(def ^:const ^String unit-tag-field "unit_tag")
diff --git a/src/lux/packager/program.clj b/src/lux/packager/program.clj
deleted file mode 100644
index bbd7da665..000000000
--- a/src/lux/packager/program.clj
+++ /dev/null
@@ -1,145 +0,0 @@
-;; 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 lux.packager.program
- (:require [clojure.core.match :as M :refer [matchv]]
- clojure.core.match.array
- (lux [base :as & :refer [|let |do return* return fail fail*]]
- [host :as &host])
- (lux.compiler [base :as &&]))
- (:import (java.io InputStream
- File
- FileInputStream
- FileOutputStream
- BufferedInputStream
- ByteArrayOutputStream)
- (java.util.jar Manifest
- Attributes$Name
- JarEntry
- JarInputStream
- JarOutputStream
- )))
-
-;; [Utils]
-(def ^:private kilobyte 1024)
-(def ^:private buffer-size (* 10 kilobyte))
-
-(def ^:private jar-resources "__LUX_PROGRAM_RESOURCES__/")
-
-(defn ^:private manifest
- "(-> Text Manifest)"
- [^String module]
- (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/CLASS_PATH jar-resources)))))
-
-(defn ^:private write-class!
- "(-> Text File JarOutputStream Null)"
- [^String path ^File file ^JarOutputStream out]
- (with-open [in (new BufferedInputStream (new FileInputStream file))]
- (let [buffer (byte-array buffer-size)]
- (doto out
- (.putNextEntry (new JarEntry (str path "/" (.getName file))))
- (-> (.write buffer 0 bytes-read)
- (->> (when (not= -1 bytes-read))
- (loop [bytes-read (.read in buffer)])))
- (.flush)
- (.closeEntry)
- ))
- ))
-
-(let [output-dir-size (inc (.length &&/output-dir))]
- (defn ^:private write-module!
- "(-> File JarOutputStream Null)"
- [^File file ^JarOutputStream out]
- (let [module-name (.substring (.getPath file) output-dir-size)
- inner-files (.listFiles file)
- inner-modules (filter #(.isDirectory ^File %) inner-files)
- inner-classes (filter #(not (.isDirectory ^File %)) inner-files)]
- (doseq [$class inner-classes]
- (write-class! module-name $class out))
- (doseq [$module inner-modules]
- (write-module! $module out)))))
-
-(defn ^:private write-resources!
- "(-> JarOutputStream (List Text) Null)"
- [^JarOutputStream out resources-dirs]
- (doseq [resources-dir (&/->seq resources-dirs)
- :let [resources-dir (new File resources-dir)]
- :when (.exists resources-dir)
- ^File res (.listFiles resources-dir)
- :let [buffer (byte-array buffer-size)]]
- (with-open [in (->> res (new FileInputStream) (new BufferedInputStream))]
- (doto out
- (.putNextEntry (new JarEntry (str jar-resources (.getName res))))
- (-> (.write buffer 0 bytes-read)
- (->> (when (not= -1 bytes-read))
- (loop [bytes-read (.read in buffer)])))
- (.flush)
- (.closeEntry))
- )))
-
-(defn ^:private fetch-available-jars []
- (->> ^java.net.URLClassLoader (ClassLoader/getSystemClassLoader)
- (.getURLs)
- (map #(.getFile ^java.net.URL %))
- (filter #(.endsWith ^String % ".jar"))
- (filter #(not (or (.contains ^String % "org/ow2/asm/asm-all")
- (.contains ^String % "org/clojure/core.match")
- (.contains ^String % "org/clojure/clojure")
- )))))
-
-(let [init-capacity (* 100 1024)
- buffer-size 1024]
- (defn ^:private ^"[B" read-stream [^InputStream is]
- (let [buffer (byte-array buffer-size)]
- (with-open [os (new ByteArrayOutputStream init-capacity)]
- (loop [bytes-read (.read is buffer 0 buffer-size)]
- (when (not= -1 bytes-read)
- (do (.write os buffer 0 bytes-read)
- (recur (.read is buffer 0 buffer-size)))))
- (.toByteArray os)))))
-
-(defn ^:private add-jar! [^File jar-file seen ^JarOutputStream out]
- (with-open [is (->> jar-file (new FileInputStream) (new JarInputStream))]
- (loop [^JarEntry entry (.getNextJarEntry is)
- seen seen]
- (if entry
- (let [entry-name (.getName entry)]
- (if (and (not (.isDirectory entry))
- (not (.startsWith entry-name "META-INF/maven/"))
- (not (contains? seen entry-name)))
- (let [entry-data (read-stream is)]
- (doto out
- (.putNextEntry (doto entry (.setCompressedSize -1)))
- (.write entry-data 0 (alength entry-data))
- (.flush)
- (.closeEntry))
- (recur (.getNextJarEntry is)
- (conj seen entry-name)))
- (recur (.getNextJarEntry is)
- seen)))
- seen
- ))))
-
-;; [Resources]
-(defn package
- "(-> Text (List Text) Null)"
- [module resources-dirs]
- (with-open [out (new JarOutputStream (->> &&/output-package (new File) (new FileOutputStream)) (manifest module))]
- (do (doseq [$group (.listFiles (new File &&/output-dir))]
- (write-module! $group out))
- (write-resources! out resources-dirs)
- (->> (fetch-available-jars)
- (filter #(and (not (.endsWith ^String % "luxc.jar"))
- (not (.endsWith ^String % "tools.nrepl-0.2.3.jar"))
- (not (.endsWith ^String % "clojure-complete-0.2.3.jar"))
- (not (.endsWith ^String % "clojure-1.6.0.jar"))
- (not (.endsWith ^String % "core.match-0.2.1.jar"))))
- (reduce (fn [s ^String j] (add-jar! (new File ^String j) s out))
- #{"META-INF/MANIFEST.MF"}))
- nil)
- ))