|
456 | 456 |
|
457 | 457 | (defn jar-file-to-disk |
458 | 458 | "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))) |
467 | 471 |
|
468 | 472 | ;; TODO: it would be nice if we could consolidate requires-compilation? |
469 | 473 | ;; logic - David |
470 | 474 | (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)))) |
484 | 493 |
|
485 | 494 | (defn find-jar-sources |
486 | 495 | [this opts] |
|
0 commit comments