Fix #1686: do not fetch deps/invoke java when deps aren't needed (#1698)

This commit is contained in:
Bob 2024-05-27 04:38:27 -04:00 committed by GitHub
parent 035a8268ba
commit 116ee1191c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 35 additions and 14 deletions

View file

@ -14,6 +14,7 @@ A preview of the next release can be installed from
- Bump org.flatland/ordered to `1.15.12`.
- Partially Fix [#1695](https://github.com/babashka/babashka/issues/1695): `--repl` arg handling should consume only one arg (itself) ([@bobisageek](https://github.com/bobisageek))
- Partially Fix [#1695](https://github.com/babashka/babashka/issues/1695): make `*command-line-args*` value available in the REPL ([@bobisageek](https://github.com/bobisageek))
- Fix [#1686](https://github.com/babashka/babashka/issues/1686): do not fetch dependencies/invoke java for `version`, `help`, and `describe` options ([@bobisageek](https://github.com/bobisageek))
## 1.3.190 (2024-04-17)

View file

@ -139,7 +139,7 @@
(binding [*out* *err*]
(apply println msgs)))
(defn print-help [_ctx _command-line-args]
(defn print-help []
(println (str "Babashka v" version))
(println "
Usage: bb [svm-opts] [global-opts] [eval opts] [cmdline args]
@ -215,8 +215,7 @@ Tooling:
File names take precedence over subcommand names.
Remaining arguments are bound to *command-line-args*.
Use -- to separate script command line args from bb command line args.
When no eval opts or subcommand is provided, the implicit subcommand is repl.")
[nil 0])
When no eval opts or subcommand is provided, the implicit subcommand is repl."))
(defn print-doc [ctx command-line-args]
(let [arg (first command-line-args)
@ -832,13 +831,12 @@ Use bb run --help to show this help output.
sci/print-length @sci/print-length
;; when adding vars here, also add them to repl.clj and nrepl_server.clj
]
(let [{version-opt :version
:keys [:shell-in :edn-in :shell-out :edn-out
:help :file :command-line-args
(let [{:keys [:shell-in :edn-in :shell-out :edn-out
:file :command-line-args
:expressions :stream? :init
:repl :socket-repl :nrepl
:debug :classpath :force?
:main :uberscript :describe?
:main :uberscript
:jar :uberjar :clojure
:doc :run :list-tasks
:print-deps :prepare]
@ -1015,12 +1013,7 @@ Use bb run --help to show this help output.
exit-code
(or exit-code
(second
(cond version-opt
[(print-version) 0]
help (print-help sci-ctx command-line-args)
doc (print-doc sci-ctx command-line-args)
describe?
[(print-describe) 0]
(cond doc (print-doc sci-ctx command-line-args)
repl (sci/binding [core/command-line-args command-line-args]
[(repl/start-repl! sci-ctx) 0])
nrepl [(start-nrepl! nrepl) 0]
@ -1109,6 +1102,15 @@ Use bb run --help to show this help output.
(uberjar/run uber-params))))))
exit-code))))
(defn exec-without-deps [cli-opts]
(let [{version-opt :version
:keys [help describe?]} cli-opts]
(cond
version-opt (print-version)
help (print-help)
describe? (print-describe)))
0)
(defn satisfies-min-version? [min-version]
(let [[major-current minor-current patch-current] version-data
[major-min minor-min patch-min] (parse-version min-version)]
@ -1149,6 +1151,10 @@ Use bb run --help to show this help output.
(str (fs/real-path f))
f))
(defn deps-not-needed [opts]
(let [fast-path-opts [:version :help :describe?]]
(some #(contains? opts %) fast-path-opts)))
(defn main [& args]
(let [bin-jar (binary-invoked-as-jar)
args (if bin-jar
@ -1205,7 +1211,9 @@ Use bb run --help to show this help output.
(binding [*out* *err*]
(println (str "WARNING: this project requires babashka "
min-bb-version " or newer, but you have: " version)))))
(exec opts)))
(if (deps-not-needed opts)
(exec-without-deps opts)
(exec opts))))
(def musl?
"Captured at compile time, to know if we are running inside a

View file

@ -88,6 +88,18 @@
(is (not (main/satisfies-min-version? "300.0.0")))
(is (not (main/satisfies-min-version? "300.0.0-SNAPSHOT"))))
(deftest version-opt-test
(is (str/starts-with? (test-utils/bb nil "version")
"babashka v")))
(deftest help-opt-test
(is (every? #(str/includes? (test-utils/bb nil "help") %)
["Babashka v" "Help:"])))
(deftest describe-opt-test
(is (every? (partial contains? (bb nil "describe"))
[:babashka/version :feature/yaml :feature/logging])))
(deftest print-error-test
(is (thrown-with-msg? Exception #"java.lang.NullPointerException"
(bb nil "(subs nil 0 0)"))))