Permalink
Browse files

simplify how we lazy load transit. cljs.analyzer/write-analysis-cache…

… now supports

writing out transit if available. cljs.closure/aot-cache-core attempts to write out
transit analysis cache for core. tweak .gitignore now for new cache file.
  • Loading branch information...
swannodette committed Jun 3, 2016
1 parent 8e88387 commit 296f2bc4311e6023e83d3f7cdfe7bd8fc336b982
Showing with 25 additions and 25 deletions.
  1. +1 −0 .gitignore
  2. +20 −23 src/main/clojure/cljs/analyzer.cljc
  3. +4 −2 src/main/clojure/cljs/closure.clj
View
@@ -28,3 +28,4 @@ nashorn_code_cache
src/main/cljs/cljs/core.aot.js
src/main/cljs/cljs/core.aot.js.map
src/main/cljs/cljs/core.cljs.cache.aot.edn
+src/main/cljs/cljs/core.cljs.cache.aot.json
@@ -32,7 +32,7 @@
[cljs.tools.reader :as reader]
[cljs.tools.reader.reader-types :as readers]
[cljs.reader :as edn]))
- #?(:clj (:import [java.io File Reader PushbackReader]
+ #?(:clj (:import [java.io File Reader PushbackReader FileOutputStream]
[java.net URL]
[java.lang Throwable]
[clojure.lang Namespace Var LazySeq ArityException]
@@ -2818,39 +2818,36 @@
(and version (not= version version'))))))))))
#?(:clj
- (def transit-writer
+ (def transit
(delay
(try
(require '[cognitect.transit])
- (some->
- (find-ns 'cognitect.transit)
- (ns-resolve 'writer)
- deref)
- (catch Throwable t
- nil)))))
-
-#?(:clj
- (def transit-reader
- (delay
- (try
- (require '[cognitect.transit])
- (some->
- (find-ns 'cognitect.transit)
- (ns-resolve 'reader)
- deref)
+ (let [ns (find-ns 'cognitect.transit)]
+ (when ns
+ {:writer @(ns-resolve ns 'writer)
+ :reader @(ns-resolve ns 'reader)
+ :write @(ns-resolve ns 'write)
+ :read @(ns-resolve ns 'read)}))
(catch Throwable t
nil)))))
#?(:clj
(defn write-analysis-cache
([ns cache-file]
(write-analysis-cache ns cache-file nil))
- ([ns cache-file src]
+ ([ns ^File cache-file src]
(util/mkdirs cache-file)
- (spit cache-file
- (str ";; Analyzed by ClojureScript " (util/clojurescript-version) "\n"
- (pr-str
- (dissoc (get-in @env/*compiler* [::namespaces ns]) :macros))))
+ (let [ext (util/ext cache-file)
+ analysis (dissoc (get-in @env/*compiler* [::namespaces ns]) :macros)]
+ (case ext
+ "edn" (spit cache-file
+ (str (when
+ (str ";; Analyzed by ClojureScript " (util/clojurescript-version) "\n"))
+ (pr-str analysis)))
+ "json" (when-let [{:keys [writer write]} @transit]
+ (write
+ (writer (FileOutputStream. cache-file) :json)
+ analysis))))
(when src
(.setLastModified ^File cache-file (util/last-modified src))))))
@@ -2133,14 +2133,16 @@
(let [base-path (io/file "src" "main" "cljs" "cljs")
src (io/file base-path "core.cljs")
dest (io/file base-path "core.aot.js")
- cache (io/file base-path "core.cljs.cache.aot.edn")]
+ cache (io/file base-path "core.cljs.cache.aot.edn")
+ tcache (io/file base-path "core.cljs.cache.aot.json")]
(util/mkdirs dest)
(env/with-compiler-env (env/default-compiler-env)
(comp/compile-file src dest
{:source-map true
:source-map-url "core.js.map"
:output-dir (str "src" File/separator "main" File/separator "cljs")})
- (ana/write-analysis-cache 'cljs.core cache src))))
+ (ana/write-analysis-cache 'cljs.core cache src)
+ (ana/write-analysis-cache 'cljs.core tcache src))))
(comment
(time

0 comments on commit 296f2bc

Please sign in to comment.