From 62d4921d62b7029b49d50b89b97f31e7482fc4a5 Mon Sep 17 00:00:00 2001 From: Arlen Cuss Date: Fri, 6 Jul 2012 20:57:33 +1000 Subject: [PATCH 1/3] Re-enable post-compile cleaning. See technomancy/leiningen#516. AOT can bring in other .classes which we don't want for ourselves. It was disabled for 2.x, but seems fine in 1.x. --- src/leiningen/compile.clj | 80 +++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/src/leiningen/compile.clj b/src/leiningen/compile.clj index ca770a9a..31376fc0 100644 --- a/src/leiningen/compile.clj +++ b/src/leiningen/compile.clj @@ -56,50 +56,50 @@ ;; .class file cleanup -;; (defn- has-source-package? -;; "Test if the class file's package exists as a directory in source-path." -;; [project f source-path] -;; (and 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- has-source-package? + "Test if the class file's package exists as a directory in source-path." + [project f source-path] + (and 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] -;; (or (has-source-package? project f (:source-paths project)) -;; (has-source-package? project f (:java-source-paths project)) -;; (.exists (io/file (str (.replace (.getParent f) -;; (:compile-path project) -;; (:source-paths project)) ".clj"))))) +(defn- class-in-project? [project f] + (or (has-source-package? project f (:source-paths project)) + (has-source-package? project f (:java-source-paths project)) + (.exists (io/file (str (.replace (.getParent f) + (:compile-path project) + (:source-paths project)) ".clj"))))) -;; (defn- relative-path [project f] -;; (let [root-length (if (= \/ (last (:compile-path project))) -;; (count (:compile-path project)) -;; (inc (count (:compile-path project))))] -;; (subs (.getAbsolutePath f) root-length))) +(defn- relative-path [project f] + (let [root-length (if (= \/ (last (:compile-path project))) + (count (:compile-path project)) + (inc (count (:compile-path project))))] + (subs (.getAbsolutePath f) root-length))) -;; (defn- blacklisted-class? [project f] -;; ;; true indicates all non-project classes are blacklisted -;; (or (true? (:clean-non-project-classes project)) -;; (some #(re-find % (relative-path project f)) -;; (:clean-non-project-classes project)))) +(defn- blacklisted-class? [project f] + ;; true indicates all non-project classes are blacklisted + (or (true? (:clean-non-project-classes project)) + (some #(re-find % (relative-path project f)) + (:clean-non-project-classes project)))) -;; (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- 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 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]] (println "The eval-in-project function has moved to the leiningen.core.eval\n" @@ -133,7 +133,7 @@ Code that should run on startup belongs in a -main defn." (main/info "Compilation succeeded.") (catch Exception e (main/abort "Compilation failed.")))) - #_(finally (clean-non-project-classes project))) + (finally (clean-non-project-classes project))) ;; TODO: omit if possible (main/info "All namespaces already :aot compiled.")))) ([project & namespaces] From e39397cbc5852ad1af9bf5fcb3c8a62fca6a926c Mon Sep 17 00:00:00 2001 From: Arlen Cuss Date: Fri, 6 Jul 2012 23:11:51 +1000 Subject: [PATCH 2/3] Fix existing :post-preview tests for cleanup. --- src/leiningen/compile.clj | 30 ++++++++++++++++++++---------- test/leiningen/test/compile.clj | 8 ++++---- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/leiningen/compile.clj b/src/leiningen/compile.clj index 31376fc0..8c9e021c 100644 --- a/src/leiningen/compile.clj +++ b/src/leiningen/compile.clj @@ -56,24 +56,34 @@ ;; .class file cleanup +(defn- package-in-project? + "Tests if the package found in the compile path exists as a directory in the source path." + [found-path compile-path source-path] + (.isDirectory (io/file (.replace found-path compile-path source-path)))) + (defn- has-source-package? - "Test if the class file's package exists as a directory in source-path." - [project f source-path] - (and source-path + "Test if the class file's package exists as a directory in source-paths." + [project f source-paths] + (and source-paths (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)))))) + (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- source-in-project? + "Tests if a file found in the compile path exists in the source path." + [parent compile-path source-path] + (.exists (io/file (str (.replace parent compile-path source-path) ".clj")))) (defn- class-in-project? [project f] (or (has-source-package? project f (:source-paths project)) (has-source-package? project f (:java-source-paths project)) - (.exists (io/file (str (.replace (.getParent f) - (:compile-path project) - (:source-paths project)) ".clj"))))) + (let [parent (.getParent f) + compile-path (:compile-path project)] + (some #(source-in-project? parent compile-path %) (:source-paths project))))) (defn- relative-path [project f] (let [root-length (if (= \/ (last (:compile-path project))) diff --git a/test/leiningen/test/compile.clj b/test/leiningen/test/compile.clj index 5d247ba8..4b7a760c 100644 --- a/test/leiningen/test/compile.clj +++ b/test/leiningen/test/compile.clj @@ -44,8 +44,8 @@ (eval/eval-in-project sample-project '(require 'nom.nom.nom)) (let [classes (seq (.list (file "test_projects" "sample" "target" "classes" "nom" "nom")))] - (doseq [r [#"nom\$fn__\d+.class" #"nom\$loading__\d+__auto____\d+.class" - #"nom\$_main__\d+.class" #"nom.class" #"nom__init.class"]] + (doseq [r [#"nom\$fn__\d+.class" #"nom\$loading__\d+__auto__.class" + #"nom\$_main.class" #"nom.class" #"nom__init.class"]] (is (some (partial re-find r) classes) (format "missing %s" r)))) (is (not (.exists (file "test_projects" "sample" "target" "classes" "sample2" "core.class")))) @@ -56,8 +56,8 @@ (compile (assoc sample-project :clean-non-project-classes [#"core"])) (let [classes (seq (.list (file "test_projects" "sample" "target" "classes" "nom" "nom")))] - (doseq [r [#"nom\$fn__\d+.class" #"nom\$loading__\d+__auto____\d+.class" - #"nom\$_main__\d+.class" #"nom.class" #"nom__init.class"]] + (doseq [r [#"nom\$fn__\d+.class" #"nom\$loading__\d+__auto__.class" + #"nom\$_main.class" #"nom.class" #"nom__init.class"]] (is (some (partial re-find r) classes) (format "missing %s" r)))) (is (not (.exists (file "test_projects" "sample" "target" "classes" "sample2" "core.class")))) From 710849c3f55a83bd9e72b398792852e2a1b8f478 Mon Sep 17 00:00:00 2001 From: Arlen Cuss Date: Fri, 6 Jul 2012 23:20:29 +1000 Subject: [PATCH 3/3] Unmark :post-preview compile tests. --- test/leiningen/test/compile.clj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/leiningen/test/compile.clj b/test/leiningen/test/compile.clj index 4b7a760c..aa685579 100644 --- a/test/leiningen/test/compile.clj +++ b/test/leiningen/test/compile.clj @@ -39,7 +39,7 @@ `(reset! eip-check true)) (is @eip-check)) -(deftest ^:post-preview test-cleared-transitive-aot +(deftest test-cleared-transitive-aot (compile (assoc sample-project :clean-non-project-classes true)) (eval/eval-in-project sample-project '(require 'nom.nom.nom)) (let [classes (seq (.list (file "test_projects" "sample" "target" @@ -52,7 +52,7 @@ (is (not (.exists (file "test_projects" "sample" "target" "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"])) (let [classes (seq (.list (file "test_projects" "sample" "target" "classes" "nom" "nom")))]