diff --git a/CHANGELOG.md b/CHANGELOG.md index 345fafa4..3b98c672 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ Babashka proper: - Compatibility with `org.clojure/data.json {:mvn/version "2.4.0}"` - Support passing `GITLIBS` via `:extra-env` in `clojure` to set git lib dir: `(clojure {:extra-env {"GITLIBS" ".gitlib"}} ,,,) [#934](https://github.com/babashka/babashka/issues/934)` +- Add `--force` option to force recomputation of bababashka deps classpath. Deps.clj: diff --git a/src/babashka/impl/deps.clj b/src/babashka/impl/deps.clj index 40aef913..8e04c2a2 100644 --- a/src/babashka/impl/deps.clj +++ b/src/babashka/impl/deps.clj @@ -56,7 +56,7 @@ keywords) which will used to calculate classpath. The classpath is then used to resolve dependencies in babashka." ([deps-map] (add-deps deps-map nil)) - ([deps-map {:keys [:aliases :extra-env]}] + ([deps-map {:keys [:aliases :env :extra-env :force]}] (when-let [paths (:paths deps-map)] (cp/add-classpath (str/join cp/path-sep paths))) (when-let [deps-map (not-empty (dissoc deps-map :paths :tasks :raw :min-bb-version))] @@ -65,12 +65,13 @@ :classpath-overrides {org.clojure/clojure "" org.clojure/spec.alpha "" org.clojure/core.specs.alpha ""}}) - args ["-Srepro" ;; do not include deps.edn from user config - "-Spath" "-Sdeps" (str deps-map) - "-Sdeps-file" "" ;; we reset deps file so the local deps.edn isn't used - ,] - args (conj args (str "-A:" (str/join ":" (cons ":org.babashka/defaults" aliases)))) - cp (with-out-str (binding [deps/*extra-env* extra-env] + args (list "-Srepro" ;; do not include deps.edn from user config + "-Spath" "-Sdeps" (str deps-map) + "-Sdeps-file" "") ;; we reset deps file so the local deps.edn isn't used + args (if force (cons "-Sforce" args) args) + args (concat args [(str "-A:" (str/join ":" (cons ":org.babashka/defaults" aliases)))]) + cp (with-out-str (binding [deps/*env* env + deps/*extra-env* extra-env] (apply deps/-main args))) cp (str/trim cp) cp (str/replace cp (re-pattern (str cp/path-sep "+$")) "")] @@ -111,6 +112,7 @@ *out* @sci/out *err* @sci/err deps/*dir* (:dir opts) + deps/*env* (:env opts) deps/*extra-env* (:extra-env opts) deps/*process-fn* (fn ([cmd] (p/process cmd opts)) diff --git a/src/babashka/main.clj b/src/babashka/main.clj index 30cd7a77..b7811121 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -124,8 +124,9 @@ Substrate VM opts: Global opts: - -cp, --classpath Classpath to use. Overrides bb.edn classpath. - --debug Print debug information and internal stacktrace in case of exception. + -cp, --classpath Classpath to use. Overrides bb.edn classpath. + --debug Print debug information and internal stacktrace in case of exception. + --force Passes -Sforce to deps.clj, forcing recalculation of the classpath. Help: @@ -505,9 +506,13 @@ Use bb run --help to show this help output. ("--doc") {:doc true :command-line-args (rest options)} + ;; renamed to --debug ("--verbose") (recur (next options) (assoc opts-map :verbose? true)) + ("--force") (recur (next options) + (assoc opts-map + :force? true)) ("--describe") (recur (next options) (assoc opts-map :describe? true)) @@ -675,7 +680,7 @@ Use bb run --help to show this help output. :help :file :command-line-args :expressions :stream? :repl :socket-repl :nrepl - :debug :classpath + :debug :classpath :force? :main :uberscript :describe? :jar :uberjar :clojure :doc :run :list-tasks]} @@ -703,7 +708,7 @@ Use bb run --help to show this help output. _ (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))) + (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) diff --git a/test/babashka/deps_test.clj b/test/babashka/deps_test.clj index e7c9719e..01ff96e5 100644 --- a/test/babashka/deps_test.clj +++ b/test/babashka/deps_test.clj @@ -1,5 +1,6 @@ (ns babashka.deps-test (:require + [babashka.fs :as fs] [babashka.test-utils :as test-utils] [clojure.edn :as edn] [clojure.test :as test :refer [deftest is testing]])) @@ -10,7 +11,8 @@ :eof nil} (apply test-utils/bb nil (map str args)))) -(deftest dependency-test (is (= #{:a :c :b} (bb " +(deftest dependency-test + (is (= #{:a :c :b} (bb " (require '[babashka.deps :as deps]) (deps/add-deps '{:deps {com.stuartsierra/dependency {:mvn/version \"1.0.0\"}}}) @@ -24,7 +26,19 @@ (dep/depend :d :c))) (dep/transitive-dependencies g1 :d) -")))) +"))) + (testing "GITLIBS can set location of .gitlibs dir" + (let [tmp-dir (fs/create-temp-dir) + libs-dir (fs/file tmp-dir ".gitlibs") + libs-dir2 (fs/file tmp-dir ".gitlibs2")] + (bb (pr-str `(do (babashka.deps/add-deps '{:deps {babashka/process {:git/url "https://github.com/babashka/process" :sha "4c6699d06b49773d3e5c5b4c11d3334fb78cc996"}}} + {:force true + :env {"GITLIBS" ~(str libs-dir)}}) nil))) + (bb (pr-str `(do (babashka.deps/add-deps '{:deps {babashka/process {:git/url "https://github.com/babashka/process" :sha "4c6699d06b49773d3e5c5b4c11d3334fb78cc996"}}} + {:force true + :extra-env {"GITLIBS" ~(str libs-dir2)}}) nil))) + (is (fs/exists? libs-dir)) + (is (fs/exists? libs-dir2))))) (deftest clojure-test (testing "-Stree prints to *out*" @@ -60,4 +74,12 @@ true (testing "start from other directory" (is (= {1 {:id 1}, 2 {:id 2}} (edn/read-string (bb " -(:out @(babashka.deps/clojure [\"-M\" \"-e\" \"(require 'medley.core) (medley.core/index-by :id [{:id 1} {:id 2}])\"] {:out :string :dir \"test-resources/clojure-dir-test\"}))")))))) +(:out @(babashka.deps/clojure [\"-M\" \"-e\" \"(require 'medley.core) (medley.core/index-by :id [{:id 1} {:id 2}])\"] {:out :string :dir \"test-resources/clojure-dir-test\"}))"))))) + (testing "GITLIBS can set location of .gitlibs dir" + (let [tmp-dir (fs/create-temp-dir) + libs-dir (fs/file tmp-dir ".gitlibs") + libs-dir2 (fs/file tmp-dir ".gitlibs2")] + (bb (pr-str `(do (babashka.deps/clojure ["-Sforce" "-Spath" "-Sdeps" "{:deps {babashka/process {:git/url \"https://github.com/babashka/process\" :sha \"4c6699d06b49773d3e5c5b4c11d3334fb78cc996\"}}}"] {:out :string :env {"GITLIBS" ~(str libs-dir)}}) nil))) + (bb (pr-str `(do (babashka.deps/clojure ["-Sforce" "-Spath" "-Sdeps" "{:deps {babashka/process {:git/url \"https://github.com/babashka/process\" :sha \"4c6699d06b49773d3e5c5b4c11d3334fb78cc996\"}}}"] {:out :string :extra-env {"GITLIBS" ~(str libs-dir2)}}) nil))) + (is (fs/exists? libs-dir)) + (is (fs/exists? libs-dir2))))) diff --git a/test/babashka/main_test.clj b/test/babashka/main_test.clj index 22f57620..8854383d 100644 --- a/test/babashka/main_test.clj +++ b/test/babashka/main_test.clj @@ -53,8 +53,8 @@ (is (= '("-e" "1") (bb nil "-e" "*command-line-args*" "--" "-e" "1"))) (let [v (bb nil "--describe")] (is (:babashka/version v)) - (is (:feature/xml v)))) - + (is (:feature/xml v))) + (is (= {:force? true} (main/parse-opts ["--force"])))) (deftest version-test (is (= [1 0 0] (main/parse-version "1.0.0-SNAPSHOT")))