diff --git a/.circleci/config.yml b/.circleci/config.yml index e55c1c0b..4d9446f1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -13,6 +13,11 @@ jobs: LEIN_ROOT: "true" steps: - checkout + - run: + name: "Pull Submodules" + command: | + git submodule init + git submodule update --remote - restore_cache: keys: - v1-dependencies-{{ checksum "project.clj" }} @@ -51,6 +56,11 @@ jobs: BABASHKA_TEST_ENV: native steps: - checkout + - run: + name: "Pull Submodules" + command: | + git submodule init + git submodule update --remote - restore_cache: keys: - linux-{{ checksum "project.clj" }}-{{ checksum ".circleci/config.yml" }} @@ -107,6 +117,11 @@ jobs: BABASHKA_TEST_ENV: native steps: - checkout + - run: + name: "Pull Submodules" + command: | + git submodule init + git submodule update --remote - restore_cache: keys: - mac-{{ checksum "project.clj" }}-{{ checksum ".circleci/config.yml" }} @@ -161,6 +176,11 @@ jobs: LEIN_ROOT: "true" steps: - checkout + - run: + name: "Pull Submodules" + command: | + git submodule init + git submodule update --remote - restore_cache: keys: - v1-dependencies-{{ checksum "project.clj" }} diff --git a/.gitignore b/.gitignore index 158a1bbd..18814153 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,3 @@ pom.xml.asc .hg/ /bb .clj-kondo/.cache -/src/sci diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..82f0685e --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "sci"] + path = sci + url = https://github.com/borkdude/sci diff --git a/project.clj b/project.clj index 98069f05..a55ada27 100644 --- a/project.clj +++ b/project.clj @@ -7,9 +7,9 @@ :url "https://github.com/borkdude/babashka"} :license {:name "Eclipse Public License 1.0" :url "http://opensource.org/licenses/eclipse-1.0.php"} - :source-paths ["src"] - :dependencies [[org.clojure/clojure "1.9.0"] - [borkdude/sci "0.0.7"]] + :source-paths ["src" "sci/src"] + :resource-paths ["resources" "sci/resources"] + :dependencies [[org.clojure/clojure "1.9.0"]] :profiles {:clojure-1.9.0 {:dependencies [[org.clojure/clojure "1.9.0"]]} :clojure-1.10.1 {:dependencies [[org.clojure/clojure "1.10.1"]]} :test {:dependencies [[clj-commons/conch "0.9.2"]]} diff --git a/sci b/sci new file mode 160000 index 00000000..6f3a1882 --- /dev/null +++ b/sci @@ -0,0 +1 @@ +Subproject commit 6f3a1882cd03cbba23a35e5bb657772c4a045615 diff --git a/script/compile b/script/compile index c4cc6ea2..2aa18da6 100755 --- a/script/compile +++ b/script/compile @@ -11,11 +11,11 @@ fi BABASHKA_VERSION=$(cat resources/BABASHKA_VERSION) -# We also need to AOT sci, else something didn't work in the Mac build on CircleCI -# See https://github.com/oracle/graal/issues/1613 -( cd /tmp; git clone https://github.com/borkdude/sci 2> /dev/null || true ) -mkdir -p src/sci -cp -R /tmp/sci/src/* src +# # We also need to AOT sci, else something didn't work in the Mac build on CircleCI +# # See https://github.com/oracle/graal/issues/1613 +# ( cd /tmp; git clone https://github.com/borkdude/sci 2> /dev/null || true ) +# mkdir -p src/sci +# cp -R /tmp/sci/src/* src lein with-profiles +clojure-1.10.1 do clean, uberjar $GRAALVM_HOME/bin/native-image \ diff --git a/src/babashka/main.clj b/src/babashka/main.clj index 873450b4..1ba8af91 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -23,6 +23,9 @@ ("--stream") (recur (rest options) (assoc opts-map :stream? true)) + ("--time") (recur (rest options) + (assoc opts-map + :time? true)) ("-i") (recur (rest options) (assoc opts-map :raw-in true)) @@ -125,56 +128,62 @@ [& args] #_(binding [*out* *err*] (prn ">> args" args)) - (or - (let [{:keys [:version :raw-in :raw-out :println? - :help? :file :command-line-args - :expression :stream?] :as _opts} (parse-opts args)] - #_(binding [*out* *err*] - (prn ">>" _opts)) - (second - (cond version - [(print-version) 0] - help? - [(print-help) 0] - :else - (try - (let [expr (if file (read-file file) expression) - read-next #(if stream? - (if raw-in (or (read-line) ::EOF) - (read-edn)) - (delay (let [in (slurp *in*)] - (if raw-in - (parse-shell-string in) - (edn/read-string in)))))] - (loop [in (read-next)] - (if (identical? ::EOF in) - [nil 0] ;; done streaming - (let [res [(do (when-not (or expression file) - (throw (Exception. "Missing expression."))) - (let [res (sci/eval-string - expr - {:bindings (assoc bindings - (with-meta '*in* - (when-not stream? {:sci/deref! true})) in - #_(with-meta 'bb/*in* - {:sci/deref! true}) #_do-in - '*command-line-args* command-line-args)})] - (if raw-out - (if (coll? res) - (doseq [l res] - (println l)) - (println res)) - ((if println? println? prn) res)))) 0]] - (if stream? - (recur (read-next)) - res))))) - (catch Exception e - (binding [*out* *err*] - (when-let [msg (or (:stderr (ex-data e)) - (.getMessage e))] - (println (str/trim msg) ))) - [nil 1]))))) - 1)) + (let [t0 (System/currentTimeMillis) + {:keys [:version :raw-in :raw-out :println? + :help? :file :command-line-args + :expression :stream? :time?] :as _opts} + (parse-opts args) + exit-code + (or + #_(binding [*out* *err*] + (prn ">>" _opts)) + (second + (cond version + [(print-version) 0] + help? + [(print-help) 0] + :else + (try + (let [expr (if file (read-file file) expression) + read-next #(if stream? + (if raw-in (or (read-line) ::EOF) + (read-edn)) + (delay (let [in (slurp *in*)] + (if raw-in + (parse-shell-string in) + (edn/read-string in)))))] + (loop [in (read-next)] + (if (identical? ::EOF in) + [nil 0] ;; done streaming + (let [res [(do (when-not (or expression file) + (throw (Exception. "Missing expression."))) + (let [res (sci/eval-string + expr + {:bindings (assoc bindings + (with-meta '*in* + (when-not stream? {:sci/deref! true})) in + #_(with-meta 'bb/*in* + {:sci/deref! true}) #_do-in + '*command-line-args* command-line-args)})] + (if raw-out + (if (coll? res) + (doseq [l res] + (println l)) + (println res)) + ((if println? println? prn) res)))) 0]] + (if stream? + (recur (read-next)) + res))))) + (catch Exception e + (binding [*out* *err*] + (when-let [msg (or (:stderr (ex-data e)) + (.getMessage e))] + (println (str/trim msg) ))) + [nil 1])))) + 1) + t1 (System/currentTimeMillis)] + (when time? (println "bb took" (str (- t1 t0) "ms."))) + exit-code)) (defn -main [& args]