Skip to content

Commit

Permalink
[#389] core.async feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Apr 29, 2020
1 parent 0d1cabd commit 02c7c51
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 14 deletions.
File renamed without changes.
8 changes: 5 additions & 3 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,26 @@
[borkdude/edamame "0.0.11-alpha.9"]
[borkdude/graal.locking "0.0.2"]
[borkdude/sci.impl.reflector "0.0.1"]
[org.clojure/core.async "1.1.587"]
[org.clojure/tools.cli "1.0.194"]
[org.clojure/data.csv "1.0.0"]
[cheshire "5.10.0"]
[fipp "0.6.22"]
[com.cognitect/transit-clj "1.0.324"]]
:profiles {:feature/xml {:source-paths ["feature-xml"]
:dependencies [[org.clojure/data.xml "0.2.0-alpha6"]]}
:profiles {:feature/xml {:source-paths ["feature-xml"]
:dependencies [[org.clojure/data.xml "0.2.0-alpha6"]]}
:feature/yaml {:source-paths ["feature-yaml"]
:dependencies [[clj-commons/clj-yaml "0.7.1"]]}
:feature/jdbc {:source-paths ["feature-jdbc"]
:dependencies [[seancorfield/next.jdbc "1.0.424"]]}
:feature/postgresql [:feature/jdbc {:dependencies [[org.postgresql/postgresql "42.2.12"]]}]
:feature/hsqldb [:feature/jdbc {:dependencies [[org.hsqldb/hsqldb "2.4.0"]]}]
:feature/core-async {:source-paths ["feature-core-async"]
:dependencies [[org.clojure/core.async "1.1.587"]]}
:test [:feature/xml
:feature/yaml
:feature/postgresql
:feature/hsqldb
:feature/core-async
{:dependencies [[clj-commons/conch "0.9.2"]
[com.clojure-goes-fast/clj-async-profiler "0.4.1"]]}]
:uberjar {:global-vars {*assert* false}
Expand Down
7 changes: 7 additions & 0 deletions script/uberjar
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ else
BABASHKA_LEIN_PROFILES+=",-feature/yaml"
fi

if [ "$BABASHKA_FEATURE_CORE_ASYNC" != "false" ]
then
BABASHKA_LEIN_PROFILES+=",+feature/core-async"
else
BABASHKA_LEIN_PROFILES+=",-feature/core-async"
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
Expand Down
6 changes: 6 additions & 0 deletions script/uberjar.bat
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ if not "%BABASHKA_FEATURE_YAML%"=="false" (
set BABASHKA_LEIN_PROFILES=%BABASHKA_LEIN_PROFILES%,-feature/yaml
)

if not "%BABASHKA_FEATURE_CORE_ASYNC%"=="false" (
set BABASHKA_LEIN_PROFILES=%BABASHKA_LEIN_PROFILES%,+feature/core-async
) else (
set BABASHKA_LEIN_PROFILES=%BABASHKA_LEIN_PROFILES%,-feature/core-async
)

call lein with-profiles %BABASHKA_LEIN_PROFILES% bb "(+ 1 2 3)"

call lein with-profiles %BABASHKA_LEIN_PROFILES%,+reflection,-uberjar do run
Expand Down
5 changes: 3 additions & 2 deletions src/babashka/impl/features.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
{:no-doc true})

;; included by default
(def yaml? (not= "false" (System/getenv "BABASHKA_FEATURE_YAML")))
(def xml? (not= "false" (System/getenv "BABASHKA_FEATURE_XML")))
(def yaml? (not= "false" (System/getenv "BABASHKA_FEATURE_YAML")))
(def xml? (not= "false" (System/getenv "BABASHKA_FEATURE_XML")))
(def core-async? (not= "false" (System/getenv "BABASHKA_FEATURE_CORE_ASYNC")))

;; excluded by default
(def jdbc? (= "true" (System/getenv "BABASHKA_FEATURE_JDBC")))
Expand Down
20 changes: 11 additions & 9 deletions src/babashka/main.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(ns babashka.main
{:no-doc true}
(:require
[babashka.impl.async :refer [async-namespace async-protocols-namespace]]
[babashka.impl.bencode :refer [bencode-namespace]]
[babashka.impl.cheshire :refer [cheshire-core-namespace]]
[babashka.impl.classes :as classes]
Expand Down Expand Up @@ -64,6 +63,9 @@
(when features/jdbc?
(require '[babashka.impl.jdbc]))

(when features/core-async?
(require '[babashka.impl.async]))

(binding [*unrestricted* true]
(sci/alter-var-root sci/in (constantly *in*))
(sci/alter-var-root sci/out (constantly *out*))
Expand Down Expand Up @@ -277,15 +279,15 @@ Everything after that is bound to *command-line-args*."))
signal babashka.signal
shell clojure.java.shell
io clojure.java.io
async clojure.core.async
csv clojure.data.csv
json cheshire.core
curl babashka.curl
transit cognitect.transit
bencode bencode.core}
features/xml? (assoc 'xml 'clojure.data.xml)
features/yaml? (assoc 'yaml 'clj-yaml.core)
features/jdbc? (assoc 'jdbc 'next.jdbc)))
features/xml? (assoc 'xml 'clojure.data.xml)
features/yaml? (assoc 'yaml 'clj-yaml.core)
features/jdbc? (assoc 'jdbc 'next.jdbc)
features/core-async? (assoc 'async 'clojure.core.async)))

(def cp-state (atom nil))

Expand All @@ -307,8 +309,6 @@ Everything after that is bound to *command-line-args*."))
'wait-for-path wait/wait-for-path}
;;'babashka.signal {'pipe-signal-received? pipe-signal-received?}
'clojure.java.io io-namespace
'clojure.core.async async-namespace
'clojure.core.async.impl.protocols async-protocols-namespace
'clojure.data.csv csv/csv-namespace
'cheshire.core cheshire-core-namespace
'clojure.stacktrace stacktrace-namespace
Expand All @@ -320,10 +320,12 @@ Everything after that is bound to *command-line-args*."))
'babashka.curl curl-namespace
'cognitect.transit transit-namespace
'bencode.core bencode-namespace}
features/xml? (assoc 'clojure.data.xml @(resolve 'babashka.impl.xml/xml-namespace))
features/xml? (assoc 'clojure.data.xml @(resolve 'babashka.impl.xml/xml-namespace))
features/yaml? (assoc 'clj-yaml.core @(resolve 'babashka.impl.yaml/yaml-namespace))
features/jdbc? (assoc 'next.jdbc @(resolve 'babashka.impl.jdbc/njdbc-namespace)
'next.jdbc.sql @(resolve 'babashka.impl.jdbc/next-sql-namespace))))
'next.jdbc.sql @(resolve 'babashka.impl.jdbc/next-sql-namespace))
features/core-async? (assoc 'clojure.core.async @(resolve 'babashka.impl.async/async-namespace)
'clojure.core.async.impl.protocols @(resolve 'babashka.impl.async/async-protocols-namespace))))

(def bindings
{'java.lang.System/exit exit ;; override exit, so we have more control
Expand Down

0 comments on commit 02c7c51

Please sign in to comment.