mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-12-25 15:33:20 +03:00
Refactor: Move dfs to its own function so that we can use let*.
This commit is contained in:
parent
898440d4f5
commit
b9f2df85ef
@ -2,6 +2,7 @@
|
||||
|
||||
(require json)
|
||||
(require racket/file)
|
||||
(require racket/function)
|
||||
(require racket/match)
|
||||
(require racket/list)
|
||||
(require racket/set)
|
||||
@ -16,8 +17,17 @@
|
||||
;; that we traverse foo-lib, and that subsequently generating the
|
||||
;; foo-lib dream-lock requires repeating the same traversal of foo-lib. How can this be avoided?
|
||||
|
||||
;; TODO: no effort is made to handle cycles right now
|
||||
(define (dfs graph u dependency-subgraph)
|
||||
(if (hash-has-key? dependency-subgraph u)
|
||||
dependency-subgraph
|
||||
(let ([destinations (hash-ref graph u)])
|
||||
(foldl (curry dfs graph)
|
||||
(hash-set dependency-subgraph u destinations)
|
||||
destinations))))
|
||||
|
||||
(define (generate-dream-lock pkgs-all-path)
|
||||
(letrec ([src-path (getenv "RACKET_SOURCE")]
|
||||
(let* ([src-path (getenv "RACKET_SOURCE")]
|
||||
[rel-path (getenv "RACKET_RELPATH")]
|
||||
[package-path (simplify-path (cleanse-path (build-path src-path (if (string=? rel-path "")
|
||||
'same
|
||||
@ -76,15 +86,7 @@
|
||||
[names-of-overridden-packages (apply set (map car dep-list-overrides))]
|
||||
[graph (make-immutable-hash (append dep-alist-from-catalog
|
||||
dep-list-overrides))]
|
||||
;; TODO: no effort is made to handle cycles right now
|
||||
[dfs (lambda (u dependency-subgraph)
|
||||
(if (hash-has-key? dependency-subgraph u)
|
||||
dependency-subgraph
|
||||
(let ([destinations (hash-ref graph u)])
|
||||
(foldl dfs
|
||||
(hash-set dependency-subgraph u destinations)
|
||||
destinations))))]
|
||||
[dependency-subgraph (dfs package-name (make-immutable-hash))]
|
||||
[dependency-subgraph (dfs graph package-name (make-immutable-hash))]
|
||||
[generic (make-immutable-hash
|
||||
`((subsystem . "racket")
|
||||
(location . ,rel-path)
|
||||
|
Loading…
Reference in New Issue
Block a user