racket/runtime-path: add support for 'share paths

Support include-if-exists for files in the "share" directory analogous
to the include-if-exists support for files in "lib".
This commit is contained in:
Matthew Flatt 2019-11-12 20:10:06 -07:00
parent 3192c02b80
commit 52b01ef88b
6 changed files with 50 additions and 2 deletions

View File

@ -0,0 +1,12 @@
#lang racket/base
(require racket/runtime-path
(for-syntax racket/base))
(define-runtime-path license '(share "LICENSE-libscheme.txt"))
(if (absolute-path? license)
"found license"
"not found")

View File

@ -272,7 +272,8 @@
(one-mz-test "embed-me31.rkt" "This is 31.\n" #f)
(one-mz-test "embed-me34.rkt" "This is 34 in a second place.\n" #f)
(one-mz-test "embed-me35.rkt" "'ok-35\n" #f)
(one-mz-test "embed-me36.rkt" "'ok-36\n" #f))
(one-mz-test "embed-me36.rkt" "'ok-36\n" #f)
(one-mz-test "embed-me38.rkt" "\"found license\"\n" #f))
;; Try unicode expr and cmdline:
(prepare dest "unicode")

View File

@ -728,6 +728,14 @@ a platform-specific shared-library extension---as produced by
@racket[(system-type 'so-suffix)]. A @racket[_vers]
can be a string, or it can be a list of strings and @racket[#f].
If @racket[expr] produces a list of the form @racket[(list 'share
_str)], the value bound to @racket[id] can be either @racket[_str] or
an absolute path; it is an absolute path when searching in the
directories reported by @racket[find-user-share-dir] and
@racket[find-share-dir] (in that order) locates the path. In this way,
files that are installed in Racket's @filepath{share} directory get
carried along in distributions.
If @racket[expr] produces a list of the form @racket[(list 'module
_module-path _var-ref)] or @racket[(list 'so _str (list
_str-or-false ...))], the value bound to @racket[id] is a
@ -798,7 +806,8 @@ In the latter two cases, the path is normally preserved in
result of @racket[collection-file-path], then the path is record as
relative to the corresponding module path.
@history[#:changed "6.0.1.6" @elem{Preserve relative paths only within a package.}]
@history[#:changed "6.0.1.6" @elem{Preserve relative paths only within a package.}
#:changed "7.5.0.7" @elem{Added support for @racket['share] in @racket[expr].}]
Examples:

View File

@ -13,6 +13,7 @@
setup/collects
file/ico
racket/private/so-search
racket/private/share-search
setup/cross-system
"private/winsubsys.rkt"
"private/macfw.rkt"
@ -1306,6 +1307,7 @@
;; record the whole DLL in the executable
#f]
[else path])]
[(share-spec? p) (share-find p)]
[(and (list? p)
(eq? 'lib (car p)))
(let ([p (if (null? (cddr p))

View File

@ -0,0 +1,21 @@
#lang racket/base
(require setup/dirs)
(provide share-spec? share-find)
(define (share-spec? p)
(and (list? p)
(= 2 (length p))
(eq? 'share (car p))
(string? (cadr p))))
(define (share-find p)
(define f (cadr p))
(define (search dir)
(and dir
(let ([p (build-path dir f)])
(and (or (file-exists? p)
(directory-exists? p))
p))))
(or (search (find-user-share-dir))
(search (find-share-dir))))

View File

@ -4,6 +4,7 @@
(require racket/list
"private/so-search.rkt"
"private/share-search.rkt"
"private/this-expression-source-directory.rkt"
(only-in "private/runtime-path-table.rkt" table)
(for-syntax racket/base))
@ -97,6 +98,8 @@
[(path? p) p]
[(so-spec? p) (or (so-find p)
(cadr p))]
[(share-spec? p) (or (share-find p)
(cadr p))]
[(and (list? p)
((length p) . > . 1)
(eq? 'lib (car p))