move compile-file' to compiler/compile-file'

The `mzlib/compile' module re-exports the moved function.

Also, fix `make-directory*' so that it never fails on an existing
directory. Remove `unstable/file', since it was just the same
clean-up of `make-directory*'.
This commit is contained in:
Matthew Flatt 2013-07-10 10:05:50 -06:00
parent 72c9162989
commit 8d3c09b38b
13 changed files with 53 additions and 79 deletions

View File

@ -1,34 +1,7 @@
#lang scribble/doc #lang scribble/doc
@(require "common.rkt" @(require "common.rkt"
(for-label mzlib/compile (for-label compiler/compile-file))
compiler/compiler
compiler/cm))
@mzlib[#:mode title compile] @mzlib[#:mode title compile]
@defproc[(compile-file [src path-string?] Re-exports @racket[compile-file] from @racketmodname[compiler/compile-file].
[dest path-string? (let-values ([(base name dir?) (split-path src)])
(build-path base "compiled"
(path-add-suffix name #".zo")))]
[filter (any/c . -> . any/c) values])
path?]{
Compiles the Scheme file @racket[src] and saves the compiled code to
@racket[dest]. If @racket[dest] is not provided and the
@filepath{compiled} subdirectory does not already exist, the
subdirectory is created. The result of @racket[compile-file] is the
destination file's path.
If the @racket[filter] procedure is provided, it is applied to each
source expression, and the result is compiled.
The @racket[compile-file] procedure is designed for compiling modules
files, in that each expression in @racket[src] is compiled
independently. If @racket[src] does not contain a single
@racket[module] expression, then earlier expressions can affect the
compilation of later expressions when @racket[src] is loaded
directly. An appropriate @racket[filter] can make compilation behave
like evaluation, but the problem is also solved (as much as possible)
by the @racket[compile-zos] procedure.
See also @racket[managed-compile-zo].}

View File

@ -0,0 +1,4 @@
#lang racket/base
(require compiler/compile-file)
(provide compile-file)

View File

@ -516,6 +516,8 @@ datastructure containing an in-memory tree representation of the collects
directory. directory.
} }
@; ----------------------------------------------------------------------
@section{Compilation Manager Hook for Syntax Transformers} @section{Compilation Manager Hook for Syntax Transformers}
@defmodule[compiler/cm-accomplice] @defmodule[compiler/cm-accomplice]
@ -549,6 +551,39 @@ recognizes the message to register a dependency on a
module (which implies a dependency on all of that module's module (which implies a dependency on all of that module's
dependencies, etc.).} dependencies, etc.).}
@; ----------------------------------------
@section{API for Simple Bytecode Creation}
@defmodule[compiler/compile-file]
@defproc[(compile-file [src path-string?]
[dest path-string? (let-values ([(base name dir?) (split-path src)])
(build-path base "compiled"
(path-add-suffix name #".zo")))]
[filter (any/c . -> . any/c) values])
path?]{
Compiles the Racket file @racket[src] and saves the compiled code to
@racket[dest]. If @racket[dest] is not provided and the
@filepath{compiled} subdirectory does not already exist, the
subdirectory is created. The result of @racket[compile-file] is the
destination file's path.
If the @racket[filter] procedure is provided, it is applied to each
source expression, and the result is compiled.
The @racket[compile-file] procedure is designed for compiling modules
files, in that each expression in @racket[src] is compiled
independently. If @racket[src] does not contain a single
@racket[module] expression, then earlier expressions can affect the
compilation of later expressions when @racket[src] is loaded
directly. An appropriate @racket[filter] can make compilation behave
like evaluation, but the problem is also solved (as much as possible)
by the @racket[compile-zos] procedure.
See also @racket[managed-compile-zo].}
@; ---------------------------------------------------------------------- @; ----------------------------------------------------------------------
@section[#:tag "zo"]{Compiling to Raw Bytecode} @section[#:tag "zo"]{Compiling to Raw Bytecode}

View File

@ -996,7 +996,8 @@ paths disappear during the scan, then an exception is raised.}
@defproc[(make-directory* [path path-string?]) void?]{ @defproc[(make-directory* [path path-string?]) void?]{
Creates directory specified by @racket[path], creating intermediate Creates directory specified by @racket[path], creating intermediate
directories as necessary.} directories as necessary, and never failing if @racket[path] exists
already.}
@defproc[(make-temporary-file [template string? "rkttmp~a"] @defproc[(make-temporary-file [template string? "rkttmp~a"]

View File

@ -23,7 +23,6 @@
scribble/private/run-pdflatex scribble/private/run-pdflatex
setup/xref setup/xref
scribble/xref scribble/xref
unstable/file
racket/place racket/place
pkg/lib pkg/lib
pkg/strip pkg/strip
@ -1103,7 +1102,7 @@
(unless latex-dest (unless latex-dest
(let ([dir (doc-dest-dir doc)]) (let ([dir (doc-dest-dir doc)])
(if (not (directory-exists? dir)) (if (not (directory-exists? dir))
(make-directory*/ignore-exists-exn dir) (make-directory* dir)
(for ([f (directory-list dir)] (for ([f (directory-list dir)]
#:when #:when
(and (file-exists? f) (and (file-exists? f)
@ -1225,7 +1224,7 @@
(let* ([filename (sxref-path latex-dest doc name)]) (let* ([filename (sxref-path latex-dest doc name)])
(prep! filename) (prep! filename)
(when (verbose) (printf " [Caching to disk ~a]\n" filename)) (when (verbose) (printf " [Caching to disk ~a]\n" filename))
(make-directory*/ignore-exists-exn (doc-dest-dir doc)) (make-directory* (doc-dest-dir doc))
(with-compile-output (with-compile-output
filename filename
(lambda (out tmp-filename) (lambda (out tmp-filename)
@ -1242,7 +1241,7 @@
(when (and (doc-pkg? doc) (when (and (doc-pkg? doc)
(not (doc-under-main? doc)) (not (doc-under-main? doc))
(not latex-dest)) (not latex-dest))
(make-directory*/ignore-exists-exn (doc-dest-dir doc)) (make-directory* (doc-dest-dir doc))
(with-compile-output (with-compile-output
(sxref-path latex-dest doc "provides.sxref") (sxref-path latex-dest doc "provides.sxref")
(lambda (out tmp-filename) (lambda (out tmp-filename)

View File

@ -1,18 +0,0 @@
#lang scribble/doc
@(require scribble/base
scribble/manual
"utils.rkt"
(for-label unstable/file
racket/file
racket/contract
racket/base))
@title[#:tag "file"]{Filesystem}
@unstable[@author+email["Jay McCarthy" "jay@racket-lang.org"]]
@defmodule[unstable/file]
@defproc[(make-directory*/ignore-exists-exn [pth path-string?])
void]{
Like @racket[make-directory*], except it ignores errors when the path already exists. Useful to deal with race conditions on processes that create directories.
}

View File

@ -81,7 +81,6 @@ Keep documentation and tests up to date.
@include-section["debug.scrbl"] @include-section["debug.scrbl"]
@include-section["define.scrbl"] @include-section["define.scrbl"]
@include-section["error.scrbl"] @include-section["error.scrbl"]
@include-section["file.scrbl"]
@include-section["find.scrbl"] @include-section["find.scrbl"]
@include-section["flonum.scrbl"] @include-section["flonum.scrbl"]
@include-section["future.scrbl"] @include-section["future.scrbl"]

View File

@ -3,7 +3,6 @@
syntax/modresolve syntax/modresolve
syntax/modread syntax/modread
setup/dirs setup/dirs
unstable/file
racket/file racket/file
racket/list racket/list
racket/path racket/path
@ -426,7 +425,7 @@
;; Write the code and dependencies: ;; Write the code and dependencies:
(when code (when code
(with-compiler-security-guard (make-directory*/ignore-exists-exn code-dir)) (with-compiler-security-guard (make-directory* code-dir))
(with-compile-output zo-name (with-compile-output zo-name
(lambda (out tmp-name) (lambda (out tmp-name)
(with-handlers ([exn:fail? (with-handlers ([exn:fail?

View File

@ -1,15 +1,14 @@
#lang racket/base #lang racket/base
(require racket/function (require racket/function
racket/path racket/path
racket/file racket/file)
unstable/file)
(provide compile-file) (provide compile-file)
(define compile-file (define compile-file
(case-lambda (case-lambda
[(src) [(src)
(define cdir (build-path (path-only src) "compiled")) (define cdir (build-path (path-only src) "compiled"))
(make-directory*/ignore-exists-exn cdir) (make-directory* cdir)
(compile-file src (build-path cdir (path-add-suffix (file-name-from-path src) #".zo")))] (compile-file src (build-path cdir (path-add-suffix (file-name-from-path src) #".zo")))]
[(src dest) [(src dest)
(compile-file src dest values)] (compile-file src dest values)]

View File

@ -18,7 +18,7 @@
syntax/moddep syntax/moddep
scheme/file scheme/file
mzlib/compile ; gets compile-file compiler/compile-file
compiler/cm compiler/cm
setup/getinfo setup/getinfo
setup/main-collects setup/main-collects

View File

@ -2,6 +2,7 @@ Version 5.3.900.6
Added identifier-binding-symbol Added identifier-binding-symbol
Changed ".plt" file unpacking to require certain literal S-expression Changed ".plt" file unpacking to require certain literal S-expression
patterns, instead of evaluating S-expressions from the archive patterns, instead of evaluating S-expressions from the archive
racket/file: make-directory* never fails on existing directories
Version 5.3.900.5 Version 5.3.900.5
Added call-with-default-reading-parameterization Added call-with-default-reading-parameterization

View File

@ -94,7 +94,8 @@
(not (directory-exists? base))) (not (directory-exists? base)))
(make-directory* base)) (make-directory* base))
(unless (directory-exists? dir) (unless (directory-exists? dir)
(make-directory dir)))) (with-handlers ([exn:fail:filesystem:exists? void])
(make-directory dir)))))
(define-syntax (make-temporary-file stx) (define-syntax (make-temporary-file stx)
(with-syntax ([app (datum->syntax stx #'#%app stx)]) (with-syntax ([app (datum->syntax stx #'#%app stx)])

View File

@ -1,19 +0,0 @@
#lang racket/base
; Responsible: Jay McCarthy
(require racket/contract/base)
(define (exn:fail:filesystem:exists? x)
(and (exn:fail:filesystem? x)
(regexp-match #rx"exists" (exn-message x))))
(define (make-directory*/ignore-exists-exn dir)
(let-values ([(base name dir?) (split-path dir)])
(when (and (path? base)
(not (directory-exists? base)))
(make-directory*/ignore-exists-exn base))
(unless (directory-exists? dir)
(with-handlers ([exn:fail:filesystem:exists? void])
(make-directory dir)))))
(provide/contract
[make-directory*/ignore-exists-exn (path-string? . -> . void?)])