Skip to content

Commit

Permalink
clojure process fn
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed May 11, 2023
1 parent 4dacdda commit e4363f6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/borkdude/deps.clj
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@
(*exit-fn* {:exit exit-code}))
string-out)))

(def ^:private ^:dynamic *process-fn* shell-command)
(defn ^:dynamic *clojure-process-fn*
"Invokes `java` with arguments to `clojure.main` to start Clojure. May
be replacement by rebinding this dynamic var."
[{:keys [cmd]}]
(shell-command cmd))

(def ^:private help-text (delay (str "Version: " @version "
Expand Down Expand Up @@ -939,7 +943,7 @@ public class ClojureToolsDownloader {
command (str/replace command "{{main-opts}}" (str main-cache-opts))
command (str/split command #"\s+")
command (into command (:args cli-opts))]
(*process-fn* command))
(*clojure-process-fn* {:cmd command}))
:else
(let [jvm-cache-opts (when (.exists (io/file jvm-file))
(-> jvm-file slurp str/split-lines))
Expand All @@ -965,4 +969,4 @@ public class ClojureToolsDownloader {
(when (and (= :repl mode)
(pos? (count (:args cli-opts))))
(warn "WARNING: Implicit use of clojure.main with options is deprecated, use -M"))
(*process-fn* main-args)))))))
(*clojure-process-fn* {:cmd main-args})))))))
4 changes: 3 additions & 1 deletion test/borkdude/deps_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@
(deliver ret*# args#)
ret#)))]
;; need to override both *process-fn* and deps/shell-command.
(binding [deps/*process-fn* sh-mock#
(binding [deps/*clojure-process-fn* (fn ~'[{:keys [cmd]}]
(prn :cmd ~'cmd)
(sh-mock# ~'cmd))
deps/*exit-fn* (fn [{:keys [~'exit ~'message]}]
(when ~'message
(throw (ex-info "mock-shell-failed"
Expand Down

0 comments on commit e4363f6

Please sign in to comment.