Make it so that DrRacket deletes .zo files when the corresponding source file isn't present anymore

(when in the DrRAcket-compiles-my-zo-files mode)
This commit is contained in:
Robby Findler 2010-12-16 15:04:20 -06:00
parent 5e51b7f335
commit ede60de584
3 changed files with 19 additions and 7 deletions

View File

@ -540,7 +540,8 @@
(lambda (src)
(parameterize ([current-load/use-compiled
(make-compilation-manager-load/use-compiled-handler/table
cache)])
cache
#f)])
(compile-root (car (use-compiled-file-paths))
(path->complete-path src)
cache
@ -548,10 +549,10 @@
#f)
(void)))))
(define (make-compilation-manager-load/use-compiled-handler)
(make-compilation-manager-load/use-compiled-handler/table (make-hash)))
(define (make-compilation-manager-load/use-compiled-handler [delete-zos-when-rkt-file-does-not-exist? #f])
(make-compilation-manager-load/use-compiled-handler/table (make-hash) delete-zos-when-rkt-file-does-not-exist?))
(define (make-compilation-manager-load/use-compiled-handler/table cache)
(define (make-compilation-manager-load/use-compiled-handler/table cache delete-zos-when-rkt-file-does-not-exist?)
(let ([orig-eval (current-eval)]
[orig-load (current-load)]
[orig-registry (namespace-module-registry (current-namespace))]
@ -564,7 +565,13 @@
(let ([p2 (rkt->ss path)])
(and (not (eq? path p2))
(file-exists? p2)))))
(trace-printf "skipping: ~a file does not exist" path)]
(trace-printf "skipping: ~a file does not exist" path)
(when delete-zos-when-rkt-file-does-not-exist?
(unless (null? modes)
(define to-delete (path-add-suffix (get-compilation-path (car modes) path) #".zo"))
(when (file-exists? to-delete)
(trace-printf "deleting: ~s" to-delete)
(delete-file to-delete))))]
[(or (null? (use-compiled-file-paths))
(not (equal? (car modes)
(car (use-compiled-file-paths)))))

View File

@ -247,7 +247,7 @@
(cons (build-path "compiled" "drracket" "errortrace")
(use-compiled-file-paths)))]))
(current-load/use-compiled (make-compilation-manager-load/use-compiled-handler))
(current-load/use-compiled (make-compilation-manager-load/use-compiled-handler #t))
(let* ([cd (find-system-path 'collects-dir)]
[no-dirs (list (CACHE-DIR)
(if (relative-path? cd)

View File

@ -117,7 +117,8 @@ and files as @exec{raco make}, so the two tools can be used together.
implements the compilation and dependency management used by
@exec{raco make} and @exec{raco setup}.}
@defproc[(make-compilation-manager-load/use-compiled-handler)
@defproc[(make-compilation-manager-load/use-compiled-handler
[delete-zos-when-rkt-file-does-not-exist? any/c #f])
(path? (or/c symbol? false/c) . -> . any)]{
Returns a procedure suitable as a value for the
@ -200,6 +201,10 @@ If @racket[use-compiled-file-paths] contains an empty list when
@racket[make-compilation-manager-load/use-compiled-handler] is called,
then @racket[exn:fail:contract] exception is raised.
If the @racket[delete-zos-when-rkt-file-does-not-exist?] argument is a true
value, then the returned handler will delete @filepath{.zo} files
when there is no corresponding original source file.
@emph{Do not} install the result of
@racket[make-compilation-manager-load/use-compiled-handler] when the
current namespace contains already-loaded versions of modules that may