Skip to content

Commit 0e3e485

Browse files
anmonteirodnolen
authored andcommitted
CLJS-2291: Set up Windows CI
1 parent 8cc8491 commit 0e3e485

File tree

10 files changed

+131
-40
lines changed

10 files changed

+131
-40
lines changed

appveyor.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
environment:
2+
nodejs_version: "6"
3+
4+
platform:
5+
- x64
6+
7+
configuration:
8+
- Release
9+
10+
matrix:
11+
allow_failures:
12+
- platform: x64
13+
configuration: Release
14+
15+
cache:
16+
- '%UserProfile%\.m2'
17+
18+
install:
19+
# these need to have a line in between because of Windows line endings
20+
- ps: >-
21+
New-Item c:\scripts -type directory
22+
23+
$env:Path += ";C:\scripts"
24+
25+
Invoke-WebRequest -Uri https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein.bat -OutFile "C:\scripts\lein.bat"
26+
27+
lein self-install
28+
29+
lein version
30+
- ps: Install-Product node $env:nodejs_version x64
31+
- ps: wget 'http://ftp.mozilla.org/pub/firefox/nightly/latest-mozilla-central/jsshell-win64.zip' -OutFile "$pwd\jsshell.zip"
32+
- ps: 7z x "-o$pwd\jsshell" jsshell.zip -r
33+
- ps: .\script\bootstrap.ps1
34+
- ps: "[Console]::OutputEncoding = [Text.UTF8Encoding]::UTF8"
35+
- ps: $env:SPIDERMONKEY_HOME = "$pwd/jsshell"
36+
- ps: $SPIDERMONKEY_HOME = "$pwd/jsshell"
37+
38+
test_script:
39+
- cmd: lein test
40+
# surprisingly this is the only way to have the output shown in Appveyor
41+
- cmd: powershell -noninteractive -noprofile -command .\script\test.ps1
42+
43+
# Don't actually build (MSBuild).
44+
build: off

script/bootstrap.ps1

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ $shell = New-Object -com shell.application
55
# Read white listed dependency version info from the /bin/sh script and store in variables
66
Get-Content $root\script\bootstrap |
77
Where-Object { $_ -match '^\s*(\w+)\s*=\s*\"([^\"]*)\"\s*$' } |
8-
Where-Object { $matches[1] -in "CLOJURE_RELEASE", "CLOSURE_RELEASE",
9-
"DJSON_RELEASE", "GCLOSURE_LIB_RELEASE", "RHINO_RELEASE", "TREADER_RELEASE" } |
8+
Where-Object { $matches[1] -in "CLOJURE_RELEASE", "SPEC_ALPHA_RELEASE",
9+
"CORE_SPECS_ALPHA_RELEASE", "CLOSURE_RELEASE", "DJSON_RELEASE",
10+
"TRANSIT_RELEASE", "GCLOSURE_LIB_RELEASE", "RHINO_RELEASE",
11+
"TREADER_RELEASE", "TEST_CHECK_RELEASE" } |
1012
Foreach-Object { New-Variable $matches[1] $matches[2] -Scope private }
1113

1214
function Get-WebResource($url, $dstPath) {
@@ -95,11 +97,26 @@ Expand-ZipFile $root\clojure-$CLOJURE_RELEASE.zip $root\lib clojure-$CLOJURE_REL
9597
Move-File $root\lib\clojure-$CLOJURE_RELEASE.jar $root\lib\clojure.jar
9698
Delete-File $root\clojure-$CLOJURE_RELEASE.zip
9799

100+
Write-Host "Fetching specs.alpha...."
101+
Get-WebResource `
102+
https://repo1.maven.org/maven2/org/clojure/spec.alpha/$SPEC_ALPHA_RELEASE/spec.alpha-$SPEC_ALPHA_RELEASE.jar `
103+
$root\lib\spec.alpha-$SPEC_ALPHA_RELEASE.jar
104+
105+
Write-Host "Fetching core.specs.alpha...."
106+
Get-WebResource `
107+
https://repo1.maven.org/maven2/org/clojure/core.specs.alpha/$CORE_SPECS_ALPHA_RELEASE/core.specs.alpha-$CORE_SPECS_ALPHA_RELEASE.jar `
108+
$root\lib\core.specs.alpha-$CORE_SPECS_ALPHA_RELEASE.jar
109+
98110
Write-Host "Fetching data.json..."
99111
Get-WebResource `
100112
https://repo1.maven.org/maven2/org/clojure/data.json/$DJSON_RELEASE/data.json-$DJSON_RELEASE.jar `
101113
$root\lib\data.json-$DJSON_RELEASE.jar
102114

115+
Write-Host "Fetching transit-clj..."
116+
Get-WebResource `
117+
https://repo1.maven.org/maven2/com/cognitect/transit-clj/$TRANSIT_RELEASE/transit-clj-$TRANSIT_RELEASE.jar `
118+
$root\lib\transit-clj-$TRANSIT_RELEASE.jar
119+
103120
# TODO: Implement Closure SVN support
104121
Write-Host "Fetching Google Closure library..."
105122
Get-WebResource `
@@ -115,7 +132,7 @@ Get-WebResource `
115132
$root\compiler-$CLOSURE_RELEASE.zip
116133
Get-ChildItem $root\closure\compiler\* | Delete-File
117134
Expand-ZipFile $root\compiler-$CLOSURE_RELEASE.zip $root\closure\compiler
118-
Copy-File $root\closure\compiler\compiler.jar $root\lib\compiler.jar
135+
Copy-File $root\closure\compiler\closure-compiler-v$CLOSURE_RELEASE.jar $root\lib\compiler.jar
119136
Delete-File $root\compiler-$CLOSURE_RELEASE.zip
120137

121138
Write-Host "Fetching Rhino..."
@@ -131,4 +148,9 @@ Get-WebResource `
131148
https://repo1.maven.org/maven2/org/clojure/tools.reader/$TREADER_RELEASE/tools.reader-$TREADER_RELEASE.jar `
132149
$root\lib\tools.reader-$TREADER_RELEASE.jar
133150

134-
Write-Host "[Bootstrap Completed]"
151+
Write-Host "Fetching test.check $TEST_CHECK_RELEASE ..."
152+
Get-WebResource `
153+
https://repo1.maven.org/maven2/org/clojure/test.check/$TEST_CHECK_RELEASE/test.check-$TEST_CHECK_RELEASE.jar `
154+
$root\lib\test.check-$TEST_CHECK_RELEASE.jar
155+
156+
Write-Host "[Bootstrap Completed]"

script/test.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ $targets =
1111
@{ env="CHAKRACORE_HOME"; name="ChakraCore"; cmd={ & "$env:CHAKRACORE_HOME\ch" $testjs } }
1212
$ran = 0
1313

14-
$opts = '{:optimizations :advanced :output-wrapper true :verbose true :compiler-stats true :output-dir \"builds\\out-adv\"}'
14+
$opts = '{:optimizations :advanced :output-wrapper true :verbose true :compiler-stats true :parallel-build true :output-dir \"builds/out-adv\" :npm-deps {:lodash \"4.17.4\"} :closure-warnings {:non-standard-jsdoc :off :global-this :off} :install-deps true :language-in :es6 :language-out :es5 :foreign-libs [{:file \"src/test/cljs/calculator_global.js\" :provides [\"calculator\"] :global-exports {calculator Calculator}} {:file \"src/test/cljs/es6_dep.js\" :module-type :es6 :provides [\"es6_calc\"]} {:file \"src/test/cljs/calculator_amd.js\" :module-type :amd :provides [\"calculator_amd\"] :requires [\"es6_calc\"]} {:file \"src/test/cljs/es6_default_hello.js\" :provides [\"es6_default_hello\"] :module-type :es6}]}"'
1515

1616
function Test-It($env, $name, [scriptblock] $cmd) {
1717
$env_val = if(Test-Path env:$env) { (Get-Item env:$env).Value } else { "" }
@@ -32,7 +32,7 @@ try {
3232

3333
New-Item builds\out-adv -ItemType Directory -Force | Out-Null
3434

35-
bin\cljsc src\test/cljs $opts | Set-Content $testjs
35+
bin\cljsc src\test\cljs $opts | Set-Content $testjs
3636

3737
$targets | Foreach-Object { Test-It @_ }
3838
}

src/main/cljs/cljs/module_deps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ md.on('end', function() {
7777
if (dep.file.indexOf('node_modules') !== -1) {
7878
var providedModule = dep.file
7979
.substring(dep.file.lastIndexOf('node_modules'))
80-
.replace('\\', '/')
80+
.replace(/\\/g, '/')
8181
.replace('node_modules/', '');
8282

8383
dep.provides = dep.provides || [];

src/main/clojure/cljs/closure.clj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,14 +2232,15 @@
22322232
(.startsWith main "./")
22332233
(subs 2))
22342234
main-path (-> pkg-json-path
2235+
(string/replace #"\\" "/")
22352236
(string/replace #"package\.json$" "")
22362237
(str main))]
2237-
(when (= main-path path)
2238+
(when (= main-path (string/replace path #"\\" "/"))
22382239
name))))
22392240
pkg-jsons)]
2240-
{:provides (let [module-rel-name (string/replace
2241-
(subs path (.lastIndexOf path "node_modules"))
2242-
#"node_modules[\\\/]" "")
2241+
{:provides (let [module-rel-name (-> (subs path (.lastIndexOf path "node_modules"))
2242+
(string/replace #"\\" "/")
2243+
(string/replace #"node_modules[\\\/]" ""))
22432244
provides (cond-> [module-rel-name (string/replace module-rel-name #"\.js(on)?$" "")]
22442245
(some? pkg-json-main)
22452246
(conj pkg-json-main))

src/main/clojure/cljs/util.cljc

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,24 @@
142142
(filename x)
143143
(last (string/split (path x) #"\/"))))
144144

145+
(def windows?
146+
(.startsWith (.toLowerCase (System/getProperty "os.name")) "windows"))
147+
145148
(defn ^String relative-name
146149
"Given a file return a path relative to the working directory. Given a
147150
URL return the JAR relative path of the resource."
148151
[x]
149152
{:pre [(or (file? x) (url? x))]}
150153
(letfn [(strip-user-dir [s]
151154
(let [user-dir (System/getProperty "user.dir")
152-
user-path (.getFile (.toURL (io/file user-dir)))
153-
user-path (cond-> user-path
154-
(not (.endsWith user-path File/separator))
155+
;; on Windows, URLs end up having forward slashes like
156+
;; /C:/Users/... - Antonio
157+
s (-> (cond-> s
158+
windows? (string/replace #"^[\\/]" ""))
159+
(string/replace "\\" File/separator)
160+
(string/replace "/" File/separator))
161+
user-path (cond-> user-dir
162+
(not (.endsWith user-dir File/separator))
155163
(str File/separator))]
156164
(string/replace s user-path "")))]
157165
(if (file? x)
@@ -316,9 +324,6 @@
316324
2 (str (first xs) " and " (second xs))
317325
(str (string/join ", " (pop xs)) " and " (peek xs)))))
318326

319-
(def windows?
320-
(.startsWith (.toLowerCase (System/getProperty "os.name")) "windows"))
321-
322327
(defn module-file-seq
323328
([] (module-file-seq (io/file "node_modules")))
324329
([dir]

src/test/clojure/cljs/build_api_tests.clj

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@
1515
[clojure.java.shell :as sh]
1616
[cljs.env :as env]
1717
[cljs.analyzer :as ana]
18+
[cljs.util :as util]
1819
[cljs.test-util :as test]
1920
[cljs.build.api :as build]
2021
[cljs.closure :as closure]))
2122

2223
(deftest test-target-file-for-cljs-ns
2324
(is (= (.getPath (build/target-file-for-cljs-ns 'example.core-lib nil))
24-
"out/example/core_lib.js"))
25+
(test/platform-path "out/example/core_lib.js")))
2526
(is (= (.getPath (build/target-file-for-cljs-ns 'example.core-lib "output"))
26-
"output/example/core_lib.js")))
27+
(test/platform-path "output/example/core_lib.js"))))
2728

2829
(deftest test-cljs-dependents-for-macro-namespaces
2930
(env/with-compiler-env (env/default-compiler-env)
@@ -200,7 +201,7 @@
200201
loader (io/file out "cljs" "loader.js")]
201202
(build/build (build/inputs (io/file inputs "bar.cljs") (io/file inputs "foo.cljs")) opts)
202203
(is (.exists loader))
203-
(is (not (nil? (re-find #"/loader_test/foo\.js" (slurp loader))))))
204+
(is (not (nil? (re-find #"[\\/]loader_test[\\/]foo\.js" (slurp loader))))))
204205
(test/delete-out-files out)
205206
(let [project (merge-with merge (loader-test-project out)
206207
{:opts {:optimizations :advanced
@@ -250,7 +251,7 @@
250251
(is (contains? (:js-module-index @cenv) "react-dom/server")))
251252
(testing "builds with string requires are idempotent"
252253
(build/build (build/inputs (io/file inputs "npm_deps_test/string_requires.cljs")) opts cenv)
253-
(is (not (nil? (re-find #"\.\./node_modules/react-dom/server\.js" (slurp (io/file out "cljs_deps.js"))))))
254+
(is (not (nil? (re-find #"\.\.[\\/]node_modules[\\/]react-dom[\\/]server\.js" (slurp (io/file out "cljs_deps.js"))))))
254255
(test/delete-out-files out)))
255256
(.delete (io/file "package.json"))
256257
(test/delete-node-modules))
@@ -406,7 +407,8 @@
406407
:konan "*"
407408
:resolve "*"
408409
:browser-resolve "*"}}))
409-
(sh/sh "npm" "install")
410+
(apply sh/sh (cond->> ["npm" "install"]
411+
util/windows? (into ["cmd" "/c"])))
410412
(let [ws (atom [])
411413
out (.getPath (io/file (test/tmp-dir) "node-modules-opt-test-out"))
412414
{:keys [inputs opts]} {:inputs (str (io/file "src" "test" "cljs_build"))

src/test/clojure/cljs/module_processing_tests.clj

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
[cljs.analyzer :as ana]
77
[cljs.compiler :as comp]
88
[cljs.js-deps :as deps]
9+
[cljs.util :as util]
910
[cljs.test-util :as test]))
1011

1112
;; Hard coded JSX transform for the test case
@@ -32,8 +33,8 @@
3233
(with-redefs [cljs.js-deps/load-library (memoize cljs.js-deps/load-library*)]
3334
(is (= {:foreign-libs []
3435
:ups-foreign-libs []
35-
:libs ["out/src/test/cljs/reactJS.js"
36-
"out/src/test/cljs/Circle.js"]
36+
:libs [(test/platform-path "out/src/test/cljs/reactJS.js")
37+
(test/platform-path "out/src/test/cljs/Circle.js")]
3738
:closure-warnings {:non-standard-jsdoc :off}}
3839
(env/with-compiler-env cenv
3940
(closure/process-js-modules
@@ -63,7 +64,7 @@
6364

6465
(is (= {:foreign-libs []
6566
:ups-foreign-libs []
66-
:libs ["out/src/test/cljs/es6_hello.js"]
67+
:libs [(test/platform-path "out/src/test/cljs/es6_hello.js")]
6768
:closure-warnings {:non-standard-jsdoc :off}}
6869
(env/with-compiler-env cenv
6970
(closure/process-js-modules
@@ -88,19 +89,23 @@
8889
(let [opts (closure/process-js-modules {:foreign-libs [{:file "src/test/cljs/calculator.js"
8990
:provides ["calculator"]
9091
:module-type :commonjs}]})
91-
compile (fn [form] (with-out-str
92-
(comp/emit (ana/analyze (ana/empty-env) form))))
93-
output "module$src$test$cljs$calculator.add((3),(4));\n"]
92+
compile (fn [form]
93+
(with-out-str
94+
(comp/emit (ana/analyze (ana/empty-env) form))))
95+
crlf (if util/windows? "\r\n" "\n")
96+
output (str "module$src$test$cljs$calculator.add((3),(4));" crlf)]
9497
(swap! cenv
9598
#(assoc % :js-dependency-index (deps/js-dependency-index opts)))
9699
(binding [ana/*cljs-ns* 'cljs.user]
97100
(is (= (compile '(ns my-calculator.core (:require [calculator :as calc :refer [subtract add] :rename {subtract sub}])))
98-
"goog.provide('my_calculator.core');\ngoog.require('cljs.core');\ngoog.require('module$src$test$cljs$calculator');\n"))
101+
(str "goog.provide('my_calculator.core');" crlf
102+
"goog.require('cljs.core');" crlf
103+
"goog.require('module$src$test$cljs$calculator');" crlf)))
99104
(is (= (compile '(calc/add 3 4)) output))
100105
(is (= (compile '(calculator/add 3 4)) output))
101106
(is (= (compile '(add 3 4)) output))
102107
(is (= (compile '(sub 5 4))
103-
"module$src$test$cljs$calculator.subtract((5),(4));\n")))))))
108+
(str "module$src$test$cljs$calculator.subtract((5),(4));" crlf))))))))
104109

105110
(deftest test-cljs-1822
106111
(test/delete-out-files)
@@ -110,8 +115,8 @@
110115
(is (= {:optimizations :simple
111116
:foreign-libs []
112117
:ups-foreign-libs []
113-
:libs ["out/src/test/cljs/react-min.js"
114-
"out/src/test/cljs/Circle-min.js"]
118+
:libs [(test/platform-path "out/src/test/cljs/react-min.js")
119+
(test/platform-path "out/src/test/cljs/Circle-min.js")]
115120
:closure-warnings {:non-standard-jsdoc :off}}
116121
(env/with-compiler-env cenv
117122
(closure/process-js-modules
@@ -141,8 +146,8 @@
141146
(with-redefs [cljs.js-deps/load-library (memoize cljs.js-deps/load-library*)]
142147
(is (= {:foreign-libs []
143148
:ups-foreign-libs []
144-
:libs ["out/src/test/cljs/reactJS.js"
145-
"out/src/test/cljs/Circle.js"]
149+
:libs [(test/platform-path "out/src/test/cljs/reactJS.js")
150+
(test/platform-path "out/src/test/cljs/Circle.js")]
146151
:closure-warnings {:non-standard-jsdoc :off}}
147152
(env/with-compiler-env cenv
148153
(closure/process-js-modules

src/test/clojure/cljs/test_util.clj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
;; You must not remove this notice, or any other, from this software.
88

99
(ns cljs.test-util
10-
(:require [clojure.java.io :as io]))
10+
(:require [clojure.java.io :as io]
11+
[clojure.string :as string])
12+
(:import [java.io File]))
1113

1214
(defn delete-out-files
1315
"Processed files are only copied/written if input has changed. In test case it
@@ -49,3 +51,6 @@
4951
"Returns the temporary directory of the system."
5052
[]
5153
(System/getProperty "java.io.tmpdir"))
54+
55+
(defn platform-path [path]
56+
(.replace path \/ (.charAt (str File/separator) 0)))

src/test/clojure/cljs/util_tests.clj

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,15 @@
2929
(sort (util/unknown-opts #{:optimisations :bogus} #{:optimizations :static-fns}))))))
3030

3131
(deftest test-relative-name
32-
(let [initial (System/getProperty "user.dir")]
33-
(System/setProperty "user.dir" "/Users/user/clojurescript")
34-
(is (= (util/relative-name (io/file "/Users/user/clojurescript/out/index.js")) "out/index.js"))
35-
(is (= (util/relative-name (io/as-url (io/file "/Users/user/clojurescript/out/index.js"))) "out/index.js"))
36-
(System/setProperty "user.dir" initial)))
32+
(if util/windows?
33+
(let [initial (System/getProperty "user.dir")]
34+
(System/setProperty "user.dir" "C:\\Users\\anmonteiro\\Downloads\\clojurescript-master")
35+
(is (= (util/relative-name (io/file "C:\\Users\\anmonteiro\\Downloads\\clojurescript-master\\out\\index.js")) "out\\index.js"))
36+
(is (= (util/relative-name (io/as-url (io/file "C:\\Users\\anmonteiro\\Downloads\\clojurescript-master\\node_modules\\lodash\\array.js"))) "node_modules\\lodash\\array.js"))
37+
(System/setProperty "user.dir" initial))
38+
;; Non-windows
39+
(let [initial (System/getProperty "user.dir")]
40+
(System/setProperty "user.dir" "/Users/user/clojurescript")
41+
(is (= (util/relative-name (io/file "/Users/user/clojurescript/out/index.js")) "out/index.js"))
42+
(is (= (util/relative-name (io/as-url (io/file "/Users/user/clojurescript/out/index.js"))) "out/index.js"))
43+
(System/setProperty "user.dir" initial))))

0 commit comments

Comments
 (0)