Some extra helper functions
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
(only-in racket-makefile
|
||||
target deps phony default-target make
|
||||
run rm-f rm-rf cleanup
|
||||
list-dir/files list-files list-dirs
|
||||
$target $deps $<)))
|
||||
|
||||
@title{racket-makefile}
|
||||
@@ -31,7 +32,7 @@ raco pkg install
|
||||
For a versioned archive, specify the package name explicitly:
|
||||
|
||||
@verbatim{
|
||||
raco pkg install --name racket-makefile racket-makefile-0.1.2.zip
|
||||
raco pkg install --name racket-makefile racket-makefile-0.1.4.zip
|
||||
}
|
||||
|
||||
After installation a makefile can start with:
|
||||
@@ -224,6 +225,59 @@ For example:
|
||||
"**.css")))
|
||||
]
|
||||
|
||||
@section{Regexp directory helpers}
|
||||
|
||||
@defproc[(list-dir/files [directory path-string?]
|
||||
[regexp regexp?]
|
||||
[#:recursive recursive any/c #f])
|
||||
list?]{
|
||||
Returns entries below @racket[directory] that match @racket[regexp]. By default
|
||||
only the direct contents of @racket[directory] are inspected. With
|
||||
@racket[#:recursive #t], the complete tree is walked using
|
||||
@racket[in-directory], and both files and directories can be returned.
|
||||
|
||||
For a non-recursive listing, complete paths are built from @racket[directory],
|
||||
so the result can be passed directly to file operations such as
|
||||
@racket[rm-f] and @racket[rm-rf].
|
||||
}
|
||||
|
||||
@defproc[(list-files [directory path-string?]
|
||||
[regexp regexp?]
|
||||
[#:recursive recursive any/c #f])
|
||||
list?]{
|
||||
Like @racket[list-dir/files], but keeps only paths for which
|
||||
@racket[file-exists?] is true.
|
||||
}
|
||||
|
||||
@defproc[(list-dirs [directory path-string?]
|
||||
[regexp regexp?]
|
||||
[#:recursive recursive any/c #f])
|
||||
list?]{
|
||||
Like @racket[list-dir/files], but keeps only paths for which
|
||||
@racket[directory-exists?] is true.
|
||||
}
|
||||
|
||||
These helpers make regexp-based cleanup concise. For example:
|
||||
|
||||
@racketblock[
|
||||
(default-target all)
|
||||
(phony all clean)
|
||||
|
||||
(target all
|
||||
(displayln "use (make clean)"))
|
||||
|
||||
(target clean
|
||||
(display "cleaning up...")
|
||||
(apply rm-rf
|
||||
(list-dirs "." #px"compiled$" #:recursive #t))
|
||||
(apply rm-f
|
||||
(list-files "." #px"(?i:(?:[.]bak|~)$)" #:recursive #t))
|
||||
(displayln "done."))
|
||||
]
|
||||
|
||||
The second regular expression is case-insensitive and matches names ending in
|
||||
@tt{.bak} or @tt{~}.
|
||||
|
||||
@section{Using ordinary Racket}
|
||||
|
||||
No separate make programming language is introduced. Definitions, functions,
|
||||
|
||||
Reference in New Issue
Block a user