Skip to content

Commit

Permalink
Automatically use file when exceeding Windows argument length (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude authored May 18, 2023
1 parent 4918fb6 commit f826518
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/borkdude/deps.clj
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,17 @@ public class ClojureToolsDownloader {
[{:keys [cache-dir checksum]}]
(.getPath (io/file cache-dir (str checksum ".basis"))))

(defn- auto-file-arg [cp]
(if (and windows? (> (count cp) 32766))
(let [tmp-file (.toFile (java.nio.file.Files/createTempFile
"file_arg" ".txt"
(into-array java.nio.file.attribute.FileAttribute [])))]
(.deleteOnExit tmp-file)
;; we use pr-str since whitespaces in the classpath will be treated as separate args otherwise
(spit tmp-file (pr-str cp))
(str "@" tmp-file))
cp))

(defn -main
"See `help-text`.
Expand Down Expand Up @@ -989,13 +1000,15 @@ public class ClojureToolsDownloader {
cp (if (or exec? tool?)
(str cp path-separator exec-cp)
cp)
;; see https://devblogs.microsoft.com/oldnewthing/20031210-00/?p=41553
;; command line limit on Windows with process builder
main-args (concat java-cmd
java-opts
proxy-settings
jvm-cache-opts
(:jvm-opts cli-opts)
[(str "-Dclojure.basis=" (relativize basis-file))
"-classpath" cp
"-classpath" (auto-file-arg cp)
"clojure.main"]
main-opts)
main-args (filterv some? main-args)
Expand Down
11 changes: 11 additions & 0 deletions test/borkdude/deps_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
version (-> (process [java "-version"] {:err :string})
check
:err str/split-lines first)]
(def java-version version)
(println :deps.clj/java :path (pr-str java) :version version))

(defn invoke-deps-cmd
Expand Down Expand Up @@ -463,3 +464,13 @@
#_#_(require 'clojure.pprint)
((requiring-resolve 'clojure.pprint/pprint) basis)
(is (contains? (:libs basis) 'medley/medley))))

(deftest long-classpath-test
(when-not (str/includes? java-version "1.8.0")
(let [prev-cp (str/trim (with-out-str (borkdude.deps/-main "-Spath")))
long-cp (str/join fs/path-separator (cons prev-cp (repeat 15000 "src")))
ret (atom nil)]
(binding [deps/*exit-fn* #(reset! ret %)]
(borkdude.deps/-main "-Scp" long-cp "-M" "-e" "nil"))
(is (or (nil? @ret)
(zero? (:exit @ret)))))))

0 comments on commit f826518

Please sign in to comment.