From 5bcb70a7bee680ad5b941e257057fac73558117d Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Thu, 22 Aug 2019 11:14:55 -0700 Subject: [PATCH] permit environment variables in watchlist --- pollen/private/cache-utils.rkt | 8 ++++++-- pollen/private/ts.rktd | 2 +- pollen/scribblings/setup.scrbl | 6 ++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/pollen/private/cache-utils.rkt b/pollen/private/cache-utils.rkt index 3741e1c..dfb5874 100644 --- a/pollen/private/cache-utils.rkt +++ b/pollen/private/cache-utils.rkt @@ -7,6 +7,7 @@ racket/file racket/path racket/list + racket/string racket/serialize sugar/coerce sugar/test @@ -22,6 +23,7 @@ ;; because cache validity is not sensitive to mod date of output path ;; (in fact we would expect it to be earlier, since we want to rely on an earlier version) (define (paths->key source-path [template-path #false] [output-path #false]) + (define-values (env-watchlist path-watchlist) (partition bytes? (setup:cache-watchlist source-path))) (define path-strings-to-track (list* source-path ;; if template has a source file, track that instead @@ -29,8 +31,10 @@ ;; is either list of files or (list #f) (append (->list (get-directory-require-files source-path)) ;; user-designated files to track - (map ->string (setup:cache-watchlist source-path))))) + (map ->string path-watchlist)))) (define pollen-env (getenv default-env-name)) + (define env-rec (for/list ([env-name (in-list (sort env-watchlist bytesstring cp) (file-or-directory-modify-seconds cp #false (λ () 0)))] [else #false]))) - (list* pollen-env poly-flag (and output-path (path->string output-path)) path+mod-time-pairs)) + (append env-rec (list pollen-env poly-flag (and output-path (path->string output-path))) path+mod-time-pairs)) (define (key->source-path key) (car (fourth key))) (define (key->output-path key) (third key)) diff --git a/pollen/private/ts.rktd b/pollen/private/ts.rktd index 740ef89..2f73eac 100644 --- a/pollen/private/ts.rktd +++ b/pollen/private/ts.rktd @@ -1 +1 @@ -1565713996 +1566497695 diff --git a/pollen/scribblings/setup.scrbl b/pollen/scribblings/setup.scrbl index 747eb3c..1892e9e 100644 --- a/pollen/scribblings/setup.scrbl +++ b/pollen/scribblings/setup.scrbl @@ -106,9 +106,9 @@ Default separators used in decoding. @defoverridable[compile-cache-max-size exact-positive-integer?]{Maximum size of the compile cache.} -@defoverridable[cache-watchlist (listof (or/c path? path-string?))]{List of extra files that the cache (= render cache + compile cache, collectively) watches during a project-server session. If one of the files on the watchlist changes, the cache is invalidated (just as it would be if @racket["pollen.rkt"] changed). +@defoverridable[cache-watchlist (listof (or/c path? path-string? bytes?))]{List of extra things that the cache (= render cache + compile cache, collectively) watches during a project-server session, which can be files (each given as a @racket[path?] or @racket[path-string?]) and environment variables (each given as @racket[bytes?]). -If the cache can't find a certain file on the watchlist, no error will arise. The file will simply be ignored. Therefore, to avoid unexpected behavior, the best policy is to use complete paths (or path strings). One way to generate a complete path to a local file is with @racket[define-runtime-path]. Another way, if you're using a module that's already installed as part of a package, is with @racket[resolve-module-path]: +Here's how files on the watchlist are handled. If one of the files on the watchlist changes, the cache is invalidated (just as it would be if @racket["pollen.rkt"] changed). If the cache can't find a certain file on the watchlist, no error will arise. The file will simply be ignored. Therefore, to avoid unexpected behavior, the best policy is to use complete paths (or path strings). One way to generate a complete path to a local file is with @racket[define-runtime-path]. Another way, if you're using a module that's already installed as part of a package, is with @racket[resolve-module-path]: @fileblock["pollen.rkt" @codeblock{ @@ -120,6 +120,8 @@ If the cache can't find a certain file on the watchlist, no error will arise. Th (define cache-watchlist (list my-local-mod my-installed-mod))) }] +Here's how environment variables on the watchlist are handled. Ordinarily the cache only watches the default @racket[#"POLLEN"] environment variable. By listing other environment variables in the watchlist, Pollen will watch those too. Unlike files, environment variables don't change during a session. But separate caches will be maintained for each distinct value of an environment variable. + @history[#:added "1.4"] }