From b43c292077a5f8266e19da99edf936624645d037 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Ga=C5=82kowski?= Date: Sat, 7 Dec 2024 02:46:47 +0100 Subject: [PATCH] lisp-modules: detect circular dependencies during quicklisp import Quicklisp's October 2024 release had such a problem between the new packages qvm and cl-quil. It caused an issue with the "nixpkgs-review" tool because the Nix interpreter was stopping with an error due to too much recursion. --- .../import/repository/quicklisp.lisp | 38 ++++++++++++++----- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/pkgs/development/lisp-modules/import/repository/quicklisp.lisp b/pkgs/development/lisp-modules/import/repository/quicklisp.lisp index 9666fc9fba2a..634795ab17a4 100644 --- a/pkgs/development/lisp-modules/import/repository/quicklisp.lisp +++ b/pkgs/development/lisp-modules/import/repository/quicklisp.lisp @@ -120,16 +120,34 @@ asds 'vector)))))) - ;; Skip known broken systems and their dependents - (dolist (system *broken-systems*) - (sql-query - "with recursive broken(name) as ( - select ? - union - select s.name from quicklisp_system s, broken b - where b.name in (select value from json_each(deps)) - ) delete from quicklisp_system where name in (select name from broken)" - system)) + ;; Weed out circular dependencies from the package graph. + (sqlite:with-transaction db + (sql-query "create temp table will_delete (root,name)") + (loop for (system) in (sql-query "select name from quicklisp_system") do + (when (sql-query + "with recursive dep(root, name) as ( + select s.name, d.value + from quicklisp_system s + cross join json_each(s.deps) d + where s.name = ? + union + select dep.root, d.value + from quicklisp_system s, dep + cross join json_each(s.deps) d + where s.name = dep.name + ) select 1 from dep where name = root" + system) + (sql-query + "with recursive broken(name) as ( + select ? + union + select s.name from quicklisp_system s, broken b + where b.name in (select value from json_each(s.deps)) + ) insert into will_delete select ?, name from broken" + system system))) + (loop for (root name) in (sql-query "select root, name from will_delete") do + (warn "Circular dependency in '~a': Omitting '~a'" root name) + (sql-query "delete from quicklisp_system where name = ?" name))) (sqlite:with-transaction db ;; Should these be temp tables, that then get queried by