-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbb.edn
140 lines (120 loc) · 6.04 KB
/
bb.edn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
{:min-bb-version "1.3.188"
:deps {babashka/fs {:mvn/version "0.5.20"}}
:tasks
{:requires ([babashka.fs :as fs]
[babashka.process :as process]
[clojure.pprint :as pprint]
[clojure.string :as str])
:init (do
(def zone-id (java.time.ZoneId/of "UTC"))
(def formatter java.time.format.DateTimeFormatter/ISO_OFFSET_DATE_TIME)
(def timestamp (.format (java.time.ZonedDateTime/now zone-id) formatter))
(defn execute
[cmd]
(some->> cmd
(process/tokenize)
(process/process)
:out
(slurp)
(str/trim-newline)))
(defn pretty-print
([x]
(pretty-print x {}))
([x {:keys [right-margin]
:or {right-margin 80}}]
(binding [*print-namespace-maps* false
pprint/*print-right-margin* right-margin]
(pprint/pprint x))))
(def os (System/getProperty "os.name"))
(def windows? (str/starts-with? os "Windows"))
(def macos? (str/starts-with? os "Mac"))
(def linux? (str/starts-with? os "Linux"))
(def java-home (System/getenv "JAVA_HOME"))
(def graalvm-home (or (System/getenv "GRAALVM_HOME") java-home))
(def gu (str (fs/file graalvm-home "bin" "gu")))
(def native-image (str (fs/file graalvm-home "bin" "native-image")))
(def organization "lazy-cat-io")
(def repository "xdeps")
(def lib "io.lazy-cat/xdeps")
(def version (-> "version" (slurp) (str/trim-newline)))
(def branch (execute "git rev-parse --abbrev-ref HEAD"))
(def commit (execute "git rev-parse --short HEAD"))
(def meta
{:organization organization
:repository repository
:branch branch
:commit commit
:version version
:timestamp timestamp}))
:enter (let [{:keys [name doc print-doc?]
:or {print-doc? true}} (current-task)]
(when (and print-doc? doc)
(println (format "▸ [%s v%s] %s" lib version doc))))
outdated {:doc "Check for outdated dependencies"
:task (case (first *command-line-args*)
"upgrade" (shell "clojure -M:nop:outdated --main antq.core --upgrade --force")
(shell "clojure -M:nop:outdated --main antq.core"))}
lint {:doc "Run linters"
:task (case (first *command-line-args*)
"fix" (do
(shell "clojure-lsp format")
(shell "clojure-lsp clean-ns"))
(do
(shell "clojure-lsp format --dry")
(shell "clojure-lsp diagnostics")))}
repl {:doc "Run nREPL"
:depends [clean -build:meta]
:override-builtin true
:task (shell "clj -M:bench:test:develop --main nrepl.cmdline --middleware '[\"cider.nrepl/cider-middleware\"]' --interactive")}
clean {:doc "Run cleanup"
:task (doseq [dir ["target" "coverage"]]
(fs/delete-tree dir))}
test {:doc "Run tests"
:task (case (first *command-line-args*)
"unit" (shell "clojure -M:nop:test --main kaocha.runner --focus :unit")
"integration" (shell "clojure -M:nop:test --main kaocha.runner --focus :integration")
(shell (str/join \space (into ["clojure -M:nop:test --main kaocha.runner"] *command-line-args*))))}
run {:doc "Run application"
:depends [clean -build:meta]
:print-doc? false
:override-builtin true
:task (apply shell "clojure -M -m xdeps.main" *command-line-args*)}
-build:meta {:doc "Write build metadata"
:task (do
(fs/create-dirs "src/main/resources/io/lazy-cat/xdeps")
(->> meta
(pretty-print)
(with-out-str)
(spit "src/main/resources/io/lazy-cat/xdeps/meta.edn")))}
-build:uberjar {:doc "Build uberjar"
:depends [clean -build:meta]
:task (shell "clojure -T:build uberjar")}
-build:native-image {:doc "Build native image"
:task (let [static? (and linux? (boolean (some #{"static"} *command-line-args*)))
env (if macos? {"MACOSX_DEPLOYMENT_TARGET" "10.13"} {})
args (cond-> ["-jar" "target/xdeps.jar"
"-H:Name=xdeps"
"-H:Path=target"
"-H:IncludeResources=io/lazy-cat/*"
"-H:+ReportExceptionStackTraces"
"-J-Dclojure.compiler.direct-linking=true"
"-J-Dclojure.spec.skip-macros=true"
"--enable-preview"
"--features=clj_easy.graal_build_time.InitClojureClasses"
"--install-exit-handlers"
"--native-image-info"
"--no-fallback"
"--no-server"]
static? (conj "--static" "--libc=musl"))]
(println "Static:" static?)
(shell gu "install" "native-image")
(apply shell env native-image args))}
build {:doc "Run build"
:print-doc? false
:task (case (first *command-line-args*)
"meta" (run '-build:meta)
"uberjar" (run '-build:uberjar)
"native-image" (run '-build:native-image)
(do
(run '-build:uberjar)
(run '-build:native-image)))}}}