Skip to content

Commit

Permalink
Throw if compilation failed (#39)
Browse files Browse the repository at this point in the history
* Throw if compilation failed

* Refactor compilation errors handling

---------

Co-authored-by: Oleksandr Yakushev <alex@bytopia.org>
  • Loading branch information
tonsky and alexander-yakushev authored Nov 11, 2024
1 parent 3f54e14 commit aad99ac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/virgil/compile.clj
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,13 @@
(defn compile-all-java
([directories] (compile-all-java directories nil false))
([directories options verbose?]
(let [diag (DiagnosticCollector.)
(let [collector (DiagnosticCollector.)
options (ArrayList. (vec options))
name->source (generate-classname->source directories)]
(println "Compiling" (count name->source)"Java source files in" directories "...")
(binding [*print-compiled-classes* verbose?]
(compile-java options diag name->source))
(print-diagnostics diag))))
(compile-java options collector name->source))
(when-let [diags (seq (.getDiagnostics collector))]
(print-diagnostics diags)
(throw (ex-info (format "Compilation failed: %d error(s)." (count diags))
{:diagnostics diags}))))))
6 changes: 3 additions & 3 deletions src/virgil/util.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns virgil.util
"Utilities for cross-tooling."
(:import (javax.tools DiagnosticCollector Diagnostic$Kind)))
(:import (javax.tools Diagnostic Diagnostic$Kind)))

(defn println-err [& args]
(binding [*out* *err*]
Expand All @@ -15,8 +15,8 @@
Diagnostic$Kind/MANDATORY_WARNING println-err
println))

(defn print-diagnostics [^DiagnosticCollector diag-coll]
(doseq [d (.getDiagnostics diag-coll)]
(defn print-diagnostics [diagnostics]
(doseq [^Diagnostic d diagnostics]
(let [k (.getKind d)
log (infer-print-function k)]
(if (nil? (.getSource d))
Expand Down

0 comments on commit aad99ac

Please sign in to comment.