|
569 | 569 | (map compiled-file
|
570 | 570 | (comp/compile-root src-dir out-dir opts))))
|
571 | 571 |
|
| 572 | +(defn build-affecting-options-sha [opts] |
| 573 | + (util/content-sha (pr-str (comp/build-affecting-options opts)) 7)) |
| 574 | + |
| 575 | +(defn ^File cache-base-path |
| 576 | + ([] |
| 577 | + (cache-base-path nil)) |
| 578 | + ([opts] |
| 579 | + (io/file (System/getProperty "user.home") |
| 580 | + ".cljs" ".aot_cache" (util/clojurescript-version) |
| 581 | + (build-affecting-options-sha opts)))) |
| 582 | + |
| 583 | +(defn cacheable-files |
| 584 | + ([ns ext] |
| 585 | + (cacheable-files ns ext nil)) |
| 586 | + ([ns ext opts] |
| 587 | + (let [path (cache-base-path opts) |
| 588 | + name (util/ns->relpath ns nil)] |
| 589 | + (into {} |
| 590 | + (map |
| 591 | + (fn [[k v]] |
| 592 | + [k (io/file path (str name v))])) |
| 593 | + {:source (str "." ext) |
| 594 | + :output-file ".js" |
| 595 | + :source-map ".js.map" |
| 596 | + :analysis-cache-edn ".cljs.cache.edn" |
| 597 | + :analysis-cache-json ".cljs.cache.json"})))) |
| 598 | + |
572 | 599 | (defn ^String path-from-jarfile
|
573 | 600 | "Given the URL of a file within a jar, return the path of the file
|
574 | 601 | from the root of the jar."
|
|
592 | 619 | (.setLastModified ^File out-file (util/last-modified url))
|
593 | 620 | out-file)))
|
594 | 621 |
|
595 |
| -(defn build-affecting-options-sha [opts] |
596 |
| - (util/content-sha (pr-str (comp/build-affecting-options opts)) 7)) |
597 |
| - |
598 |
| -(defn cache-base-path |
599 |
| - ([] |
600 |
| - (cache-base-path nil)) |
601 |
| - ([opts] |
602 |
| - (io/file (System/getProperty "user.home") |
603 |
| - ".cljs" ".aot_cache" (util/clojurescript-version) |
604 |
| - (build-affecting-options-sha opts)))) |
605 |
| - |
606 |
| -(defn cacheable-files |
607 |
| - ([ns] |
608 |
| - (cacheable-files ns nil)) |
609 |
| - ([ns opts] |
610 |
| - (let [path (cache-base-path opts) |
611 |
| - name (util/ns->relpath ns nil)] |
612 |
| - (map #(io/file path (str name %)) |
613 |
| - [".js" ".cljs" ".cljs.cache.edn" ".cljs.cache.json" ".js.map"])))) |
614 |
| - |
615 | 622 | ;; TODO: it would be nice if we could consolidate requires-compilation?
|
616 | 623 | ;; logic - David
|
617 | 624 | (defn compile-from-jar
|
618 | 625 | "Compile a file from a jar if necessary. Returns IJavaScript."
|
619 | 626 | [jar-file {:keys [output-file] :as opts}]
|
620 |
| - (let [out-file (when output-file |
621 |
| - (io/file (util/output-directory opts) output-file))] |
622 |
| - (if (or (nil? out-file) |
623 |
| - (not (.exists ^File out-file)) |
624 |
| - (not= (util/compiled-by-version out-file) |
625 |
| - (util/clojurescript-version)) |
626 |
| - (util/changed? jar-file out-file)) |
| 627 | + (let [{:keys [ns]} (ana/parse-ns jar-file) |
| 628 | + out-file (when output-file |
| 629 | + (io/file (util/output-directory opts) output-file)) |
| 630 | + cacheable (cacheable-files ns (util/ext jar-file) opts)] |
| 631 | + (when (or (nil? out-file) |
| 632 | + (not (.exists ^File out-file)) |
| 633 | + (not= (util/compiled-by-version out-file) |
| 634 | + (util/clojurescript-version)) |
| 635 | + (util/changed? jar-file out-file)) |
627 | 636 | ;; actually compile from JAR
|
628 |
| - (let [file-on-disk (jar-file-to-disk jar-file (util/output-directory opts) opts)] |
629 |
| - (-compile file-on-disk opts)) |
630 |
| - ;; have to call compile-file as it includes more IJavaScript |
631 |
| - ;; information than ana/parse-ns |
632 |
| - (compile-file |
633 |
| - (io/file (util/output-directory opts) |
634 |
| - (last (string/split (.getPath ^URL jar-file) #"\.jar!/"))) |
635 |
| - opts)))) |
| 637 | + (let [cache-path (cache-base-path opts)] |
| 638 | + (when-not (.exists (:output-file cacheable)) |
| 639 | + (-compile (jar-file-to-disk jar-file cache-path opts) opts)) |
| 640 | + (doseq [[k ^File f] cacheable] |
| 641 | + (when (.exists f) |
| 642 | + (let [target (io/file (util/output-directory opts) |
| 643 | + (-> (.getAbsolutePath f) |
| 644 | + (string/replace (.getAbsolutePath cache-path) "") |
| 645 | + (subs 1)))] |
| 646 | + (when (and ana/*verbose* (= :source k)) |
| 647 | + (util/debug-prn (str "Copying cached " f " to " target))) |
| 648 | + (spit target (slurp f)) |
| 649 | + (.setLastModified target (util/last-modified jar-file))))))) |
| 650 | + ;; have to call compile-file as it includes more IJavaScript |
| 651 | + ;; information than ana/parse-ns for now |
| 652 | + (compile-file |
| 653 | + (io/file (util/output-directory opts) |
| 654 | + (last (string/split (.getPath ^URL jar-file) #"\.jar!/"))) |
| 655 | + opts))) |
636 | 656 |
|
637 | 657 | (defn find-jar-sources
|
638 |
| - [this opts] |
| 658 | + [this opts] () |
639 | 659 | [(comp/find-source (jar-file-to-disk this (util/output-directory opts)))])
|
640 | 660 |
|
641 | 661 | (extend-protocol Compilable
|
|
2736 | 2756 | (binding [comp/*recompiled* (when-not (false? (:recompile-dependents opts))
|
2737 | 2757 | (atom #{}))
|
2738 | 2758 | ana/*checked-arrays* checked-arrays
|
| 2759 | + ana/parse-ns (memoize ana/parse-ns) |
2739 | 2760 | ana/*cljs-static-fns* static-fns?
|
2740 | 2761 | ana/*fn-invoke-direct* (or (and static-fns?
|
2741 | 2762 | (:fn-invoke-direct opts))
|
|
0 commit comments