From 8fc3d25be4fffc1cace11985a913701d8c816ef3 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Fri, 11 May 2012 06:28:22 -0600 Subject: [PATCH] cm: collect dependencies for submodules --- collects/compiler/cm.rkt | 21 +++++++++++++++------ collects/tests/racket/cm.rktl | 9 +++++---- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/collects/compiler/cm.rkt b/collects/compiler/cm.rkt index df1331b2c2..d2f827dc6a 100644 --- a/collects/compiler/cm.rkt +++ b/collects/compiler/cm.rkt @@ -121,12 +121,21 @@ (t (string-append (indent) (apply format fmt args)))))) (define (get-deps code path) - (filter-map (lambda (x) - (let* ([r (resolve-module-path-index x path)] - [r (if (pair? r) (cadr r) r)]) - (and (path? r) - (path->bytes r)))) - (append-map cdr (module-compiled-imports code)))) + (define ht + (let loop ([code code] [ht (hash)]) + (define new-ht + (for*/fold ([ht ht]) ([imports (in-list (module-compiled-imports code))] + [x (in-list (cdr imports))]) + (let* ([r (resolve-module-path-index x path)] + [r (if (pair? r) (cadr r) r)]) + (if (and (path? r) + (not (equal? path r))) + (hash-set ht (path->bytes r) #t) + ht)))) + (for*/fold ([ht new-ht]) ([non-star? (in-list '(#f #t))] + [subcode (in-list (module-compiled-submodules code non-star?))]) + (loop subcode ht)))) + (for/list ([k (in-hash-keys ht)]) k)) (define (get-compilation-dir+name mode path) (let-values ([(base name must-be-dir?) (split-path path)]) diff --git a/collects/tests/racket/cm.rktl b/collects/tests/racket/cm.rktl index d199588e0b..b96cf6ffe8 100644 --- a/collects/tests/racket/cm.rktl +++ b/collects/tests/racket/cm.rktl @@ -85,12 +85,13 @@ ("f.rkt" "(module f scheme/base (provide (all-from-out scheme/base)))" #t) ("g.rkt" "(module g scheme/base (require (for-syntax scheme/base scheme/include \"i.rkt\")) (define-syntax (f stx) (include \"h.sch\")))" #t) ("h.sch" "(quote-syntax 12)" #f) - ("i.rkt" "(module i scheme/base)" #t)) + ("i.rkt" "(module i scheme/base)" #t) + ("j.rkt" "(module j racket/base (module+ main (require \"b.rkt\")))" #t)) '([("a.rkt") ("a.rkt") ("a.rkt")] - [("b.rkt") ("a.rkt") ("a.rkt" "b.rkt")] - [("b.rkt") ("b.rkt") ("b.rkt")] + [("b.rkt") ("a.rkt") ("a.rkt" "b.rkt" "j.rkt")] + [("b.rkt") ("b.rkt") ("b.rkt" "j.rkt")] [() ("a.rkt") ("a.rkt")] - [("c.sch") ("a.rkt") ("a.rkt" "b.rkt")] + [("c.sch") ("a.rkt") ("a.rkt" "b.rkt" "j.rkt")] [("f.rkt") ("a.rkt") ("a.rkt" "d.rkt" "f.rkt")] [("e.rkt") ("e.rkt") ("e.rkt")] [() ("a.rkt") ("a.rkt" "d.rkt")]