Skip to content

Commit 7a10a24

Browse files
authored
Choose PowerShell exec program on Windows based on availability (#1133)
* Invoke project executables on win based on PowerShell availability * Fix linter * Add classpath integration-test * Install all clojure build tools for ci integration test * clojure build tools for graalvm integration test * Support jvm cli builds and integration-test on MS-Windows * Support ci pod test on jvm MS-Windows * Upgrade to babashka.fs v0.1.11 Solves path separator issue when compiling Linux jar to Windows executable. * Add changelong entry Co-authored-by: ikappaki <ikappaki@users.noreply.github.com>
1 parent 5fb98c4 commit 7a10a24

File tree

21 files changed

+547
-77
lines changed

21 files changed

+547
-77
lines changed

.github/workflows/ci.yml

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ jobs:
8585
with:
8686
java-version: ${{ matrix.jdk }}
8787

88-
- name: Install Clojure
88+
- name: Install clojure build tools
8989
uses: DeLaGuardo/setup-clojure@master
9090
with:
9191
cli: '1.10.3.1013'
92-
93-
- name: Install Babashka
94-
run: curl -s https://raw.githubusercontent.com/borkdude/babashka/master/install | sudo bash
92+
lein: '2.9.1'
93+
boot: '2.8.3'
94+
bb: '0.9.161'
9595

9696
- name: Generate embedded binary
9797
run: make prod-cli
@@ -102,6 +102,51 @@ jobs:
102102
- name: Run babashka pod tests
103103
run: make pod-test
104104

105+
jvm-integration-test-windows:
106+
runs-on: windows-2022
107+
strategy:
108+
fail-fast: false
109+
matrix:
110+
jdk: [8]
111+
steps:
112+
- uses: actions/checkout@v2.2.0
113+
with:
114+
fetch-depth: 0
115+
116+
- name: Set up JDK ${{ matrix.jdk }}
117+
uses: actions/setup-java@v1
118+
with:
119+
java-version: ${{ matrix.jdk }}
120+
121+
- name: Install clojure build tools
122+
uses: DeLaGuardo/setup-clojure@master
123+
with:
124+
cli: '1.10.3.1013'
125+
lein: '2.9.1'
126+
boot: '2.8.3'
127+
bb: '0.9.161'
128+
129+
- name: Install launch4j
130+
uses: crazy-max/ghaction-chocolatey@v1
131+
with:
132+
args: install launch4j
133+
134+
- name: Generate embedded binary
135+
env:
136+
LAUNCH4J_HOME: "C:\\Program Files (x86)\\Launch4j"
137+
run: |
138+
cd cli
139+
clojure -T:build prod-cli
140+
- name: Run integration tests
141+
run: |
142+
cd cli
143+
bb integration-test ../clojure-lsp.exe
144+
145+
- name: Run babashka pod tests
146+
run: |
147+
cd cli
148+
clojure -M:pod-test
149+
105150
graalvm-build:
106151
runs-on: ubuntu-latest
107152
strategy:
@@ -156,13 +201,13 @@ jobs:
156201
steps:
157202
- uses: actions/checkout@v2
158203

159-
- name: Install Clojure
204+
- name: Install clojure build tools
160205
uses: DeLaGuardo/setup-clojure@master
161206
with:
162207
cli: '1.10.3.1013'
163-
164-
- name: Install Babashka
165-
run: curl -s https://raw.githubusercontent.com/borkdude/babashka/master/install | sudo bash
208+
lein: '2.9.1'
209+
boot: '2.8.3'
210+
bb: '0.9.161'
166211

167212
- uses: actions/download-artifact@v2
168213
name: clojure-lsp-native

.github/workflows/release.yml

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ jobs:
8787
with:
8888
name: clojure-lsp-standalone.jar
8989

90-
- name: Install Clojure
90+
- name: Install clojure build tools
9191
uses: DeLaGuardo/setup-clojure@master
9292
with:
9393
cli: '1.10.3.1013'
94-
95-
- name: Install Babashka
96-
run: curl -s https://raw.githubusercontent.com/borkdude/babashka/master/install | sudo bash
94+
lein: '2.9.1'
95+
boot: '2.8.3'
96+
bb: '0.9.161'
9797

9898
- name: Install GraalVM
9999
uses: DeLaGuardo/setup-graalvm@master
@@ -145,13 +145,13 @@ jobs:
145145
with:
146146
name: clojure-lsp-standalone.jar
147147

148-
- name: Install Clojure
148+
- name: Install clojure build tools
149149
uses: DeLaGuardo/setup-clojure@master
150150
with:
151151
cli: '1.10.3.1013'
152-
153-
- name: Install Babashka
154-
run: curl -s https://raw.githubusercontent.com/borkdude/babashka/master/install | sudo bash
152+
lein: '2.9.1'
153+
boot: '2.8.3'
154+
bb: '0.9.161'
155155

156156
- uses: graalvm/setup-graalvm@v1
157157
with:
@@ -277,13 +277,13 @@ jobs:
277277
with:
278278
name: clojure-lsp-standalone.jar
279279

280-
- name: Install Clojure
280+
- name: Install clojure build tools
281281
uses: DeLaGuardo/setup-clojure@master
282282
with:
283283
cli: '1.10.3.1013'
284-
285-
- name: Install Babashka
286-
run: curl -s https://raw.githubusercontent.com/borkdude/babashka/master/install | sudo bash
284+
lein: '2.9.1'
285+
boot: '2.8.3'
286+
bb: '0.9.161'
287287

288288
- name: Install GraalVM
289289
uses: DeLaGuardo/setup-graalvm@master
@@ -341,14 +341,13 @@ jobs:
341341
with:
342342
java-version: 11
343343

344-
- name: Install Clojure
345-
run: |
346-
iwr -useb download.clojure.org/install/win-install-1.10.3.1013.ps1 | iex
347-
348-
- name: Install Babashka
349-
uses: turtlequeue/setup-babashka@v1.3.0
344+
- name: Install clojure build tools
345+
uses: DeLaGuardo/setup-clojure@master
350346
with:
351-
babashka-version: 0.7.8
347+
cli: '1.10.3.1013'
348+
lein: '2.9.1'
349+
boot: '2.8.3'
350+
bb: '0.9.161'
352351

353352
- name: Install MSVC
354353
uses: ilammy/msvc-dev-cmd@v1
@@ -383,10 +382,10 @@ jobs:
383382
with:
384383
file: clojure-lsp.exe
385384

386-
# Windows return the json in the same line but for some reason clients seems to accept that.
387-
# - name: Run integration tests
388-
# run: |
389-
# bb integration-test/run-all.clj .\clojure-lsp.exe
385+
- name: Run integration tests
386+
run: |
387+
cd cli
388+
bb integration-test ../clojure-lsp.exe
390389
391390
- name: Zip binary
392391
run: |

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ cli/integration-test/sample-test/clojure-lsp.integration-test.out
2828
output.calva-repl
2929

3030
result
31+
32+
# emacs
33+
*~

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
- Generate nightly builds for macos aarch64 (M1/M2) every push on master.
1212
- Bump lsp4clj to `1.2.1`.
1313
- Bump cljfmt to `0.9.0`.
14-
14+
- Fix issue with classpath clojure build tools invocation on MS-Windows. #1132
15+
- Bump babashka/fs to `0.1.11`.
16+
1517
- Editor
1618
- Improve completion sorting, showing locals before functions and other completion items. #1158
1719
- Fix hover to show current var definition docs instead of `def`/`defn`. #1157

cli/build.clj

Lines changed: 71 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
(ns build
22
(:require
3+
[babashka.fs :as fs]
4+
[babashka.process :as p]
35
[clojure.java.io :as io]
46
[clojure.string :as string]
5-
[clojure.tools.build.api :as b]))
7+
[clojure.tools.build.api :as b]
8+
[clojure.xml :as xml]))
69

710
(def lib 'com.github.clojure-lsp/clojure-lsp)
811
(def clojars-lib 'com.github.clojure-lsp/clojure-lsp-standalone)
@@ -49,13 +52,74 @@
4952
:main 'clojure-lsp.main
5053
:basis basis})))
5154

52-
(defn ^:private bin [opts]
55+
(defn ^:private l4j-xml
56+
"Return a launch4j configuration xml document to convert the JAR file
57+
to an executable at OUTFILE using the java installation at JRE-PATH
58+
and JRE-OPTS."
59+
[jar outfile jre-path jvm-opts]
60+
(-> (with-out-str (xml/emit-element
61+
{:tag :launch4jConfig :attrs nil
62+
:content [{:tag :dontWrapJar :attrs nil :content ["false"]}
63+
{:tag :headerType :attrs nil :content ["console"]}
64+
{:tag :jar :attrs nil :content [jar]}
65+
{:tag :outfile :attrs nil :content [outfile]}
66+
{:tag :chdir :attrs nil :content ["."]}
67+
{:tag :priority :attrs nil :content ["normal"]}
68+
{:tag :stayAlive :attrs nil :content ["false"]}
69+
{:tag :restartOnCrash :attrs nil :content ["false"]}
70+
{:tag :jre :attrs nil :content
71+
(into [{:tag :path :attrs nil :content [jre-path]}
72+
{:tag :bundledJre64Bit :attrs nil :content ["true"]}
73+
{:tag :bundledJreAsFallback :attrs nil :content ["false"]}
74+
{:tag :jdkPreference :attrs nil :content ["preferJre"]}
75+
{:tag :runtimeBits :attrs nil :content ["64/32"]}]
76+
(for [opt jvm-opts]
77+
{:tag :opt :attrs nil :content [opt]}))}]}))
78+
(string/replace #"\r\n" "")))
79+
80+
(defn ^:private bin
81+
"Create a binary out of UBER-FILE jar with OPTS.
82+
83+
OPTS can be a map of
84+
:jvm-opts A vector of options ot pass to the JVM.
85+
86+
launch4j is uses on MS-Windows for the conversion to binary file. It
87+
requires its installation path to be either set in the LAUNCH4J_HOME
88+
environment variable or included in the PATH env variable. It also
89+
requires a java installation path to be set in the JAVA_HOME
90+
environment variable."
91+
[opts]
5392
(println "Generating bin...")
54-
((requiring-resolve 'deps-bin.impl.bin/build-bin)
55-
{:jar uber-file
56-
:name "clojure-lsp"
57-
:jvm-opts (concat (:jvm-opts opts []) ["-Xmx2g" "-server"])
58-
:skip-realign true}))
93+
94+
(let [jvm-opts (concat (:jvm-opts opts []) ["-Xmx2g" "-server"])]
95+
(if (fs/windows?)
96+
(if-let [l4j (or (some-> (System/getenv "LAUNCH4J_HOME") (fs/path "launch4jc.exe")
97+
(#(when (fs/executable? %) %)))
98+
(fs/which "launch4jc.exe"))]
99+
(let [jar (-> (fs/real-path uber-file) .toString)
100+
outfile (-> "../clojure-lsp.exe" fs/absolutize fs/path .toString)
101+
java-home (System/getenv "JAVA_HOME")]
102+
(fs/with-temp-dir
103+
[temp-dir]
104+
(let [l4jxml (-> (fs/path temp-dir "l4j.xml") .toString)]
105+
(spit l4jxml (l4j-xml jar outfile java-home jvm-opts))
106+
(let [{:keys [exit] :as _proc} @(p/process [(.toString l4j) l4jxml]
107+
{:dir "."
108+
:out :inherit
109+
:err :inherit})]
110+
(System/exit exit)))))
111+
112+
(throw (Exception. "Cannot locate launch4j.exe either in LAUNCH4J_HOME environment variable or in PATH.")))
113+
114+
((requiring-resolve 'deps-bin.impl.bin/build-bin)
115+
{:jar uber-file
116+
:name "clojure-lsp"
117+
:jvm-opts jvm-opts
118+
:skip-realign true}))))
119+
120+
(defn debug-jar [opts]
121+
(uber-aot (merge opts {:extra-aliases [:debug :test]
122+
:extra-dirs ["dev"]})))
59123

60124
(def prod-jar uber-aot)
61125

cli/deps.edn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
:sha "6df443fabf0d7313c8956cb6f55e47318402991f"}}
1919
:main-opts ["-m" "cognitect.test-runner" "-d" "pod-test"]}
2020
:build {:extra-paths ["../lib/resources"]
21+
:extra-deps {babashka/fs {:mvn/version "0.1.11"}
22+
babashka/process {:mvn/version "0.1.7"}}
2123
:replace-deps {io.github.clojure/tools.build {:tag "v0.8.3" :sha "0d20256"}
2224
com.github.ericdallo/deps-bin {:mvn/version "0.1.2"}
2325
slipset/deps-deploy {:mvn/version "0.2.0"}}

cli/integration-test/entrypoint.clj

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,38 @@
11
(ns entrypoint
22
(:require
3+
[babashka.fs :as fs]
34
[clojure.test :as t]
45
[medley.core :as medley]
56
[clojure.java.shell :as sh]))
67

8+
79
(def namespaces
8-
'[
9-
integration.initialize-test
10-
integration.definition-test
11-
integration.declaration-test
12-
integration.implementation-test
13-
integration.text-change-test
14-
integration.code-action-test
15-
integration.completion-test
16-
integration.diagnostics-test
17-
integration.settings-change-test
18-
integration.formatting-test
19-
integration.rename-test
20-
integration.document-highlight-test
21-
integration.document-symbol-test
22-
integration.linked-editing-range-test
23-
integration.cursor-info-test
24-
integration.java-interop-test
25-
integration.stubs-test
26-
integration.api.version-test
27-
integration.api.clean-ns-test
28-
integration.api.diagnostics-test
29-
integration.api.format-test
30-
integration.api.rename-test
31-
])
10+
(if (fs/windows?)
11+
'[integration.classpath-test]
12+
13+
'[integration.initialize-test
14+
integration.definition-test
15+
integration.declaration-test
16+
integration.implementation-test
17+
integration.text-change-test
18+
integration.code-action-test
19+
integration.completion-test
20+
integration.diagnostics-test
21+
integration.settings-change-test
22+
integration.formatting-test
23+
integration.rename-test
24+
integration.document-highlight-test
25+
integration.document-symbol-test
26+
integration.linked-editing-range-test
27+
integration.cursor-info-test
28+
integration.java-interop-test
29+
integration.stubs-test
30+
integration.classpath-test
31+
integration.api.version-test
32+
integration.api.clean-ns-test
33+
integration.api.diagnostics-test
34+
integration.api.format-test
35+
integration.api.rename-test]))
3236

3337
(defn timeout [timeout-ms callback]
3438
(let [fut (future (callback))

0 commit comments

Comments
 (0)