Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reflect scripts as bb tasks #63

Merged
merged 4 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 5 additions & 31 deletions bb.edn
Original file line number Diff line number Diff line change
@@ -1,38 +1,11 @@
{:paths ["resources"]
{:paths ["resources" "bb"]

:tasks
{:requires [[babashka.deps :as deps]
[babashka.fs :as fs]
[babashka.process :as p]
[clojure.string :as str]]
[babashka.process :as p]]

compile {:doc "Compile library to standalone jar and an executable program."
:task (let [graalvm-home (or (System/getenv "GRAALVM_HOME")
(throw (Exception. "Please set GRAALVM_HOME.")))
java-home (str (fs/path graalvm-home "bin"))
deps-clj-version (slurp "resources/DEPS_CLJ_VERSION")]
(println "Building deps " deps-clj-version)
(p/shell "lein" "deps.clj" "-Spath" "-Sdeps" "{:deps {borkdude/deps.clj {:mvn/version \"0.0.1\"}}}")
(p/shell "lein with-profiles +native-image do clean, uberjar")
(let [native-image (str (fs/path graalvm-home "bin"
(if (fs/windows?) "native-image.cmd" "native-image")))]
(println :graalvm-home graalvm-home :java-home java-home)
(p/shell native-image "-jar" (format "target/deps.clj-%s-standalone.jar" deps-clj-version)
"-H:Name=deps"
"-H:+ReportExceptionStackTraces"
"-J-Dclojure.spec.skip-macros=true"
"-J-Dclojure.compiler.direct-linking=true"
"-H:IncludeResources=DEPS_CLJ_VERSION"
"--initialize-at-build-time"
"-H:Log=registerResource:"
"-H:EnableURLProtocols=http,https"
"--enable-all-security-services"
"--no-fallback"
"--verbose"
"--no-server"
"-J-Xmx3g"))
(p/shell "lein clean")
(p/shell "./deps" "-Spath" "-Sdeps" "{:deps {borkdude/deps.clj {:mvn/version \"0.0.1\"}}}"))}
compile tasks/compile-native

bump-version (load-file "script/bump_version.clj")
changelog (load-file "script/changelog.clj")
Expand All @@ -47,7 +20,8 @@
"-e" "(let [{:keys [:fail :error]} (t/run-tests 'borkdude.deps-test)] (System/exit (+ fail error)))"))}

exe-test {:doc "Run tests with deps exec calling to deps exec."
:task (p/shell {:extra-env {"DEPS_CLJ_TEST_ENV" "native"}} "./deps.exe" "-M:test")}
:task (p/shell {:extra-env {"DEPS_CLJ_TEST_ENV" "native"}}
(if (fs/windows?) "./deps.exe" "./deps") "-M:test")}

jvm-clj-test {:doc "Run tests with clojure calling to clojure deps lib."
:task (-> (deps/clojure '[-M:test])
Expand Down
35 changes: 35 additions & 0 deletions bb/tasks.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
(ns tasks
(:require [babashka.deps :as deps]
[babashka.fs :as fs]
[babashka.process :as p]
[clojure.string :as str]))

(defn compile-native
"Compile library to standalone jar and a native executable program."
[]
(let [graalvm-home (or (System/getenv "GRAALVM_HOME")
(throw (Exception. "Please set GRAALVM_HOME.")))
java-home (str (fs/path graalvm-home "bin"))
deps-clj-version (slurp "resources/DEPS_CLJ_VERSION")]
(println "Building deps " deps-clj-version)
(p/shell "lein" "deps.clj" "-Spath" "-Sdeps" "{:deps {borkdude/deps.clj {:mvn/version \"0.0.1\"}}}")
(p/shell "lein with-profiles +native-image do clean, uberjar")
(let [native-image (str (fs/path graalvm-home "bin"
ikappaki marked this conversation as resolved.
Show resolved Hide resolved
(if (fs/windows?) "native-image.cmd" "native-image")))]
borkdude marked this conversation as resolved.
Show resolved Hide resolved
(println :graalvm-home graalvm-home :java-home java-home)
(p/shell native-image "-jar" (format "target/deps.clj-%s-standalone.jar" deps-clj-version)
"-H:Name=deps"
"-H:+ReportExceptionStackTraces"
"-J-Dclojure.spec.skip-macros=true"
"-J-Dclojure.compiler.direct-linking=true"
"-H:IncludeResources=DEPS_CLJ_VERSION"
"--initialize-at-build-time"
"-H:Log=registerResource:"
"-H:EnableURLProtocols=http,https"
"--enable-all-security-services"
"--no-fallback"
"--verbose"
"--no-server"
"-J-Xmx3g"))
(p/shell "lein clean")
(p/shell "./deps" "-Spath" "-Sdeps" "{:deps {borkdude/deps.clj {:mvn/version \"0.0.1\"}}}")))