Merge pull request #675 from unnali/re_enable_post_compile_cleaning

Re-enable post-compile cleaning.
This commit is contained in:
Michael Klishin 2012-07-06 06:49:05 -07:00
commit 5afa5bff68
2 changed files with 56 additions and 46 deletions

View file

@ -56,50 +56,60 @@
;; .class file cleanup ;; .class file cleanup
;; (defn- has-source-package? (defn- package-in-project?
;; "Test if the class file's package exists as a directory in source-path." "Tests if the package found in the compile path exists as a directory in the source path."
;; [project f source-path] [found-path compile-path source-path]
;; (and source-path (.isDirectory (io/file (.replace found-path compile-path source-path))))
;; (let [[[parent] [_ _ proxy-mod-parent]]
;; (->> f, (iterate #(.getParentFile %)),
;; (take-while identity), rest,
;; (split-with #(not (re-find #"^proxy\$" (.getName %)))))]
;; (.isDirectory (io/file (.replace (.getPath (or proxy-mod-parent parent))
;; (:compile-path project)
;; source-path))))))
;; (defn- class-in-project? [project f] (defn- has-source-package?
;; (or (has-source-package? project f (:source-paths project)) "Test if the class file's package exists as a directory in source-paths."
;; (has-source-package? project f (:java-source-paths project)) [project f source-paths]
;; (.exists (io/file (str (.replace (.getParent f) (and source-paths
;; (:compile-path project) (let [[[parent] [_ _ proxy-mod-parent]]
;; (:source-paths project)) ".clj"))))) (->> f, (iterate #(.getParentFile %)),
(take-while identity), rest,
(split-with #(not (re-find #"^proxy\$" (.getName %)))))
found-path (.getPath (or proxy-mod-parent parent))
compile-path (:compile-path project)]
(some #(package-in-project? found-path compile-path %) source-paths))))
;; (defn- relative-path [project f] (defn- source-in-project?
;; (let [root-length (if (= \/ (last (:compile-path project))) "Tests if a file found in the compile path exists in the source path."
;; (count (:compile-path project)) [parent compile-path source-path]
;; (inc (count (:compile-path project))))] (.exists (io/file (str (.replace parent compile-path source-path) ".clj"))))
;; (subs (.getAbsolutePath f) root-length)))
;; (defn- blacklisted-class? [project f] (defn- class-in-project? [project f]
;; ;; true indicates all non-project classes are blacklisted (or (has-source-package? project f (:source-paths project))
;; (or (true? (:clean-non-project-classes project)) (has-source-package? project f (:java-source-paths project))
;; (some #(re-find % (relative-path project f)) (let [parent (.getParent f)
;; (:clean-non-project-classes project)))) compile-path (:compile-path project)]
(some #(source-in-project? parent compile-path %) (:source-paths project)))))
;; (defn- whitelisted-class? [project f] (defn- relative-path [project f]
;; (or (class-in-project? project f) (let [root-length (if (= \/ (last (:compile-path project)))
;; (and (:class-file-whitelist project) (count (:compile-path project))
;; (re-find (:class-file-whitelist project) (inc (count (:compile-path project))))]
;; (relative-path project f))))) (subs (.getAbsolutePath f) root-length)))
;; (defn clean-non-project-classes [project] (defn- blacklisted-class? [project f]
;; (when (:clean-non-project-classes project) ;; true indicates all non-project classes are blacklisted
;; (doseq [f (file-seq (io/file (:compile-path project))) (or (true? (:clean-non-project-classes project))
;; :when (and (.isFile f) (some #(re-find % (relative-path project f))
;; (not (whitelisted-class? project f)) (:clean-non-project-classes project))))
;; (blacklisted-class? project f))]
;; (.delete f)))) (defn- whitelisted-class? [project f]
(or (class-in-project? project f)
(and (:class-file-whitelist project)
(re-find (:class-file-whitelist project)
(relative-path project f)))))
(defn clean-non-project-classes [project]
(when (:clean-non-project-classes project)
(doseq [f (file-seq (io/file (:compile-path project)))
:when (and (.isFile f)
(not (whitelisted-class? project f))
(blacklisted-class? project f))]
(.delete f))))
(defn eval-in-project [project form & [_ _ init]] (defn eval-in-project [project form & [_ _ init]]
(println "The eval-in-project function has moved to the leiningen.core.eval\n" (println "The eval-in-project function has moved to the leiningen.core.eval\n"
@ -133,7 +143,7 @@ Code that should run on startup belongs in a -main defn."
(main/info "Compilation succeeded.") (main/info "Compilation succeeded.")
(catch Exception e (catch Exception e
(main/abort "Compilation failed.")))) (main/abort "Compilation failed."))))
#_(finally (clean-non-project-classes project))) (finally (clean-non-project-classes project)))
;; TODO: omit if possible ;; TODO: omit if possible
(main/info "All namespaces already :aot compiled.")))) (main/info "All namespaces already :aot compiled."))))
([project & namespaces] ([project & namespaces]

View file

@ -39,25 +39,25 @@
`(reset! eip-check true)) `(reset! eip-check true))
(is @eip-check)) (is @eip-check))
(deftest ^:post-preview test-cleared-transitive-aot (deftest test-cleared-transitive-aot
(compile (assoc sample-project :clean-non-project-classes true)) (compile (assoc sample-project :clean-non-project-classes true))
(eval/eval-in-project sample-project '(require 'nom.nom.nom)) (eval/eval-in-project sample-project '(require 'nom.nom.nom))
(let [classes (seq (.list (file "test_projects" "sample" "target" (let [classes (seq (.list (file "test_projects" "sample" "target"
"classes" "nom" "nom")))] "classes" "nom" "nom")))]
(doseq [r [#"nom\$fn__\d+.class" #"nom\$loading__\d+__auto____\d+.class" (doseq [r [#"nom\$fn__\d+.class" #"nom\$loading__\d+__auto__.class"
#"nom\$_main__\d+.class" #"nom.class" #"nom__init.class"]] #"nom\$_main.class" #"nom.class" #"nom__init.class"]]
(is (some (partial re-find r) classes) (format "missing %s" r)))) (is (some (partial re-find r) classes) (format "missing %s" r))))
(is (not (.exists (file "test_projects" "sample" "target" (is (not (.exists (file "test_projects" "sample" "target"
"classes" "sample2" "core.class")))) "classes" "sample2" "core.class"))))
(is (not (.exists (file "test_projects" "sample" "target" (is (not (.exists (file "test_projects" "sample" "target"
"classes" "sample2" "alt.class"))))) "classes" "sample2" "alt.class")))))
(deftest ^:post-preview test-cleared-transitive-aot-by-regexes (deftest test-cleared-transitive-aot-by-regexes
(compile (assoc sample-project :clean-non-project-classes [#"core"])) (compile (assoc sample-project :clean-non-project-classes [#"core"]))
(let [classes (seq (.list (file "test_projects" "sample" "target" (let [classes (seq (.list (file "test_projects" "sample" "target"
"classes" "nom" "nom")))] "classes" "nom" "nom")))]
(doseq [r [#"nom\$fn__\d+.class" #"nom\$loading__\d+__auto____\d+.class" (doseq [r [#"nom\$fn__\d+.class" #"nom\$loading__\d+__auto__.class"
#"nom\$_main__\d+.class" #"nom.class" #"nom__init.class"]] #"nom\$_main.class" #"nom.class" #"nom__init.class"]]
(is (some (partial re-find r) classes) (format "missing %s" r)))) (is (some (partial re-find r) classes) (format "missing %s" r))))
(is (not (.exists (file "test_projects" "sample" "target" (is (not (.exists (file "test_projects" "sample" "target"
"classes" "sample2" "core.class")))) "classes" "sample2" "core.class"))))