Skip to content

Commit

Permalink
Remove debugger hard dependency on org.clojure/clojurescript
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan Pedro Monetta Sanchez authored and Juan Pedro Monetta Sanchez committed Oct 18, 2022
1 parent 2a4a121 commit eda9c04
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 37 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

### Changes

- Remove flow-storm hard dependency on org.clojure/clojurescript artifact. Will lazy require when needed for ClojureScript, assuming the dependency will be provided

### Bugs fixed

## 3.1.259 (17-10-2022)
Expand Down
10 changes: 1 addition & 9 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
nrepl/nrepl {:mvn/version "1.0.0"}
org.clojure/tools.namespace {:mvn/version "1.2.0"}
com.cognitect/transit-cljs {:mvn/version "0.8.280"}
org.clojure/clojurescript {:mvn/version "1.11.60"}
;---------------------------------------------------------------------

}
Expand Down Expand Up @@ -49,17 +48,10 @@
:extra-deps {;; Namespaces instrumentation
org.clojure/tools.namespace {:mvn/version "1.2.0"}
com.cognitect/transit-cljs {:mvn/version "0.8.280"}
org.clojure/clojurescript {:mvn/version "1.11.60"
;;:local/root "/home/jmonetta/my-projects/clojurescript"
}
}}

:dev {:extra-paths ["src-dev"]
:extra-deps {com.clojure-goes-fast/clj-async-profiler {:mvn/version "0.5.1"}
;; to self instrument
com.github.jpmonettas/flow-storm-dbg {:mvn/version "2.0.38"}
com.github.jpmonettas/flow-storm-inst {:mvn/version "2.0.38"}
}
:extra-deps {}
:jvm-opts ["-Djdk.attach.allowAttachSelf" "-XX:+UnlockDiagnosticVMOptions" "-XX:+DebugNonSafepoints" ;; for the profilers
"-Xmx10500m" ;; for instrumenting big codebases
]}
Expand Down
12 changes: 6 additions & 6 deletions src-inst/flow_storm/instrument/forms.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
(:require
[clojure.walk :as walk]
[clojure.string :as str]
[cljs.analyzer :as ana]
[cljs.analyzer.api :as ana-api]
[flow-storm.tracer :as tracer]
[flow-storm.instrument.runtime :refer [*runtime-ctx*]]
[flow-storm.utils :as utils]
Expand Down Expand Up @@ -979,10 +977,12 @@
(let [form-id (hash form)
compiler (compiler-from-env env)
[macroexpand-1-fn expand-symbol] (case compiler
:cljs [(partial ana/macroexpand-1 env)
(fn [symb]
(or (:name (ana-api/resolve env symb))
symb))]
:cljs (let [cljs-macroexpand-1 (requiring-resolve 'cljs.analyzer/macroexpand-1)
cljs-resolve (requiring-resolve 'cljs.analyzer.api/resolve)]
[(partial cljs-macroexpand-1 env)
(fn [symb]
(or (:name (cljs-resolve env symb))
symb))])
:clj [macroexpand-1
(fn [symb]
(if-let [v (resolve symb)]
Expand Down
47 changes: 25 additions & 22 deletions src-inst/flow_storm/runtime/debuggers_api.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
#?@(:clj [[flow-storm.instrument.forms :as inst-forms]
[clojure.string :as str]
[flow-storm.instrument.namespaces :as inst-ns]
[cljs.repl :as cljs-repl]
[cljs.analyzer :as ana]
[cljs.analyzer.api :as ana-api]
[clojure.java.io :as io]
[clojure.set :as set]
[clojure.tools.namespace.parse :as tools-ns-parse]
Expand Down Expand Up @@ -234,39 +231,44 @@
instr-form))))

#?(:clj
(defmacro cljs-get-all-ns []
(mapv str (ana-api/all-ns))))
(defmacro cljs-get-all-ns []
(let [all-ns (requiring-resolve 'cljs.analyzer.api/all-ns)]
(mapv str (all-ns)))))

#?(:clj
(defmacro cljs-get-ns-interns [ns-symb]
(->> (ana-api/ns-interns ns-symb)
keys
(mapv str))))
(defmacro cljs-get-ns-interns [ns-symb]
(let [ns-interns (requiring-resolve 'cljs.analyzer.api/ns-interns)]
(->> (ns-interns ns-symb)
keys
(mapv str)))))

#?(:clj
(defmacro cljs-source-fn [symb]
(cljs-repl/source-fn &env symb)))
(let [source-fn (requiring-resolve 'cljs.repl/source-fn)]
(source-fn &env symb))))

#?(:clj
(defn- cljs-file-forms [ns-symb file-url]
(let [found-ns (ana-api/find-ns ns-symb)
(let [find-ns (requiring-resolve 'cljs.analyzer.api/find-ns)
forms-seq (requiring-resolve 'cljs.analyzer.api/forms-seq)
found-ns (find-ns ns-symb)
def-dynamic? (fn [form]
(and (= 'def (first form))
(let [symb-name (str (second form))]
(and (str/starts-with? symb-name "*")
(str/ends-with? symb-name "*")))))]
(try
(binding [ana/*cljs-ns* ns-symb]
(let [file-str (slurp file-url)
file-forms (ana-api/forms-seq (StringReader. file-str))]
(->> file-forms
rest ;; discard the (ns ...) form
(mapv (fn [form]
(if (def-dynamic? form)
(utils/lazy-binding [cljs.analyzer/*cljs-ns* ns-symb]
(let [file-str (slurp file-url)
file-forms (forms-seq (StringReader. file-str))]
(->> file-forms
rest ;; discard the (ns ...) form
(mapv (fn [form]
(if (def-dynamic? form)

(binding [*print-meta* true] (pr-str form))
(binding [*print-meta* true] (pr-str form))

(pr-str form)))))))
(pr-str form)))))))
(catch Exception e
(binding [*out* *err*]
(println "Error reading forms for " ns-symb file-url "after finding ns" found-ns)
Expand All @@ -282,9 +284,10 @@
Used by tools from the repl to retrieve namespaces forms to instrument/uninstrument"

[ns-symbs]
(let [all-ns-info (->> ns-symbs
(let [find-ns (requiring-resolve 'cljs.analyzer.api/find-ns)
all-ns-info (->> ns-symbs
(map (fn [ns-symb]
(let [file-name (-> (ana-api/find-ns ns-symb) :meta :file)
(let [file-name (-> (find-ns ns-symb) :meta :file)
file (try (io/resource file-name) (catch Exception _ nil))
ns-decl-form (try (tools-ns-file/read-file-ns-decl file) (catch Exception _ nil))
deps (try (tools-ns-parse/deps-from-ns-decl ns-decl-form) (catch Exception _ nil))]
Expand Down
15 changes: 15 additions & 0 deletions src-shared/flow_storm/utils.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,18 @@
(new ~name ~@fields)
~@body)))
)

#?(:clj
(defmacro lazy-binding
"Like clojure.core/binding but instead of a vec of vars it accepts a vec
of symbols, and will resolve the vars with requiring-resolve"
[bindings & body]
(let [vars-binds (mapcat (fn [[var-symb var-val]]
[`(clojure.core/requiring-resolve '~var-symb) var-val])
(partition 2 bindings))]
`(let []
(push-thread-bindings (hash-map ~@vars-binds))
(try
~@body
(finally
(pop-thread-bindings)))))))

0 comments on commit eda9c04

Please sign in to comment.