diff --git a/collects/scheme/runtime-path.ss b/collects/scheme/runtime-path.ss index a5f9fe0de8..5142d32309 100644 --- a/collects/scheme/runtime-path.ss +++ b/collects/scheme/runtime-path.ss @@ -3,6 +3,32 @@ (require mzlib/runtime-path) (provide (all-from-out mzlib/runtime-path) - (for-syntax #%datum)) + (for-syntax #%datum) + define-runtime-module-path) +(define-syntax (define-runtime-module-path stx) + (syntax-case stx () + [(_ id mod-path) + (begin + (unless (memq (syntax-local-context) '(top-level module module-begin)) + (raise-syntax-error #f + "allowed only in a module top-level or top-level context" + stx)) + (unless (identifier? #'id) + (raise-syntax-error #f + "expected an identifier to bind" + stx + #'id)) + (unless (module-path? (syntax->datum #'mod-path)) + (raise-syntax-error #f + "expected a literal module path" + stx + #'mod-path)) + #`(begin + (require (only-in (for-label mod-path))) + (define id (combine-module-path (#%variable-reference) 'mod-path))))])) +(define (combine-module-path vr mod-path) + (module-path-index-resolve (module-path-index-join + mod-path + (variable-reference->resolved-module-path vr)))) diff --git a/collects/scribblings/reference/filesystem.scrbl b/collects/scribblings/reference/filesystem.scrbl index 06f2f72270..b1448278d0 100644 --- a/collects/scribblings/reference/filesystem.scrbl +++ b/collects/scribblings/reference/filesystem.scrbl @@ -521,6 +521,28 @@ Like @scheme[define-runtime-path], but @scheme[expr] should produce a list of paths.} +@defform[(define-runtime-module-path id module-path)]{ + +Similar to @scheme[define-runtime-path], but @scheme[id] is bound to a +@tech{resolved module path}. The @tech{resolved module path} for +@scheme[id] corresponds to @scheme[module-path] (with the same syntax +as a module path for @scheme[require]), which can be relative to the +enclosing module. + +Use @scheme[define-runtime-module-path] to bind a module path that is +passed to a reflective function like @scheme[dynamic-require] while +also creating a module dependency for building and distributing +executables. + +The @scheme[define-runtime-module-path] form creates a +@scheme[for-label] dependency from an enclosing module to +@scheme[module-path]. Since the dependency is merely +@scheme[for-label], @scheme[module-path] is not @tech{instantiate}d or +@tech{visit}ed when the enclosing module is @tech{instantiate}d or +@tech{visit}ed (unless such a dependency is created by other +@scheme[require]s).} + + @defform[(runtime-paths module-path)]{ This form is mainly for use by tools such as executable builders. It @@ -529,7 +551,8 @@ expands to a quoted list containing the run-time paths declared by declaration @scheme[expr]s, except that paths are converted to byte strings. The enclosing module must require (directly or indirectly) the module specified by @scheme[module-path], which is an unquoted -module path.} +module path. The resulting list does @emph{not} include module paths +bound through @scheme[define-runtime-module-path].} @;------------------------------------------------------------------------ @section[#:tag "file-lib"]{More File and Directory Utilities}