Last active
September 26, 2021 09:28
-
-
Save borkdude/1d04d23d43b2cdc59041fe6dc17a7071 to your computer and use it in GitHub Desktop.
Download deps using bb and unpack in out dir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns vendor-deps | |
(:require | |
[babashka.classpath :as cp] | |
[babashka.deps :as deps] | |
[babashka.fs :as fs] | |
[clojure.string :as str]) | |
(:import [java.nio.file Files])) | |
(defn unzip [{:keys [^java.io.File zip-file | |
^java.io.File destination-dir]}] | |
(let [output-path (.toPath destination-dir) | |
zip-file (fs/file zip-file) | |
_ (fs/create-dirs destination-dir)] | |
(with-open | |
[fis (Files/newInputStream (.toPath zip-file) (into-array java.nio.file.OpenOption [])) | |
zis (java.util.zip.ZipInputStream. fis)] | |
(loop [] | |
(let [entry (.getNextEntry zis)] | |
(when entry | |
(let [entry-name (.getName entry) | |
new-path (.resolve output-path entry-name)] | |
(if (.isDirectory entry) | |
(Files/createDirectories new-path ^"[Ljava.nio.file.attribute.FileAttribute;" | |
(into-array java.nio.file.attribute.FileAttribute [])) | |
(Files/copy ^java.io.InputStream zis | |
new-path | |
^"[Ljava.nio.file.CopyOption;" | |
(into-array | |
java.nio.file.CopyOption | |
[java.nio.file.StandardCopyOption/REPLACE_EXISTING])))) | |
(recur))))))) | |
(def pre-classpath (or (cp/get-classpath) "")) | |
(deps/add-deps | |
'{:deps | |
{;; cheshire/cheshire {:mvn/version "5.10.0"} | |
;; com.taoensso/nippy {:mvn/version "3.1.1"} | |
com.github.clj-easy/graal-config-cheshire {:git/url "https://github.com/clj-easy/graal-config" | |
:git/sha "b06e33694d2c878169958f7317ea01d9c0353ab4" | |
:deps/root "config/cheshire/cheshire"} | |
com.github.clj-easy/graal-config-nippy {:git/url "https://github.com/clj-easy/graal-config" | |
:git/sha "b06e33694d2c878169958f7317ea01d9c0353ab4" | |
:deps/root "config/com.taoensso/nippy"}}}) | |
(def post-classpath | |
(str/replace (cp/get-classpath) (re-pattern (str "^" (str/re-quote-replacement pre-classpath) ":?")) "")) | |
(def target "out") | |
(fs/create-dirs target) | |
(run! (fn [s] | |
(if (str/ends-with? s ".jar") | |
(unzip {:zip-file s | |
:destination-dir target}) | |
(fs/copy-tree s target {:replace-existing true}))) | |
(cp/split-classpath post-classpath)) | |
;; ls out/META-INF/native-image | |
;; cheshire com.taoensso |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment