From 73dc8e0fdb350a75ff3d1294fca27235ef407bf2 Mon Sep 17 00:00:00 2001 From: Zach Tellman Date: Wed, 29 Jan 2025 14:41:00 -0800 Subject: [PATCH 1/3] add back tools.namespaces, and reload namespaces after compilation --- deps.edn | 1 + src/virgil/compile.clj | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/deps.edn b/deps.edn index e9ee0a4..ac3792e 100644 --- a/deps.edn +++ b/deps.edn @@ -1,5 +1,6 @@ {:paths ["src"] :deps {org.clojure/clojure {:mvn/version "1.12.0" :mvn/scope "provided"} + org.clojure/tools.namespace {:mvn/version "1.5.0"} org.ow2.asm/asm {:mvn/version "9.7"}} :aliases diff --git a/src/virgil/compile.clj b/src/virgil/compile.clj index 48da47e..f52ecde 100644 --- a/src/virgil/compile.clj +++ b/src/virgil/compile.clj @@ -2,6 +2,7 @@ (:require [clojure.java.io :as io] [virgil.watch :as watch] + [clojure.tools.namespace.repl :refer (refresh-all)] [virgil.decompile :as decompile] [virgil.util :refer [print-diagnostics]] [clojure.string :as str]) @@ -154,6 +155,10 @@ (println "\nCompiling" (count name->source)"Java source files in" directories "...") (binding [*print-compiled-classes* verbose?] (compile-java options collector name->source)) + ;; We need to create a thread binding for *ns* so that + ;; refresh-all can use in-ns. + (binding [*ns* *ns*] + (refresh-all)) (when-let [diags (seq (.getDiagnostics collector))] (print-diagnostics diags) diags)))) From 2d751653259e2010cf8c50e3cf118cac339bcc70 Mon Sep 17 00:00:00 2001 From: Zach Tellman Date: Wed, 29 Jan 2025 14:56:00 -0800 Subject: [PATCH 2/3] fix tests (*dir* was being reset by reload behavior, so I took out the dynamic var) --- test/virgil_test.clj | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/test/virgil_test.clj b/test/virgil_test.clj index a36e67e..b24c84f 100644 --- a/test/virgil_test.clj +++ b/test/virgil_test.clj @@ -12,8 +12,6 @@ (println "Running on Clojure" (clojure-version)) (when v (is (clojure.string/starts-with? (clojure-version) v))))) -(def ^:dynamic *dir*) - (defn mk-tmp [] (.toFile (Files/createTempDirectory "virgil" (into-array FileAttribute [])))) @@ -22,8 +20,8 @@ c (Class/forName "virgil.B" false cl)] (eval `(. (new ~c) magicNumber)))) -(defn cp [file class] - (let [dest (io/file *dir* "virgil")] +(defn cp [dir file class] + (let [dest (io/file dir "virgil")] (.mkdir dest) (io/copy (io/file "test" (str file ".java")) (io/file dest (str class ".java"))))) @@ -37,11 +35,13 @@ (wait) (when-not (f) (recur (dec i)))))) -(defn recompile [] - (virgil/compile-java [(str *dir*)])) +(defn recompile [dir] + (virgil/compile-java [(str dir)])) (deftest manual-compile-test - (binding [*dir* (mk-tmp)] + (let [dir (mk-tmp) + recompile #(virgil/compile-java [(str dir)]) + cp #(cp dir %1 %2)] (cp "A" 'A) (cp "B" 'B) (recompile) @@ -83,15 +83,15 @@ (is (= 42 (magic-number))))) (deftest warnings-shouldnt-throw-test - (binding [*dir* (mk-tmp)] - (cp "ClassWithWarning" 'ClassWithWarning) - (is (nil? (recompile)))) + (let [dir (mk-tmp)] + (cp dir "ClassWithWarning" 'ClassWithWarning) + (is (nil? (recompile dir)))) - (binding [*dir* (mk-tmp)] - (cp "ClassWithError" 'ClassWithError) - (is (thrown? clojure.lang.ExceptionInfo (recompile))))) + (let [dir (mk-tmp)] + (cp dir "ClassWithError" 'ClassWithError) + (is (thrown? clojure.lang.ExceptionInfo (recompile dir))))) (deftest errors-shouldnt-break-watch-and-recompile-test - (binding [*dir* (mk-tmp)] - (cp "ClassWithError" 'ClassWithError) - (is (nil? (virgil/watch-and-recompile [(str *dir*)]))))) + (let [dir (mk-tmp)] + (cp dir "ClassWithError" 'ClassWithError) + (is (nil? (virgil/watch-and-recompile [(str dir)]))))) From d8111580ad56e4fd42962c8f6c29663049e220d8 Mon Sep 17 00:00:00 2001 From: Zach Tellman Date: Wed, 29 Jan 2025 14:57:17 -0800 Subject: [PATCH 3/3] slight cleanup --- test/virgil_test.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/virgil_test.clj b/test/virgil_test.clj index b24c84f..6073981 100644 --- a/test/virgil_test.clj +++ b/test/virgil_test.clj @@ -40,7 +40,7 @@ (deftest manual-compile-test (let [dir (mk-tmp) - recompile #(virgil/compile-java [(str dir)]) + recompile #(recompile dir) cp #(cp dir %1 %2)] (cp "A" 'A) (cp "B" 'B)