Skip to content

Instantly share code, notes, and snippets.

@prepor

prepor/build.boot Secret

Last active Feb 18, 2019
Embed
What would you like to do?
(require '[boot.pod :as pod])
(require '[firebird.boot.deps :refer [deps-uber]])
(def mergers
[[#"data_readers.clj$" pod/into-merger]
[#"duct_hierarchy.edn$" pod/into-merger]
[#"META-INF/services/.*" pod/concat-merger]
[#".*" pod/first-wins-merger]])
(deftask build
[]
(comp (deps-uber :merge mergers)
(aot :namespace '[project.core])
(jar :file "standalone.jar"
:main 'project.core)
(sift :include #{#"standalone.jar"})
(target)))
(ns firebird.boot.deps
(:require [boot.core :as boot]
[boot.pod :as pod]
[boot.util :as util]
[boot.file :as file]
[boot.from.digest :as digest]
[clojure.java.io :as io]))
(defn make-pod []
(pod/make-pod
(update-in (boot/get-env) [:dependencies]
conj '[org.clojure/tools.deps.alpha "0.5.460"])))
(boot/deftask deps-uber
[i include MATCH #{regex} "The set of regexes that paths must match."
e exclude MATCH #{regex} "The set of regexes that paths must not match."
m merge REGEX=FN [[regex code]] "The list of duplicate file mergers."]
(let [pod (make-pod)
{:keys [classpaths paths]}
(pod/with-eval-in pod
(require '[clojure.tools.deps.alpha :as deps])
(require '[clojure.tools.deps.alpha.reader :as reader])
(let [deps (reader/read-deps ["./deps.edn"])]
{:classpaths (deps/resolve-deps deps {})
:paths (:paths deps)}))
exclude (or exclude pod/standard-jar-exclusions)
merge (or merge pod/standard-jar-mergers)]
(pod/destroy-pod pod)
(boot/with-pre-wrap fs
(let [fs' (atom fs)]
(doseq [[dep {:keys [paths]}] classpaths
path paths
:let [f (io/file path)]]
(util/dbug "Add deps resource: %s [%s]\n" dep path)
(if (.isFile f)
(swap! fs' boot/add-cached-resource
(digest/md5 f) (partial pod/unpack-jar f)
:include include :exclude exclude :mergers merge)
(let [tgt (boot/tmp-dir!)]
(file/copy-files f tgt)
(swap! fs' boot/add-resource tgt
:include include :exclude exclude :mergers merge))))
(doseq [p paths
:let [tgt (boot/tmp-dir!)]]
(file/copy-files p tgt)
(swap! fs' boot/add-resource tgt
:include include :exclude exclude :mergers merge))
(boot/commit! @fs')))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment