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 3 commits
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
29 changes: 23 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ jobs:
wget -nc https://download.clojure.org/install/linux-install-1.10.3.998.sh
chmod +x linux-install-1.10.3.998.sh
sudo ./linux-install-1.10.3.998.sh
- run:
name: Install babashka
command: |
bash <(curl -s https://raw.githubusercontent.com/borkdude/babashka/master/install) --dir ~
sudo mv ~/bb /usr/local/bin/bb
- run:
name: Run JVM tests
command: |
script/jvm_test
bb jvm-test
- save_cache:
paths:
- ~/.m2
Expand Down Expand Up @@ -64,7 +69,7 @@ jobs:
- run:
name: Run babashka tests
command: |
script/babashka_test
bb babashka-test
- save_cache:
paths:
- ~/.m2
Expand All @@ -89,6 +94,11 @@ jobs:
wget https://download.clojure.org/install/linux-install-1.10.3.998.sh
chmod +x linux-install-1.10.3.998.sh
sudo ./linux-install-1.10.3.998.sh
- run:
name: Install babashka
command: |
bash <(curl -s https://raw.githubusercontent.com/borkdude/babashka/master/install) --dir ~
sudo mv ~/bb /usr/local/bin/bb
- run:
name: Install lsof
command: |
Expand All @@ -106,15 +116,16 @@ jobs:
curl -O -sL https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-21.0.0.2/graalvm-ce-java11-linux-amd64-21.0.0.2.tar.gz
tar xzf graalvm-ce-java11-linux-amd64-21.0.0.2.tar.gz
fi
"$GRAALVM_HOME/bin/gu" install native-image || true
- run:
name: Build binary
command: |
script/compile
bb compile
no_output_timeout: 30m
- run:
name: Run tests
command: |
script/exe_test
bb exe-test
- run:
name: Release
command: |
Expand Down Expand Up @@ -142,6 +153,11 @@ jobs:
name: Install Clojure
command: |
.circleci/script/install-clojure /usr/local
- run:
name: Install babashka
command: |
bash <(curl -s https://raw.githubusercontent.com/borkdude/babashka/master/install) --dir ~
sudo mv ~/bb /usr/local/bin/bb
- run:
name: Install Leiningen
command: |
Expand All @@ -155,15 +171,16 @@ jobs:
curl -O -sL https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-21.0.0.2/graalvm-ce-java11-darwin-amd64-21.0.0.2.tar.gz
tar xzf graalvm-ce-java11-darwin-amd64-21.0.0.2.tar.gz
fi
"$GRAALVM_HOME/bin/gu" install native-image || true
- run:
name: Build binary
command: |
script/compile
bb compile
no_output_timeout: 30m
- run:
name: Run tests
command: |
script/exe_test
bb exe-test
- run:
name: Release
command: |
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
/.clj-kondo/.cache
/deps
/deps.build_artifacts.txt

# Emacs
*~
\#*\#
13 changes: 9 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ cache:

build_script:
- cmd: >-
powershell -Command "(New-Object Net.WebClient).DownloadFile('https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein.bat', 'lein.bat')"
choco install lein
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of making changes to CI builds if they are not necessary. The powershell command worked before. Switching to choco may slow down stuff or additional stuff may be installed which causes new unforeseen issues. The reason I'm saying this is that I've used brew on macOS CI and this was very very slow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I forgot to mention that I did that because the compile script only looks in PATH to locate lein, and not in the CWD as per the above installation does. I had a few futile attempts trying to add it in the appveyor PATH and in the end settled at using choco (courtesy of grep.app).

Understood. I've reverted the change and updated the compile task to look at CWD for lein. There is an inherent difficulty trying to locate windows executable programs/scripts outside of PATH without mentioning the extension. I might open a babashka.fs to discuss the problem.

Thanks

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for explaining!


call lein self-install
- cmd: >-
powershell -Command "if (Test-Path('bb.exe')) { return } else { (New-Object Net.WebClient).DownloadFile('https://github.com/babashka/babashka/releases/download/v0.9.162/babashka-0.9.162-windows-amd64.zip', 'bb.zip') }"

powershell -Command "if (Test-Path('bb.exe')) { return } else { Expand-Archive bb.zip . }"

- cmd: >-
call lein do clean, uberjar
Expand All @@ -34,11 +37,13 @@ build_script:

powershell -Command "if (Test-Path('graalvm')) { return } else { Expand-Archive graalvm.zip graalvm }"

call script/compile.bat
%GRAALVM_HOME%\bin\gu.cmd install native-image

bb compile

test_script:
- cmd: >-
call script/exe_test.bat
bb exe-test

artifacts:
- path: deps.clj-*-windows-amd64.zip
Expand Down
39 changes: 30 additions & 9 deletions bb.edn
Original file line number Diff line number Diff line change
@@ -1,16 +1,37 @@
{:paths ["resources"]
{:paths ["resources" "bb"]

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

compile tasks/compile-native

bump-version (load-file "script/bump_version.clj")
changelog (load-file "script/changelog.clj")
gen-script {:doc "Regen `./deps[.clj|.bat]` from `src/borkdude/deps.clj`."
:task (load-file "script/gen_script.clj")}

test {:doc "Run all tests."
:task
(doseq [args '[[-M:test] [-M -m borkdude.deps -M:test]]]
(println :testing... 'clojure args)
(-> (deps/clojure args)
p/check)
(println))}}}
babashka-test {:doc "Run tests with bb calling to bb deps lib."
:task (let [bb (str \" (.get (.command (.info (java.lang.ProcessHandle/current)))) \")]
(p/shell {:extra-env {"DEPS_CLJ_TEST_ENV" "babashka"}}
bb "-cp" (str/join fs/path-separator ["src" "test" "resources"])
"-e" "(require '[clojure.test :as t] '[borkdude.deps-test])"
"-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"}}
(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])
p/check)}
jvm-deps-test {:doc "Run tests with clojure deps lib calling to clojure deps lib."
:task (-> (deps/clojure '[-M -m borkdude.deps -M:test])
p/check)}
jvm-test {:doc "Run both jvm-clj-test and jvm-deps-test."
:task (doseq [task '[jvm-clj-test jvm-deps-test]]
(println :running... task)
(run task)
(println))}}}
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\"}}}")))
8 changes: 0 additions & 8 deletions script/babashka_test

This file was deleted.

5 changes: 0 additions & 5 deletions script/babashka_test.bat

This file was deleted.

36 changes: 0 additions & 36 deletions script/compile

This file was deleted.

42 changes: 0 additions & 42 deletions script/compile.bat

This file was deleted.

5 changes: 0 additions & 5 deletions script/exe_test

This file was deleted.

3 changes: 0 additions & 3 deletions script/exe_test.bat

This file was deleted.

7 changes: 0 additions & 7 deletions script/jvm_test

This file was deleted.