Skip to content

Commit 47f47af

Browse files
committedDec 10, 2021
cider-macroexpand: Bind LOADER if unbound
1 parent 1cfd596 commit 47f47af

File tree

7 files changed

+49
-5
lines changed

7 files changed

+49
-5
lines changed
 

‎.circleci/config.yml

+14
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ commands:
8585
- save_cache:
8686
paths:
8787
- ~/.m2
88+
- linux-install-1.10.3.1040.sh
89+
- clojure-tools-1.10.3.1040.tar.gz
8890
- .cpcache
8991
key: clojure-<< parameters.cache_version >>-{{ checksum "/tmp/clojure_cache_seed" }}
9092

@@ -131,6 +133,18 @@ jobs:
131133
- run:
132134
name: Running tests with inlined deps
133135
command: make test smoketest
136+
- run:
137+
name: Install the Clojure CLI
138+
command: |
139+
# the `nc` option skips downloading a file as already present
140+
# (as allowed by the Circle caching).
141+
wget -nc https://download.clojure.org/install/linux-install-1.10.3.1040.sh
142+
sed -i 's/curl -O/wget -nc/g' linux-install-1.10.3.1040.sh
143+
chmod +x linux-install-1.10.3.1040.sh
144+
sudo ./linux-install-1.10.3.1040.sh
145+
- run:
146+
name: Running tests specific to tools.deps
147+
command: make tools-deps-test
134148

135149
######################################################################
136150
#

‎CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Bugs fixed
66

7+
* [#721](https://github.com/clojure-emacs/cider-nrepl/issues/721): `middleware.macroexpand`: support a corner case for tools.deps.
78
* [#735](https://github.com/clojure-emacs/cider-nrepl/issues/735): `middleware.test.extensions`: make `:actual` reporting clearer.
89
* [#737](https://github.com/clojure-emacs/cider-nrepl/pull/737): Fix a regression in `middleware.out` that could result in duplicate output.
910

‎Makefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ test/resources/cider/nrepl/clojuredocs/export.edn:
1111

1212
inline-deps: .inline-deps
1313

14-
test: .inline-deps test/resources/cider/nrepl/clojuredocs/export.edn
14+
test: clean .inline-deps test/resources/cider/nrepl/clojuredocs/export.edn
1515
lein with-profile -user,-dev,+$(CLOJURE_VERSION),+test,+plugin.mranderson/config test
1616

1717
quick-test: clean
1818
lein with-profile -user,-dev,+$(CLOJURE_VERSION),+test test
1919

20+
tools-deps-test: clean install
21+
cd tools-deps-testing; clojure -M:test
22+
2023
eastwood:
2124
lein with-profile -user,-dev,+$(CLOJURE_VERSION),+eastwood eastwood
2225

‎src/cider/nrepl/middleware/macroexpand.clj

+10-4
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,16 @@
113113
context of the given :ns, using the provided :expander and :display-namespaces
114114
options."
115115
[{:keys [code expander ns] :as msg}]
116-
(->> (let [expander-fn (resolve-expander-clj expander)]
117-
(binding [*ns* (find-ns ns)]
118-
(expander-fn (read-string code))))
119-
(walk/prewalk (post-expansion-walker-clj msg))))
116+
;; Bind LOADER, which can be unbound under certain code paths, particularly when using tools.deps:
117+
(with-bindings {clojure.lang.Compiler/LOADER
118+
(if (instance? clojure.lang.Var$Unbound
119+
@clojure.lang.Compiler/LOADER)
120+
(clojure.lang.DynamicClassLoader. (clojure.lang.RT/baseLoader))
121+
@clojure.lang.Compiler/LOADER)}
122+
(->> (let [expander-fn (resolve-expander-clj expander)]
123+
(binding [*ns* (find-ns ns)]
124+
(expander-fn (read-string code))))
125+
(walk/prewalk (post-expansion-walker-clj msg)))))
120126

121127
;; ClojureScript impl
122128

‎tools-deps-testing/deps.edn

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{:paths ["."]
2+
:aliases {:test {:main-opts ["-m" "macroexpand-tools-deps-test"]
3+
:jvm-opts ["-XX:-OmitStackTraceInFastThrow"
4+
"-Dclojure.main.report=stderr"]}}
5+
:deps {cider/cider-nrepl {:mvn/version "RELEASE"}}}

‎tools-deps-testing/example.clj

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(ns example)
2+
3+
(defmacro foo []
4+
(println (class @clojure.lang.Compiler/LOADER))
5+
(assert (not (instance? clojure.lang.Var$Unbound @clojure.lang.Compiler/LOADER)))
6+
42)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(ns macroexpand-tools-deps-test
2+
(:require
3+
[example]
4+
[cider.nrepl.middleware.macroexpand]))
5+
6+
(defn -main [& _]
7+
(println (cider.nrepl.middleware.macroexpand/macroexpansion {:ns 'example
8+
:code "(foo)"}))
9+
(System/exit 0))

0 commit comments

Comments
 (0)
Please sign in to comment.