diff --git a/src/babashka/main.clj b/src/babashka/main.clj index b957d0c3..e1714279 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -52,11 +52,11 @@ [hf.depstar.uberjar :as uberjar] [sci.addons :as addons] [sci.core :as sci] + [sci.impl.io :as sio] [sci.impl.namespaces :as sci-namespaces] [sci.impl.types :as sci-types] [sci.impl.unrestrict :refer [*unrestricted*]] - [sci.impl.vars :as vars] - [sci.impl.io :as sio]) + [sci.impl.vars :as vars]) (:gen-class)) (def windows? @@ -669,8 +669,8 @@ Use bb run --help to show this help output. opts-key (if (str/ends-with? opt ".jar") :jar :file)] (assoc opts-map - opts-key opt - :command-line-args (next options)))) + opts-key opt + :command-line-args (next options)))) (defn parse-opts ([options] (parse-opts options nil)) @@ -765,16 +765,25 @@ Use bb run --help to show this help output. :expressions [(:source res)]}) {}) res)))) - (when-let [pod (get @pod-namespaces namespace)] - (pods/load-pod (:pod-spec pod) (:opts pod))) - (case namespace - clojure.spec.alpha - (binding [*out* *err*] - (println "[babashka] WARNING: Use the babashka-compatible version of clojure.spec.alpha, available here: https://github.com/babashka/spec.alpha")) - clojure.core.specs.alpha - (binding [*out* *err*] - (println "[babashka] WARNING: clojure.core.specs.alpha is removed from the classpath, unless you explicitly add the dependency.")) - nil))) + (if-let [pod (get @pod-namespaces namespace)] + (if uberscript + (do + (swap! uberscript-sources conj + (format + "(babashka.pods/load-pod '%s \"%s\" '%s)\n" + (:pod-spec pod) (:version (:opts pod)) + (dissoc (:opts pod) + :version :metadata))) + {}) + (pods/load-pod (:pod-spec pod) (:opts pod))) + (case namespace + clojure.spec.alpha + (binding [*out* *err*] + (println "[babashka] WARNING: Use the babashka-compatible version of clojure.spec.alpha, available here: https://github.com/babashka/spec.alpha")) + clojure.core.specs.alpha + (binding [*out* *err*] + (println "[babashka] WARNING: clojure.core.specs.alpha is removed from the classpath, unless you explicitly add the dependency.")) + nil)))) main (if (and jar (not main)) (when-let [res (cp/getResource (cp/loader jar) @@ -939,7 +948,7 @@ Use bb run --help to show this help output. (->> {:pods bb-edn-pods} pr-str (spit bb-edn-resource)) (let [cp-with-bb-edn (str cp cp/path-sep bb-edn-dir)] (uberjar/run (assoc uber-params - :classpath cp-with-bb-edn))))) + :classpath cp-with-bb-edn))))) (uberjar/run uber-params))) (throw (Exception. "The uberjar task needs a classpath.")))) exit-code)))) @@ -968,8 +977,8 @@ Use bb run --help to show this help output. (let [raw-string (slurp bb-edn-file) edn (edn/read-string raw-string) edn (assoc edn - :raw raw-string - :file bb-edn-file) + :raw raw-string + :file bb-edn-file) edn (if-let [deps-root (or (:deps-root global-opts) (some-> config fs/parent))] (assoc edn :deps-root deps-root) diff --git a/test-resources/babashka/uberscript/src/my/main_pod.clj b/test-resources/babashka/uberscript/src/my/main_pod.clj new file mode 100644 index 00000000..139b5e48 --- /dev/null +++ b/test-resources/babashka/uberscript/src/my/main_pod.clj @@ -0,0 +1,6 @@ +(ns my.main-pod + (:require [my.other-ns-with-pod] + [pod.babashka.go-sqlite3 :as sqlite])) + +(defn -main [& _args] + (sqlite/query ":memory:" ["SELECT 1 + 2 as sum"])) diff --git a/test-resources/babashka/uberscript/src/my/other_ns_with_pod.clj b/test-resources/babashka/uberscript/src/my/other_ns_with_pod.clj new file mode 100644 index 00000000..b8f061ba --- /dev/null +++ b/test-resources/babashka/uberscript/src/my/other_ns_with_pod.clj @@ -0,0 +1,2 @@ +(ns my.other-ns-with-pod + (:require [pod.babashka.go-sqlite3])) diff --git a/test/babashka/uberscript_test.clj b/test/babashka/uberscript_test.clj index 4fbc1af8..9a111b18 100644 --- a/test/babashka/uberscript_test.clj +++ b/test/babashka/uberscript_test.clj @@ -1,7 +1,8 @@ (ns babashka.uberscript-test (:require [babashka.test-utils :as tu] - [clojure.test :as t :refer [deftest is]])) + [clojure.test :as t :refer [deftest is]] + [clojure.string :as str])) (deftest basic-test (let [tmp-file (java.io.File/createTempFile "uberscript" ".clj")] @@ -23,3 +24,12 @@ (is (= ":clojure.string/foo\ntrue\n(\"1\" \"2\" \"3\" \"4\")\n" (tu/bb nil "--file" (.getPath tmp-file) "1" "2" "3" "4")))))) +(deftest pods-test + (let [tmp-file (java.io.File/createTempFile "uberscript" ".clj")] + (.deleteOnExit tmp-file) + (tu/with-config (pr-str '{:paths ["test-resources/babashka/uberscript/src"] + :pods {org.babashka/go-sqlite3 {:version "0.1.0"}}}) + (is (empty? (tu/bb nil "uberscript" (.getPath tmp-file) "-m" "my.main-pod"))) + (is (= 1 (count (re-seq #"load-pod 'org.babashka/go-sqlite3" + (str/join (str/split-lines (slurp tmp-file)))))))) + (is (str/includes? (tu/bb nil "--file" (.getPath tmp-file)) "3"))))