babashka.classpath
This commit is contained in:
parent
b933610626
commit
5a63d37486
1 changed files with 17 additions and 17 deletions
|
|
@ -220,6 +220,19 @@ Everything after that is bound to *command-line-args*."))
|
||||||
csv clojure.data.csv
|
csv clojure.data.csv
|
||||||
json cheshire.core})
|
json cheshire.core})
|
||||||
|
|
||||||
|
(def cp-state (atom {:loader nil
|
||||||
|
:cp nil}))
|
||||||
|
|
||||||
|
(defn add-classpath* [add-to-cp]
|
||||||
|
(swap! cp-state
|
||||||
|
(fn [{:keys [:cp]}]
|
||||||
|
(let [new-cp
|
||||||
|
(if-not cp add-to-cp
|
||||||
|
(str cp (System/getProperty "path.separator") add-to-cp))]
|
||||||
|
{:loader (cp/loader new-cp)
|
||||||
|
:cp new-cp})))
|
||||||
|
nil)
|
||||||
|
|
||||||
(def namespaces
|
(def namespaces
|
||||||
{'clojure.tools.cli tools-cli-namespace
|
{'clojure.tools.cli tools-cli-namespace
|
||||||
'clojure.edn {'read edn/read
|
'clojure.edn {'read edn/read
|
||||||
|
|
@ -234,7 +247,8 @@ Everything after that is bound to *command-line-args*."))
|
||||||
'cheshire.core cheshire-core-namespace
|
'cheshire.core cheshire-core-namespace
|
||||||
'clojure.stacktrace stacktrace-namespace
|
'clojure.stacktrace stacktrace-namespace
|
||||||
'clojure.main {'demunge demunge}
|
'clojure.main {'demunge demunge}
|
||||||
'clojure.repl {'demunge demunge}})
|
'clojure.repl {'demunge demunge}
|
||||||
|
'babashka.classpath {'add-classpath add-classpath*}})
|
||||||
|
|
||||||
(def bindings
|
(def bindings
|
||||||
{'java.lang.System/exit exit ;; override exit, so we have more control
|
{'java.lang.System/exit exit ;; override exit, so we have more control
|
||||||
|
|
@ -253,19 +267,6 @@ Everything after that is bound to *command-line-args*."))
|
||||||
(flush)
|
(flush)
|
||||||
[nil 1])))))
|
[nil 1])))))
|
||||||
|
|
||||||
(def cp-state (atom {:loader nil
|
|
||||||
:cp nil}))
|
|
||||||
|
|
||||||
(defn add-classpath! [add-to-cp]
|
|
||||||
(swap! cp-state
|
|
||||||
(fn [{:keys [:cp]}]
|
|
||||||
(let [new-cp
|
|
||||||
(if-not cp add-to-cp
|
|
||||||
(str cp (System/getProperty "path.separator") add-to-cp))]
|
|
||||||
{:loader (cp/loader new-cp)
|
|
||||||
:cp new-cp})))
|
|
||||||
nil)
|
|
||||||
|
|
||||||
(defn main
|
(defn main
|
||||||
[& args]
|
[& args]
|
||||||
(handle-pipe!)
|
(handle-pipe!)
|
||||||
|
|
@ -296,7 +297,7 @@ Everything after that is bound to *command-line-args*."))
|
||||||
classpath (or classpath
|
classpath (or classpath
|
||||||
(System/getenv "BABASHKA_CLASSPATH"))
|
(System/getenv "BABASHKA_CLASSPATH"))
|
||||||
_ (when classpath
|
_ (when classpath
|
||||||
(add-classpath! classpath))
|
(add-classpath* classpath))
|
||||||
load-fn (fn [{:keys [:namespace]}]
|
load-fn (fn [{:keys [:namespace]}]
|
||||||
(when-let [{:keys [:loader]} @cp-state]
|
(when-let [{:keys [:loader]} @cp-state]
|
||||||
(let [res (cp/source-for-namespace loader namespace nil)]
|
(let [res (cp/source-for-namespace loader namespace nil)]
|
||||||
|
|
@ -310,8 +311,7 @@ Everything after that is bound to *command-line-args*."))
|
||||||
'*command-line-args*
|
'*command-line-args*
|
||||||
(sci/new-dynamic-var '*command-line-args* command-line-args)
|
(sci/new-dynamic-var '*command-line-args* command-line-args)
|
||||||
'*file* vars/file-var
|
'*file* vars/file-var
|
||||||
'*warn-on-reflection* reflection-var
|
'*warn-on-reflection* reflection-var))
|
||||||
'add-classpath! add-classpath!))
|
|
||||||
(assoc-in ['clojure.java.io 'resource]
|
(assoc-in ['clojure.java.io 'resource]
|
||||||
#(when-let [{:keys [:loader]} @cp-state] (cp/getResource loader % {:url? true}))))
|
#(when-let [{:keys [:loader]} @cp-state] (cp/getResource loader % {:url? true}))))
|
||||||
:bindings bindings
|
:bindings bindings
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue