add dry-run switch to render and setup

pull/218/head
Matthew Butterick 5 years ago
parent ab6691ea86
commit 72df2d2477

@ -28,22 +28,22 @@
(define (dispatch command-name)
(with-logging-to-port
(current-error-port)
(λ ()
(case command-name
[("test" "xyzzy") (handle-test)]
[(#f "help") (handle-help)]
[("start") (handle-start)] ; parses its own args
;; "second" arg is actually third in command line args, so use cddr not cdr
[("render") (handle-render)] ; render parses its own args from current-command-line-arguments
[("version") (handle-version)]
[("reset") (handle-reset (get-first-arg-or-current-dir))]
[("setup") (handle-setup)]
[("clone" "publish") (handle-publish)]
[else (handle-unknown command-name)]))
#:logger pollen-logger
'info
'pollen))
(current-error-port)
(λ ()
(case command-name
[("test" "xyzzy") (handle-test)]
[(#f "help") (handle-help)]
[("start") (handle-start)] ; parses its own args
;; "second" arg is actually third in command line args, so use cddr not cdr
[("render") (handle-render)] ; render parses its own args from current-command-line-arguments
[("version") (handle-version)]
[("reset") (handle-reset (get-first-arg-or-current-dir))]
[("setup") (handle-setup)]
[("clone" "publish") (handle-publish)]
[else (handle-unknown command-name)]))
#:logger pollen-logger
'info
'pollen))
(define (very-nice-path x)
(path->complete-path (simplify-path (cleanse-path (->path x)))))
@ -76,18 +76,20 @@ version print the version" (current-server-port) (make-publish-di
(define (handle-setup)
(message "preheating cache ...")
(define setup-parallel? (make-parameter #false))
(define dry-run? (make-parameter #false))
(define parsed-args
(command-line #:program "raco pollen setup"
#:argv (vector-drop (current-command-line-arguments) 1) ; snip the 'setup' from the front
#:once-any
[("-p" "--parallel") "Setup in parallel using all cores" (setup-parallel? #true)]
[("-j" "--jobs") job-count "Setup in parallel using <job-count> jobs" (setup-parallel? (or (string->number job-count) (raise-argument-error 'handle-setup "exact positive integer" job-count)))]
[("-d" "--dry-run") "Print paths that would be compiled" (dry-run? #true)]
#:args other-args
other-args))
(define starting-dir (match parsed-args
[(list dir) dir]
[_ (current-directory)]))
((dynamic-require 'pollen/private/preheat-cache 'preheat-cache) starting-dir (setup-parallel?)))
((dynamic-require 'pollen/private/preheat-cache 'preheat-cache) starting-dir (setup-parallel?) (dry-run?)))
(define (handle-render)
(define render-batch (dynamic-require 'pollen/render 'render-batch))
@ -96,6 +98,7 @@ version print the version" (current-server-port) (make-publish-di
(define render-target-wanted (make-parameter (current-poly-target)))
(define render-with-subdirs? (make-parameter #f))
(define render-parallel? (make-parameter #f))
(define dry-run? (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
@ -105,11 +108,18 @@ 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)]
[("-d" "--dry-run") "Print paths that would be rendered" (dry-run? #true)]
#:once-any
[("-p" "--parallel") "Render in parallel using all cores" (render-parallel? #true)]
[("-j" "--jobs") job-count "Render in parallel using <job-count> jobs" (render-parallel? (or (string->number job-count) (raise-argument-error 'handle-render "exact positive integer" job-count)))]
#:args other-args
other-args))
(define (handle-batch-render paths)
(if (dry-run?)
(for-each message paths)
(apply render-batch paths #:parallel (render-parallel?))))
(parameterize ([current-poly-target (render-target-wanted)]) ;; applies to both cases
(let loop ([args parsed-args])
(match args
@ -137,14 +147,14 @@ version print the version" (current-server-port) (make-publish-di
[_
(message (format "rendering preproc & pagetree files in directory ~a" dir))
(append preprocs static-pagetrees)])))
(apply render-batch paths-to-render #:parallel (render-parallel?))
(handle-batch-render paths-to-render)
(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) " ")))
(apply render-batch (map very-nice-path path-args) #:parallel (render-parallel?))]))))
(handle-batch-render (map very-nice-path path-args))]))))
(define (handle-start)
(define launch-wanted #f)
@ -193,7 +203,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)

@ -16,7 +16,7 @@
(and (file-exists? cache-db-file)
(hash-has-key? (file->value cache-db-file) (paths->key path))))
(define (preheat-cache starting-dir [wants-parallel-setup #false])
(define (preheat-cache starting-dir [wants-parallel-setup? #false] [wants-dry-run? #false])
(unless (and (path-string? starting-dir) (directory-exists? starting-dir))
(raise-argument-error 'preheat-cache "directory" starting-dir))
@ -33,17 +33,17 @@
(path->complete-path path)))
(cond
[(null? uncached-paths)
(message "all cached files are up to date")]
[wants-parallel-setup
[wants-dry-run? (for-each message uncached-paths)]
[(null? uncached-paths) (message "all cached files are up to date")]
[wants-parallel-setup?
(define job-count
(min
(length uncached-paths)
(match wants-parallel-setup
(match wants-parallel-setup?
[#true (processor-count)]
[(? exact-positive-integer? count) count]
[_ (raise-argument-error 'preheat-cache "exact positive integer" wants-parallel-setup)])))
[_ (raise-argument-error 'preheat-cache "exact positive integer" wants-parallel-setup?)])))
(define worker-evts
(for/list ([wpidx (in-range job-count)])

@ -1 +1 @@
1573164977
1573239737

@ -49,7 +49,7 @@ Displays a list of available commands.
Start the project server from the current directory using the default port, which is the value of the parameter @racket[current-server-port] (by default, port @id[default-project-server-port]).
This command can be invoked with two optional arguments, and one optional switch.
This command can be invoked with two optional arguments, and several optional switches.
@racket[raco pollen start _path] will start the project server from @racket[_path] rather than the current directory (making @racket[_path] its root directory).
@ -115,6 +115,8 @@ As a rule of thumb, parallel rendering works best if you do @exec{raco setup} fi
> raco pollen render -p
}
The optional @exec{--dry-run} or @exec{-d} switch prints the paths that would be rendered by this command without actually doing so.
@italic{Warning}: In all cases, the newly rendered output file will overwrite any previous output file.
@ -167,6 +169,8 @@ The alternative @exec{--jobs <count>} or @exec{-j <count>} switch does the same
> raco pollen setup -j 4
}
The optional @exec{--dry-run} or @exec{-d} switch prints the paths that would be compiled by this command without actually doing so.
@section{@exec{raco pollen reset}}

Loading…
Cancel
Save