diff --git a/pkgs/compatibility-pkgs/compatibility-doc/mzlib/scribblings/compile.scrbl b/pkgs/compatibility-pkgs/compatibility-doc/mzlib/scribblings/compile.scrbl index 572ba3142b..0bc69bb28b 100644 --- a/pkgs/compatibility-pkgs/compatibility-doc/mzlib/scribblings/compile.scrbl +++ b/pkgs/compatibility-pkgs/compatibility-doc/mzlib/scribblings/compile.scrbl @@ -1,34 +1,7 @@ #lang scribble/doc @(require "common.rkt" - (for-label mzlib/compile - compiler/compiler - compiler/cm)) + (for-label compiler/compile-file)) @mzlib[#:mode title compile] -@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 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].} +Re-exports @racket[compile-file] from @racketmodname[compiler/compile-file]. diff --git a/pkgs/compatibility-pkgs/compatibility-lib/mzlib/compile.rkt b/pkgs/compatibility-pkgs/compatibility-lib/mzlib/compile.rkt new file mode 100644 index 0000000000..af29dccd74 --- /dev/null +++ b/pkgs/compatibility-pkgs/compatibility-lib/mzlib/compile.rkt @@ -0,0 +1,4 @@ +#lang racket/base +(require compiler/compile-file) + +(provide compile-file) diff --git a/pkgs/racket-pkgs/racket-doc/scribblings/raco/make.scrbl b/pkgs/racket-pkgs/racket-doc/scribblings/raco/make.scrbl index 37faa0e626..98ec80a1f4 100644 --- a/pkgs/racket-pkgs/racket-doc/scribblings/raco/make.scrbl +++ b/pkgs/racket-pkgs/racket-doc/scribblings/raco/make.scrbl @@ -516,6 +516,8 @@ datastructure containing an in-memory tree representation of the collects directory. } +@; ---------------------------------------------------------------------- + @section{Compilation Manager Hook for Syntax Transformers} @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 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} diff --git a/pkgs/racket-pkgs/racket-doc/scribblings/reference/filesystem.scrbl b/pkgs/racket-pkgs/racket-doc/scribblings/reference/filesystem.scrbl index e7294538ed..dee96faa68 100644 --- a/pkgs/racket-pkgs/racket-doc/scribblings/reference/filesystem.scrbl +++ b/pkgs/racket-pkgs/racket-doc/scribblings/reference/filesystem.scrbl @@ -996,7 +996,8 @@ paths disappear during the scan, then an exception is raised.} @defproc[(make-directory* [path path-string?]) void?]{ 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"] diff --git a/pkgs/racket-pkgs/racket-index/setup/scribble.rkt b/pkgs/racket-pkgs/racket-index/setup/scribble.rkt index ea36853c48..02242904c5 100644 --- a/pkgs/racket-pkgs/racket-index/setup/scribble.rkt +++ b/pkgs/racket-pkgs/racket-index/setup/scribble.rkt @@ -23,7 +23,6 @@ scribble/private/run-pdflatex setup/xref scribble/xref - unstable/file racket/place pkg/lib pkg/strip @@ -1103,7 +1102,7 @@ (unless latex-dest (let ([dir (doc-dest-dir doc)]) (if (not (directory-exists? dir)) - (make-directory*/ignore-exists-exn dir) + (make-directory* dir) (for ([f (directory-list dir)] #:when (and (file-exists? f) @@ -1225,7 +1224,7 @@ (let* ([filename (sxref-path latex-dest doc name)]) (prep! 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 filename (lambda (out tmp-filename) @@ -1242,7 +1241,7 @@ (when (and (doc-pkg? doc) (not (doc-under-main? doc)) (not latex-dest)) - (make-directory*/ignore-exists-exn (doc-dest-dir doc)) + (make-directory* (doc-dest-dir doc)) (with-compile-output (sxref-path latex-dest doc "provides.sxref") (lambda (out tmp-filename) diff --git a/pkgs/unstable/scribblings/file.scrbl b/pkgs/unstable/scribblings/file.scrbl deleted file mode 100644 index e0ba272d51..0000000000 --- a/pkgs/unstable/scribblings/file.scrbl +++ /dev/null @@ -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. -} diff --git a/pkgs/unstable/scribblings/unstable.scrbl b/pkgs/unstable/scribblings/unstable.scrbl index 2c44a38210..16a34a2794 100644 --- a/pkgs/unstable/scribblings/unstable.scrbl +++ b/pkgs/unstable/scribblings/unstable.scrbl @@ -81,7 +81,6 @@ Keep documentation and tests up to date. @include-section["debug.scrbl"] @include-section["define.scrbl"] @include-section["error.scrbl"] -@include-section["file.scrbl"] @include-section["find.scrbl"] @include-section["flonum.scrbl"] @include-section["future.scrbl"] diff --git a/racket/lib/collects/compiler/cm.rkt b/racket/lib/collects/compiler/cm.rkt index 15a7844021..abff94cc15 100644 --- a/racket/lib/collects/compiler/cm.rkt +++ b/racket/lib/collects/compiler/cm.rkt @@ -3,7 +3,6 @@ syntax/modresolve syntax/modread setup/dirs - unstable/file racket/file racket/list racket/path @@ -426,7 +425,7 @@ ;; Write the code and dependencies: (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 (lambda (out tmp-name) (with-handlers ([exn:fail? diff --git a/racket/lib/collects/mzlib/compile.rkt b/racket/lib/collects/compiler/compile-file.rkt similarity index 96% rename from racket/lib/collects/mzlib/compile.rkt rename to racket/lib/collects/compiler/compile-file.rkt index a097b724db..2fcab1b0ed 100644 --- a/racket/lib/collects/mzlib/compile.rkt +++ b/racket/lib/collects/compiler/compile-file.rkt @@ -1,15 +1,14 @@ #lang racket/base (require racket/function racket/path - racket/file - unstable/file) + racket/file) (provide compile-file) (define compile-file (case-lambda [(src) (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")))] [(src dest) (compile-file src dest values)] diff --git a/racket/lib/collects/compiler/compiler-unit.rkt b/racket/lib/collects/compiler/compiler-unit.rkt index 32c3cdc0d2..a02c29f0ee 100644 --- a/racket/lib/collects/compiler/compiler-unit.rkt +++ b/racket/lib/collects/compiler/compiler-unit.rkt @@ -18,7 +18,7 @@ syntax/moddep scheme/file - mzlib/compile ; gets compile-file + compiler/compile-file compiler/cm setup/getinfo setup/main-collects diff --git a/racket/lib/collects/racket/HISTORY.txt b/racket/lib/collects/racket/HISTORY.txt index 7916b928ce..b48254d097 100644 --- a/racket/lib/collects/racket/HISTORY.txt +++ b/racket/lib/collects/racket/HISTORY.txt @@ -2,6 +2,7 @@ Version 5.3.900.6 Added identifier-binding-symbol Changed ".plt" file unpacking to require certain literal S-expression patterns, instead of evaluating S-expressions from the archive +racket/file: make-directory* never fails on existing directories Version 5.3.900.5 Added call-with-default-reading-parameterization diff --git a/racket/lib/collects/racket/file.rkt b/racket/lib/collects/racket/file.rkt index 591cec2557..f1196385ee 100644 --- a/racket/lib/collects/racket/file.rkt +++ b/racket/lib/collects/racket/file.rkt @@ -94,7 +94,8 @@ (not (directory-exists? base))) (make-directory* base)) (unless (directory-exists? dir) - (make-directory dir)))) + (with-handlers ([exn:fail:filesystem:exists? void]) + (make-directory dir))))) (define-syntax (make-temporary-file stx) (with-syntax ([app (datum->syntax stx #'#%app stx)]) diff --git a/racket/lib/collects/unstable/file.rkt b/racket/lib/collects/unstable/file.rkt deleted file mode 100644 index ab785ff45b..0000000000 --- a/racket/lib/collects/unstable/file.rkt +++ /dev/null @@ -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?)])