Skip to content

Commit 675f00e

Browse files
authored
Merge pull request #17 from athos/feature/babashka-support
Babashka support
2 parents ff159d3 + 71d78de commit 675f00e

7 files changed

Lines changed: 71 additions & 52 deletions

File tree

.github/workflows/build.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ jobs:
1212
with:
1313
distribution: 'temurin'
1414
java-version: '11'
15-
- name: Setup Clojure CLI
16-
uses: DeLaGuardo/setup-clojure@6.0
15+
- name: Setup Clojure CLI & Babashka
16+
uses: DeLaGuardo/setup-clojure@9.5
1717
with:
18-
tools-deps: latest
18+
cli: latest
19+
bb: latest
1920
- name: Cache deps
2021
uses: actions/cache@v3
2122
with:
@@ -41,6 +42,8 @@ jobs:
4142
run: clojure -M:1.8:test
4243
- name: Run CLJS tests on Node
4344
run: clojure -M:test:cljs:test-cljs
45+
- name: Run tests on Babashka
46+
run: bb test
4447
- name: Measure test coverage
4548
run: clojure -A:test:coverage
4649
- name: Upload coverage report to CodeCov

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ A tiny data-oriented debugging tool for Clojure(Script), powered by transducers
1111
- Logs are just Clojure data, so you can use DataScript, REBL or whatever tools for more sophisticated log analysis
1212
- [Integration with transducers](#integration-with-transducers) enables various flexible logging strategies
1313
- [Instrumentation](#instrumentation) on vars makes it easier to debug functions without touching their code
14-
- Supports Clojure/ClojureScript/self-hosted ClojureScript
14+
- Supports most of Clojure platforms (namely, Clojure, ClojureScript, self-hosted ClojureScript and Babashka)
1515
- Possible to use for debugging multi-threaded programs
1616

1717
## Synopsis
@@ -85,6 +85,7 @@ A tiny data-oriented debugging tool for Clojure(Script), powered by transducers
8585

8686
- Clojure 1.8+, or
8787
- ClojureScript 1.10.238+, or
88+
- Babashka v0.10.163+, or
8889
- Planck 2.24.0+, or
8990
- Lumo 1.10.1+
9091

bb.edn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{:paths ["src" "test"]
2+
:deps {net.cgrand/macrovich {:mvn/version "0.2.1"}}
3+
:tasks {test postmortem.test-runner/-main}}

src/postmortem/core.cljc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
(defn session?
1212
"Returns true if x is a session."
1313
[x]
14-
(satisfies? proto/ISession x))
14+
(satisfies? #?(:bb proto/ILogStorage :default proto/ISession) x))
1515

1616
(defn make-unsafe-session
1717
"Creates and returns a new thread-unsafe session.
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
(:require [clojure.string :as str]
33
[postmortem.instrument.core :as instr]
44
[postmortem.utils :refer [with-lock]])
5-
(:import [java.util.concurrent.locks ReentrantLock]))
5+
#?@(:bb []
6+
:clj ((:import [java.util.concurrent.locks ReentrantLock]))))
67

7-
(def ^:private ^ReentrantLock instrument-lock
8-
(ReentrantLock.))
8+
#?(:bb
9+
(def instrument-lock (Object.))
10+
:clj
11+
(def ^:private ^ReentrantLock instrument-lock
12+
(ReentrantLock.)))
913

1014
(defn- collectionize [x]
1115
(if (symbol? x)

src/postmortem/session.cljc

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
(ns postmortem.session
22
(:require [postmortem.protocols :as proto]
33
#?(:clj [postmortem.utils :refer [with-lock]]))
4-
#?(:clj (:import [java.util.concurrent.locks ReentrantLock])))
4+
#?@(:bb []
5+
:clj ((:import [java.util.concurrent.locks ReentrantLock]))))
56

67
(defn- xf->rf
78
([xform] (xf->rf xform conj))
@@ -123,37 +124,43 @@
123124
(-complete! [_ keys]
124125
(proto/-complete! session keys)))))
125126

126-
#?(:clj
127+
#?(:cljs (do)
128+
:default
129+
(deftype SynchronizedSession [session lock]
130+
proto/ISession
131+
proto/ILogStorage
132+
(-add-item! [_ key xform' item]
133+
(with-lock lock
134+
(proto/-add-item! session key xform' item)))
135+
(-keys [_]
136+
(with-lock lock
137+
(proto/-keys session)))
138+
(-logs [_]
139+
(with-lock lock
140+
(proto/-logs session)))
141+
(-logs [_ keys]
142+
(with-lock lock
143+
(proto/-logs session keys)))
144+
(-reset! [_]
145+
(with-lock lock
146+
(proto/-reset! session)))
147+
(-reset! [_ keys]
148+
(with-lock lock
149+
(proto/-reset! session keys)))
150+
proto/ICompletable
151+
(-completed? [_ key]
152+
(with-lock lock
153+
(proto/-completed? session key)))
154+
(-complete! [_]
155+
(with-lock lock
156+
(proto/-complete! session)))
157+
(-complete! [_ keys]
158+
(with-lock lock
159+
(proto/-complete! session keys)))))
160+
161+
#?(:bb
162+
(defn synchronized [session]
163+
(->SynchronizedSession session (Object.)))
164+
:clj
127165
(defn synchronized [session]
128-
(let [^ReentrantLock lock (ReentrantLock.)]
129-
(reify
130-
proto/ISession
131-
proto/ILogStorage
132-
(-add-item! [_ key xform' item]
133-
(with-lock lock
134-
(proto/-add-item! session key xform' item)))
135-
(-keys [_]
136-
(with-lock lock
137-
(proto/-keys session)))
138-
(-logs [_]
139-
(with-lock lock
140-
(proto/-logs session)))
141-
(-logs [_ keys]
142-
(with-lock lock
143-
(proto/-logs session keys)))
144-
(-reset! [_]
145-
(with-lock lock
146-
(proto/-reset! session)))
147-
(-reset! [_ keys]
148-
(with-lock lock
149-
(proto/-reset! session keys)))
150-
proto/ICompletable
151-
(-completed? [_ key]
152-
(with-lock lock
153-
(proto/-completed? session key)))
154-
(-complete! [_]
155-
(with-lock lock
156-
(proto/-complete! session)))
157-
(-complete! [_ keys]
158-
(with-lock lock
159-
(proto/-complete! session keys)))))))
166+
(->SynchronizedSession session (ReentrantLock.))))

src/postmortem/utils.cljc

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
;; to avoid using the locking macro, which is problematic in some environments (see CLJ-1472)
99
(defmacro with-lock [lock & body]
1010
(macros/case
11-
:clj
12-
`(let [lock# ~lock]
13-
(.lock lock#)
14-
(try
15-
~@body
16-
(finally
17-
(.unlock lock#))))
11+
:clj
12+
#?(:bb
13+
`(locking ~lock ~@body)
14+
:clj
15+
`(let [^java.util.concurrent.locks.ReentrantLock lock# ~lock]
16+
(.lock lock#)
17+
(try
18+
~@body
19+
(finally
20+
(.unlock lock#)))))
1821
:cljs
19-
`(do ~@body)))
20-
21-
)
22+
`(do ~@body))))

0 commit comments

Comments
 (0)