From ede60de584f2e99cb99f34393ee00a08e598fdd0 Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Thu, 16 Dec 2010 15:04:20 -0600 Subject: [PATCH] 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) --- collects/compiler/cm.rkt | 17 ++++++++++++----- collects/drracket/private/module-language.rkt | 2 +- collects/scribblings/raco/make.scrbl | 7 ++++++- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/collects/compiler/cm.rkt b/collects/compiler/cm.rkt index ef4e1cd820..b4a0e2b25d 100644 --- a/collects/compiler/cm.rkt +++ b/collects/compiler/cm.rkt @@ -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))))) diff --git a/collects/drracket/private/module-language.rkt b/collects/drracket/private/module-language.rkt index 054dd60c06..71d1f568c9 100644 --- a/collects/drracket/private/module-language.rkt +++ b/collects/drracket/private/module-language.rkt @@ -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) diff --git a/collects/scribblings/raco/make.scrbl b/collects/scribblings/raco/make.scrbl index 0c226af111..8f0419cc02 100644 --- a/collects/scribblings/raco/make.scrbl +++ b/collects/scribblings/raco/make.scrbl @@ -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