Skip to content

Commit 8d72633

Browse files
author
dnolen
committed
fix issue where files in JARs would get copied to out without correct timestamping
add more logging minor code cleanup and comments for readability
1 parent e090f18 commit 8d72633

File tree

1 file changed

+30
-21
lines changed

1 file changed

+30
-21
lines changed

src/main/clojure/cljs/closure.clj

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -456,31 +456,40 @@
456456

457457
(defn jar-file-to-disk
458458
"Copy a file contained within a jar to disk. Return the created file."
459-
[url out-dir]
460-
(let [out-file (io/file out-dir (path-from-jarfile url))
461-
content (with-open [reader (io/reader url)]
462-
(slurp reader))]
463-
(util/mkdirs out-file)
464-
(spit out-file content)
465-
(.setLastModified ^File out-file (util/last-modified url))
466-
out-file))
459+
([url out-dir]
460+
(jar-file-to-disk url out-dir nil))
461+
([url out-dir opts]
462+
(let [out-file (io/file out-dir (path-from-jarfile url))
463+
content (with-open [reader (io/reader url)]
464+
(slurp reader))]
465+
(when (and url (or ana/*verbose* (:verbose opts)))
466+
(util/debug-prn "Copying" (str url) "to" (str out-file)))
467+
(util/mkdirs out-file)
468+
(spit out-file content)
469+
(.setLastModified ^File out-file (util/last-modified url))
470+
out-file)))
467471

468472
;; TODO: it would be nice if we could consolidate requires-compilation?
469473
;; logic - David
470474
(defn compile-from-jar
471-
"Compile a file from a jar."
472-
[this {:keys [output-file] :as opts}]
473-
(or (when output-file
474-
(let [out-file (io/file (util/output-directory opts) output-file)]
475-
(when (and (.exists out-file)
476-
(= (util/compiled-by-version out-file)
477-
(util/clojurescript-version)))
478-
(compile-file
479-
(io/file (util/output-directory opts)
480-
(last (string/split (.getPath ^URL this) #"\.jar!/")))
481-
opts))))
482-
(let [file-on-disk (jar-file-to-disk this (util/output-directory opts))]
483-
(-compile file-on-disk opts))))
475+
"Compile a file from a jar if necessary. Returns IJavaScript."
476+
[jar-file {:keys [output-file] :as opts}]
477+
(let [out-file (when output-file
478+
(io/file (util/output-directory opts) output-file))]
479+
(if (or (nil? out-file)
480+
(not (.exists ^File out-file))
481+
(not= (util/compiled-by-version out-file)
482+
(util/clojurescript-version))
483+
(util/changed? jar-file out-file))
484+
;; actually compile from JAR
485+
(let [file-on-disk (jar-file-to-disk jar-file (util/output-directory opts) opts)]
486+
(-compile file-on-disk opts))
487+
;; have to call compile-file as it includes more IJavaScript
488+
;; information than ana/parse-ns
489+
(compile-file
490+
(io/file (util/output-directory opts)
491+
(last (string/split (.getPath ^URL jar-file) #"\.jar!/")))
492+
opts))))
484493

485494
(defn find-jar-sources
486495
[this opts]

0 commit comments

Comments
 (0)