skip unnecessary steps for non-interactive sessions

dev-nonsettable
Matthew Butterick 4 years ago
parent 7163f9bc77
commit 149f2cc389

@ -61,38 +61,44 @@
(define-namespace-anchor cache-utils-module-ns) (define-namespace-anchor cache-utils-module-ns)
(define my-caching-compile-proc (make-caching-managed-compile-zo)) ;; faster than the usual `managed-compile-zo`
;; check 'gc not 'vm because 'gc is supported before 6.7 (define caching-zo-compiler (make-caching-managed-compile-zo))
(define running-on-cs? (eq? (system-type 'gc) 'cs))
(define (path->hash path) (define (path->hash path)
(for ([p (in-list (or (get-directory-require-files path) null))]) (define compilation-namespace
(my-caching-compile-proc p)) (cond
(when running-on-cs? [(current-session-interactive?)
;; this makes builds faster, ;; in interactive mode, we need a fresh namespace every time
;; but a bytecode-caching bug in Racket BC ;; and can't use bytecode, because it's possible that path
;; restricts it to CS for now ;; or any dependency (say, "pollen.rkt") has changed
(my-caching-compile-proc path)) (define bns (make-base-namespace))
(apply hasheq (define outer-ns (namespace-anchor->namespace cache-utils-module-ns))
(let ([doc-key (setup:main-export)] [meta-key (setup:meta-export)]) ;; bring in currently instantiated params (unlike namespace-require)
(unless (and (symbol? doc-key) (symbol? meta-key)) (namespace-attach-module outer-ns 'pollen/setup bns)
(raise-argument-error 'path->hash "symbols for doc and meta key" (cons doc-key meta-key))) bns]
;; I monkeyed around with using the metas submodule to pull out the metas (for speed) [else
;; but in practice most files get their doc requested too. ;; make bytecode, because we know that in a non-interactive sesssion
;; so it's just simpler to get both at once and be done with it. ;; the sources won't change in the midst
;; the savings of avoiding two cache fetches at the outset outweighs (for-each caching-zo-compiler (cons path (or (get-directory-require-files path) null)))
;; the benefit of not reloading doc when you just need metas. ; recycle namespace
;; new namespace forces `dynamic-require` to re-instantiate `path` (current-namespace)]))
;; otherwise it gets cached in current namespace. (define doc-key (setup:main-export))
(parameterize ([current-namespace (make-base-namespace)] (define meta-key (setup:meta-export))
[current-directory (dirname path)]) (unless (and (symbol? doc-key) (symbol? meta-key))
;; brings in currently instantiated params (unlike namespace-require) (raise-argument-error 'path->hash "symbols for doc and meta key" (cons doc-key meta-key)))
(define outer-ns (namespace-anchor->namespace cache-utils-module-ns)) ;; I monkeyed around with using the metas submodule to pull out the metas (for speed)
(namespace-attach-module outer-ns 'pollen/setup) ;; but in practice most files get their doc requested too.
(define doc-missing-thunk (λ () "")) ;; so it's just simpler to get both at once and be done with it.
(define metas-missing-thunk (λ () (hasheq))) ;; the savings of avoiding two cache fetches at the outset outweighs
(list doc-key (dynamic-require path doc-key doc-missing-thunk) ;; the benefit of not reloading doc when you just need metas.
meta-key (dynamic-require path meta-key metas-missing-thunk)))))) ;; new namespace forces `dynamic-require` to re-instantiate `path`
;; otherwise it gets cached in current namespace.
(define doc-missing-thunk (λ () ""))
(define metas-missing-thunk (λ () (hasheq)))
(parameterize ([current-namespace compilation-namespace]
[current-directory (dirname path)])
(hasheq doc-key (dynamic-require path doc-key doc-missing-thunk)
meta-key (dynamic-require path meta-key metas-missing-thunk))))
(define (my-make-directory* dir) (define (my-make-directory* dir)
(define base (dirname dir)) (define base (dirname dir))
@ -151,5 +157,5 @@
"cache attempt failed: could not acquire shared lock") (void)] "cache attempt failed: could not acquire shared lock") (void)]
[_ (log-pollen-error str)]))) [_ (log-pollen-error str)])))
#;(with-input-from-file dest-file #;(with-input-from-file dest-file
(λ () (fasl->s-exp (port->bytes)))) (λ () (fasl->s-exp (port->bytes))))
(deserialize (file->value dest-file))) (deserialize (file->value dest-file)))

@ -192,7 +192,8 @@ version print the version" (current-server-port) (make-publish-di
(error (format "~a is not a valid port number" http-port))) (error (format "~a is not a valid port number" http-port)))
(parameterize ([current-project-root dir] (parameterize ([current-project-root dir]
[current-server-port (or http-port (setup:project-server-port))] [current-server-port (or http-port (setup:project-server-port))]
[current-server-listen-ip (and localhost-wanted "127.0.0.1")]) [current-server-listen-ip (and localhost-wanted "127.0.0.1")]
[current-session-interactive? #true])
(message "starting project server ...") (message "starting project server ...")
((dynamic-require 'pollen/private/project-server 'start-server) (format "/~a" (setup:main-pagetree dir)) launch-wanted))) ((dynamic-require 'pollen/private/project-server 'start-server) (format "/~a" (setup:main-pagetree dir)) launch-wanted)))

@ -1 +1 @@
1588786944 1588815041

@ -106,6 +106,11 @@
(define+provide current-render-source (make-parameter #f)) (define+provide current-render-source (make-parameter #f))
;; used to distinguish one-shot rendering (e.g., using `raco pollen setup` or `render`
;; from an interactive session with the project server (using `raco pollen start`)
;; in one-shot mode, certain features needed for dynamic recompilation are disabled for speed.
(define+provide current-session-interactive? (make-parameter #false))
(define-settable dashboard-css "poldash.css") (define-settable dashboard-css "poldash.css")
(define-runtime-path server-extras-dir "private/server-extras") (define-runtime-path server-extras-dir "private/server-extras")

@ -16,7 +16,8 @@
;; test makes sure that file render changes after pollen.rkt changes ;; test makes sure that file render changes after pollen.rkt changes
(parameterize ([current-output-port (open-output-string)] (parameterize ([current-output-port (open-output-string)]
[current-directory rerequire-dir] [current-directory rerequire-dir]
[current-project-root rerequire-dir]) [current-project-root rerequire-dir]
[current-session-interactive? #true])
(display-to-file @string-append{#lang racket/base (display-to-file @string-append{#lang racket/base
(provide id) (provide id)

Loading…
Cancel
Save