(in-package :cl-user)
(load #P "~/works/patchwork/tools/dependency-cycles.lisp")
(use-package :com.informatimago.dependency-cycles)
(use-package :com.informatimago.common-lisp.cesarum.utility)

(defparameter *pjb-sources-order*
  '((pjb-advices register debug message gnus-art gnus cus-edit rmailsort message mail-utils sendmail mouse pjb-strings cl)
    (pjb-asm7090 font-lock asm-mode pjb-cl cl)
    (pjb-blink)
    (pjb-cl-magic pjb-sources pjb-cl)
    (pjb-cl parse-time eieio-opt eieio cl)
    (pjb-class pjb-list pjb-cl)
    (pjb-dodo pjb-cl)
    (pjb-emacs morse pjb-sources pjb-font pjb-euro pjb-cl sgml-mode picture browse-url font devices eieio cl)
    (pjb-erc erc pjb-html pjb-make-depends pjb-cl xml w3-forms w3 cl)
    (pjb-euro pjb-html pjb-strings pjb-utilities pjb-list pjb-cl)
    (pjb-font pjb-list font devices cl)
    (pjb-html pjb-cl cl)
    (pjb-list pjb-cl)
    (pjb-gnus)
    (pjb-mail sendmail mm mailheader pjb-pgp pjb-emacs pjb-strings pjb-list pjb-cl)
    (pjb-object eieio pjb-cl)
    (pjb-page)
    (pjb-pgp pjb-emacs url w3 mailheader pjb-strings)
    (pjb-queue pjb-utilities)
    (pjb-ruby)
    (pjb-shell shell)
    (pjb-sources pjb-emacs pjb-utilities pjb-cl add-log font-lock)
    (pjb-state-coding pjb-cl)
    (pjb-strings pjb-list pjb-cl)
    (pjb-utilities calendar comint forms pjb-cl pjb-strings)
    (pjb-work pjb-cl pjb-utilities)
    (pjb-xresources)
    (pjb-thi)
    (pjb-pl1)
    (pjb-vm-kill-file pjb-strings pjb-cl cl)
    (pjb-computer-paper pjb-cl)
    (pjb-constants pjb-strings pjb-cl cl)
    (pjb-cvs pjb-dot pjb-graph pjb-object)
    (pjb-cvspass)
    (pjb-dot pjb-graph pjb-cl)
    (pjb-graph pjb-utilities pjb-strings pjb-class pjb-object eieio pjb-cl)
    (pjb-cl-faces pjb-sources pjb-cl cc-engine lisp-mode custom font-lock)
    (pjb-cl-magic-lambda-lists)
    (pjb-i2p-expression pjb-cl)
    (pjb-s2p-expression eieio pjb-cl pjb-strings pjb-utilities)
    (pjb-layers)
    (pjb-make-depends pjb-utilities pjb-list pjb-strings)
    (pjb-roman)
    (pjb-secouer pjb-cl)
    (pjb-server pjb-utilities pjb-queue pjb-cl)
    (pjb-transpose pjb-strings pjb-cl)
    (pjb-worldfact pjb-cl pjb-sources)
    (pjb-banks pjb-strings pjb-euro)
    (pjb-bourse pjb-object pjb-strings pjb-euro pjb-utilities pjb-list pjb-cl)
    (pjb-selftrade pjb-strings)))

(defparameter *reachable* (make-hash-table))


(defmethod adjacency-list ((file symbol))
  (cdr (assoc file *pjb-sources-order*)))

(defmethod reachable-list ((file symbol))
  (multiple-value-bind (rl got-it) (gethash file *reachable*)
    (if got-it
        rl
        (setf (gethash file *reachable*)
              (compute-closure (function adjacency-list) (adjacency-list file))))))

(find-cycles (mapcar (function car) *pjb-sources-order*))
;; --> ((pjb-emacs pjb-sources pjb-emacs)
;;      (pjb-sources pjb-emacs pjb-sources))
ViewGit