|
Distribution.Simple.Utils | Portability | portable | Maintainer | cabal-devel@haskell.org |
|
|
|
|
|
Description |
A large and somewhat miscellaneous collection of utility functions used
throughout the rest of the Cabal lib and in other tools that use the Cabal
lib like cabal-install. It has a very simple set of logging actions. It
has low level functions for running programs, a bunch of wrappers for
various directory and file functions that do extra logging.
|
|
Synopsis |
|
|
|
Documentation |
|
|
|
|
|
logging and errors
|
|
|
|
|
|
|
|
|
Non fatal conditions that may be indicative of an error or problem.
We display these at the normal verbosity level.
|
|
|
Useful status messages.
We display these at the normal verbosity level.
This is for the ordinary helpful status messages that users see. Just
enough information to know that things are working but not floods of detail.
|
|
|
|
|
More detail on the operation of some action.
We display these messages when the verbosity level is verbose
|
|
|
Detailed internal debugging information
We display these messages when the verbosity level is deafening
|
|
|
:: String | a description of the action we were attempting
| -> IO () | the action itself
| -> IO () | | Perform an IO action, catching any IO exceptions and printing an error
if one occurs.
|
|
|
running programs
|
|
|
|
|
Run a command and return its output.
The output is assumed to be text in the locale encoding.
|
|
|
:: Verbosity | | -> FilePath | | -> [String] | | -> Maybe (String, Bool) | input text and binary mode
| -> Bool | output in binary mode
| -> IO (String, String, ExitCode) | output, errors, exit
| Run a command and return its output, errors and exit status. Optionally
also supply some input. Also provides control over whether the binary/text
mode of the input and output.
|
|
|
|
|
|
Like the unix xargs program. Useful for when we've got very long command
lines that might overflow an OS limit on command line length and so you
need to invoke a command multiple times to get all the args in.
Use it with either of the rawSystem variants above. For example:
xargs (32*1024) (rawSystemExit verbosity) prog fixedArgs bigArgs
|
|
|
Look for a program on the path.
|
|
|
:: String | version args
| -> String -> String | function to select version
number from program output
| -> Verbosity | | -> FilePath | location
| -> IO (Maybe Version) | | Look for a program and try to find it's version number. It can accept
either an absolute path or the name of a program binary, in which case we
will look for the program on the path.
|
|
|
copying files
|
|
|
|
|
Same as createDirectoryIfMissing but logs at higher verbosity levels.
|
|
|
Copies a file without copying file permissions. The target file is created
with default permissions. Any existing target file is replaced.
At higher verbosity levels it logs an info message.
|
|
|
|
|
Copies a bunch of files to a target directory, preserving the directory
structure in the target location. The target directories are created if they
do not exist.
The files are identified by a pair of base directory and a path relative to
that base. It is only the relative part that is preserved in the
destination.
For example:
copyFiles normal "dist/src"
[("", "src/Foo.hs"), ("dist/build/", "src/Bar.hs")]
This would copy "src/Foo.hs" to "dist/src/src/Foo.hs" and
copy "dist/build/src/Bar.hs" to "dist/src/src/Bar.hs".
This operation is not atomic. Any IO failure during the copy (including any
missing source files) leaves the target in an unknown state so it is best to
use it with a freshly created directory so that it can be simply deleted if
anything goes wrong.
|
|
installing files
|
|
|
Install an ordinary file. This is like a file copy but the permissions
are set appropriately for an installed file. On Unix it is "-rw-r--r--"
while on Windows it uses the default permissions for the target directory.
|
|
|
Install an executable file. This is like a file copy but the permissions
are set appropriately for an installed file. On Unix it is "-rwxr-xr-x"
while on Windows it uses the default permissions for the target directory.
|
|
|
This is like copyFiles but uses installOrdinaryFile.
|
|
|
This installs all the files in a directory to a target location,
preserving the directory layout. All the files are assumed to be ordinary
rather than executable files.
|
|
file names
|
|
|
The path name that represents the current directory.
In Unix, it's ".", but this is system-specific.
(E.g. AmigaOS uses the empty string "" for the current directory.)
|
|
finding files
|
|
|
:: [FilePath] | search locations
| -> FilePath | File Name
| -> IO FilePath | | Find a file by looking in a search path. The file path must match exactly.
|
|
|
|
Find a file by looking in a search path with one of a list of possible
file extensions. The file base name should be given and it will be tried
with each of the extensions in each element of the search path.
|
|
|
Like findFileWithExtension but returns which element of the search path
the file was found in, and the file path relative to that base directory.
|
|
|
:: [FilePath] | build prefix (location of objects)
| -> [String] | search suffixes
| -> ModuleName | module
| -> IO (FilePath, FilePath) | | Find the file corresponding to a Haskell module name.
This is similar to findFileWithExtension' but specialised to a module
name. The function fails if the file corresponding to the module is missing.
|
|
|
|
|
|
|
List all the files in a directory and all subdirectories.
The order places files in sub-directories after all the files in their
parent directories. The list is generated lazily so is not well defined if
the source directory structure changes before the list is used.
|
|
simple file globbing
|
|
|
|
|
|
|
|
|
Constructors | NoGlob FilePath | No glob at all, just an ordinary file
| FileGlob FilePath String | dir prefix and extension, like "foo/bar/*.baz" corresponds to
FileGlob "foo/bar" ".baz"
|
|
|
|
temp files and dirs
|
|
|
|
|
|
Create and use a temporary directory.
Creates a new temporary directory inside the given directory, making use
of the template. The temp directory is deleted after use. For example:
withTempDirectory verbosity "src" "sdist." $ \tmpDir -> do ...
The tmpDir will be a new subdirectory of the given directory, e.g.
src/sdist.342.
|
|
.cabal and .buildinfo files
|
|
|
Package description file (pkgname.cabal)
|
|
|
:: FilePath | Where to look
| -> IO FilePath | pkgname.cabal
| Find a package description file in the given directory. Looks for
.cabal files.
|
|
|
|
Optional auxiliary package information file (pkgname.buildinfo)
|
|
|
:: FilePath | Directory to search
| -> IO (Maybe FilePath) | dir/pkgname.buildinfo, if present
| Find auxiliary package information in the given directory.
Looks for .buildinfo files.
|
|
|
reading and writing files safely
|
|
|
Gets the contents of a file, but guarantee that it gets closed.
The file is read lazily but if it is not fully consumed by the action then
the remaining input is truncated and the file is closed.
|
|
|
Writes a file atomically.
The file is either written sucessfully or an IO exception is raised and
the original file is left unchanged.
On windows it is not possible to delete a file that is open by a process.
This case will give an IO exception but the atomic property is not affected.
|
|
|
Write a file but only if it would have new content. If we would be writing
the same as the existing content then leave the file as is so that we do not
update the file's modification time.
|
|
Unicode
|
|
|
|
|
|
|
Reads a UTF8 encoded text file as a Unicode String
Reads lazily using ordinary readFile.
|
|
|
Reads a UTF8 encoded text file as a Unicode String
Same behaviour as withFileContents.
|
|
|
Writes a Unicode String as a UTF8 encoded text file.
Uses writeFileAtomic, so provides the same guarantees.
|
|
|
Fix different systems silly line ending conventions
|
|
generic utils
|
|
|
|
|
|
|
|
intercalate :: [a] -> [[a]] -> [a] | Source |
|
|
|
|
|
Wraps text to the default line width. Existing newlines are preserved.
|
|
|
Wraps a list of words to a list of lines of words of a particular width.
|
|
Produced by Haddock version 2.6.1 |