Keep track of (and return) a list of modules (re)loaded during dynamic-rerequire
This commit is contained in:
parent
012e08cd74
commit
9fb5346652
|
@ -7,7 +7,7 @@
|
|||
|
||||
@defproc[(dynamic-rerequire [module-path module-path?]
|
||||
[#:verbosity verbosity (or/c 'all 'reload 'none) 'reload])
|
||||
void?]{
|
||||
(listof string?)]{
|
||||
|
||||
Like @racket[(dynamic-require module-path 0)], but with reloading
|
||||
support. The @racket[dynamic-rerequire] function is intended for use
|
||||
|
@ -22,6 +22,10 @@ module is re-loaded. Re-loading support works only for modules that
|
|||
are first loaded (either directly or indirectly through transitive
|
||||
@racket[require]s) via @racket[dynamic-rerequire].
|
||||
|
||||
The returned list contains the absolute paths to the modules that were
|
||||
reloaded on this call to @racket[dynamic-rerequire]. If ths returned
|
||||
list is empty, no modules were changed or loaded.
|
||||
|
||||
When @racket[enter!] loads or re-loads a module from a file, it can
|
||||
print a message to @racket[(current-error-port)], depending on
|
||||
@racket[verbosity]: @racket['verbose] prints a message for all loads and
|
||||
|
|
|
@ -16,20 +16,25 @@
|
|||
(define loaded (make-hash))
|
||||
|
||||
(define (rerequire mod verbosity)
|
||||
(define loaded-paths '())
|
||||
(define (collect-loaded-path! path) (set! loaded-paths (cons path loaded-paths)))
|
||||
;; Collect dependencies while loading:
|
||||
(parameterize ([current-load/use-compiled
|
||||
(rerequire-load/use-compiled (current-load/use-compiled)
|
||||
#f verbosity)])
|
||||
#f verbosity collect-loaded-path!)])
|
||||
(dynamic-require mod 0))
|
||||
;; Reload anything that's not up to date:
|
||||
(check-latest mod verbosity))
|
||||
(check-latest mod verbosity collect-loaded-path!)
|
||||
;; Return a list of the paths that were loaded this time, in order:
|
||||
(reverse loaded-paths))
|
||||
|
||||
(define (rerequire-load/use-compiled orig re? verbosity)
|
||||
(define (rerequire-load/use-compiled orig re? verbosity path-collector)
|
||||
(define notify
|
||||
(if (or (eq? 'all verbosity) (and re? (eq? 'reload verbosity)))
|
||||
(lambda (path)
|
||||
(eprintf " [~aloading ~a]\n" (if re? "re-" "") path))
|
||||
void))
|
||||
(eprintf " [~aloading ~a]\n" (if re? "re-" "") path)
|
||||
(path-collector path))
|
||||
path-collector))
|
||||
(lambda (path name)
|
||||
(if (and name
|
||||
(not (and (pair? name)
|
||||
|
@ -79,7 +84,7 @@
|
|||
(values -inf.0 path)))
|
||||
(values -inf.0 path)))))
|
||||
|
||||
(define (check-latest mod verbosity)
|
||||
(define (check-latest mod verbosity path-collector)
|
||||
(define mpi (module-path-index-join mod #f))
|
||||
(define done (make-hash))
|
||||
(let loop ([mpi mpi])
|
||||
|
@ -97,8 +102,8 @@
|
|||
(when (ts . > . (mod-timestamp mod))
|
||||
(define orig (current-load/use-compiled))
|
||||
(parameterize ([current-load/use-compiled
|
||||
(rerequire-load/use-compiled orig #f verbosity)]
|
||||
(rerequire-load/use-compiled orig #f verbosity path-collector)]
|
||||
[current-module-declare-name rpath]
|
||||
[current-module-declare-source actual-path])
|
||||
((rerequire-load/use-compiled orig #t verbosity)
|
||||
((rerequire-load/use-compiled orig #t verbosity path-collector)
|
||||
npath (mod-name mod)))))))))
|
||||
|
|
Loading…
Reference in New Issue
Block a user