Skip to content

Commit e6d7f36

Browse files
committed
CLJS-897: AOT core.cljs
CLJS-899: AOT cache core.cljs analysis fix build script to create cache files with proper version information fix `cljs.compiler/compile-file*` to only consider cache file when compiling cljs.core ns update .iml
1 parent a423884 commit e6d7f36

File tree

3 files changed

+96
-66
lines changed

3 files changed

+96
-66
lines changed

Clojurescript.iml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<module type="JAVA_MODULE" version="4">
2+
<module cursive.leiningen.project.LeiningenProjectsManager.isLeinModule="true" type="JAVA_MODULE" version="4">
33
<component name="NewModuleRootManager" inherit-compiler-output="false">
44
<output url="file://$MODULE_DIR$/target/classes" />
55
<output-test url="file://$MODULE_DIR$/target/classes" />
@@ -25,19 +25,22 @@
2525
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
2626
<orderEntry type="sourceFolder" forTests="false" />
2727
<orderEntry type="library" name="Leiningen: clojure-complete:0.2.3" level="project" />
28-
<orderEntry type="library" name="Leiningen: com.google.javascript/closure-compiler:v20140625" level="project" />
28+
<orderEntry type="library" name="Leiningen: com.google.javascript/closure-compiler:v20150126" level="project" />
2929
<orderEntry type="library" name="Leiningen: org.clojure/clojure:1.6.0" level="project" />
3030
<orderEntry type="library" name="Leiningen: org.clojure/data.json:0.2.3" level="project" />
3131
<orderEntry type="library" name="Leiningen: org.clojure/google-closure-library:0.0-20140718-946a7d39" level="project" />
3232
<orderEntry type="library" name="Leiningen: org.clojure/tools.nrepl:0.2.3" level="project" />
3333
<orderEntry type="library" name="Leiningen: org.clojure/tools.reader:0.8.10" level="project" />
34-
<orderEntry type="library" name="Leiningen: org.mozilla/rhino:1.7R4" level="project" />
34+
<orderEntry type="library" name="Leiningen: org.mozilla/rhino:1.7R5" level="project" />
3535
<orderEntry type="library" name="Leiningen: args4j:2.0.26" level="project" />
3636
<orderEntry type="library" name="Leiningen: com.google.code.findbugs/jsr305:1.3.9" level="project" />
37-
<orderEntry type="library" name="Leiningen: com.google.guava/guava:17.0" level="project" />
38-
<orderEntry type="library" name="Leiningen: com.google.javascript/closure-compiler-externs:v20140625" level="project" />
37+
<orderEntry type="library" name="Leiningen: com.google.code.gson/gson:2.2.4" level="project" />
38+
<orderEntry type="library" name="Leiningen: com.google.guava/guava:18.0" level="project" />
39+
<orderEntry type="library" name="Leiningen: com.google.javascript/closure-compiler-externs:v20150126" level="project" />
3940
<orderEntry type="library" name="Leiningen: com.google.protobuf/protobuf-java:2.5.0" level="project" />
40-
<orderEntry type="library" name="Leiningen: org.json/json:20090211" level="project" />
41+
<orderEntry type="library" name="Leiningen: com.google.truth/truth:0.24" level="project" />
42+
<orderEntry type="library" name="Leiningen: junit:4.10" level="project" />
43+
<orderEntry type="library" name="Leiningen: org.hamcrest/hamcrest-core:1.1" level="project" />
4144
<orderEntry type="library" name="Leiningen: org.clojure/google-closure-library-third-party:0.0-20140718-946a7d39" level="project" />
4245
</component>
4346
</module>

script/build

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@ CLJS_FILE=`mktemp /tmp/core.cljs.XXXXXXXXXXX`
3636
sed -e 's/^.def \*clojurescript-version\*.*$/(def *clojurescript-version* '\""0.0-$REVISION"\"')/' src/cljs/cljs/core.cljs > $CLJS_FILE
3737
mv $CLJS_FILE src/cljs/cljs/core.cljs
3838

39+
rm -f src/cljs/cljs/core.aot.js
40+
rm -f src/cljs/cljs/core.aot.js.map
41+
rm -f src/cljs/cljs/core.cljs.cache.aot.edn
42+
43+
./script/aot_core
44+
45+
AOT_FILE=`mktemp /tmp/core.aot.js.XXXXXXXXXXX`
46+
sed -e 's/0.0-0000/0.0-$REVISION/' src/cljs/cljs/core.aot.js > $AOT_FILE
47+
mv $AOT_FILE src/cljs/cljs/core.aot.js
48+
49+
AOT_CACHE_FILE=`mktemp /tmp/core.cljs.cache.aot.edn.XXXXXXXXXXX`
50+
sed -e 's/0.0-0000/0.0-$REVISION/' src/cljs/cljs/core.cljs.cache.aot.edn > $AOT_CACHE_FILE
51+
mv $AOT_CACHE_FILE src/cljs/cljs/core.cljs.cache.aot.edn
52+
3953
# For Hudson server
4054
if [ "$HUDSON" = "true" ]; then
4155
mvn --fail-at-end -Psonatype-oss-release \

src/clj/cljs/compiler.clj

Lines changed: 73 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -949,66 +949,79 @@
949949
(defn compile-file*
950950
([src dest] (compile-file* src dest nil))
951951
([src dest opts]
952-
(env/ensure
953-
(with-core-cljs opts
954-
(fn []
955-
(when (or ana/*verbose* (:verbose opts))
956-
(util/debug-prn "Compiling " src))
957-
(with-open [out ^java.io.Writer (io/make-writer dest {})]
958-
(binding [*out* out
959-
ana/*cljs-ns* 'cljs.user
960-
ana/*cljs-file* (.getPath ^File src)
961-
reader/*alias-map* (or reader/*alias-map* {})
962-
ana/*cljs-static-fns* (or ana/*cljs-static-fns* (:static-fns opts))
963-
*source-map-data* (when (:source-map opts)
964-
(atom
965-
{:source-map (sorted-map)
966-
:gen-col 0
967-
:gen-line 0}))]
968-
(emitln (compiled-by-string opts))
969-
(loop [forms (ana/forms-seq src)
970-
ns-name nil
971-
deps nil]
972-
(if (seq forms)
973-
(let [env (ana/empty-env)
974-
ast (ana/analyze env (first forms) nil opts)]
975-
(emit ast)
976-
(if (= (:op ast) :ns)
977-
(recur (rest forms) (:name ast) (merge (:uses ast) (:requires ast)))
978-
(recur (rest forms) ns-name deps)))
979-
(let [sm-data (when *source-map-data* @*source-map-data*)
980-
ret (merge
981-
{:ns (or ns-name 'cljs.user)
982-
:provides [ns-name]
983-
:requires (if (= ns-name 'cljs.core)
984-
(set (vals deps))
985-
(cond-> (conj (set (vals deps)) 'cljs.core)
986-
(get-in @env/*compiler* [:opts :emit-constants])
987-
(conj 'constants-table)))
988-
:file dest
989-
:source-file src}
990-
(when sm-data
991-
{:source-map (:source-map sm-data)}))]
992-
(when (and sm-data (= (:optimizations opts) :none))
993-
(let [sm-file (io/file (str (.getPath ^File dest) ".map"))]
994-
(emits "\n//# sourceMappingURL=" (.getName sm-file)
995-
(if (true? (:source-map-timestamp opts))
996-
(str "?rel=" (System/currentTimeMillis))
997-
""))
998-
(spit sm-file
999-
(sm/encode {(url-path src) (:source-map sm-data)}
1000-
{:lines (+ (:gen-line sm-data) 2)
1001-
:file (url-path dest)
1002-
:source-map-timestamp (:source-map-timestamp opts)
1003-
:source-map-pretty-print (:source-map-pretty-print opts)}))))
1004-
(let [path (.getPath (.toURL ^File dest))]
1005-
(swap! env/*compiler* assoc-in [::compiled-cljs path] ret)
1006-
(swap! env/*compiler* assoc-in [::ana/analyzed-cljs path] true))
1007-
(let [{:keys [output-dir cache-analysis]} opts]
1008-
(when (and (true? cache-analysis) output-dir)
1009-
(ana/write-analysis-cache ns-name
1010-
(ana/cache-file src output-dir)))
1011-
ret)))))))))))
952+
(env/ensure
953+
(with-core-cljs opts
954+
(fn []
955+
(when (or ana/*verbose* (:verbose opts))
956+
(util/debug-prn "Compiling " src))
957+
(if-let [cached (and (= (:optimizations opts) :none)
958+
(= (:ns (ana/parse-ns src)) 'cljs.core)
959+
(io/resource "cljs/core.aot.js"))]
960+
;; no need to bother with analysis cache reading, handled by
961+
;; with-core-cljs
962+
(do
963+
(when (or ana/*verbose* (:verbose opts))
964+
(util/debug-prn "Using cached cljs.core " src))
965+
(spit dest (slurp cached))
966+
(when (true? (:source-map opts))
967+
(spit (io/file (str dest ".map"))
968+
(slurp (io/resource "cljs/core.aot.js.map"))))
969+
(ana/parse-ns src dest nil))
970+
(with-open [out ^java.io.Writer (io/make-writer dest {})]
971+
(binding [*out* out
972+
ana/*cljs-ns* 'cljs.user
973+
ana/*cljs-file* (.getPath ^File src)
974+
reader/*alias-map* (or reader/*alias-map* {})
975+
ana/*cljs-static-fns* (or ana/*cljs-static-fns* (:static-fns opts))
976+
*source-map-data* (when (:source-map opts)
977+
(atom
978+
{:source-map (sorted-map)
979+
:gen-col 0
980+
:gen-line 0}))]
981+
(emitln (compiled-by-string opts))
982+
(loop [forms (ana/forms-seq src)
983+
ns-name nil
984+
deps nil]
985+
(if (seq forms)
986+
(let [env (ana/empty-env)
987+
ast (ana/analyze env (first forms) nil opts)]
988+
(emit ast)
989+
(if (= (:op ast) :ns)
990+
(recur (rest forms) (:name ast) (merge (:uses ast) (:requires ast)))
991+
(recur (rest forms) ns-name deps)))
992+
(let [sm-data (when *source-map-data* @*source-map-data*)
993+
ret (merge
994+
{:ns (or ns-name 'cljs.user)
995+
:provides [ns-name]
996+
:requires (if (= ns-name 'cljs.core)
997+
(set (vals deps))
998+
(cond-> (conj (set (vals deps)) 'cljs.core)
999+
(get-in @env/*compiler* [:opts :emit-constants])
1000+
(conj 'constants-table)))
1001+
:file dest
1002+
:source-file src}
1003+
(when sm-data
1004+
{:source-map (:source-map sm-data)}))]
1005+
(when (and sm-data (= (:optimizations opts) :none))
1006+
(let [sm-file (io/file (str (.getPath ^File dest) ".map"))]
1007+
(emits "\n//# sourceMappingURL=" (.getName sm-file)
1008+
(if (true? (:source-map-timestamp opts))
1009+
(str "?rel=" (System/currentTimeMillis))
1010+
""))
1011+
(spit sm-file
1012+
(sm/encode {(url-path src) (:source-map sm-data)}
1013+
{:lines (+ (:gen-line sm-data) 2)
1014+
:file (url-path dest)
1015+
:source-map-timestamp (:source-map-timestamp opts)
1016+
:source-map-pretty-print (:source-map-pretty-print opts)}))))
1017+
(let [path (.getPath (.toURL ^File dest))]
1018+
(swap! env/*compiler* assoc-in [::compiled-cljs path] ret)
1019+
(swap! env/*compiler* assoc-in [::ana/analyzed-cljs path] true))
1020+
(let [{:keys [output-dir cache-analysis]} opts]
1021+
(when (and (true? cache-analysis) output-dir)
1022+
(ana/write-analysis-cache ns-name
1023+
(ana/cache-file src output-dir)))
1024+
ret))))))))))))
10121025

10131026
(defn requires-compilation?
10141027
"Return true if the src file requires compilation."

0 commit comments

Comments
 (0)