From 1de0eff38d5d2b6981d2662b93ccecc34c0934d0 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Sun, 3 May 2020 10:14:33 -0700 Subject: [PATCH] add --force option to raco pollen render, take 2 --- pollen/private/command.rkt | 28 +++++++++++++++++++--------- pollen/private/ts.rktd | 2 +- pollen/scribblings/raco.scrbl | 2 ++ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/pollen/private/command.rkt b/pollen/private/command.rkt index 3f0ed24..f708855 100644 --- a/pollen/private/command.rkt +++ b/pollen/private/command.rkt @@ -1,4 +1,4 @@ -#lang racket/base +#lang debug racket/base (require racket/file racket/path racket/vector @@ -44,11 +44,11 @@ [(let ([str (getenv "PLTSTDERR")]) (and str (regexp-match "@pollen" str))) (dispatch-thunk)] [else (with-logging-to-port - (current-error-port) - dispatch-thunk - #:logger pollen-logger - 'info - 'pollen)])) + (current-error-port) + dispatch-thunk + #:logger pollen-logger + 'info + 'pollen)])) (define (very-nice-path x) (path->complete-path (simplify-path (cleanse-path (->path x))))) @@ -104,6 +104,7 @@ version print the version" (current-server-port) (make-publish-di (define render-with-subdirs? (make-parameter #f)) (define render-parallel? (make-parameter #f)) (define special-output? (make-parameter #f)) + (define force-render? (make-parameter #f)) (define parsed-args (command-line #:program "raco pollen render" #:argv (vector-drop (current-command-line-arguments) 1) ; snip the 'render' from the front @@ -113,6 +114,7 @@ version print the version" (current-server-port) (make-publish-di [("-r" "--recursive") "Render subdirectories recursively" (render-with-subdirs? 'recursive)] [("-s" "--subdir") "Render subdirectories nonrecursively" (render-with-subdirs? 'include)] + [("-f" "--force") "Force render" (force-render? #true)] #:once-any [("-d" "--dry-run") "Print paths that would be rendered" (special-output? 'dry-run)] [("-n" "--null") "Suppress file output" (special-output? 'null)] @@ -122,7 +124,15 @@ version print the version" (current-server-port) (make-publish-di #:args other-args other-args)) + (define timestamp (current-seconds)) ; keeps timestamp consistent through whole render (define (handle-batch-render paths) + (when (force-render?) + ;; forcing works like `touch`: updates the mod date of the files, + ;; which invalidates any cached results. + (for* ([path (in-list paths)] + [sp (in-value (get-source path))] + #:when sp) + (file-or-directory-modify-seconds sp timestamp))) (apply render-batch (map very-nice-path paths) #:parallel (render-parallel?) #:special (special-output?))) (parameterize ([current-poly-target (render-target-wanted)]) ;; applies to both cases @@ -153,7 +163,7 @@ version print the version" (current-server-port) (make-publish-di (when (render-with-subdirs?) (for ([path (in-list dirlist)] #:when (directory-exists? path)) - (render-one-dir (->complete-path path)))))))] + (render-one-dir (->complete-path path)))))))] [path-args ;; path mode (message (format "rendering ~a" (string-join (map ->string path-args) " "))) (handle-batch-render path-args)])))) @@ -205,7 +215,7 @@ version print the version" (current-server-port) (make-publish-di (and (>= (length xs) (length prefix)) (andmap equal? prefix (for/list ([(x idx) (in-indexed xs)] #:break (= idx (length prefix))) - x)))) + x)))) ((explode-path possible-subdir) . has-prefix? . (explode-path possible-superdir))) (define (handle-publish) @@ -268,7 +278,7 @@ version print the version" (current-server-port) (make-publish-di [do-publish-operation? (when (directory-exists? dest-dir) (with-handlers ([exn:fail:filesystem? (λ (exn) (raise-user-error 'publish (format "operation failed: could not delete ~a" dest-dir)))]) - (delete-directory/files dest-dir))) + (delete-directory/files dest-dir))) (copy-directory/files source-dir dest-dir) ;; if source-dir is provided, we want it to be treated as current-directory. ;; if no source-dir is provided, it is set to current-directory, diff --git a/pollen/private/ts.rktd b/pollen/private/ts.rktd index 0701088..67b7703 100644 --- a/pollen/private/ts.rktd +++ b/pollen/private/ts.rktd @@ -1 +1 @@ -1588261516 +1588526073 diff --git a/pollen/scribblings/raco.scrbl b/pollen/scribblings/raco.scrbl index 2e09d37..ef2dc8a 100644 --- a/pollen/scribblings/raco.scrbl +++ b/pollen/scribblings/raco.scrbl @@ -83,6 +83,8 @@ This command can be invoked two ways: in source mode or directory mode. In both modes, the optional @exec{--dry-run} or @exec{-d} switch prints the paths that would be rendered by this command without actually doing so. +In both modes, the optional @exec{--force} or @exec{-f} switch forces a fresh render from source, even if the file is already cached, by updating the modification date of the file (à la @exec{touch}). Thus, if modification dates are important to you, don't use this option. + In both modes, the optional @exec{--null} or @exec{-n} switch renders as usual, but doesn't write any files. (Convenient if you're arranging special render behavior, for instance writing to a database or network server.)