ghcup-0.1.17.2: ghc toolchain installer
Copyright(c) Julian Ospald 2020
LicenseLGPL-3.0
Maintainerhasufell@hasufell.de
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

GHCup.Utils

Description

This module contains GHCup helpers specific to installation and introspection of files/versions etc.

Synopsis

Documentation

ghcLinkDestination Source #

Arguments

:: (MonadReader env m, HasDirs env, MonadThrow m, MonadIO m) 
=> FilePath

the tool, such as ghc, haddock etc.

-> GHCTargetVersion 
-> m FilePath 

The symlink destination of a ghc tool.

rmMinorSymlinks :: (MonadReader env m, HasDirs env, MonadIO m, HasLog env, MonadThrow m, MonadFail m, MonadMask m) => GHCTargetVersion -> Excepts '[NotInstalled] m () Source #

Removes the minor GHC symlinks, e.g. ghc-8.6.5.

rmPlain Source #

Arguments

:: (MonadReader env m, HasDirs env, HasLog env, MonadThrow m, MonadFail m, MonadIO m, MonadMask m) 
=> Maybe Text

target

-> Excepts '[NotInstalled] m () 

Removes the set ghc version for the given target, if any.

rmMajorSymlinks :: (MonadReader env m, HasDirs env, MonadIO m, HasLog env, MonadThrow m, MonadFail m, MonadMask m) => GHCTargetVersion -> Excepts '[NotInstalled] m () Source #

Remove the major GHC symlink, e.g. ghc-8.6.

ghcInstalled :: (MonadIO m, MonadReader env m, HasDirs env, MonadThrow m) => GHCTargetVersion -> m Bool Source #

Whether the given GHC versin is installed.

ghcSrcInstalled :: (MonadIO m, MonadReader env m, HasDirs env, MonadThrow m) => GHCTargetVersion -> m Bool Source #

Whether the given GHC version is installed from source.

ghcSet Source #

Arguments

:: (MonadReader env m, HasDirs env, MonadThrow m, MonadIO m) 
=> Maybe Text

the target of the GHC version, if any (e.g. armv7-unknown-linux-gnueabihf)

-> m (Maybe GHCTargetVersion) 

Whether the given GHC version is set as the current.

getInstalledGHCs :: (MonadReader env m, HasDirs env, MonadIO m) => m [Either FilePath GHCTargetVersion] Source #

Get all installed GHCs by reading ~.ghcupghc/dir. If a dir cannot be parsed, returns left.

getInstalledCabals :: (MonadReader env m, HasDirs env, MonadIO m, MonadCatch m) => m [Either FilePath Version] Source #

Get all installed cabals, by matching on ~/.ghcup/bin/cabal-*.

cabalInstalled :: (MonadIO m, MonadReader env m, HasDirs env, MonadCatch m) => Version -> m Bool Source #

Whether the given cabal version is installed.

getInstalledHLSs :: (MonadReader env m, HasDirs env, MonadIO m, MonadCatch m) => m [Either FilePath Version] Source #

Get all installed hls, by matching on ~/.ghcup/bin/haskell-language-server-wrapper-hlsver.

getInstalledStacks :: (MonadReader env m, HasDirs env, MonadIO m, MonadCatch m) => m [Either FilePath Version] Source #

Get all installed stacks, by matching on ~/.ghcup/bin/stack-stackver.

stackInstalled :: (MonadIO m, MonadReader env m, HasDirs env, MonadCatch m) => Version -> m Bool Source #

Whether the given Stack version is installed.

hlsInstalled :: (MonadIO m, MonadReader env m, HasDirs env, MonadCatch m) => Version -> m Bool Source #

Whether the given HLS version is installed.

hlsGHCVersions :: (MonadReader env m, HasDirs env, MonadIO m, MonadThrow m, MonadCatch m) => m [Version] Source #

Return the GHC versions the currently selected HLS supports.

hlsServerBinaries Source #

Arguments

:: (MonadReader env m, HasDirs env, MonadIO m) 
=> Version 
-> Maybe Version

optional GHC version

-> m [FilePath] 

Get all server binaries for an hls version, if any.

hlsWrapperBinary :: (MonadReader env m, HasDirs env, MonadThrow m, MonadIO m) => Version -> m (Maybe FilePath) Source #

Get the wrapper binary for an hls version, if any.

hlsAllBinaries :: (MonadReader env m, HasDirs env, MonadIO m, MonadThrow m) => Version -> m [FilePath] Source #

Get all binaries for an hls version, if any.

hlsSymlinks :: (MonadReader env m, HasDirs env, MonadIO m, MonadCatch m) => m [FilePath] Source #

Get the active symlinks for hls.

getMajorMinorV :: MonadThrow m => Version -> m (Int, Int) Source #

Extract (major, minor) from any version.

matchPVPrefix :: PVP -> PVP -> Bool Source #

Match PVP prefix.

>>> matchPVPrefix [pver|8.8|] [pver|8.8.4|]
True
>>> matchPVPrefix [pver|8|] [pver|8.8.4|]
True
>>> matchPVPrefix [pver|8.10|] [pver|8.8.4|]
False
>>> matchPVPrefix [pver|8.10|] [pver|8.10.7|]
True

toL :: PVP -> [Int] Source #

getGHCForPVP Source #

Arguments

:: (MonadReader env m, HasDirs env, MonadIO m, MonadThrow m) 
=> PVP 
-> Maybe Text

the target triple

-> m (Maybe GHCTargetVersion) 

Get the latest installed full GHC version that satisfies the given (possibly partial) PVP version.

getGHCForPVP' Source #

Arguments

:: MonadThrow m 
=> PVP 
-> [(PVP, Maybe Text)]

installed GHCs

-> Maybe Text

the target triple

-> m (Maybe GHCTargetVersion) 

Like getGHCForPVP, except with explicit input parameter.

>>> fmap prettyShow $ getGHCForPVP' [pver|8|] installedVersions Nothing
"Just 8.10.7"
>>> fmap prettyShow $ getGHCForPVP' [pver|8.8|] installedVersions Nothing
"Just 8.8.4"
>>> fmap prettyShow $ getGHCForPVP' [pver|8.10.4|] installedVersions Nothing
"Just 8.10.4"

getLatestToolFor :: MonadThrow m => Tool -> PVP -> GHCupDownloads -> m (Maybe (PVP, VersionInfo)) Source #

Get the latest available ghc for the given PVP version, which may only contain parts.

>>> (fmap . fmap) fst $ getLatestToolFor GHC [pver|8|] r
Just (PVP {_pComponents = 8 :| [10,7]})
>>> (fmap . fmap) fst $ getLatestToolFor GHC [pver|8.8|] r
Just (PVP {_pComponents = 8 :| [8,4]})
>>> (fmap . fmap) fst $ getLatestToolFor GHC [pver|8.8.4|] r
Just (PVP {_pComponents = 8 :| [8,4]})

unpackToDir Source #

Arguments

:: (MonadReader env m, HasLog env, MonadIO m, MonadThrow m) 
=> FilePath

destination dir

-> FilePath

archive path

-> Excepts '[UnknownArchive, ArchiveResult] m () 

Unpack an archive to a temporary directory and return that path.

intoSubdir Source #

Arguments

:: (MonadReader env m, HasLog env, MonadIO m, MonadThrow m, MonadCatch m) 
=> FilePath

unpacked tar dir

-> TarDir

how to descend

-> Excepts '[TarDirDoesNotExist] m FilePath 

getTagged :: Tag -> Fold (Map Version VersionInfo) (Version, VersionInfo) Source #

Get the tool version that has this tag. If multiple have it, picks the greatest version.

getLatestBaseVersion :: GHCupDownloads -> PVP -> Maybe (Version, VersionInfo) Source #

Gets the latest GHC with a given base version.

ghcToolFiles :: (MonadReader env m, HasDirs env, MonadThrow m, MonadFail m, MonadIO m) => GHCTargetVersion -> Excepts '[NotInstalled] m [FilePath] Source #

Get tool files from ~/.ghcup/bin/ghc/<ver>/bin/* while ignoring *-<ver> symlinks and accounting for cross triple prefix.

Returns unversioned relative files without extension, e.g.:

  • ["hsc2hs","haddock","hpc","runhaskell","ghc","ghc-pkg","ghci","runghc","hp2ps"]

ghcUpSrcBuiltFile :: FilePath Source #

This file, when residing in ~/.ghcup/ghc/<ver>/ signals that this GHC was built from source. It contains the build config.

make :: (MonadThrow m, MonadIO m, MonadReader env m, HasDirs env, HasSettings env) => [String] -> Maybe FilePath -> m (Either ProcessError ()) Source #

Calls gmake if it exists in PATH, otherwise make.

applyPatches Source #

Arguments

:: (MonadReader env m, HasDirs env, HasLog env, MonadIO m) 
=> FilePath

dir containing patches

-> FilePath

dir to apply patches in

-> Excepts '[PatchFailed] m () 

Try to apply patches in order. Fails with PatchFailed on first failure.

runBuildAction Source #

Arguments

:: (Pretty (V e), Show (V e), PopVariant BuildFailed e, ToVariantMaybe BuildFailed e, MonadReader env m, HasDirs env, HasSettings env, MonadIO m, MonadMask m, HasLog env, MonadUnliftIO m, MonadFail m, MonadCatch m) 
=> FilePath

build directory (cleaned up depending on Settings)

-> Maybe FilePath

dir to *always* clean up on exception

-> Excepts e m a 
-> Excepts '[BuildFailed] m a 

Execute a build action while potentially cleaning up:

  1. the build directory, depending on the KeepDirs setting
  2. the install destination, depending on whether the build failed

rmBDir :: (MonadReader env m, HasLog env, MonadUnliftIO m, MonadIO m) => FilePath -> m () Source #

Remove a build directory, ignoring if it doesn't exist and gracefully printing other errors without crashing.

exeExt :: String Source #

The file extension for executables.

exeExt' :: ByteString Source #

The file extension for executables.

enableAnsiSupport :: IO (Either String Bool) Source #

Enables ANSI support on windows, does nothing on unix.

Returns 'Left str' on errors and 'Right bool' on success, where bool markes whether ansi support was already enabled.

This function never crashes.

Rip-off of https://docs.rs/ansi_term/0.12.1/x86_64-pc-windows-msvc/src/ansi_term/windows.rs.html#10-61

getLinkTarget :: FilePath -> IO FilePath Source #

On unix, we can use symlinks, so we just get the symbolic link target.

On windows, we have to emulate symlinks via shims, see createLink.

pathIsLink :: FilePath -> IO Bool Source #

Checks whether the path is a link.

rmLink :: (MonadReader env m, HasDirs env, MonadIO m, MonadMask m) => FilePath -> m () Source #

createLink Source #

Arguments

:: (MonadMask m, MonadThrow m, HasLog env, MonadIO m, MonadReader env m, HasDirs env, MonadUnliftIO m, MonadFail m) 
=> FilePath

path to the target executable

-> FilePath

path to be created

-> m () 

Creates a symbolic link on unix and a fake symlink on windows for executables, which: 1. is a shim exe 2. has a corresponding .shim file in the same directory that contains the target

This overwrites previously existing files.

On windows, this requires that ensureGlobalTools was run beforehand.

ensureDirectories :: Dirs -> IO () Source #

Ensure ghcup directory structure exists.

ghcBinaryName :: GHCTargetVersion -> String Source #

For ghc without arch triple, this is:

  • ghc-ver (e.g. ghc-8.10.4)

For ghc with arch triple:

  • triple-ghc-ver (e.g. arm-linux-gnueabihf-ghc-8.10.4)