File tree 6 files changed +54
-9
lines changed
main/clojure/clojure/tools/build
test/clojure/clojure/tools/build/tasks
6 files changed +54
-9
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ Changelog
2
2
===========
3
3
4
4
* next
5
+ * compile-clj - add stream control args for compilation so out and err can be captured
5
6
* java-command - remove assert that : basis is required (that is no longer true)
6
7
* v0.10.5 2a21b7a on July 12, 2024
7
8
* compile-clj - fix ordering of namespaces not included in topo sort
Original file line number Diff line number Diff line change 307
307
:auto (default) - use only if os=windows && Java >= 9 && command length >= 8k
308
308
:always - always write classpath to temp file and include
309
309
:never - never write classpath to temp file (pass on command line)
310
+ :out - one of :inherit :capture :write :append :ignore
311
+ :err - one of :inherit :capture :write :append :ignore
312
+ :out-file - file path to write if :out is :write or :append
313
+ :err-file - file path to write if :err is :write or :append
310
314
311
- Returns nil."
315
+ Returns nil, or if needed a map with keys:
316
+ :out captured-out
317
+ :err captured-err"
312
318
[params]
313
319
(assert-required " compile-clj" params [:basis :class-dir ])
314
320
(assert-specs " compile-clj" params
Original file line number Diff line number Diff line change 96
96
97
97
; ; java-command will run in context of *project-dir* - basis, classpaths, etc
98
98
; ; should all be relative to that (or absolute like working-compile-dir)
99
- process-args (process/java-command (merge
100
- (select-keys params [:java-cmd :java-opts :use-cp-file ])
101
- {:cp [(.getPath working-compile-dir) class-dir]
102
- :basis basis
103
- :main 'clojure.main
104
- :main-args [(.getCanonicalPath compile-script)]}))
99
+ process-args (merge
100
+ (process/java-command
101
+ (merge
102
+ (select-keys params [:java-cmd :java-opts :use-cp-file ])
103
+ {:cp [(.getPath working-compile-dir) class-dir]
104
+ :basis basis
105
+ :main 'clojure.main
106
+ :main-args [(.getCanonicalPath compile-script)]}))
107
+ (select-keys params [:out :err :out-file :err-file ]))
105
108
_ (spit (jio/file working-dir " compile.args" ) (str/join " " (:command-args process-args)))
106
- exit ( :exit (process/process process-args) )]
109
+ { exit :exit , ps-out :out , ps-err :err } (process/process process-args)]
107
110
(if (zero? exit)
108
111
(do
109
112
(if (seq filter-nses)
110
113
(file/copy-contents working-compile-dir compile-dir-file (map ns->path filter-nses))
111
114
(file/copy-contents working-compile-dir compile-dir-file))
112
115
; ; only delete on success, otherwise leave the evidence!
113
- (file/delete working-dir))
116
+ (file/delete working-dir)
117
+ (cond-> nil
118
+ ps-out (assoc :out ps-out)
119
+ ps-err (assoc :err ps-err)))
114
120
(throw (ex-info (str " Clojure compilation failed, working dir preserved: " (.toString working-dir)) {})))))
Original file line number Diff line number Diff line change 83
83
(api/compile-clj (assoc compile-params :bindings {#'clojure.core/*assert* false })) ; ; turn off asserts
84
84
(is (= {:exit 0 , :out (str " 100" (System/lineSeparator ))} (invoke ))))))
85
85
86
+ (deftest test-capture-reflection
87
+ (with-test-dir " test-data/reflecting"
88
+ (api/set-project-root! (.getAbsolutePath *test-dir*))
89
+ (let [basis (api/create-basis nil )
90
+ compile-params {:class-dir " target/classes"
91
+ :src-dirs [" src" ]
92
+ :basis basis
93
+ :ns-compile ['foo.bar]}]
94
+
95
+ ; ; by default, reflection does not warn
96
+ (is (nil? (api/compile-clj compile-params))) ; ; no :bindings set
97
+
98
+ ; ; compile with reflection warnings and capture the error output
99
+ (api/delete {:path " target/classes" })
100
+ (is (str/starts-with?
101
+ (:err
102
+ (api/compile-clj (merge compile-params
103
+ {:bindings {#'clojure.core/*warn-on-reflection* true }
104
+ :err :capture })))
105
+ " Reflection warning" )))))
106
+
86
107
(deftest test-accidental-basis-delay
87
108
(with-test-dir " test-data/p1"
88
109
(api/set-project-root! (.getAbsolutePath *test-dir*))
Original file line number Diff line number Diff line change
1
+ {:paths [" src" ]
2
+ :deps
3
+ {org.clojure/clojure {:mvn/version " 1.12.0" }}
4
+ }
Original file line number Diff line number Diff line change
1
+ (ns foo.bar
2
+ (:gen-class ))
3
+
4
+ (defn foo [s] (.length s))
5
+
6
+ (defn -main [& args]
7
+ (println (foo " abc" )))
You can’t perform that action at this time.
0 commit comments