Fix #1330: allow *warn-on-reflection* in programmatic nREPL (#1398)

This commit is contained in:
Michiel Borkent 2022-10-18 17:54:38 +02:00 committed by GitHub
parent 351723fdb6
commit 0e57b9d461
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 18 deletions

View file

@ -12,6 +12,7 @@ A preview of the next release can be installed from
- [#1369](https://github.com/babashka/babashka/issues/1369): provide `.sha256` files for every released asset - [#1369](https://github.com/babashka/babashka/issues/1369): provide `.sha256` files for every released asset
- [#1397](https://github.com/babashka/babashka/issues/1397): Add `clojure.lang.Namespace` as alias for `sci.lang.Namespace`, such that `(instance? clojure.lang.Namespace *ns*)` returns `true` in bb - [#1397](https://github.com/babashka/babashka/issues/1397): Add `clojure.lang.Namespace` as alias for `sci.lang.Namespace`, such that `(instance? clojure.lang.Namespace *ns*)` returns `true` in bb
- [#1384](https://github.com/babashka/babashka/issues/1384): allow `.indexOf` on `LazySeq` - [#1384](https://github.com/babashka/babashka/issues/1384): allow `.indexOf` on `LazySeq`
- [#1330](https://github.com/babashka/babashka/issues/1330): allow `(set! *warn-on-reflection*)` in programmatic nREPL
## 0.10.163 (2022-09-24) ## 0.10.163 (2022-09-24)

View file

@ -1,6 +1,10 @@
(ns babashka.impl.common) (ns babashka.impl.common
(:require
[clojure.java.io :as io]
[clojure.string :as str]))
;; placeholder for ctx ;; placeholder for ctx
(def ctx (volatile! nil)) (def ctx (volatile! nil))
(def bb-edn (volatile! nil)) (def bb-edn (volatile! nil))
(def debug (volatile! false)) (def debug (volatile! false))
(def version (str/trim (slurp (io/resource "BABASHKA_VERSION"))))

View file

@ -1,14 +1,21 @@
(ns babashka.impl.nrepl-server (ns babashka.impl.nrepl-server
{:no-doc true} {:no-doc true}
(:require [babashka.impl.common :as common] (:require
[babashka.nrepl.server :as server] [babashka.impl.clojure.core]
[sci.core :as sci])) [babashka.impl.common :as common]
[babashka.nrepl.server :as server]
[sci.core :as sci]))
(defn start-server! (defn start-server!
([] ([]
(server/start-server! @common/ctx)) (start-server! nil))
([opts] ([opts]
(server/start-server! @common/ctx opts))) (let [dev? (= "true" (System/getenv "BABASHKA_DEV"))
opts (merge {:debug dev?
:describe {"versions" {"babashka" common/version}}
:thread-bind [babashka.impl.clojure.core/warn-on-reflection]}
opts)]
(server/start-server! @common/ctx opts))))
(def nrepl-server-namespace (def nrepl-server-namespace
(let [ns-sci (sci/create-ns 'babashka.nrepl.server)] (let [ns-sci (sci/create-ns 'babashka.nrepl.server)]

View file

@ -96,7 +96,8 @@
;; echo '1' | java -agentlib:native-image-agent=config-output-dir=/tmp -jar target/babashka-xxx-standalone.jar '...' ;; echo '1' | java -agentlib:native-image-agent=config-output-dir=/tmp -jar target/babashka-xxx-standalone.jar '...'
;; with the java provided by GraalVM. ;; with the java provided by GraalVM.
(def version (str/trim (slurp (io/resource "BABASHKA_VERSION")))) (def version common/version)
(defn parse-version [version] (defn parse-version [version]
(mapv #(Integer/parseInt %) (mapv #(Integer/parseInt %)
(-> version (-> version
@ -305,16 +306,11 @@ Use bb run --help to show this help output.
(defn start-socket-repl! [address ctx] (defn start-socket-repl! [address ctx]
(socket-repl/start-repl! address ctx)) (socket-repl/start-repl! address ctx))
(defn start-nrepl! [address ctx] (defn start-nrepl! [address]
(let [dev? (= "true" (System/getenv "BABASHKA_DEV")) (let [opts (nrepl-server/parse-opt address)]
nrepl-opts (nrepl-server/parse-opt address) (babashka.impl.nrepl-server/start-server! opts))
nrepl-opts (assoc nrepl-opts (binding [*out* *err*]
:debug dev? (println "For more info visit: https://book.babashka.org/#_nrepl"))
:describe {"versions" {"babashka" version}}
:thread-bind [core/warn-on-reflection])]
(nrepl-server/start-server! ctx nrepl-opts)
(binding [*out* *err*]
(println "For more info visit: https://book.babashka.org/#_nrepl")))
;; hang until SIGINT ;; hang until SIGINT
@(promise)) @(promise))
@ -958,7 +954,7 @@ Use bb run --help to show this help output.
describe? describe?
[(print-describe) 0] [(print-describe) 0]
repl [(repl/start-repl! sci-ctx) 0] repl [(repl/start-repl! sci-ctx) 0]
nrepl [(start-nrepl! nrepl sci-ctx) 0] nrepl [(start-nrepl! nrepl) 0]
uberjar [nil 0] uberjar [nil 0]
list-tasks [(tasks/list-tasks sci-ctx) 0] list-tasks [(tasks/list-tasks sci-ctx) 0]
print-deps [(print-deps/print-deps (:print-deps-format cli-opts)) 0] print-deps [(print-deps/print-deps (:print-deps-format cli-opts)) 0]