2014-03-28 182 views
3

如何查找Common Lisp中給定項目的完整依賴關係樹?查找系統的依賴關係

我使用(ql-dist:dependency-tree "my-project")哪些錯誤((ql-dist:find-system "my-project")返回nil我的系統是否加載與否)審判,(slot-value (asdf/system:find-system "my-project") 'asdf/component:sideway-dependencies)似乎只返回直接依賴,我正在尋找完整的樹(也彷彿回到有條件/特定於實現的依賴關係,例如sb-posixsb-bsd-sockets,我寧願不這樣做)。

是否有一個標準的單步執行此操作的方法,或者是否需要遞歸地執行該sideway-dependencies插槽的輸出並以特殊方式過濾?

回答

1

下面是在解決方案的裂縫:

取3(這也許可能是在這個階段自己的項目)

(defgeneric ->key (thing)) 

(defmethod ->key ((thing string)) 
    (intern (string-upcase thing) :keyword)) 

(defmethod ->key ((thing symbol)) 
    (if (keywordp thing) 
     thing 
     (intern (symbol-name thing) :keyword))) 

(defgeneric dependencies-of (system)) 
(defmethod dependencies-of ((system symbol)) 
    (mapcar #'->key (slot-value (asdf/system:find-system system) 'asdf/component:sideway-dependencies))) 

(defun ordered-dep-tree (dep-tree) 
    (let ((res)) 
    (labels ((in-res? (dep-name) (member dep-name res)) 
      (insert-pass (remaining) 
       (loop for (dep . sub-deps) in remaining 
         for unmet-sub-deps = (remove-if #'in-res? sub-deps) 
         if (null unmet-sub-deps) do (push dep res) 
         else collect (cons dep unmet-sub-deps) into next-rems 
         finally (return next-rems)))) 
     (loop for (dep . callers) in dep-tree for deps-of = (dependencies-of dep) 
      if (null deps-of) do (push dep res) 
      else collect (cons dep deps-of) into non-zeros 
      finally (loop while non-zeros 
          do (setf non-zeros (insert-pass non-zeros))))) 
     (reverse res))) 

(defgeneric dependency-tree (system)) 
(defmethod dependency-tree ((system symbol)) 
    (let ((res (make-hash-table))) 
    (labels ((rec (sys) 
       (loop with deps = (dependencies-of sys) 
        for dep in deps for dep-k = (->key dep) 
        unless (gethash dep-k res) do (rec dep) 
        do (pushnew (->key sys) (gethash dep-k res))))) 
     (rec system)) 
    (ordered-dep-tree (alexandria:hash-table-alist res)))) 

仍然無法爲sb-*式的篩選包,但我想我可以做一個單獨的通行證。它似乎工作,雖然...

CL-USER> (dependency-tree :hunchentoot) 

(:SB-BSD-SOCKETS :TRIVIAL-BACKTRACE :RFC2388 :SB-ROTATE-BYTE 
:TRIVIAL-GARBAGE :TRIVIAL-FEATURES :CL-PPCRE :ALEXANDRIA :SB-POSIX 
:CL-BASE64 :TRIVIAL-GRAY-STREAMS :USOCKET :MD5 :BABEL :FLEXI-STREAMS 
:BORDEAUX-THREADS :CHUNGA :CFFI :CL-FAD :CL+SSL) 

認爲這是需要:hunchentoot之前加載的所有包的列表中,它們可以被加載的順序呈現(不包其所有相關性之前出現出現)。它不處理循環依賴,但我不認爲asdf也是,所以...