|
3833 | 3833 | ([format] |
3834 | 3834 | (if (and (= format :transit) @transit) "json" "edn")))) |
3835 | 3835 |
|
| 3836 | +#?(:clj |
| 3837 | + (defn build-affecting-options [opts] |
| 3838 | + (select-keys opts |
| 3839 | + [:static-fns :fn-invoke-direct :optimize-constants :elide-asserts :target |
| 3840 | + :cache-key :checked-arrays :language-out]))) |
| 3841 | + |
| 3842 | +#?(:clj |
| 3843 | + (defn build-affecting-options-sha [path opts] |
| 3844 | + (let [m (assoc (build-affecting-options opts) :path path)] |
| 3845 | + (util/content-sha (pr-str m) 7)))) |
| 3846 | + |
| 3847 | +#?(:clj |
| 3848 | + (defn ^File cache-base-path |
| 3849 | + ([path] |
| 3850 | + (cache-base-path path nil)) |
| 3851 | + ([path opts] |
| 3852 | + (io/file (System/getProperty "user.home") |
| 3853 | + ".cljs" ".aot_cache" (util/clojurescript-version) |
| 3854 | + (build-affecting-options-sha path opts))))) |
| 3855 | + |
| 3856 | +#?(:clj |
| 3857 | + (defn cacheable-files |
| 3858 | + ([rsrc ext] |
| 3859 | + (cacheable-files rsrc ext nil)) |
| 3860 | + ([rsrc ext opts] |
| 3861 | + (let [{:keys [ns]} (parse-ns rsrc) |
| 3862 | + path (cache-base-path (util/path rsrc) opts) |
| 3863 | + name (util/ns->relpath ns nil File/separatorChar)] |
| 3864 | + (into {} |
| 3865 | + (map |
| 3866 | + (fn [[k v]] |
| 3867 | + [k (io/file path |
| 3868 | + (if (and (= (str "cljs" File/separatorChar "core$macros") name) |
| 3869 | + (= :source k)) |
| 3870 | + (str "cljs" File/separatorChar "core.cljc") |
| 3871 | + (str name v)))])) |
| 3872 | + {:source (str "." ext) |
| 3873 | + :output-file ".js" |
| 3874 | + :source-map ".js.map" |
| 3875 | + :analysis-cache-edn (str "." ext ".cache.edn") |
| 3876 | + :analysis-cache-json (str "." ext ".cache.json")}))))) |
| 3877 | + |
3836 | 3878 | #?(:clj |
3837 | 3879 | (defn cache-file |
3838 | 3880 | "Given a ClojureScript source file returns the read/write path to the analysis |
3839 | 3881 | cache file. Defaults to the read path which is usually also the write path." |
3840 | 3882 | ([src] (cache-file src "out")) |
3841 | 3883 | ([src output-dir] (cache-file src (parse-ns src) output-dir)) |
3842 | 3884 | ([src ns-info output-dir] |
3843 | | - (cache-file src (parse-ns src) output-dir :read)) |
| 3885 | + (cache-file src ns-info output-dir :read nil)) |
3844 | 3886 | ([src ns-info output-dir mode] |
| 3887 | + (cache-file src ns-info output-dir mode nil)) |
| 3888 | + ([src ns-info output-dir mode opts] |
3845 | 3889 | {:pre [(map? ns-info)]} |
3846 | 3890 | (let [ext (cache-analysis-ext)] |
3847 | 3891 | (if-let [core-cache |
3848 | 3892 | (and (= mode :read) |
3849 | 3893 | (= (:ns ns-info) 'cljs.core) |
3850 | 3894 | (io/resource (str "cljs/core.cljs.cache.aot." ext)))] |
3851 | 3895 | core-cache |
3852 | | - (let [target-file (util/to-target-file output-dir ns-info |
3853 | | - (util/ext (:source-file ns-info)))] |
3854 | | - (io/file (str target-file ".cache." ext)))))))) |
| 3896 | + (let [aot-cache-file |
| 3897 | + (when (util/url? src) |
| 3898 | + ((keyword (str "analysis-cache-" ext)) |
| 3899 | + (cacheable-files src (util/ext src) opts)))] |
| 3900 | + (if (and aot-cache-file (.exists ^File aot-cache-file)) |
| 3901 | + aot-cache-file |
| 3902 | + (let [target-file (util/to-target-file output-dir ns-info |
| 3903 | + (util/ext (:source-file ns-info)))] |
| 3904 | + (io/file (str target-file ".cache." ext)))))))))) |
3855 | 3905 |
|
3856 | 3906 | #?(:clj |
3857 | 3907 | (defn requires-analysis? |
|
3861 | 3911 | ([src] (requires-analysis? src "out")) |
3862 | 3912 | ([src output-dir] |
3863 | 3913 | (let [cache (cache-file src output-dir)] |
3864 | | - (requires-analysis? src cache output-dir))) |
| 3914 | + (requires-analysis? src cache output-dir nil))) |
3865 | 3915 | ([src cache output-dir] |
| 3916 | + (requires-analysis? src cache output-dir nil)) |
| 3917 | + ([src cache output-dir opts] |
3866 | 3918 | (cond |
3867 | 3919 | (util/url? cache) |
3868 | 3920 | (let [path (.getPath ^URL cache)] |
|
3876 | 3928 | true |
3877 | 3929 |
|
3878 | 3930 | :else |
3879 | | - (let [out-src (util/to-target-file output-dir (parse-ns src))] |
3880 | | - (if (not (.exists out-src)) |
| 3931 | + (let [out-src (util/to-target-file output-dir (parse-ns src)) |
| 3932 | + cache-src (:output-file (cacheable-files src (util/ext src) opts))] |
| 3933 | + (if (and (not (.exists out-src)) |
| 3934 | + (not (.exists ^File cache-src))) |
3881 | 3935 | true |
3882 | | - (util/changed? src cache))))))) |
| 3936 | + (or (not cache) (util/changed? src cache)))))))) |
3883 | 3937 |
|
3884 | 3938 | #?(:clj |
3885 | 3939 | (defn- get-spec-vars |
|
4049 | 4103 | (.getPath ^File res) |
4050 | 4104 | (.getPath ^URL res)) |
4051 | 4105 | cache (when (:cache-analysis opts) |
4052 | | - (cache-file res ns-info output-dir))] |
| 4106 | + (cache-file res ns-info output-dir :read opts))] |
4053 | 4107 | (when-not (get-in @env/*compiler* [::namespaces (:ns ns-info) :defs]) |
4054 | | - (if (or skip-cache (not cache) (requires-analysis? res output-dir)) |
| 4108 | + (if (or skip-cache (not cache) (requires-analysis? res cache output-dir opts)) |
4055 | 4109 | (binding [*cljs-ns* 'cljs.user |
4056 | 4110 | *cljs-file* path |
4057 | 4111 | reader/*alias-map* (or reader/*alias-map* {})] |
|
0 commit comments