use `envvar-watchlist`

pull/218/head
Matthew Butterick 5 years ago
parent 070b9655d2
commit f161f5f465

@ -1,4 +1,4 @@
#lang racket/base
#lang debug racket/base
(require "file-utils.rkt"
"../setup.rkt"
"project.rkt"
@ -7,6 +7,7 @@
racket/file
racket/path
racket/list
racket/match
racket/string
racket/serialize
sugar/coerce
@ -23,7 +24,6 @@
;; 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 symbol? (setup:cache-watchlist source-path)))
(define path-strings-to-track
(list* source-path
;; if template has a source file, track that instead
@ -31,10 +31,11 @@
;; is either list of files or (list #f)
(append (->list (get-directory-require-files source-path))
;; user-designated files to track
(map ->string path-watchlist))))
(define pollen-env (getenv default-env-name))
(define env-rec (for/list ([env-name (in-list (sort env-watchlist bytes<?))])
(cons env-name (getenv (symbol->string env-name)))))
(map ->string (setup:cache-watchlist source-path)))))
(define env-rec (for/list ([env-name (in-list (cons default-env-name (sort (setup:envvar-watchlist source-path) bytes<?)))])
(cons env-name (match (getenv env-name)
[#false #false]
[str (string-downcase (->string str))]))))
(define poly-flag (and (has-inner-poly-ext? source-path) (current-poly-target)))
(define path+mod-time-pairs
(for/list ([ps (in-list path-strings-to-track)])
@ -44,10 +45,10 @@
(message (format "watchlist file /~a does not exist" (find-relative-path (current-project-root) cp))))
(cons (path->string cp) (file-or-directory-modify-seconds cp #false (λ () 0)))]
[else #false])))
(list* env-rec pollen-env poly-flag (and output-path (path->string output-path)) path+mod-time-pairs))
(list* env-rec poly-flag (and output-path (path->string output-path)) path+mod-time-pairs))
(define (key->source-path key) (car (fifth key)))
(define (key->output-path key) (fourth key))
(define (key->source-path key) (car (fourth key)))
(define (key->output-path key) (third key))
(module-test-internal
(define ps "/users/nobody/project/source.html.pm")

@ -1 +1 @@
1566498885
1566500904

@ -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? symbol?))]{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 a @racket[symbol?]).
@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).
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]:
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,11 +120,14 @@ Here's how files on the watchlist are handled. If one of the files on the watchl
(define cache-watchlist (list my-local-mod my-installed-mod)))
}]
Here's how environment variables on the watchlist are handled. By default, the cache always watches the default @racket[POLLEN] environment variable, but no others. 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"]
}
@defoverridable[envvar-watchlist (listof string?)]{List of extra environment variables that are used in cache keys. Separate caches will be maintained for each distinct value of an environment variable. @secref["The_POLLEN_environment_variable"] is always used, regardless of how this value is set.
@history[#:added "2.1"]}
@defoverridable[publish-directory (or/c path-string? path-for-some-system?)]{Default target for @secref{raco_pollen_publish}. A complete path is used as is; a relative path is published to the desktop.. @history[#:added "1.1"]}

@ -47,6 +47,7 @@
(dynamic-require `(submod ,(apply get-path-to-override get-path-args) WORLD-SUBMOD) 'NAME NAME-FAIL-THUNKED))))))]))
(define-settable cache-watchlist null)
(define-settable envvar-watchlist null)
(define-settable preproc-source-ext 'pp)
(define-settable markup-source-ext 'pm)

Loading…
Cancel
Save