diff --git a/js-assembler/db-cache.rkt b/js-assembler/db-cache.rkt index 5c169e4..bf259a4 100644 --- a/js-assembler/db-cache.rkt +++ b/js-assembler/db-cache.rkt @@ -10,9 +10,13 @@ racket/contract) -(provide/contract - [cached? (path? . -> . (or/c false/c bytes?))] - [save-in-cache! (path? bytes? . -> . any)]) +(provide cached? save-in-cache!) + +;; Contracts are off because when I dynamic-require, I can't +;; dynamic require the syntaxes exposed by the contract. +#;(provide/contract + [cached? (path? . -> . (or/c false/c bytes?))] + [save-in-cache! (path? bytes? . -> . any)]) (define cache-directory-path diff --git a/js-assembler/package.rkt b/js-assembler/package.rkt index 57e1fed..809f17a 100644 --- a/js-assembler/package.rkt +++ b/js-assembler/package.rkt @@ -21,7 +21,30 @@ (prefix-in query: "../lang/js/query.rkt") (prefix-in resource-query: "../resource/query.rkt") (prefix-in runtime: "get-runtime.rkt") - (prefix-in racket: racket/base)) + (prefix-in racket: racket/base) + racket/runtime-path) + + +;; Here, I'm trying to dynamically require the db-cache module +;; because not everyone's going to have Sqlite3 installed. +;; If this fails, just gracefully fall back to no caching. +(define-runtime-path db-cache.rkt "db-cache.rkt") +(define-values (db-cache:cached? db-cache:save-in-cache!) + (with-handlers ([exn:fail? + (lambda (exn) + (log-debug "Unable to use Sqlite3 cache. Falling back to no-cache.") + (values (lambda (path) + #f) + (lambda (path data) + (void))))]) + (parameterize ([current-namespace (make-base-namespace)]) + (values + (dynamic-require `(file ,(path->string db-cache.rkt)) + 'cached?) + (dynamic-require `(file ,(path->string db-cache.rkt)) + 'save-in-cache!))))) + + ;; There is a dynamic require for (planet dyoo/closure-compile) that's done ;; if compression is turned on. @@ -375,13 +398,16 @@ M.modules[~s] = ;; Returns a true value (the cached bytes) if we've seen this path ;; and know its JavaScript-compiled bytes. (define (cached? path) - #f) + (db-cache:cached? path)) + ;; cacheable?: path -> boolean ;; Produces true if the file should be cached. +;; At the current time, only cache modules that are provided +;; by whalesong itself. (define (cacheable? path) - #f) + (within-whalesong-path? path)) ;; save-in-cache!: path bytes -> void @@ -389,7 +415,8 @@ M.modules[~s] = ;; TODO: Needs to sign with the internal version of Whalesong, and ;; the md5sum of the path's content. (define (save-in-cache! path bytes) - (void)) + (db-cache:save-in-cache! path bytes)) + diff --git a/lang/kernel.rkt b/lang/kernel.rkt index 62a9ec4..fbeb074 100644 --- a/lang/kernel.rkt +++ b/lang/kernel.rkt @@ -124,6 +124,7 @@ begin-for-syntax prefix-in only-in + rename-in provide planet all-defined-out diff --git a/parser/path-rewriter.rkt b/parser/path-rewriter.rkt index 4db0038..abaaada 100644 --- a/parser/path-rewriter.rkt +++ b/parser/path-rewriter.rkt @@ -9,7 +9,8 @@ -(provide/contract [rewrite-path (complete-path? . -> . (or/c symbol? false/c))]) +(provide/contract [rewrite-path (complete-path? . -> . (or/c symbol? false/c))] + [within-whalesong-path? (complete-path? . -> . boolean?)]) @@ -31,7 +32,7 @@ (define (rewrite-path a-path) (let ([a-path (normalize-path a-path)]) (cond - [(within-this-project-path? a-path) + [(within-whalesong-path? a-path) (string->symbol (string-append "whalesong/" (path->string @@ -60,7 +61,7 @@ (within? collects-path a-path)) -(define (within-this-project-path? a-path) +(define (within-whalesong-path? a-path) (within? normal-whalesong-path a-path)) diff --git a/version.rkt b/version.rkt index 5b66238..a2974aa 100644 --- a/version.rkt +++ b/version.rkt @@ -6,4 +6,4 @@ (provide version) (: version String) -(define version "1.10") +(define version "1.19")