Skip to content

Instantly share code, notes, and snippets.

@borkdude
Last active September 30, 2021 19:37
Show Gist options
  • Save borkdude/2b963db1582654ec28bfd40b4dc35748 to your computer and use it in GitHub Desktop.
Save borkdude/2b963db1582654ec28bfd40b4dc35748 to your computer and use it in GitHub Desktop.
Print API breakage warnings
#!/usr/bin/env bash
#_" -*- mode: clojure; -*-"
#_(
"exec" "clojure" "-Sdeps" "{:deps {clj-kondo/clj-kondo {:mvn/version \"2020.12.12\"} org.clojure/tools.deps.alpha {:mvn/version \"0.9.857\"} org.slf4j/slf4j-nop {:mvn/version \"1.7.30\"} lambdaisland/deep-diff2 {:mvn/version \"2.0.108\"} juji/editscript {:mvn/version \"0.5.4\"}}}" "-M" "$0" "$@"
)
;; Example usage:
;; api_diff.clj org.clojure/clojure "1.8.0" "1.10.1" > /tmp/diff.txt
(require '[clj-kondo.core :as clj-kondo])
(require '[clojure.edn :as edn])
(def lib (edn/read-string (first *command-line-args*)))
(def v1 (second *command-line-args*))
(def v2 (nth *command-line-args* 2))
(require '[clojure.tools.deps.alpha :as tda])
(require '[clojure.tools.deps.alpha.util.maven :as mvn])
(defn path [lib v]
(let [deps `{:deps {~lib {:mvn/version ~v}} :mvn/repos ~mvn/standard-repos}]
(-> (tda/resolve-deps deps {})
(get lib)
:paths first)))
(def path1 (path lib v1))
(def path2 (path lib v2))
(defn index-by
[f coll]
(persistent! (reduce #(assoc! %1 (f %2) %2) (transient {}) coll)))
(defn group [vars]
(->> vars
(map #(select-keys % [:ns :name :fixed-arities :varargs-min-arity]))
(index-by (juxt :ns :name))))
(defn vars [lib]
(-> (clj-kondo/run! {:lint [lib] :config {:output {:analysis true :format :edn}}})
:analysis :var-definitions #_ clean))
(def vars-1 (vars path1))
(def vars-2 (vars path2))
#_(require '[lambdaisland.deep-diff2 :as ddiff])
#_(ddiff/pretty-print (ddiff/diff vars-1 vars-2))
;; (require '[editscript.core :as c])
;; (require '[editscript.edit :as e])
;; (def d (c/diff vars-1 vars-2))
;; (require '[clojure.pprint :refer [pprint]])
;; (pprint (e/get-edits d))
(defn var-symbol [[k v]]
(str k "/" v))
(def compare-group-1 (group vars-1))
(def compare-group-2 (group vars-2))
(def lookup-1 (index-by (juxt :ns :name) vars-1))
(doseq [[k var-1] compare-group-1]
(if-let [var-2 (get compare-group-2 k)]
(let [fixed-arities-v1 (:fixed-arities var-1)
fixed-arities-v2 (:fixed-arities var-2)
varargs-min-arity (:varargs-min-arity var-2)]
(doseq [arity fixed-arities-v1]
(when-not (or (contains? fixed-arities-v2 arity)
(and varargs-min-arity (>= arity varargs-min-arity)))
(let [{:keys [:filename :row :col :private]} (get lookup-1 k)]
(println (str filename ":" row ":" col ":") (str (if private "warning" "error") ":")
"Arity" arity "of" (var-symbol k) "was removed.")))))
(let [{:keys [:filename :row :col :private]} (get lookup-1 k)]
(println (str filename ":" row ":" col ":") (str (if private "warning" "error") ":")
(var-symbol k) "was removed."))))
@borkdude
Copy link
Author

borkdude commented Jan 7, 2021

clojure/pprint/cl_format.clj:168:1: warning: Arity 1 of clojure.pprint/format-simple-number was removed.
clojure/core_deftype.clj:572:1: warning: Arity 4 of clojure.core/emit-method-builder was removed.
clojure/core/reducers.clj:24:1: warning: clojure.core.reducers/compile-if was removed.

Screenshot 2021-01-07 at 23 16 21

Also check out the bb version here: https://gist.github.com/borkdude/ba372c8cee311e31020b04063d88e1be

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment