fix raco exe' for cycles created via
define-runtime-module-path'
This commit is contained in:
parent
a0378d956a
commit
e640041dd6
|
@ -341,187 +341,194 @@
|
||||||
|
|
||||||
;; Loads module code, using .zo if there, compiling from .scm if not
|
;; Loads module code, using .zo if there, compiling from .scm if not
|
||||||
(define (get-code filename module-path codes prefixes verbose? collects-dest on-extension
|
(define (get-code filename module-path codes prefixes verbose? collects-dest on-extension
|
||||||
compiler expand-namespace get-extra-imports)
|
compiler expand-namespace get-extra-imports working)
|
||||||
(let ([a (assoc filename (unbox codes))])
|
(let ([a (assoc filename (unbox codes))])
|
||||||
(if a
|
(cond
|
||||||
;; Already have this module. Make sure that library-referenced
|
[a
|
||||||
;; modules are consistently referenced through library paths:
|
;; Already have this module. Make sure that library-referenced
|
||||||
(let ([found-lib? (is-lib-path? (mod-mod-path a))]
|
;; modules are consistently referenced through library paths:
|
||||||
[look-lib? (is-lib-path? module-path)])
|
(let ([found-lib? (is-lib-path? (mod-mod-path a))]
|
||||||
|
[look-lib? (is-lib-path? module-path)])
|
||||||
|
(cond
|
||||||
|
[(and found-lib? look-lib?)
|
||||||
|
'ok]
|
||||||
|
[(or found-lib? look-lib?)
|
||||||
|
(error 'find-module
|
||||||
|
"module referenced both as a library and through a path: ~a"
|
||||||
|
filename)]
|
||||||
|
[else 'ok]))]
|
||||||
|
[(hash-ref working filename #f)
|
||||||
|
;; in the process of loading the module; a cycle
|
||||||
|
;; is possible through `define-runtime-path'
|
||||||
|
'ok]
|
||||||
|
[else
|
||||||
|
;; First use of the module. Get code and then get code for imports.
|
||||||
|
(when verbose?
|
||||||
|
(fprintf (current-error-port) "Getting ~s\n" filename))
|
||||||
|
(let ([actual-filename filename]) ; `set!'ed below to adjust file suffix
|
||||||
|
(hash-set! working filename #t)
|
||||||
|
(let ([code (get-module-code filename
|
||||||
|
"compiled"
|
||||||
|
compiler
|
||||||
|
(if on-extension
|
||||||
|
(lambda (f l?)
|
||||||
|
(on-extension f l?)
|
||||||
|
#f)
|
||||||
|
(lambda (file _loader?)
|
||||||
|
(if _loader?
|
||||||
|
(error 'create-embedding-executable
|
||||||
|
"cannot use a _loader extension: ~e"
|
||||||
|
file)
|
||||||
|
(make-extension file))))
|
||||||
|
#:choose
|
||||||
|
;; Prefer extensions, if we're handling them:
|
||||||
|
(lambda (src zo so)
|
||||||
|
(set! actual-filename src) ; remember convert soure name
|
||||||
|
(if on-extension
|
||||||
|
#f
|
||||||
|
(if (and (file-exists? so)
|
||||||
|
((file-date so) . >= . (file-date zo)))
|
||||||
|
'so
|
||||||
|
#f))))]
|
||||||
|
[name (let-values ([(base name dir?) (split-path filename)])
|
||||||
|
(path->string (path-replace-suffix name #"")))]
|
||||||
|
[prefix (let ([a (assoc filename prefixes)])
|
||||||
|
(if a
|
||||||
|
(cdr a)
|
||||||
|
(generate-prefix)))])
|
||||||
(cond
|
(cond
|
||||||
[(and found-lib? look-lib?)
|
[(extension? code)
|
||||||
'ok]
|
(when verbose?
|
||||||
[(or found-lib? look-lib?)
|
(fprintf (current-error-port) " using extension: ~s\n" (extension-path code)))
|
||||||
(error 'find-module
|
(set-box! codes
|
||||||
"module referenced both as a library and through a path: ~a"
|
(cons (make-mod filename module-path code
|
||||||
filename)]
|
name prefix (string->symbol
|
||||||
[else 'ok]))
|
(format "~a~a" prefix name))
|
||||||
;; First use of the module. Get code and then get code for imports.
|
null null null
|
||||||
(begin
|
actual-filename)
|
||||||
(when verbose?
|
(unbox codes)))]
|
||||||
(fprintf (current-error-port) "Getting ~s\n" filename))
|
[code
|
||||||
(let ([actual-filename filename]) ; `set!'ed below to adjust file suffix
|
(let ([importss (module-compiled-imports code)])
|
||||||
(let ([code (get-module-code filename
|
(let ([all-file-imports (filter (lambda (x)
|
||||||
"compiled"
|
(let-values ([(x base) (module-path-index-split x)])
|
||||||
compiler
|
(not (and (pair? x)
|
||||||
(if on-extension
|
(eq? 'quote (car x))))))
|
||||||
(lambda (f l?)
|
(apply append (map cdr importss)))]
|
||||||
(on-extension f l?)
|
[extra-paths
|
||||||
#f)
|
(map symbol-to-lib-form (get-extra-imports actual-filename code))])
|
||||||
(lambda (file _loader?)
|
(let* ([runtime-paths
|
||||||
(if _loader?
|
(parameterize ([current-namespace expand-namespace])
|
||||||
(error 'create-embedding-executable
|
(eval code)
|
||||||
"cannot use a _loader extension: ~e"
|
(let ([module-path
|
||||||
file)
|
(if (path? module-path)
|
||||||
(make-extension file))))
|
(path->complete-path module-path)
|
||||||
#:choose
|
module-path)])
|
||||||
;; Prefer extensions, if we're handling them:
|
(syntax-case (expand `(,#'module m mzscheme
|
||||||
(lambda (src zo so)
|
(require (only ,module-path)
|
||||||
(set! actual-filename src) ; remember convert soure name
|
mzlib/runtime-path)
|
||||||
(if on-extension
|
(runtime-paths ,module-path))) (quote)
|
||||||
#f
|
[(_ m mz (#%mb rfs req (quote (spec ...))))
|
||||||
(if (and (file-exists? so)
|
(syntax->datum #'(spec ...))]
|
||||||
((file-date so) . >= . (file-date zo)))
|
[_else (error 'create-empbedding-executable
|
||||||
'so
|
"expansion mismatch when getting external paths")])))]
|
||||||
#f))))]
|
|
||||||
[name (let-values ([(base name dir?) (split-path filename)])
|
[extra-runtime-paths (filter
|
||||||
(path->string (path-replace-suffix name #"")))]
|
values
|
||||||
[prefix (let ([a (assoc filename prefixes)])
|
(map (lambda (p)
|
||||||
(if a
|
(and (pair? p)
|
||||||
(cdr a)
|
(eq? (car p) 'module)
|
||||||
(generate-prefix)))])
|
(cadr p)))
|
||||||
(cond
|
runtime-paths))])
|
||||||
[(extension? code)
|
(let ([sub-files (map (lambda (i) (normalize (resolve-module-path-index i filename)))
|
||||||
(when verbose?
|
all-file-imports)]
|
||||||
(fprintf (current-error-port) " using extension: ~s\n" (extension-path code)))
|
[sub-paths (map (lambda (i) (collapse-module-path-index i module-path))
|
||||||
(set-box! codes
|
all-file-imports)]
|
||||||
(cons (make-mod filename module-path code
|
[normalized-extra-paths (map (lambda (i) (collapse-module-path i module-path))
|
||||||
name prefix (string->symbol
|
(append extra-runtime-paths extra-paths))]
|
||||||
(format "~a~a" prefix name))
|
[extra-files (map (lambda (i) (normalize (resolve-module-path-index (module-path-index-join i #f)
|
||||||
null null null
|
filename)))
|
||||||
actual-filename)
|
;; getting runtime-module-path symbols below
|
||||||
(unbox codes)))]
|
;; relies on extra-runtime-paths being first:
|
||||||
[code
|
(append extra-runtime-paths extra-paths))])
|
||||||
(let ([importss (module-compiled-imports code)])
|
;; Get code for imports:
|
||||||
(let ([all-file-imports (filter (lambda (x)
|
(for-each (lambda (sub-filename sub-path)
|
||||||
(let-values ([(x base) (module-path-index-split x)])
|
(get-code sub-filename
|
||||||
(not (and (pair? x)
|
sub-path
|
||||||
(eq? 'quote (car x))))))
|
codes
|
||||||
(apply append (map cdr importss)))]
|
prefixes
|
||||||
[extra-paths
|
verbose?
|
||||||
(map symbol-to-lib-form (get-extra-imports actual-filename code))])
|
collects-dest
|
||||||
(let* ([runtime-paths
|
on-extension
|
||||||
(parameterize ([current-namespace expand-namespace])
|
compiler
|
||||||
(eval code)
|
expand-namespace
|
||||||
(let ([module-path
|
get-extra-imports
|
||||||
(if (path? module-path)
|
working))
|
||||||
(path->complete-path module-path)
|
(append sub-files extra-files)
|
||||||
module-path)])
|
(append sub-paths normalized-extra-paths))
|
||||||
(syntax-case (expand `(,#'module m mzscheme
|
(when verbose?
|
||||||
(require (only ,module-path)
|
(unless (null? runtime-paths)
|
||||||
mzlib/runtime-path)
|
(fprintf (current-error-port) "Runtime paths for ~s: ~s\n"
|
||||||
(runtime-paths ,module-path))) (quote)
|
filename
|
||||||
[(_ m mz (#%mb rfs req (quote (spec ...))))
|
runtime-paths)))
|
||||||
(syntax->datum #'(spec ...))]
|
(if (and collects-dest
|
||||||
[_else (error 'create-empbedding-executable
|
(is-lib-path? module-path))
|
||||||
"expansion mismatch when getting external paths")])))]
|
;; Install code as .zo:
|
||||||
|
(begin
|
||||||
[extra-runtime-paths (filter
|
(with-output-to-file (lib-module-filename collects-dest module-path)
|
||||||
values
|
#:exists 'truncate/replace
|
||||||
(map (lambda (p)
|
(lambda ()
|
||||||
(and (pair? p)
|
(write code)))
|
||||||
(eq? (car p) 'module)
|
;; Record module as copied
|
||||||
(cadr p)))
|
(set-box! codes
|
||||||
runtime-paths))])
|
(cons (make-mod filename module-path #f
|
||||||
(let ([sub-files (map (lambda (i) (normalize (resolve-module-path-index i filename)))
|
#f #f #f
|
||||||
all-file-imports)]
|
null null null
|
||||||
[sub-paths (map (lambda (i) (collapse-module-path-index i module-path))
|
actual-filename)
|
||||||
all-file-imports)]
|
(unbox codes))))
|
||||||
[normalized-extra-paths (map (lambda (i) (collapse-module-path i module-path))
|
;; Build up relative module resolutions, relative to this one,
|
||||||
(append extra-runtime-paths extra-paths))]
|
;; that will be requested at run-time.
|
||||||
[extra-files (map (lambda (i) (normalize (resolve-module-path-index (module-path-index-join i #f)
|
(let ([mappings (map (lambda (sub-i sub-filename sub-path)
|
||||||
filename)))
|
(and (not (and collects-dest
|
||||||
;; getting runtime-module-path symbols below
|
(is-lib-path? sub-path)))
|
||||||
;; relies on extra-runtime-paths being first:
|
(let-values ([(path base) (module-path-index-split sub-i)])
|
||||||
(append extra-runtime-paths extra-paths))])
|
(and base ; can be #f if path isn't relative
|
||||||
;; Get code for imports:
|
(begin
|
||||||
(for-each (lambda (sub-filename sub-path)
|
;; Assert: base should refer to this module:
|
||||||
(get-code sub-filename
|
(let-values ([(path2 base2) (module-path-index-split base)])
|
||||||
sub-path
|
(when (or path2 base2)
|
||||||
codes
|
(error 'embed "unexpected nested module path index")))
|
||||||
prefixes
|
(let ([m (assoc sub-filename (unbox codes))])
|
||||||
verbose?
|
(cons path (mod-full-name m))))))))
|
||||||
collects-dest
|
all-file-imports sub-files sub-paths)])
|
||||||
on-extension
|
;; Record the module
|
||||||
compiler
|
(set-box! codes
|
||||||
expand-namespace
|
(cons (make-mod filename module-path code
|
||||||
get-extra-imports))
|
name prefix (string->symbol
|
||||||
(append sub-files extra-files)
|
(format "~a~a" prefix name))
|
||||||
(append sub-paths normalized-extra-paths))
|
(filter (lambda (p)
|
||||||
(when verbose?
|
(and p (cdr p)))
|
||||||
(unless (null? runtime-paths)
|
mappings)
|
||||||
(fprintf (current-error-port) "Runtime paths for ~s: ~s\n"
|
runtime-paths
|
||||||
filename
|
;; extract runtime-path module symbols:
|
||||||
runtime-paths)))
|
(let loop ([runtime-paths runtime-paths]
|
||||||
(if (and collects-dest
|
[extra-files extra-files])
|
||||||
(is-lib-path? module-path))
|
(cond
|
||||||
;; Install code as .zo:
|
[(null? runtime-paths) null]
|
||||||
(begin
|
[(let ([p (car runtime-paths)])
|
||||||
(with-output-to-file (lib-module-filename collects-dest module-path)
|
(and (pair? p) (eq? (car p) 'module)))
|
||||||
#:exists 'truncate/replace
|
(cons (mod-full-name (assoc (car extra-files) (unbox codes)))
|
||||||
(lambda ()
|
(loop (cdr runtime-paths) (cdr extra-files)))]
|
||||||
(write code)))
|
[else
|
||||||
;; Record module as copied
|
(cons #f (loop (cdr runtime-paths) extra-files))]))
|
||||||
(set-box! codes
|
actual-filename)
|
||||||
(cons (make-mod filename module-path #f
|
(unbox codes)))))))))]
|
||||||
#f #f #f
|
[else
|
||||||
null null null
|
(set-box! codes
|
||||||
actual-filename)
|
(cons (make-mod filename module-path code
|
||||||
(unbox codes))))
|
name #f #f
|
||||||
;; Build up relative module resolutions, relative to this one,
|
null null null
|
||||||
;; that will be requested at run-time.
|
actual-filename)
|
||||||
(let ([mappings (map (lambda (sub-i sub-filename sub-path)
|
(unbox codes)))])))])))
|
||||||
(and (not (and collects-dest
|
|
||||||
(is-lib-path? sub-path)))
|
|
||||||
(let-values ([(path base) (module-path-index-split sub-i)])
|
|
||||||
(and base ; can be #f if path isn't relative
|
|
||||||
(begin
|
|
||||||
;; Assert: base should refer to this module:
|
|
||||||
(let-values ([(path2 base2) (module-path-index-split base)])
|
|
||||||
(when (or path2 base2)
|
|
||||||
(error 'embed "unexpected nested module path index")))
|
|
||||||
(let ([m (assoc sub-filename (unbox codes))])
|
|
||||||
(cons path (mod-full-name m))))))))
|
|
||||||
all-file-imports sub-files sub-paths)])
|
|
||||||
;; Record the module
|
|
||||||
(set-box! codes
|
|
||||||
(cons (make-mod filename module-path code
|
|
||||||
name prefix (string->symbol
|
|
||||||
(format "~a~a" prefix name))
|
|
||||||
(filter (lambda (p)
|
|
||||||
(and p (cdr p)))
|
|
||||||
mappings)
|
|
||||||
runtime-paths
|
|
||||||
;; extract runtime-path module symbols:
|
|
||||||
(let loop ([runtime-paths runtime-paths]
|
|
||||||
[extra-files extra-files])
|
|
||||||
(cond
|
|
||||||
[(null? runtime-paths) null]
|
|
||||||
[(let ([p (car runtime-paths)])
|
|
||||||
(and (pair? p) (eq? (car p) 'module)))
|
|
||||||
(cons (mod-full-name (assoc (car extra-files) (unbox codes)))
|
|
||||||
(loop (cdr runtime-paths) (cdr extra-files)))]
|
|
||||||
[else
|
|
||||||
(cons #f (loop (cdr runtime-paths) extra-files))]))
|
|
||||||
actual-filename)
|
|
||||||
(unbox codes)))))))))]
|
|
||||||
[else
|
|
||||||
(set-box! codes
|
|
||||||
(cons (make-mod filename module-path code
|
|
||||||
name #f #f
|
|
||||||
null null null
|
|
||||||
actual-filename)
|
|
||||||
(unbox codes)))])))))))
|
|
||||||
|
|
||||||
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
@ -822,7 +829,8 @@
|
||||||
[get-code-at (lambda (f mp)
|
[get-code-at (lambda (f mp)
|
||||||
(get-code f mp codes prefix-mapping verbose? collects-dest
|
(get-code f mp codes prefix-mapping verbose? collects-dest
|
||||||
on-extension compiler expand-namespace
|
on-extension compiler expand-namespace
|
||||||
get-extra-imports))]
|
get-extra-imports
|
||||||
|
(make-hash)))]
|
||||||
[__
|
[__
|
||||||
;; Load all code:
|
;; Load all code:
|
||||||
(for-each get-code-at files collapsed-mps)]
|
(for-each get-code-at files collapsed-mps)]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user