move things to compile time
This commit is contained in:
parent
c2059b4a1d
commit
d12b503b8a
4 changed files with 97 additions and 83 deletions
2
deps.edn
2
deps.edn
|
|
@ -63,7 +63,7 @@
|
|||
:lib-tests
|
||||
{:extra-paths ["process/src" "process/test" "test-resources/lib_tests"]
|
||||
:extra-deps {org.clj-commons/clj-http-lite {:mvn/version "0.4.392"}
|
||||
org.babashka/spec.alpha {:git/url "https://github.com/babashka/spec.alpha"
|
||||
#_#_org.babashka/spec.alpha {:git/url "https://github.com/babashka/spec.alpha"
|
||||
:sha "0dec1f88cbde74a0470b454396f09a03adb4ae39"}
|
||||
lambdaisland/regal {:mvn/version "0.0.143"}
|
||||
cprop/cprop {:mvn/version "0.1.16"}
|
||||
|
|
|
|||
2
sci
2
sci
|
|
@ -1 +1 @@
|
|||
Subproject commit b4c51fd5a0cedf19f1804c9bef1301ffb4e73bf0
|
||||
Subproject commit 3d0a6e0ba050c288c5e5985423b77735eef9cf05
|
||||
|
|
@ -89,6 +89,7 @@
|
|||
|
||||
(def signal-ns {'pipe-signal-received? (sci/copy-var pipe-signal-received? (sci/create-ns 'babashka.signal nil))})
|
||||
|
||||
(sci/enable-unrestricted-access!)
|
||||
(sci/alter-var-root sci/in (constantly *in*))
|
||||
(sci/alter-var-root sci/out (constantly *out*))
|
||||
(sci/alter-var-root sci/err (constantly *err*))
|
||||
|
|
@ -744,8 +745,6 @@ Use bb run --help to show this help output.
|
|||
:else
|
||||
(parse-args options opts-map))))))
|
||||
|
||||
(def env (atom {}))
|
||||
|
||||
(def pod-namespaces (volatile! {}))
|
||||
|
||||
(defn download-only?
|
||||
|
|
@ -767,62 +766,14 @@ Use bb run --help to show this help output.
|
|||
env-os-name-present? (not= env-os-name sys-os-name)
|
||||
env-os-arch-present? (not= env-os-arch sys-os-arch))))
|
||||
|
||||
(defn exec [cli-opts]
|
||||
(binding [*unrestricted* true]
|
||||
(sci/binding [core/warn-on-reflection @core/warn-on-reflection
|
||||
core/unchecked-math @core/unchecked-math
|
||||
core/data-readers @core/data-readers
|
||||
sci/ns @sci/ns
|
||||
sci/print-length @sci/print-length]
|
||||
(let [{version-opt :version
|
||||
:keys [:shell-in :edn-in :shell-out :edn-out
|
||||
:help :file :command-line-args
|
||||
:expressions :stream? :init
|
||||
:repl :socket-repl :nrepl
|
||||
:debug :classpath :force?
|
||||
:main :uberscript :describe?
|
||||
:jar :uberjar :clojure
|
||||
:doc :run :list-tasks
|
||||
:print-deps :prepare]
|
||||
exec-fn :exec}
|
||||
cli-opts
|
||||
_ (when debug (vreset! common/debug true))
|
||||
_ (do ;; set properties
|
||||
(when main (System/setProperty "babashka.main" main))
|
||||
;; TODO: what about exec here?
|
||||
(System/setProperty "babashka.version" version))
|
||||
read-next (fn [*in*]
|
||||
(if (pipe-signal-received?)
|
||||
::EOF
|
||||
(if stream?
|
||||
(if shell-in (or (read-line) ::EOF)
|
||||
(edn/read {:readers edn-readers
|
||||
:default tagged-literal
|
||||
:eof ::EOF} *in*))
|
||||
(delay (cond shell-in
|
||||
(shell-seq *in*)
|
||||
edn-in
|
||||
(edn-seq *in*)
|
||||
:else
|
||||
(edn/read {:readers edn-readers
|
||||
:default tagged-literal} *in*))))))
|
||||
uberscript-sources (atom ())
|
||||
classpath (or classpath
|
||||
(System/getenv "BABASHKA_CLASSPATH"))
|
||||
_ (if classpath
|
||||
(cp/add-classpath classpath)
|
||||
;; when classpath isn't set, we calculate it from bb.edn, if present
|
||||
(when-let [bb-edn @common/bb-edn] (deps/add-deps bb-edn {:force force?})))
|
||||
abs-path (when file
|
||||
(let [abs-path (.getAbsolutePath (io/file file))]
|
||||
(vars/bindRoot sci/file abs-path)
|
||||
(System/setProperty "babashka.file" abs-path)
|
||||
abs-path))
|
||||
_ (when jar
|
||||
(cp/add-classpath jar))
|
||||
load-fn (fn [{:keys [:namespace :reload]}]
|
||||
(def !uberscript (volatile! nil))
|
||||
(def !uberscript-sources (volatile! nil))
|
||||
|
||||
(defn load-fn [{:keys [namespace reload]}]
|
||||
(let [{:keys [loader]}
|
||||
@cp/cp-state]
|
||||
@cp/cp-state
|
||||
uberscript @!uberscript
|
||||
uberscript-sources @!uberscript-sources]
|
||||
(or
|
||||
(when ;; ignore built-in namespaces when uberscripting, unless with :reload
|
||||
(and uberscript
|
||||
|
|
@ -866,30 +817,87 @@ Use bb run --help to show this help output.
|
|||
(binding [*out* *err*]
|
||||
(println "[babashka] WARNING: clojure.core.specs.alpha is removed from the classpath, unless you explicitly add the dependency."))
|
||||
nil))))
|
||||
|
||||
(def opts (-> {:aliases aliases
|
||||
:namespaces (-> namespaces
|
||||
(assoc 'clojure.core
|
||||
(assoc core-extras
|
||||
'load-file (sci-copy-vars/new-var 'load-file load-file*))))
|
||||
:features #{:bb :clj}
|
||||
:classes @classes/class-map
|
||||
:imports classes/imports
|
||||
:load-fn load-fn
|
||||
;; :readers core/data-readers
|
||||
:reify-fn reify-fn
|
||||
:proxy-fn proxy-fn}
|
||||
addons/future))
|
||||
|
||||
(defn new-sci-ctx []
|
||||
(let [ctx (sci/init opts)]
|
||||
(ctx-store/reset-ctx! ctx)
|
||||
ctx))
|
||||
|
||||
(def sci-ctx (new-sci-ctx))
|
||||
|
||||
(defn exec [cli-opts]
|
||||
(binding [*unrestricted* true]
|
||||
(sci/binding [core/warn-on-reflection @core/warn-on-reflection
|
||||
core/unchecked-math @core/unchecked-math
|
||||
core/data-readers @core/data-readers
|
||||
sci/ns @sci/ns
|
||||
sci/print-length @sci/print-length]
|
||||
(let [{version-opt :version
|
||||
:keys [shell-in edn-in shell-out edn-out
|
||||
help file command-line-args
|
||||
expressions stream? init
|
||||
repl socket-repl nrepl
|
||||
debug classpath force?
|
||||
main uberscript describe?
|
||||
jar uberjar clojure
|
||||
doc run list-tasks
|
||||
print-deps prepare]
|
||||
exec-fn :exec}
|
||||
cli-opts
|
||||
_ (when debug (vreset! common/debug true))
|
||||
_ (do ;; set properties
|
||||
(when main (System/setProperty "babashka.main" main))
|
||||
;; TODO: what about exec here?
|
||||
(System/setProperty "babashka.version" version))
|
||||
read-next (fn [*in*]
|
||||
(if (pipe-signal-received?)
|
||||
::EOF
|
||||
(if stream?
|
||||
(if shell-in (or (read-line) ::EOF)
|
||||
(edn/read {:readers edn-readers
|
||||
:default tagged-literal
|
||||
:eof ::EOF} *in*))
|
||||
(delay (cond shell-in
|
||||
(shell-seq *in*)
|
||||
edn-in
|
||||
(edn-seq *in*)
|
||||
:else
|
||||
(edn/read {:readers edn-readers
|
||||
:default tagged-literal} *in*))))))
|
||||
uberscript-sources (atom ())
|
||||
classpath (or classpath
|
||||
(System/getenv "BABASHKA_CLASSPATH"))
|
||||
_ (if classpath
|
||||
(cp/add-classpath classpath)
|
||||
;; when classpath isn't set, we calculate it from bb.edn, if present
|
||||
(when-let [bb-edn @common/bb-edn] (deps/add-deps bb-edn {:force force?})))
|
||||
abs-path (when file
|
||||
(let [abs-path (.getAbsolutePath (io/file file))]
|
||||
(vars/bindRoot sci/file abs-path)
|
||||
(System/setProperty "babashka.file" abs-path)
|
||||
abs-path))
|
||||
_ (when jar
|
||||
(cp/add-classpath jar))
|
||||
main (if (and jar (not main))
|
||||
(when-let [res (cp/getResource
|
||||
(cp/loader jar)
|
||||
["META-INF/MANIFEST.MF"] {:url? true})]
|
||||
(cp/main-ns res))
|
||||
main)
|
||||
;; TODO: pull more of these values to compile time
|
||||
opts {:aliases aliases
|
||||
:namespaces (-> namespaces
|
||||
(assoc 'clojure.core
|
||||
(assoc core-extras
|
||||
'load-file (sci-copy-vars/new-var 'load-file load-file*))))
|
||||
:env env
|
||||
:features #{:bb :clj}
|
||||
:classes @classes/class-map
|
||||
:imports classes/imports
|
||||
:load-fn load-fn
|
||||
:uberscript uberscript
|
||||
;; :readers core/data-readers
|
||||
:reify-fn reify-fn
|
||||
:proxy-fn proxy-fn}
|
||||
opts (addons/future opts)
|
||||
sci-ctx (sci/init opts)
|
||||
_ (ctx-store/reset-ctx! sci-ctx)
|
||||
_ (when-let [pods (:pods @common/bb-edn)]
|
||||
(when-let [pod-metadata (pods/load-pods-metadata
|
||||
pods {:download-only (download-only?)})]
|
||||
|
|
@ -970,8 +978,13 @@ Use bb run --help to show this help output.
|
|||
print-deps [(print-deps/print-deps (:print-deps-format cli-opts)) 0]
|
||||
prepare [nil 0]
|
||||
uberscript
|
||||
[nil (do (uberscript/uberscript {:ctx sci-ctx
|
||||
[nil (do
|
||||
(vreset! !uberscript true)
|
||||
(vreset! !uberscript-sources uberscript-sources)
|
||||
(uberscript/uberscript {:ctx sci-ctx
|
||||
:expressions expressions})
|
||||
(vreset! !uberscript nil)
|
||||
(vreset! !uberscript-sources nil)
|
||||
0)]
|
||||
expressions
|
||||
;; execute code
|
||||
|
|
|
|||
|
|
@ -10,7 +10,8 @@
|
|||
[clojure.test :as test :refer [*report-counters*]]
|
||||
[clojure.tools.reader.reader-types :as r]
|
||||
[sci.core :as sci]
|
||||
[sci.impl.vars :as vars]))
|
||||
[sci.impl.vars :as vars]
|
||||
[sci.ctx-store :as ctx-store]))
|
||||
|
||||
(set! *warn-on-reflection* true)
|
||||
|
||||
|
|
@ -46,7 +47,7 @@
|
|||
|
||||
(defn bb-jvm [input-or-opts & args]
|
||||
(reset! cp/cp-state nil)
|
||||
(reset! main/env {})
|
||||
(alter-var-root #'main/sci-ctx (constantly (main/new-sci-ctx)))
|
||||
(vreset! common/bb-edn nil)
|
||||
(System/clearProperty "babashka.config")
|
||||
(let [args (cond-> args *bb-edn-path*
|
||||
|
|
|
|||
Loading…
Reference in a new issue