Skip to content

Commit c1ce927

Browse files
authored
Setup improvements (#183)
* Improve clj-kondo setup * Prefer the official lein-clj-kondo plugin * Use and cache the clj-kondo analysis * Makefile: cache spec2 directory * Add a repl helper with enrich-classpath * Follows https://github.com/clojure-emacs/enrich-classpath#any-lein-or-toolsdeps-project * Bump cider-nrepl * Refine README * Refine `make repl`
1 parent 29ce583 commit c1ce927

File tree

5 files changed

+63
-13
lines changed

5 files changed

+63
-13
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
/checkouts
44
/src-spec-alpha-2
55
/classes
6+
.javac
7+
.enrich-classpath-lein-repl
68
/gh-pages
79
/unzipped-jdk-source
810
/target

Makefile

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
1-
.PHONY: test docs eastwood cljfmt deploy clean .EXPORT_ALL_VARIABLES
1+
.PHONY: test quick-test docs eastwood cljfmt kondo install deploy clean lein-repl repl .EXPORT_ALL_VARIABLES
2+
.DEFAULT_GOAL := install
23

4+
HOME=$(shell echo $$HOME)
35
VERSION ?= 1.11
4-
56
TEST_PROFILES ?= +test
6-
77
SPEC2_SOURCE_DIR = src-spec-alpha-2
88

9+
# The Lein profiles that will be selected for `lein-repl`.
10+
# Feel free to upgrade this, or to override it with an env var named LEIN_PROFILES.
11+
# Expected format: "+dev,+test"
12+
# Don't use spaces here.
13+
LEIN_PROFILES ?= "+dev,+test,+1.11"
14+
15+
# The enrich-classpath version to be injected.
16+
# Feel free to upgrade this.
17+
ENRICH_CLASSPATH_VERSION="1.16.0"
18+
919
resources/clojuredocs/export.edn:
1020
curl -o $@ https://github.com/clojure-emacs/clojuredocs-export-edn/raw/master/exports/export.compact.edn
1121

1222
# .EXPORT_ALL_VARIABLES passes TEST_PROFILES to Lein so that it can inspect the active profiles, which is needed for a complete Eastwood setup:
13-
test: clean spec-2 .EXPORT_ALL_VARIABLES
23+
test: clean $(SPEC2_SOURCE_DIR) .EXPORT_ALL_VARIABLES
1424
lein with-profile -user,-dev,+$(VERSION),$(TEST_PROFILES) test
1525

1626
quick-test: test
@@ -21,8 +31,12 @@ eastwood:
2131
cljfmt:
2232
lein with-profile -user,-dev,+$(VERSION),+deploy,+cljfmt cljfmt check
2333

24-
kondo:
25-
lein with-profile -user,-dev,+clj-kondo run -m clj-kondo.main --lint src test src-jdk8 src-newer-jdks test-newer-jdks test-cljs .circleci/deploy
34+
# Note that -dev is necessary for not hitting OOM errors in CircleCI
35+
.make_kondo_prep: project.clj .clj-kondo/config.edn
36+
lein with-profile -dev,+test,+clj-kondo,+deploy clj-kondo --copy-configs --dependencies --parallel --lint '$$classpath' > $@
37+
38+
kondo: .make_kondo_prep
39+
lein with-profile -dev,+test,+clj-kondo,+deploy clj-kondo
2640

2741
# Deployment is performed via CI by creating a git tag prefixed with "v".
2842
# Please do not deploy locally as it skips various measures.
@@ -37,8 +51,28 @@ clean:
3751
lein with-profile -user,-dev clean
3852
rm -rf $(SPEC2_SOURCE_DIR)
3953

40-
spec-2:
41-
@if [ ! -d "$(SPEC2_SOURCE_DIR)" ]; then git clone https://github.com/clojure/spec-alpha2.git $(SPEC2_SOURCE_DIR); fi
54+
$(SPEC2_SOURCE_DIR):
55+
@if [ ! -d "$(SPEC2_SOURCE_DIR)" ]; then git clone https://github.com/clojure/spec-alpha2.git $(SPEC2_SOURCE_DIR) --depth=1; fi
56+
57+
.javac: $(wildcard test-java/orchard/*.clj)
58+
lein with-profile +test javac
59+
touch $@
60+
61+
# Create and cache a `java` command. project.clj is mandatory; the others are optional but are taken into account for cache recomputation.
62+
# It's important not to silence with step with @ syntax, so that Enrich progress can be seen as it resolves dependencies.
63+
.enrich-classpath-lein-repl: .javac $(SPEC2_SOURCE_DIR) Makefile project.clj $(wildcard checkouts/*/project.clj) $(wildcard deps.edn) $(wildcard $(HOME)/.clojure/deps.edn) $(wildcard profiles.clj) $(wildcard $(HOME)/.lein/profiles.clj) $(wildcard $(HOME)/.lein/profiles.d) $(wildcard /etc/leiningen/profiles.clj)
64+
bash 'lein' 'update-in' ':plugins' 'conj' "[mx.cider/lein-enrich-classpath \"$(ENRICH_CLASSPATH_VERSION)\"]" '--' 'with-profile' $(LEIN_PROFILES) 'update-in' ':middleware' 'conj' 'cider.enrich-classpath.plugin-v2/middleware' '--' 'repl' | grep " -cp " > $@
65+
66+
# Launches a repl, falling back to vanilla lein repl if something went wrong during classpath calculation.
67+
lein-repl: .enrich-classpath-lein-repl
68+
@if grep --silent " -cp " .enrich-classpath-lein-repl; then \
69+
eval "$$(cat .enrich-classpath-lein-repl) --interactive"; \
70+
else \
71+
echo "Falling back to lein repl... (you can avoid further falling back by removing .enrich-classpath-lein-repl)"; \
72+
lein with-profiles $(LEIN_PROFILES) repl; \
73+
fi
74+
75+
repl: lein-repl
4276

4377
check-env:
4478
ifndef CLOJARS_USERNAME

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,15 @@ clients can make of use of the general functionality contained in
144144

145145
### Development
146146

147+
enrich-classpath is important for development of Java-related features in Orchard, since it makes the Java sources available. Certain features parse those Java sources as a source of information.
148+
149+
You can fire up a repl (and nrepl server) that uses cider-nrepl and enrich-classpath like so:
150+
151+
```bash
152+
# or `make lein-repl`
153+
make repl
154+
```
155+
147156
You can install Orchard locally like this:
148157

149158
```

dev/user.clj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
(ns user
2+
{:clj-kondo/config '{:linters {:unused-namespace {:level :off}
3+
:unused-referred-var {:level :off}}}}
24
(:require
35
[clojure.java.javadoc :refer [javadoc]]
46
[clojure.pprint :refer [pprint]]

project.clj

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,16 @@
6060
"-Dorchard.internal.has-enriched-classpath=false"]
6161
:source-paths ["test" "src-spec-alpha-2/src/main/clojure"]}
6262

63-
:enrich-classpath {:plugins [[mx.cider/enrich-classpath "1.9.0"]]
63+
:enrich-classpath {:plugins [[mx.cider/enrich-classpath "1.16.0"]]
6464
:middleware [cider.enrich-classpath/middleware]
65-
:jvm-opts ["-Dorchard.internal.has-enriched-classpath=true"]}
65+
:jvm-opts ["-Dorchard.internal.has-enriched-classpath=true"]
66+
:enrich-classpath {:shorten true}}
6667

6768
;; Development tools
68-
:dev {:dependencies [[org.clojure/tools.namespace "1.4.4"]]
69+
:dev {:plugins [[cider/cider-nrepl "0.37.1"]
70+
[refactor-nrepl "3.9.0"]]
71+
:dependencies [[nrepl/nrepl "1.0.0"]
72+
[org.clojure/tools.namespace "1.4.4"]]
6973
:source-paths ["dev" "src-spec-alpha-2/src/main/clojure"]
7074
:resource-paths ["test-resources"]}
7175

@@ -75,8 +79,7 @@
7579
merge-meta [[:inner 0]]
7680
letfn [[:block 1] [:inner 2]]}}}
7781

78-
:clj-kondo [:test
79-
{:dependencies [[clj-kondo "2023.07.13"]]}]
82+
:clj-kondo {:plugins [[com.github.clj-kondo/lein-clj-kondo "2023.07.13"]]}
8083

8184
:eastwood {:plugins [[jonase/eastwood "1.4.0"]]
8285
:eastwood {:exclude-namespaces ~(cond-> '[clojure.alpha.spec

0 commit comments

Comments
 (0)