Skip to content

Commit

Permalink
Proof of concept for babashka#50
Browse files Browse the repository at this point in the history
Test with 
```
bb bbin install io.github.borkdude/carve --as carve-dev && cat $(which carve-dev) && carve-dev ; time carve-dev
```

0.069

Vs 

bbin install io.github.borkdude/carve --as carve-wrapped && cat $(which carve-wrapped) && carve-wrapped ; time carve-wrapped

0.100
  • Loading branch information
jeroenvandijk committed Jan 26, 2023
1 parent 5a1076e commit 5edad1f
Showing 1 changed file with 18 additions and 26 deletions.
44 changes: 18 additions & 26 deletions src/babashka/bbin/scripts.clj
Original file line number Diff line number Diff line change
Expand Up @@ -194,27 +194,12 @@
;
; :bbin/end
(require '[babashka.process :as process]
'[babashka.fs :as fs]
'[clojure.string :as str])
(require '[babashka.deps :refer [add-deps]])
(def script-root {{script/root|pr-str}})
(def script-lib '{{script/lib}})
(def script-coords {{script/coords|str}})
(def script-main-opts-first {{script/main-opts.0|pr-str}})
(def script-main-opts-second {{script/main-opts.1|pr-str}})
(add-deps '{{script/deps}})
(def tmp-edn
(doto (fs/file (fs/temp-dir) (str (gensym \"bbin\")))
(spit (str \"{:deps {\" script-lib script-coords \"}}\"))
(fs/delete-on-exit)))
(def base-command
[\"bb\" \"--deps-root\" script-root \"--config\" (str tmp-edn)
script-main-opts-first script-main-opts-second
\"--\"])
(process/exec (into base-command *command-line-args*))
(require '[{{script/main-ns}}])
(apply {{script/main-ns}}/-main *command-line-args*)
"))

(defn- http-url->script-name [http-url]
Expand Down Expand Up @@ -434,7 +419,9 @@
_ (when (and (not tool-mode) (not (seq main-opts)))
(throw (ex-info "Main opts not found. Use --main-opts or :bbin/bin to provide main opts."
{})))
template-opts {:script/meta (->> script-edn-out
template-opts {:script/deps (pr-str {:deps script-deps})

:script/meta (->> script-edn-out
str/split-lines
(map #(str comment-char " " %))
(str/join "\n"))
Expand All @@ -443,12 +430,17 @@
:script/coords (binding [*print-namespace-maps* false] (pr-str (val (first script-deps))))}
template-opts' (if tool-mode
(assoc template-opts :script/ns-default (:ns-default script-config))
(assoc template-opts :script/main-opts
[(first main-opts)
(if (= "-f" (first main-opts))
(fs/canonicalize (fs/file script-root (second main-opts))
{:nofollow-links true})
(second main-opts))]))
(let [main-fn (symbol (second main-opts))
main-ns (namespace main-fn)]
(-> template-opts
(assoc :script/main-ns main-ns)
(assoc :script/main-fn main-fn)
(assoc :script/main-opts
[(first main-opts)
(if (= "-f" (first main-opts))
(fs/canonicalize (fs/file script-root (second main-opts))
{:nofollow-links true})
(second main-opts))]))))
template-str (if tool-mode
(if (#{::no-lib} lib)
local-dir-tool-template-str
Expand Down

0 comments on commit 5edad1f

Please sign in to comment.