From e8c5ef5c6ea9683a10ff2655497578c38ef3d9f7 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sun, 1 Jan 2017 11:55:24 -0400 Subject: - Improved support for Windows. --- lux-lein/src/leiningen/lux/utils.clj | 86 +++++++++++++++++++++++------------- luxc/src/lux/compiler/base.clj | 12 ++--- luxc/src/lux/compiler/cache.clj | 20 ++++++--- luxc/src/lux/compiler/io.clj | 2 +- 4 files changed, 76 insertions(+), 44 deletions(-) diff --git a/lux-lein/src/leiningen/lux/utils.clj b/lux-lein/src/leiningen/lux/utils.clj index 5cc0c4497..40eb5bad8 100644 --- a/lux-lein/src/leiningen/lux/utils.clj +++ b/lux-lein/src/leiningen/lux/utils.clj @@ -9,12 +9,23 @@ InputStreamReader BufferedReader))) -(def ^:const ^String output-dir "target/jvm") +(def ^:const ^String output-dir (str "target" java.io.File/separator "jvm")) (def ^:const ^String output-package "program.jar") (def ^:private unit-separator (str (char 31))) -(def ^:private vm-options "-server -Xms2048m -Xmx2048m -XX:+OptimizeStringConcat") +(def ^:private vm-options + "" + ;; "-server -Xms2048m -Xmx2048m -XX:+OptimizeStringConcat" + ) + +(defn ^:private prepare-path [path] + (let [path (if (and (.startsWith path "/") + (= "\\" java.io.File/separator)) + (.substring path 1) + path) + path (.replace path "/" java.io.File/separator)] + path)) (defn compile-path [project module source-paths] (let [output-dir (get-in project [:lux :target] output-dir) @@ -22,23 +33,24 @@ (.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) + compiler-path (prepare-path (some (fn [^:private path] + (if (.contains path "com/github/luxlang/luxc-jvm") + path + nil)) + jar-paths)) + stdlib-path (prepare-path (some (fn [^:private path] + (if (.contains path "com/github/luxlang/lux-stdlib") + path + nil)) + jar-paths)) + deps-paths (map prepare-path + (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") + android-path (str sdk-path java.io.File/separator "platforms" java.io.File/separator "android-" (get-in project [:lux :android :version]) java.io.File/separator "android.jar") deps-paths (if (.exists (new File android-path)) (cons android-path deps-paths) deps-paths)] @@ -48,9 +60,10 @@ (list* stdlib-path) (interpose java.io.File/pathSeparator) (reduce str "")) + class-path (.replace class-path "/" java.io.File/separator) 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) + (str java-cmd " " jvm-opts " " vm-options " -cp " (str compiler-path java.io.File/pathSeparator class-path) " lux release " module " " (->> (get project :resource-paths (list)) (interpose unit-separator) (apply str)) " " (->> source-paths (interpose unit-separator) (apply str)) @@ -61,20 +74,31 @@ (.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 "")) + compiler-path (prepare-path (some (fn [^:private path] + (if (.contains path "com/github/luxlang/luxc-jvm") + path + nil)) + jar-paths)) + stdlib-path (prepare-path (some (fn [^:private path] + (if (.contains path "com/github/luxlang/lux-stdlib") + path + nil)) + jar-paths)) + deps-paths (map prepare-path + (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) + (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) + (str java-cmd " " jvm-opts " " vm-options " -cp " (str compiler-path java.io.File/pathSeparator class-path) " lux repl " (->> source-paths (interpose unit-separator) (apply str)))))) (defn run-process [command working-directory pre post] diff --git a/luxc/src/lux/compiler/base.clj b/luxc/src/lux/compiler/base.clj index e57571fef..c396504f4 100644 --- a/luxc/src/lux/compiler/base.clj +++ b/luxc/src/lux/compiler/base.clj @@ -54,14 +54,14 @@ (defn ^:private write-output [module name data] (let [module* (&host/->module-class module) - module-dir (str @!output-dir "/" module*)] + module-dir (str @!output-dir java.io.File/separator module*)] (.mkdirs (File. module-dir)) - (write-file (str module-dir "/" name ".class") data))) + (write-file (str module-dir java.io.File/separator name ".class") data))) (defn class-exists? [^String module ^String class-name] "(-> Text Text (IO Bool))" (|do [_ (return nil) - :let [full-path (str @!output-dir "/" module "/" class-name ".class") + :let [full-path (str @!output-dir java.io.File/separator module java.io.File/separator class-name ".class") exists? (.exists (File. full-path))]] (return exists?))) @@ -86,14 +86,14 @@ (defn write-module-descriptor! [^String name ^String descriptor] (|do [_ (return nil) - :let [lmd-dir (str @!output-dir "/" name) + :let [lmd-dir (str @!output-dir java.io.File/separator name) _ (.mkdirs (File. lmd-dir)) - _ (write-file (str lmd-dir "/" lux-module-descriptor-name) (.getBytes descriptor java.nio.charset.StandardCharsets/UTF_8))]] + _ (write-file (str lmd-dir java.io.File/separator lux-module-descriptor-name) (.getBytes descriptor java.nio.charset.StandardCharsets/UTF_8))]] (return nil))) (defn read-module-descriptor! [^String name] (|do [_ (return nil)] - (return (slurp (str @!output-dir "/" name "/" lux-module-descriptor-name) + (return (slurp (str @!output-dir java.io.File/separator name java.io.File/separator lux-module-descriptor-name) :encoding "UTF-8")))) (do-template [ ] diff --git a/luxc/src/lux/compiler/cache.clj b/luxc/src/lux/compiler/cache.clj index 726ea784d..4bb144734 100644 --- a/luxc/src/lux/compiler/cache.clj +++ b/luxc/src/lux/compiler/cache.clj @@ -49,12 +49,18 @@ (defn cached? [module] "(-> Text Bool)" - (.exists (new File (str @&&/!output-dir "/" (&host/->module-class module) "/" module-class-file)))) + (.exists (new File (str @&&/!output-dir + java.io.File/separator + (.replace ^String (&host/->module-class module) "/" java.io.File/separator) + java.io.File/separator + module-class-file)))) (defn delete [module] "(-> Text (Lux Null))" (fn [state] - (do (clean-file (new File (str @&&/!output-dir "/" (&host/->module-class module)))) + (do (clean-file (new File (str @&&/!output-dir + java.io.File/separator + (.replace ^String (&host/->module-class module) "/" java.io.File/separator)))) (return* state nil)))) (defn ^:private module-dirs @@ -70,7 +76,7 @@ (defn clean [state] "(-> Compiler Null)" (let [needed-modules (->> state (&/get$ &/$modules) &/|keys &/->seq set) - output-dir-prefix (str (.getAbsolutePath (new File ^String @&&/!output-dir)) "/") + output-dir-prefix (str (.getAbsolutePath (new File ^String @&&/!output-dir)) java.io.File/separator) outdated? #(->> % (contains? needed-modules) not) outdated-modules (->> (new File ^String @&&/!output-dir) .listFiles (filter #(.isDirectory ^File %)) @@ -197,7 +203,9 @@ (->> output-dir enumerate-cached-modules!* rest - (map #(.substring ^String % prefix-to-subtract)) + (map #(-> ^String % + (.replace java.io.File/separator "/") + (.substring prefix-to-subtract))) &/->list))) (defn ^:private pre-load! [source-dirs cache-table module module-hash] @@ -211,9 +219,9 @@ (|do [loader &/loader !classes &/classes :let [module* (&host-generics/->class-name module) - module-path (str @&&/!output-dir "/" module) + module-path (str @&&/!output-dir java.io.File/separator module) class-name (str module* "." &/module-class-name) - ^Class module-class (do (swap! !classes assoc class-name (read-file (new File (str module-path "/" module-class-file)))) + ^Class module-class (do (swap! !classes assoc class-name (read-file (new File (str module-path java.io.File/separator module-class-file)))) (&&/load-class! loader class-name)) installed-classes (install-all-classes-in-module !classes module* module-path) valid-cache? (and (= module-hash (get-field &/hash-field module-class)) diff --git a/luxc/src/lux/compiler/io.clj b/luxc/src/lux/compiler/io.clj index 179e2a097..12073a0a5 100644 --- a/luxc/src/lux/compiler/io.clj +++ b/luxc/src/lux/compiler/io.clj @@ -17,7 +17,7 @@ (defn read-file [source-dirs ^String file-name] (|case (&/|some (fn [source-dir] - (let [file (new java.io.File (str source-dir "/" file-name))] + (let [file (new java.io.File source-dir file-name)] (if (.exists file) (&/$Some file) &/$None))) -- cgit v1.2.3