cabal-install-3.10.2.1: The command-line interface for Cabal and Hackage.

Safe Haskell | None
Language | Haskell2010

Distribution.Client.Utils

Synopsis

- data MergeResult a b
  - = OnlyInLeft a
  - | InBoth a b
  - | OnlyInRight b
- mergeBy :: (a -> b -> Ordering) -> [a] -> [b] -> [MergeResult a b]
- duplicates :: Ord a => [a] -> [[a]]
- duplicatesBy :: (a -> a -> Ordering) -> [a] -> [[a]]
- readMaybe :: Read a => String -> Maybe a
- inDir :: Maybe FilePath -> IO a -> IO a
- withEnv :: String -> String -> IO a -> IO a
- withEnvOverrides :: [(String, Maybe FilePath)] -> IO a -> IO a
- logDirChange :: (String -> IO ()) -> Maybe FilePath -> IO a -> IO a
- withExtraPathEnv :: [FilePath] -> IO a -> IO a
- determineNumJobs :: Flag (Maybe Int) -> Int
- numberOfProcessors :: Int
- removeExistingFile :: FilePath -> IO ()
- withTempFileName :: FilePath -> String -> (FilePath -> IO a) -> IO a
- makeAbsoluteToCwd :: FilePath -> IO FilePath
- makeRelativeToCwd :: FilePath -> IO FilePath
- makeRelativeToDir :: FilePath -> FilePath -> IO FilePath
- makeRelativeCanonical :: FilePath -> FilePath -> FilePath
- filePathToByteString :: FilePath -> ByteString
- byteStringToFilePath :: ByteString -> FilePath
- tryCanonicalizePath :: FilePath -> IO FilePath
- canonicalizePathNoThrow :: FilePath -> IO FilePath
- moreRecentFile :: FilePath -> FilePath -> IO Bool
- existsAndIsMoreRecentThan :: FilePath -> FilePath -> IO Bool
- tryFindAddSourcePackageDesc :: Verbosity -> FilePath -> String -> IO FilePath
- tryFindPackageDesc :: Verbosity -> FilePath -> String -> IO FilePath
- findOpenProgramLocation :: Platform -> IO (Either String FilePath)
- relaxEncodingErrors :: Handle -> IO ()
- data ProgressPhase
  - = ProgressDownloading
  - | ProgressDownloaded
  - | ProgressStarting
  - | ProgressBuilding
  - | ProgressHaddock
  - | ProgressInstalling
  - | ProgressCompleted
- progressMessage :: Verbosity -> ProgressPhase -> String -> IO ()
- pvpize :: Bool -> Version -> VersionRange
- incVersion :: Int -> Version -> Version
- getCurrentYear :: IO Integer
- listFilesRecursive :: FilePath -> IO [FilePath]
- listFilesInside :: (FilePath -> IO Bool) -> FilePath -> IO [FilePath]
- safeRead :: Read a => String -> Maybe a
- hasElem :: Ord a => [a] -> a -> Bool

# Documentation

data MergeResult a b #

Constructors

OnlyInLeft a |
InBoth a b |
OnlyInRight b |

mergeBy :: (a -> b -> Ordering) -> [a] -> [b] -> [MergeResult a b] #

Generic merging utility. For sorted input lists this is a full outer join.

duplicates :: Ord a => [a] -> [[a]] #

duplicatesBy :: (a -> a -> Ordering) -> [a] -> [[a]] #

readMaybe :: Read a => String -> Maybe a #

Parse a string using the `Read` instance. Succeeds if there is exactly one valid result.

    >>> readMaybe "123" :: Maybe Int
    Just 123

    >>> readMaybe "hello" :: Maybe Int
    Nothing

Since: base-4.6.0.0

inDir :: Maybe FilePath -> IO a -> IO a #

Executes the action in the specified directory.

Warning: This operation is NOT thread-safe, because current working directory is a process-global concept.

withEnv :: String -> String -> IO a -> IO a #

Executes the action with an environment variable set to some value.

Warning: This operation is NOT thread-safe, because current environment is a process-global concept.

withEnvOverrides :: [(String, Maybe FilePath)] -> IO a -> IO a #

Executes the action with a list of environment variables and corresponding overrides, where

- ``Just` v` means "set the environment variable's value to `v`".
- `Nothing` means "unset the environment variable".

Warning: This operation is NOT thread-safe, because current environment is a process-global concept.

logDirChange :: (String -> IO ()) -> Maybe FilePath -> IO a -> IO a #

Log directory change in `make` compatible syntax

withExtraPathEnv :: [FilePath] -> IO a -> IO a #

Executes the action, increasing the PATH environment in some way

Warning: This operation is NOT thread-safe, because the environment variables are a process-global concept.

determineNumJobs :: Flag (Maybe Int) -> Int #

Determine the number of jobs to use given the value of the '-j' flag.

numberOfProcessors :: Int #

removeExistingFile :: FilePath -> IO () #

Like `removeFile`, but does not throw an exception when the file does not exist.

withTempFileName :: FilePath -> String -> (FilePath -> IO a) -> IO a #

A variant of `withTempFile` that only gives us the file name, and while it will clean up the file afterwards, it's lenient if the file is moved/deleted.

makeAbsoluteToCwd :: FilePath -> IO FilePath #

Given a relative path, make it absolute relative to the current directory. Absolute paths are returned unmodified.

makeRelativeToCwd :: FilePath -> IO FilePath #

Given a path (relative or absolute), make it relative to the current directory, including using `../..` if necessary.

makeRelativeToDir :: FilePath -> FilePath -> IO FilePath #

Given a path (relative or absolute), make it relative to the given directory, including using `../..` if necessary.

makeRelativeCanonical :: FilePath -> FilePath -> FilePath #

Given a canonical absolute path and canonical absolute dir, make the path relative to the directory, including using `../..` if necessary. Returns the original absolute path if it is not on the same drive as the given dir.

filePathToByteString :: FilePath -> ByteString #

Convert a `FilePath` to a lazy `ByteString`. Each `Char` is encoded as a little-endian `Word32`.

byteStringToFilePath :: ByteString -> FilePath #

Reverse operation to `filePathToByteString`.

tryCanonicalizePath :: FilePath -> IO FilePath #

Workaround for the inconsistent behaviour of `canonicalizePath`. Always throws an error if the path refers to a non-existent file.

canonicalizePathNoThrow :: FilePath -> IO FilePath #

A non-throwing wrapper for `canonicalizePath`. If `canonicalizePath` throws an exception, returns the path argument unmodified.

moreRecentFile :: FilePath -> FilePath -> IO Bool #

Like Distribution.Simple.Utils.moreRecentFile, but uses getModTime instead of getModificationTime for higher precision. We can't merge the two because Distribution.Client.Time uses MIN_VERSION macros.

existsAndIsMoreRecentThan :: FilePath -> FilePath -> IO Bool #

Like `moreRecentFile`, but also checks that the first file exists.

tryFindAddSourcePackageDesc :: Verbosity -> FilePath -> String -> IO FilePath #

Like `tryFindPackageDesc`, but with error specific to add-source deps.

tryFindPackageDesc :: Verbosity -> FilePath -> String -> IO FilePath #

Try to find a `.cabal` file, in directory `depPath`. Fails if one cannot be found, with `err` prefixing the error message. This function simply allows us to give a more descriptive error than that provided by `findPackageDesc`.

findOpenProgramLocation :: Platform -> IO (Either String FilePath) #

relaxEncodingErrors :: Handle -> IO () #

Sets the handler for encoding errors to one that transliterates invalid characters into one present in the encoding (i.e., '?'). This is opposed to the default behavior, which is to throw an exception on error. This function will ignore file handles that have a Unicode encoding set. It's a no-op for versions of `base` less than 4.4.

data ProgressPhase #

Phase of building a dependency. Represents current status of package dependency processing. See #4040 for details.

Constructors

ProgressDownloading |
ProgressDownloaded |
ProgressStarting |
ProgressBuilding |
ProgressHaddock |
ProgressInstalling |
ProgressCompleted |

progressMessage :: Verbosity -> ProgressPhase -> String -> IO () #

pvpize :: Bool -> Version -> VersionRange #

Given a version, return an API-compatible (according to PVP) version range.

If the boolean argument denotes whether to use a desugared representation (if `True`) or the new-style `^>=`-form (if `False`).

Example: `pvpize True (mkVersion [0,4,1])` produces the version range `>= 0.4 && < 0.5` (which is the same as `0.4.*`).

incVersion :: Int -> Version -> Version #

Increment the nth version component (counting from 0).

getCurrentYear :: IO Integer #

Returns the current calendar year.

listFilesRecursive :: FilePath -> IO [FilePath] #

From System.Directory.Extra https://hackage.haskell.org/package/extra-1.7.9

listFilesInside :: (FilePath -> IO Bool) -> FilePath -> IO [FilePath] #

From System.Directory.Extra https://hackage.haskell.org/package/extra-1.7.9

safeRead :: Read a => String -> Maybe a #

hasElem :: Ord a => [a] -> a -> Bool #

`hasElem xs x = elem x xs` except that `xs` is turned into a `Set` first. Use underapplied to speed up subsequent lookups, e.g. `filter (hasElem xs) ys`. Only amortized when used several times!

Time complexity \(O((n+m) \log(n))\) for \(m\) lookups in a list of length \(n\). (Compare this to `elem'`s \(O(nm)\).)

This is Agda.Utils.List.hasElem.