From 959477b4a4af9d181242e5b45636dcb1c79f54cb Mon Sep 17 00:00:00 2001 From: ikappaki <34983288+ikappaki@users.noreply.github.com> Date: Wed, 12 Oct 2022 20:02:34 +0100 Subject: [PATCH] Reflect scripts as bb tasks (#63) Co-authored-by: ikappaki --- .circleci/config.yml | 29 +++++++++++++++++++++------ .gitignore | 4 ++++ appveyor.yml | 11 +++++++++-- bb.edn | 39 ++++++++++++++++++++++++++++--------- bb/tasks.clj | 41 +++++++++++++++++++++++++++++++++++++++ script/babashka_test | 8 -------- script/babashka_test.bat | 5 ----- script/compile | 36 ---------------------------------- script/compile.bat | 42 ---------------------------------------- script/exe_test | 5 ----- script/exe_test.bat | 3 --- script/jvm_test | 7 ------- 12 files changed, 107 insertions(+), 123 deletions(-) create mode 100644 bb/tasks.clj delete mode 100755 script/babashka_test delete mode 100644 script/babashka_test.bat delete mode 100755 script/compile delete mode 100644 script/compile.bat delete mode 100755 script/exe_test delete mode 100644 script/exe_test.bat delete mode 100755 script/jvm_test diff --git a/.circleci/config.yml b/.circleci/config.yml index 496ca36..4b58860 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 @@ -64,7 +69,7 @@ jobs: - run: name: Run babashka tests command: | - script/babashka_test + bb babashka-test - save_cache: paths: - ~/.m2 @@ -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: | @@ -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: | @@ -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: | @@ -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: | diff --git a/.gitignore b/.gitignore index 3be5361..ec9e2e1 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,7 @@ /.clj-kondo/.cache /deps /deps.build_artifacts.txt + +# Emacs +*~ +\#*\# \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml index 662092d..4b0c43f 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -20,6 +20,11 @@ build_script: 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 @@ -34,11 +39,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 diff --git a/bb.edn b/bb.edn index 41a1459..7b7187e 100644 --- a/bb.edn +++ b/bb.edn @@ -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))}}} diff --git a/bb/tasks.clj b/bb/tasks.clj new file mode 100644 index 0000000..8bd6861 --- /dev/null +++ b/bb/tasks.clj @@ -0,0 +1,41 @@ +(ns tasks + (:require [babashka.fs :as fs] + [babashka.process :as p])) + +(defn compile-native + "Compile library to standalone jar and a native executable program. + It requires both leiningen and graalvm to be installed. + + It expects to find the graalvm home path in the GRAALVM_HOME env + var, while searches for leiningen first in cwd, and then, if not + found, in PATH." + [] + (let [graalvm-home (or (System/getenv "GRAALVM_HOME") + (throw (Exception. "Please set GRAALVM_HOME."))) + java-home (str (fs/path graalvm-home "bin")) + lein (let [lein (cond-> "./lein" (fs/windows?) (str ".bat"))] + (str (or (if (fs/executable? lein) lein (fs/which "lein")) + (throw (Exception. "Cannot find lein in the cwd or in PATH."))))) + deps-clj-version (slurp "resources/DEPS_CLJ_VERSION")] + (println "Building deps " deps-clj-version) + (println :lein lein :graalvm-home graalvm-home :java-home java-home) + (p/shell lein "deps.clj" "-Spath" "-Sdeps" "{:deps {borkdude/deps.clj {:mvn/version \"0.0.1\"}}}") + (p/shell (str 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")))] + (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\"}}}"))) diff --git a/script/babashka_test b/script/babashka_test deleted file mode 100755 index 33de722..0000000 --- a/script/babashka_test +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -export DEPS_CLJ_TEST_ENV=babashka - -bb -cp "src:test:resources" \ - -e "(require '[clojure.test :as t] '[borkdude.deps-test]) - (let [{:keys [:fail :error]} (t/run-tests 'borkdude.deps-test)] - (System/exit (+ fail error)))" diff --git a/script/babashka_test.bat b/script/babashka_test.bat deleted file mode 100644 index b0f6833..0000000 --- a/script/babashka_test.bat +++ /dev/null @@ -1,5 +0,0 @@ -set DEPS_CLJ_TEST_ENV=babashka - -bb -cp "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)))" diff --git a/script/compile b/script/compile deleted file mode 100755 index f5a3756..0000000 --- a/script/compile +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash - -set -eo pipefail - -if [ -z "$GRAALVM_HOME" ]; then - echo "Please set GRAALVM_HOME" - exit 1 -fi - -"$GRAALVM_HOME/bin/gu" install native-image || true - -DEPS_CLJ_VERSION=$(cat resources/DEPS_CLJ_VERSION) - -lein deps.clj -Spath -Sdeps '{:deps {borkdude/deps.clj {:mvn/version "0.0.1"}}}' - -lein with-profiles +native-image do clean, uberjar - -"$GRAALVM_HOME/bin/native-image" \ - -jar target/deps.clj-$DEPS_CLJ_VERSION-standalone.jar \ - -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: \ - --verbose \ - --no-fallback \ - "-H:EnableURLProtocols=http,https" \ - "--enable-all-security-services" \ - --no-server \ - "-J-Xmx3g" - -lein clean - -./deps -Spath -Sdeps '{:deps {borkdude/deps.clj {:mvn/version "0.0.1"}}}' diff --git a/script/compile.bat b/script/compile.bat deleted file mode 100644 index 2f541e1..0000000 --- a/script/compile.bat +++ /dev/null @@ -1,42 +0,0 @@ -@echo off - -Rem set GRAALVM_HOME=C:\Users\IEUser\Downloads\graalvm\graalvm-ce-19.2.1 -Rem set PATH=%PATH%;C:\Users\IEUser\bin - -if "%GRAALVM_HOME%"=="" ( - echo Please set GRAALVM_HOME - exit /b -) -set JAVA_HOME=%GRAALVM_HOME%\bin -set PATH=%PATH%;%GRAALVM_HOME%\bin - -set /P DEPS_CLJ_VERSION=< resources\DEPS_CLJ_VERSION -echo Building deps %DEPS_CLJ_VERSION% - -call lein with-profiles +native-image do clean, uberjar -if %errorlevel% neq 0 exit /b %errorlevel% - -call %GRAALVM_HOME%\bin\gu.cmd install native-image - -call %GRAALVM_HOME%\bin\native-image.cmd ^ - "-jar" "target/deps.clj-%DEPS_CLJ_VERSION%-standalone.jar" ^ - "-H:Name=deps" ^ - "-H:+ReportExceptionStackTraces" ^ - "-J-Dclojure.spec.skip-macros=true" ^ - "-J-Dclojure.compiler.direct-linking=true" ^ - "--initialize-at-build-time" ^ - "-H:Log=registerResource:" ^ - "-H:EnableURLProtocols=http,https" ^ - "--enable-all-security-services" ^ - "--no-fallback" ^ - "--verbose" ^ - "-J-Xmx3g" - -if %errorlevel% neq 0 exit /b %errorlevel% - -echo Creating zip archive -jar -cMf deps.clj-%DEPS_CLJ_VERSION%-windows-amd64.zip deps.exe - -echo Test run -rm -rf ~/.deps.clj -call deps -Spath -Sdeps "{:deps {borkdude/deps.clj {:mvn/version ""0.0.1""}}}" diff --git a/script/exe_test b/script/exe_test deleted file mode 100755 index 93a9a61..0000000 --- a/script/exe_test +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash - -export DEPS_CLJ_TEST_ENV=native - -./deps -M:test diff --git a/script/exe_test.bat b/script/exe_test.bat deleted file mode 100644 index 7565d3e..0000000 --- a/script/exe_test.bat +++ /dev/null @@ -1,3 +0,0 @@ -set DEPS_CLJ_TEST_ENV=native - -.\deps -M:test diff --git a/script/jvm_test b/script/jvm_test deleted file mode 100755 index d0a0d65..0000000 --- a/script/jvm_test +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash - -set -eo pipefail - -clojure -M:test - -clojure -M -m borkdude.deps -M:test