Skip to content

Commit 0f10898

Browse files
anmonteiroswannodette
authored andcommitted
CLJS-2304: Fix compiler infrastructure tests on Windows
1 parent bf60427 commit 0f10898

File tree

6 files changed

+38
-23
lines changed

6 files changed

+38
-23
lines changed

src/main/clojure/cljs/closure.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1571,7 +1571,8 @@
15711571
(util/ns->relpath (first provides) "js")
15721572
(if (.endsWith lib-path ".js")
15731573
(util/get-name url)
1574-
(let [path (util/path url)]
1574+
(let [path (util/path url)
1575+
lib-path (util/normalize-path lib-path)]
15751576
(subs path (+ (inc (.lastIndexOf path lib-path)) (.length lib-path)))))))
15761577

15771578
(defn ^String rel-output-path

src/main/clojure/cljs/module_graph.cljc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,9 @@
292292
(cond->> rel-path
293293
asset-path (str asset-path)))
294294
(get-rel-path* [output-dir file]
295-
(string/replace (.. (io/file file) getAbsoluteFile getPath) output-dir ""))]
295+
(-> (.. (io/file file) getAbsoluteFile getPath)
296+
(string/replace output-dir "")
297+
(string/replace #"[\\/]" "/")))]
296298
(let [get-rel-path (partial get-rel-path*
297299
(.. (io/file output-dir)
298300
getAbsoluteFile getPath))]

src/main/clojure/cljs/util.cljc

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@
108108
{:pre [(or (nil? opts) (map? opts))]}
109109
(or (:output-dir opts) default)))
110110

111+
(def windows?
112+
(.startsWith (.toLowerCase (System/getProperty "os.name")) "windows"))
113+
111114
(defn file? [f]
112115
(instance? File f))
113116

@@ -117,10 +120,21 @@
117120
(defn ^String filename [^File f]
118121
(.getName f))
119122

123+
;; on Windows, URLs end up having forward slashes like
124+
;; /C:/Users/... - Antonio
125+
(defn ^String normalize-path [^String x]
126+
(-> (cond-> x
127+
windows? (string/replace #"^[\\/]" ""))
128+
(string/replace "\\" File/separator)
129+
(string/replace "/" File/separator)))
130+
120131
(defn ^String path [x]
121132
(cond
122133
(file? x) (.getAbsolutePath ^File x)
123-
(url? x) (.getPath ^URL x)
134+
(url? x) (if windows?
135+
(let [f (URLDecoder/decode (.getFile x))]
136+
(normalize-path f))
137+
(.getPath ^URL x))
124138
(string? x) x
125139
:else (throw (Exception. (str "Expected file, url, or string. Got " (pr-str x))))))
126140

@@ -140,10 +154,7 @@
140154
{:pre [(or (file? x) (url? x))]}
141155
(if (file? x)
142156
(filename x)
143-
(last (string/split (path x) #"\/"))))
144-
145-
(def windows?
146-
(.startsWith (.toLowerCase (System/getProperty "os.name")) "windows"))
157+
(last (string/split (path x) #"[\\\/]"))))
147158

148159
(defn ^String relative-name
149160
"Given a file return a path relative to the working directory. Given a
@@ -152,12 +163,7 @@
152163
{:pre [(or (file? x) (url? x))]}
153164
(letfn [(strip-user-dir [s]
154165
(let [user-dir (System/getProperty "user.dir")
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))
166+
s (normalize-path s)
161167
user-path (cond-> user-dir
162168
(not (.endsWith user-dir File/separator))
163169
(str File/separator))]

src/test/clojure/cljs/build_api_tests.clj

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -197,21 +197,21 @@
197197
(deftest cljs-2077-test-loader
198198
(let [out (.getPath (io/file (test/tmp-dir) "loader-test-out"))]
199199
(test/delete-out-files out)
200-
(let [{:keys [inputs opts]} (merge-with merge (loader-test-project out))
200+
(let [{:keys [inputs opts]} (loader-test-project out)
201201
loader (io/file out "cljs" "loader.js")]
202-
(build/build (build/inputs (io/file inputs "bar.cljs") (io/file inputs "foo.cljs")) opts)
202+
(build/build (build/inputs inputs) opts)
203203
(is (.exists loader))
204204
(is (not (nil? (re-find #"[\\/]loader_test[\\/]foo\.js" (slurp loader))))))
205205
(test/delete-out-files out)
206-
(let [project (merge-with merge (loader-test-project out)
207-
{:opts {:optimizations :advanced
208-
:source-map true}})]
209-
(build/build (build/inputs (:inputs project)) (:opts project)))
206+
(let [{:keys [inputs opts]} (merge-with merge (loader-test-project out)
207+
{:opts {:optimizations :advanced
208+
:source-map true}})]
209+
(build/build (build/inputs inputs) opts))
210210
(testing "string inputs in modules"
211211
(test/delete-out-files out)
212-
(let [project (merge-with merge (loader-test-project out)
213-
{:opts {:optimizations :whitespace}})]
214-
(build/build (build/inputs (:inputs project)) (:opts project))))))
212+
(let [{:keys [inputs opts]} (merge-with merge (loader-test-project out)
213+
{:opts {:optimizations :whitespace}})]
214+
(build/build (build/inputs inputs) opts)))))
215215

216216
(deftest test-npm-deps
217217
(test/delete-node-modules)

src/test/clojure/cljs/closure_tests.clj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@
6666
(.add module (closure/js-source-file nil (io/file out file))))
6767
(.sortInputsByDeps module compiler)
6868
(is (= (->> (.getInputs module)
69-
(map #(string/replace (.getName %) (str out File/separator) "")))
69+
(map #(string/replace
70+
(.getName %)
71+
(str (string/replace out #"[\\\/]" "/") "/") "")))
7072
["cljs/core.js"
7173
"cljs/core/constants.js"
7274
"module_test/modules/a.js"])))))

src/test/clojure/cljs/util_tests.clj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,7 @@
4141
(is (= (util/relative-name (io/file "/Users/user/clojurescript/out/index.js")) "out/index.js"))
4242
(is (= (util/relative-name (io/as-url (io/file "/Users/user/clojurescript/out/index.js"))) "out/index.js"))
4343
(System/setProperty "user.dir" initial))))
44+
45+
(deftest test-path
46+
(is (= (.getAbsolutePath (io/file "src/main/clojure/cljs/closure.clj"))
47+
(util/path (io/as-url (io/file "src/main/clojure/cljs/closure.clj"))))))

0 commit comments

Comments
 (0)