From dc930250a4ff5ad63fe6d3dd3afdd72b213ece88 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Sat, 24 Apr 2021 12:16:50 +0200 Subject: [PATCH] version-clj --- deps.edn | 1 + .../babashka/impl/version_clj.clj | 49 +++---------------- script/compile | 1 + script/uberjar | 7 +++ script/uberjar.bat | 5 ++ src/babashka/impl/features.clj | 4 ++ src/babashka/main.clj | 13 +++-- 7 files changed, 33 insertions(+), 47 deletions(-) diff --git a/deps.edn b/deps.edn index 2abcafbf..185540b7 100644 --- a/deps.edn +++ b/deps.edn @@ -8,6 +8,7 @@ "feature-test-check" "feature-spec-alpha" "feature-rewrite-clj" + "feature-version-clj" "pods/src" "babashka.nrepl/src" "depstar/src" "process/src" diff --git a/feature-version-clj/babashka/impl/version_clj.clj b/feature-version-clj/babashka/impl/version_clj.clj index 9d80f075..2ee2ba4d 100644 --- a/feature-version-clj/babashka/impl/version_clj.clj +++ b/feature-version-clj/babashka/impl/version_clj.clj @@ -1,34 +1,9 @@ -(ns babashka.impl.rewrite-clj +(ns babashka.impl.version-clj {:no-doc true} - (:require [version-clj.core :as v] - [sci.core :as sci])) + (:require [sci.core :as sci] + [version-clj.core])) -(def nns (sci/create-ns 'rewrite-clj.node nil)) -(def pens (sci/create-ns 'rewrite-clj.paredit nil)) -(def pns (sci/create-ns 'rewrite-clj.parser nil)) -(def zns (sci/create-ns 'rewrite-clj.zip nil)) -(def zsns (sci/create-ns 'rewrite-clj.zip.subedit nil)) - -#_(defmacro copy-var - "Copies contents from var `sym` to a new sci var. The value `ns` is an - object created with `sci.core/create-ns`." - ([sym ns] - `(let [ns# ~ns - var# (var ~sym) - val# (deref var#) - m# (-> var# meta) - ns-name# (vars/getName ns#) - name# (:name m#) - name-sym# (symbol (str ns-name#) (str name#)) - new-m# {:doc (:doc m#) - :name name# - :arglists (:arglists m#) - :ns ns#}] - (cond (:dynamic m#) - (new-dynamic-var name# val# new-m#) - (:macro m#) - (new-macro-var name# val# new-m#) - :else (new-var name# val# new-m#))))) +(def vns (sci/create-ns 'version-clj.core nil)) (defn make-ns [ns sci-ns] (reduce (fn [ns-map [var-name var]] @@ -47,17 +22,5 @@ {} (ns-publics ns))) -(def node-namespace - (make-ns 'rewrite-clj.node nns)) - -(def parser-namespace - (make-ns 'rewrite-clj.parser pns)) - -(def paredit-namespace - (make-ns 'rewrite-clj.paredit pens)) - -(def zip-namespace - (make-ns 'rewrite-clj.zip zns)) - -(def subedit-namespace - (make-ns 'rewrite-clj.zip.subedit zsns)) +(def version-clj-namespace + (make-ns 'version-clj.core vns)) diff --git a/script/compile b/script/compile index 95291f3f..b4d36110 100755 --- a/script/compile +++ b/script/compile @@ -104,6 +104,7 @@ then export BABASHKA_FEATURE_TEST_CHECK="${BABASHKA_FEATURE_TEST_CHECK:-false}" export BABASHKA_FEATURE_SPEC_ALPHA="${BABASHKA_FEATURE_SPEC_ALPHA:-false}" export BABASHKA_FEATURE_REWRITE_CLJ="${BABASHKA_FEATURE_REWRITE_CLJ:-false}" + export BABASHKA_FEATURE_REWRITE_CLJ="${BABASHKA_FEATURE_VERSION_CLJ:-false}" fi "$GRAALVM_HOME/bin/native-image" "${args[@]}" diff --git a/script/uberjar b/script/uberjar index cc699bab..f5bc591c 100755 --- a/script/uberjar +++ b/script/uberjar @@ -153,6 +153,13 @@ else BABASHKA_LEIN_PROFILES+=",-feature/rewrite-clj" fi +if [ "$BABASHKA_FEATURE_VERSION_CLJ" != "false" ] +then + BABASHKA_LEIN_PROFILES+=",+feature/version-clj" +else + BABASHKA_LEIN_PROFILES+=",-feature/version-clj" +fi + if [ -z "$BABASHKA_JAR" ]; then lein with-profiles "$BABASHKA_LEIN_PROFILES,+reflection,-uberjar" do run lein with-profiles "$BABASHKA_LEIN_PROFILES" do clean, uberjar diff --git a/script/uberjar.bat b/script/uberjar.bat index fba9e27c..6b4fcd6e 100755 --- a/script/uberjar.bat +++ b/script/uberjar.bat @@ -118,6 +118,11 @@ set BABASHKA_LEIN_PROFILES=%BABASHKA_LEIN_PROFILES%,+feature/rewrite-clj set BABASHKA_LEIN_PROFILES=%BABASHKA_LEIN_PROFILES%,-feature/rewrite-clj ) +if not "%BABASHKA_FEATURE_VERSION_CLJ%"=="false" ( +set BABASHKA_LEIN_PROFILES=%BABASHKA_LEIN_PROFILES%,+feature/version-clj +) else ( +set BABASHKA_LEIN_PROFILES=%BABASHKA_LEIN_PROFILES%,-feature/version-clj +) call lein with-profiles %BABASHKA_LEIN_PROFILES% bb "(+ 1 2 3)" diff --git a/src/babashka/impl/features.clj b/src/babashka/impl/features.clj index acca92fa..88bea263 100644 --- a/src/babashka/impl/features.clj +++ b/src/babashka/impl/features.clj @@ -15,6 +15,7 @@ (def hiccup? (not= "false" (System/getenv "BABASHKA_FEATURE_HICCUP"))) (def test-check? (not= "false" (System/getenv "BABASHKA_FEATURE_TEST_CHECK"))) (def rewrite-clj? (not= "false" (System/getenv "BABASHKA_FEATURE_REWRITE_CLJ"))) +(def version-clj? (not= "false" (System/getenv "BABASHKA_FEATURE_VERSION_CLJ"))) ;; excluded by default (def jdbc? (= "true" (System/getenv "BABASHKA_FEATURE_JDBC"))) @@ -70,3 +71,6 @@ (when rewrite-clj? (require '[babashka.impl.rewrite-clj])) + +(when version-clj? + (require '[babashka.impl.version-clj])) diff --git a/src/babashka/main.clj b/src/babashka/main.clj index 6f6674e4..9c8f0e31 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -191,7 +191,8 @@ When no eval opts or subcommand is provided, the implicit subcommand is repl.") :feature/hiccup %s :feature/test-check %s :feature/spec-alpha %s - :feature/rewrite-clj %s}") + :feature/rewrite-clj %s + :feature/version-clj %s}") version features/core-async? features/csv? @@ -209,7 +210,8 @@ When no eval opts or subcommand is provided, the implicit subcommand is repl.") features/hiccup? features/test-check? features/spec-alpha? - features/rewrite-clj?))) + features/rewrite-clj? + features/version-clj?))) (defn read-file [file] (let [f (io/file file)] @@ -260,7 +262,8 @@ When no eval opts or subcommand is provided, the implicit subcommand is repl.") features/jdbc? (assoc 'jdbc 'next.jdbc) features/core-async? (assoc 'async 'clojure.core.async) features/csv? (assoc 'csv 'clojure.data.csv) - features/transit? (assoc 'transit 'cognitect.transit))) + features/transit? (assoc 'transit 'cognitect.transit) + features/version-clj? (assoc 'version 'version-clj.core))) ;;(def ^:private server-ns-obj (sci/create-ns 'clojure.core.server nil)) @@ -349,7 +352,9 @@ When no eval opts or subcommand is provided, the implicit subcommand is repl.") 'rewrite-clj.zip @(resolve 'babashka.impl.rewrite-clj/zip-namespace) 'rewrite-clj.zip.subedit - @(resolve 'babashka.impl.rewrite-clj/subedit-namespace)))) + @(resolve 'babashka.impl.rewrite-clj/subedit-namespace)) + features/version-clj? (assoc 'version-clj.core + @(resolve 'babashka.impl.version-clj/version-clj-namespace)))) (def imports '{ArithmeticException java.lang.ArithmeticException