2005-02-24 09:30:07 -05:00
|
|
|
(define (rc->dfs-node rc)
|
2005-03-08 08:14:36 -05:00
|
|
|
(let ((target (rule-cand-target rc))
|
|
|
|
(prereqs (rule-cand-prereqs rc))
|
|
|
|
(wants-build? (rule-cand-up-to-date?-func rc))
|
|
|
|
(build-func (rule-cand-build-func rc)))
|
2005-02-24 09:30:07 -05:00
|
|
|
(make-dfs target prereqs (list wants-build? build-func))))
|
|
|
|
|
2005-01-21 10:40:59 -05:00
|
|
|
(define (rcs->dag rcs)
|
|
|
|
(map (lambda (rc)
|
2005-03-08 08:14:36 -05:00
|
|
|
(let ((target (rule-cand-target rc))
|
|
|
|
(prereqs (rule-cand-prereqs rc))
|
|
|
|
(wants-build? (rule-cand-up-to-date?-func rc))
|
|
|
|
(build-func (rule-cand-build-func rc)))
|
2005-02-04 03:05:55 -05:00
|
|
|
(make-dfs target prereqs (list wants-build? build-func))))
|
2005-01-21 10:40:59 -05:00
|
|
|
rcs))
|
|
|
|
|
|
|
|
(define (dag->rcs dag)
|
|
|
|
(map (lambda (node)
|
|
|
|
(let* ((ls (dfs->list node))
|
2005-02-04 03:05:55 -05:00
|
|
|
(target (list-ref ls 0))
|
|
|
|
(prereqs (list-ref ls 1))
|
|
|
|
(ignored (list-ref ls 2)))
|
|
|
|
(if ignored
|
|
|
|
(let ((wants-build? (car ignored))
|
|
|
|
(build-func (cadr ignored)))
|
2005-03-08 08:14:36 -05:00
|
|
|
(make-rule-cand target prereqs wants-build? build-func))
|
2005-02-24 09:30:07 -05:00
|
|
|
(error "node without wants-build? and build-func"))))
|
2005-01-21 10:40:59 -05:00
|
|
|
dag))
|
|
|
|
|
2005-03-08 08:14:36 -05:00
|
|
|
(define (lookup-rc pred rc rcs)
|
2005-01-21 10:40:59 -05:00
|
|
|
(let ((maybe-rc (find (lambda (current)
|
2005-03-08 08:14:36 -05:00
|
|
|
(pred (car rc) (car current)))
|
2005-01-21 10:40:59 -05:00
|
|
|
rcs)))
|
|
|
|
(if maybe-rc maybe-rc (error "lookup-rc: rc not found."))))
|
|
|
|
|
2005-03-08 08:14:36 -05:00
|
|
|
(define (lookup-fname pred fname rcs)
|
2005-03-07 12:37:46 -05:00
|
|
|
(let ((maybe-fname (find (lambda (current)
|
2005-03-08 08:14:36 -05:00
|
|
|
(pred fname (car current)))
|
2005-02-04 03:05:55 -05:00
|
|
|
rcs)))
|
2005-03-10 04:49:34 -05:00
|
|
|
(if maybe-fname maybe-fname #f)))
|
2005-01-21 10:40:59 -05:00
|
|
|
|
2005-03-07 12:37:46 -05:00
|
|
|
(define (lookup-rule pred fname rules)
|
|
|
|
(let ((maybe-rule (find (lambda (current)
|
|
|
|
(pred fname (car current)))
|
|
|
|
rules)))
|
2005-02-04 03:05:55 -05:00
|
|
|
(if maybe-rule
|
|
|
|
(cdr maybe-rule)
|
|
|
|
(error "lookup-rule: fname not found in rules."))))
|
2005-01-21 04:09:31 -05:00
|
|
|
|
2005-03-07 12:37:46 -05:00
|
|
|
(define (rcs+commons->rules pred rule-candidates common-rcs)
|
2005-02-24 09:30:07 -05:00
|
|
|
(let* ((common-rules (common-rcs->common-rules common-rcs))
|
|
|
|
(create-leaf (lambda (maybe-target)
|
|
|
|
(rc->dfs-node
|
|
|
|
(search-match-in-common-rules common-rules
|
|
|
|
maybe-target))))
|
2005-03-08 08:14:36 -05:00
|
|
|
(unsorted-dag (rcs->dag rule-candidates))
|
|
|
|
(sorted-dag (dfs unsorted-dag pred #t create-leaf))
|
2005-02-04 03:05:55 -05:00
|
|
|
(sorted-rcs (dag->rcs sorted-dag)))
|
2005-03-08 08:14:36 -05:00
|
|
|
;; (dfs-dag-show sorted-dag)
|
2005-02-04 03:05:55 -05:00
|
|
|
(if (not (null? sorted-rcs))
|
|
|
|
(let for-all-rcs ((rc (car sorted-rcs))
|
|
|
|
(todo (cdr sorted-rcs))
|
|
|
|
(last-done '()))
|
2005-03-08 08:14:36 -05:00
|
|
|
(let* ((target (rule-cand-target rc))
|
|
|
|
(prereqs (rule-cand-prereqs rc))
|
|
|
|
(wants-build? (rule-cand-up-to-date?-func rc))
|
|
|
|
(build-func (rule-cand-build-func rc))
|
2005-02-04 03:05:55 -05:00
|
|
|
(done (cons (cons target
|
2005-03-07 12:37:46 -05:00
|
|
|
(make-rule (map (lambda (prereq)
|
|
|
|
(lookup-rule pred
|
|
|
|
prereq
|
|
|
|
last-done))
|
2005-02-04 03:05:55 -05:00
|
|
|
prereqs)
|
|
|
|
wants-build?
|
|
|
|
build-func))
|
|
|
|
last-done)))
|
2005-03-07 12:37:46 -05:00
|
|
|
(if (null? todo)
|
|
|
|
done
|
|
|
|
(for-all-rcs (car todo) (cdr todo) done))))
|
|
|
|
sorted-rcs)))
|
2005-02-04 03:05:55 -05:00
|
|
|
|
|
|
|
(define (rules->rule-set rule-alist)
|
|
|
|
(if (not (null? rule-alist))
|
|
|
|
(let ((rules (map cdr rule-alist)))
|
|
|
|
(let for-each-rule ((current-rule (car rules))
|
|
|
|
(rules-to-do (cdr rules))
|
|
|
|
(rule-set (make-empty-rule-set)))
|
|
|
|
(let ((next-rule-set (rule-set-add current-rule rule-set)))
|
|
|
|
(if (not (null? rules-to-do))
|
2005-03-08 08:14:36 -05:00
|
|
|
(for-each-rule (car rules-to-do)
|
2005-02-04 03:05:55 -05:00
|
|
|
(cdr rules-to-do)
|
|
|
|
next-rule-set)
|
|
|
|
next-rule-set))))))
|