Skip to content

Commit

Permalink
Fix Windows issues with spaces (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude authored Apr 16, 2021
1 parent 5e10c17 commit 1d85389
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 35 deletions.
6 changes: 3 additions & 3 deletions deps.bat
Original file line number Diff line number Diff line change
Expand Up @@ -523,9 +523,9 @@ For more info, see:
(let [res (shell-command (into clj-main-cmd
(concat
["-m" "clojure.tools.deps.alpha.script.make-classpath2"
"--config-user" config-user
"--config-project" config-project
"--basis-file" basis-file
"--config-user" (double-quote config-user)
"--config-project" (double-quote config-project)
"--basis-file" (double-quote basis-file)
"--libs-file" (double-quote libs-file)
"--cp-file" (double-quote cp-file)
"--jvm-file" (double-quote jvm-file)
Expand Down
6 changes: 3 additions & 3 deletions deps.clj
Original file line number Diff line number Diff line change
Expand Up @@ -517,9 +517,9 @@ For more info, see:
(let [res (shell-command (into clj-main-cmd
(concat
["-m" "clojure.tools.deps.alpha.script.make-classpath2"
"--config-user" config-user
"--config-project" config-project
"--basis-file" basis-file
"--config-user" (double-quote config-user)
"--config-project" (double-quote config-project)
"--basis-file" (double-quote basis-file)
"--libs-file" (double-quote libs-file)
"--cp-file" (double-quote cp-file)
"--jvm-file" (double-quote jvm-file)
Expand Down
50 changes: 21 additions & 29 deletions src/borkdude/deps.clj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
(warn msg)
(System/exit exit-code))))

(def windows?
(-> (System/getProperty "os.name")
(str/lower-case)
(str/includes? "windows")))

(defn shell-command
"Executes shell command.
Expand All @@ -37,6 +42,9 @@
([args] (shell-command args nil))
([args {:keys [:to-string?]}]
(let [args (mapv str args)
args (if windows?
(mapv #(str/replace % "\"" "\\\"") args)
args)
pb (cond-> (ProcessBuilder. ^java.util.List args)
true (.redirectError ProcessBuilder$Redirect/INHERIT)
(not to-string?) (.redirectOutput ProcessBuilder$Redirect/INHERIT)
Expand Down Expand Up @@ -143,19 +151,6 @@ For more info, see:
(print "\n ") (describe-line line))
(println "}")))

(defn windows? []
(-> (System/getProperty "os.name")
(str/lower-case)
(str/includes? "windows")))

(defn double-quote
"Double quotes shell arguments on Windows. On other platforms it just
passes through the string."
[s]
(if (windows?)
(format "\"\"%s\"\"" s)
s))

(defn cksum
[^String s]
(let [hashed (.digest (java.security.MessageDigest/getInstance "MD5")
Expand All @@ -178,7 +173,7 @@ For more info, see:
(recur (rest paths))))))))

(defn home-dir []
(if (windows?)
(if windows?
;; workaround for https://github.com/oracle/graal/issues/1630
(System/getenv "userprofile")
(System/getProperty "user.home")))
Expand Down Expand Up @@ -294,8 +289,7 @@ For more info, see:
s))

(defn -main [& command-line-args]
(let [windows? (windows?)
args (loop [command-line-args (seq command-line-args)
(let [args (loop [command-line-args (seq command-line-args)
acc {:mode :repl}]
(if command-line-args
(let [arg (first command-line-args)
Expand Down Expand Up @@ -487,9 +481,7 @@ For more info, see:
(when (or stale (:pom args))
(cond-> []
(not (str/blank? (:deps-data args)))
(conj "--config-data" (if windows?
(pr-str (:deps-data args))
(:deps-data args)))
(conj "--config-data" (:deps-data args))
(:resolve-aliases args)
(conj (str "-R" (:resolve-aliases args)))
(:classpath-aliases args)
Expand All @@ -515,16 +507,16 @@ For more info, see:
(when (:verbose args)
(warn "Refreshing classpath"))
(let [res (shell-command (into clj-main-cmd
(concat
["-m" "clojure.tools.deps.alpha.script.make-classpath2"
"--config-user" config-user
"--config-project" config-project
"--basis-file" basis-file
"--libs-file" (double-quote libs-file)
"--cp-file" (double-quote cp-file)
"--jvm-file" (double-quote jvm-file)
"--main-file" (double-quote main-file)]
tools-args))
(concat
["-m" "clojure.tools.deps.alpha.script.make-classpath2"
"--config-user" config-user
"--config-project" config-project
"--basis-file" basis-file
"--libs-file" libs-file
"--cp-file" cp-file
"--jvm-file" jvm-file
"--main-file" main-file]
tools-args))
{:to-string? tree?})]
(when tree?
(print res) (flush))))
Expand Down

0 comments on commit 1d85389

Please sign in to comment.