Fixup rest of the PR

This commit is contained in:
Julian Ospald 2021-08-11 12:24:51 +02:00
parent bd18fd9aa1
commit 3b24f503d1
Signed by: hasufell
GPG Key ID: 3786C5262ECB4A3F
5 changed files with 69 additions and 46 deletions

View File

@ -209,6 +209,21 @@ sha3=$(sha_sum "${GHCUP_DIR}/cache/ghcup-${JSON_VERSION}.yaml")
[ "${etag2}" = "${etag3}" ] [ "${etag2}" = "${etag3}" ]
[ "${sha2}" = "${sha3}" ] [ "${sha2}" = "${sha3}" ]
# test isolated installs
eghcup install ghc -i "$(pwd)/isolated" 8.10.5
[ "$(isolated/bin/ghc --numeric-version)" = "8.10.5" ]
! eghcup install ghc -i "$(pwd)/isolated" 8.10.5
if [ "${ARCH}" = "64" ] ; then
if [ "${OS}" = "LINUX" ] || [ "${OS}" = "WINDOWS" ] ; then
eghcup install cabal -i "$(pwd)/isolated" 3.4.0.0
[ "$(isolated/cabal --numeric-version)" = "3.4.0.0" ]
eghcup install stack -i "$(pwd)/isolated" 2.7.3
[ "$(isolated/stack --numeric-version)" = "2.7.3" ]
eghcup install hls -i "$(pwd)/isolated" 1.3.0
[ "$(isolated/haskell-language-server-wrapper --numeric-version)" = "1.3.0" ] ||
[ "$(isolated/haskell-language-server-wrapper --numeric-version)" = "1.3.0.0" ]
fi
fi
eghcup upgrade eghcup upgrade
eghcup upgrade -f eghcup upgrade -f

View File

@ -440,6 +440,7 @@ install' _ (_, ListResult {..}) = do
, TagNotFound , TagNotFound
, DigestError , DigestError
, DownloadFailed , DownloadFailed
, DirNotEmpty
, NoUpdate , NoUpdate
, TarDirDoesNotExist , TarDirDoesNotExist
, FileAlreadyExistsError , FileAlreadyExistsError

View File

@ -1469,6 +1469,8 @@ Report bugs at <https://gitlab.haskell.org/haskell/ghcup-hs/issues>|]
#endif #endif
, FileDoesNotExistError , FileDoesNotExistError
, CopyError , CopyError
, NotInstalled
, DirNotEmpty
, NoDownload , NoDownload
, NotInstalled , NotInstalled
, BuildFailed , BuildFailed
@ -1580,6 +1582,7 @@ Report bugs at <https://gitlab.haskell.org/haskell/ghcup-hs/issues>|]
, UnknownArchive , UnknownArchive
, TarDirDoesNotExist , TarDirDoesNotExist
, NotInstalled , NotInstalled
, DirNotEmpty
#if !defined(TAR) #if !defined(TAR)
, ArchiveResult , ArchiveResult
#endif #endif

View File

@ -196,6 +196,7 @@ installGHCBindist :: ( MonadFail m
, NotInstalled , NotInstalled
, UnknownArchive , UnknownArchive
, TarDirDoesNotExist , TarDirDoesNotExist
, DirNotEmpty
#if !defined(TAR) #if !defined(TAR)
, ArchiveResult , ArchiveResult
#endif #endif
@ -262,6 +263,7 @@ installPackedGHC :: ( MonadMask m
'[ BuildFailed '[ BuildFailed
, UnknownArchive , UnknownArchive
, TarDirDoesNotExist , TarDirDoesNotExist
, DirNotEmpty
#if !defined(TAR) #if !defined(TAR)
, ArchiveResult , ArchiveResult
#endif #endif
@ -269,6 +271,8 @@ installPackedGHC :: ( MonadMask m
installPackedGHC dl msubdir inst ver = do installPackedGHC dl msubdir inst ver = do
PlatformRequest {..} <- lift getPlatformReq PlatformRequest {..} <- lift getPlatformReq
liftE $ installDestSanityCheck inst
-- unpack -- unpack
tmpUnpack <- lift mkGhcupTmpDir tmpUnpack <- lift mkGhcupTmpDir
liftE $ unpackToDir tmpUnpack dl liftE $ unpackToDir tmpUnpack dl
@ -282,6 +286,22 @@ installPackedGHC dl msubdir inst ver = do
liftE $ runBuildAction tmpUnpack liftE $ runBuildAction tmpUnpack
(Just inst) (Just inst)
(installUnpackedGHC workdir inst ver) (installUnpackedGHC workdir inst ver)
where
-- | Does basic checks for isolated installs
-- Isolated Directory:
-- 1. if it doesn't exist -> proceed
-- 2. if it exists and is empty -> proceed
-- 3. if it exists and is non-empty -> panic and leave the house
installDestSanityCheck :: ( MonadIO m
, MonadCatch m
) =>
FilePath ->
Excepts '[DirNotEmpty] m ()
installDestSanityCheck isoDir = do
hideErrorDef [doesNotExistErrorType] () $ do
contents <- liftIO $ getDirectoryContentsRecursive isoDir
unless (null contents) (throwE $ DirNotEmpty isoDir)
-- | Install an unpacked GHC distribution. This only deals with the GHC -- | Install an unpacked GHC distribution. This only deals with the GHC
@ -361,6 +381,7 @@ installGHCBin :: ( MonadFail m
, NotInstalled , NotInstalled
, UnknownArchive , UnknownArchive
, TarDirDoesNotExist , TarDirDoesNotExist
, DirNotEmpty
#if !defined(TAR) #if !defined(TAR)
, ArchiveResult , ArchiveResult
#endif #endif
@ -438,10 +459,10 @@ installCabalBindist dlinfo ver isoFilepath = do
case isoFilepath of case isoFilepath of
Just isoDir -> do -- isolated install Just isoDir -> do -- isolated install
lift $ $(logInfo) [i|isolated installing Cabal to #{isoDir}|] lift $ $(logInfo) [i|isolated installing Cabal to #{isoDir}|]
liftE $ installCabalUnpacked workdir isoDir ver liftE $ installCabalUnpacked workdir isoDir Nothing
Nothing -> do -- regular install Nothing -> do -- regular install
liftE $ installCabalUnpacked workdir binDir ver liftE $ installCabalUnpacked workdir binDir (Just ver)
-- create symlink if this is the latest version for regular installs -- create symlink if this is the latest version for regular installs
cVers <- lift $ fmap rights getInstalledCabals cVers <- lift $ fmap rights getInstalledCabals
@ -452,17 +473,16 @@ installCabalBindist dlinfo ver isoFilepath = do
installCabalUnpacked :: (MonadLogger m, MonadCatch m, MonadIO m) installCabalUnpacked :: (MonadLogger m, MonadCatch m, MonadIO m)
=> FilePath -- ^ Path to the unpacked cabal bindist (where the executable resides) => FilePath -- ^ Path to the unpacked cabal bindist (where the executable resides)
-> FilePath -- ^ Path to install to -> FilePath -- ^ Path to install to
-> Version -> Maybe Version -- ^ Nothing for isolated install
-> Excepts '[CopyError, FileAlreadyExistsError] m () -> Excepts '[CopyError, FileAlreadyExistsError] m ()
installCabalUnpacked path inst ver = do installCabalUnpacked path inst mver' = do
lift $ $(logInfo) "Installing cabal" lift $ $(logInfo) "Installing cabal"
let cabalFile = "cabal" let cabalFile = "cabal"
liftIO $ createDirRecursive' inst liftIO $ createDirRecursive' inst
let destFileName = cabalFile <> "-" <> T.unpack (prettyVer ver) <> exeExt let destFileName = cabalFile
<> maybe "" (("-" <>) . T.unpack . prettyVer) mver'
<> exeExt
let destPath = inst </> destFileName let destPath = inst </> destFileName
whenM
(liftIO $ doesFileExist destPath)
(throwE $ FileAlreadyExistsError destPath)
handleIO (throwE . CopyError . show) $ liftIO $ copyFile handleIO (throwE . CopyError . show) $ liftIO $ copyFile
(path </> cabalFile <> exeExt) (path </> cabalFile <> exeExt)
destPath destPath
@ -567,10 +587,10 @@ installHLSBindist dlinfo ver isoFilepath = do
case isoFilepath of case isoFilepath of
Just isoDir -> do Just isoDir -> do
lift $ $(logInfo) [i|isolated installing HLS to #{isoDir}|] lift $ $(logInfo) [i|isolated installing HLS to #{isoDir}|]
liftE $ installHLSUnpacked workdir isoDir ver liftE $ installHLSUnpacked workdir isoDir Nothing
Nothing -> do Nothing -> do
liftE $ installHLSUnpacked workdir binDir ver liftE $ installHLSUnpacked workdir binDir (Just ver)
-- create symlink if this is the latest version in a regular install -- create symlink if this is the latest version in a regular install
hlsVers <- lift $ fmap rights getInstalledHLSs hlsVers <- lift $ fmap rights getInstalledHLSs
@ -582,9 +602,9 @@ installHLSBindist dlinfo ver isoFilepath = do
installHLSUnpacked :: (MonadFail m, MonadLogger m, MonadCatch m, MonadIO m) installHLSUnpacked :: (MonadFail m, MonadLogger m, MonadCatch m, MonadIO m)
=> FilePath -- ^ Path to the unpacked hls bindist (where the executable resides) => FilePath -- ^ Path to the unpacked hls bindist (where the executable resides)
-> FilePath -- ^ Path to install to -> FilePath -- ^ Path to install to
-> Version -> Maybe Version -- ^ Nothing for isolated install
-> Excepts '[CopyError] m () -> Excepts '[CopyError] m ()
installHLSUnpacked path inst ver = do installHLSUnpacked path inst mver' = do
lift $ $(logInfo) "Installing HLS" lift $ $(logInfo) "Installing HLS"
liftIO $ createDirRecursive' inst liftIO $ createDirRecursive' inst
@ -597,7 +617,8 @@ installHLSUnpacked path inst ver = do
) )
forM_ bins $ \f -> do forM_ bins $ \f -> do
let toF = dropSuffix exeExt f let toF = dropSuffix exeExt f
<> "~" <> T.unpack (prettyVer ver) <> exeExt <> maybe "" (("~" <>) . T.unpack . prettyVer) mver'
<> exeExt
handleIO (throwE . CopyError . show) $ liftIO $ copyFile handleIO (throwE . CopyError . show) $ liftIO $ copyFile
(path </> f) (path </> f)
(inst </> toF) (inst </> toF)
@ -605,7 +626,9 @@ installHLSUnpacked path inst ver = do
-- install haskell-language-server-wrapper -- install haskell-language-server-wrapper
let wrapper = "haskell-language-server-wrapper" let wrapper = "haskell-language-server-wrapper"
toF = wrapper <> "-" <> T.unpack (prettyVer ver) <> exeExt toF = wrapper
<> maybe "" (("-" <>) . T.unpack . prettyVer) mver'
<> exeExt
handleIO (throwE . CopyError . show) $ liftIO $ copyFile handleIO (throwE . CopyError . show) $ liftIO $ copyFile
(path </> wrapper <> exeExt) (path </> wrapper <> exeExt)
(inst </> toF) (inst </> toF)
@ -745,9 +768,9 @@ installStackBindist dlinfo ver isoFilepath = do
case isoFilepath of case isoFilepath of
Just isoDir -> do -- isolated install Just isoDir -> do -- isolated install
lift $ $(logInfo) [i|isolated installing Stack to #{isoDir}|] lift $ $(logInfo) [i|isolated installing Stack to #{isoDir}|]
liftE $ installStackUnpacked workdir isoDir ver liftE $ installStackUnpacked workdir isoDir Nothing
Nothing -> do -- regular install Nothing -> do -- regular install
liftE $ installStackUnpacked workdir binDir ver liftE $ installStackUnpacked workdir binDir (Just ver)
-- create symlink if this is the latest version and a regular install -- create symlink if this is the latest version and a regular install
sVers <- lift $ fmap rights getInstalledStacks sVers <- lift $ fmap rights getInstalledStacks
@ -759,13 +782,15 @@ installStackBindist dlinfo ver isoFilepath = do
installStackUnpacked :: (MonadLogger m, MonadCatch m, MonadIO m) installStackUnpacked :: (MonadLogger m, MonadCatch m, MonadIO m)
=> FilePath -- ^ Path to the unpacked stack bindist (where the executable resides) => FilePath -- ^ Path to the unpacked stack bindist (where the executable resides)
-> FilePath -- ^ Path to install to -> FilePath -- ^ Path to install to
-> Version -> Maybe Version -- ^ Nothing for isolated installs
-> Excepts '[CopyError] m () -> Excepts '[CopyError] m ()
installStackUnpacked path inst ver = do installStackUnpacked path inst mver' = do
lift $ $(logInfo) "Installing stack" lift $ $(logInfo) "Installing stack"
let stackFile = "stack" let stackFile = "stack"
liftIO $ createDirRecursive' inst liftIO $ createDirRecursive' inst
let destFileName = stackFile <> "-" <> T.unpack (prettyVer ver) <> exeExt let destFileName = stackFile
<> maybe "" (("-" <>) . T.unpack . prettyVer) mver'
<> exeExt
let destPath = inst </> destFileName let destPath = inst </> destFileName
handleIO (throwE . CopyError . show) $ liftIO $ copyFile handleIO (throwE . CopyError . show) $ liftIO $ copyFile
(path </> stackFile <> exeExt) (path </> stackFile <> exeExt)
@ -1765,6 +1790,7 @@ compileGHC :: ( MonadMask m
, UnknownArchive , UnknownArchive
, TarDirDoesNotExist , TarDirDoesNotExist
, NotInstalled , NotInstalled
, DirNotEmpty
#if !defined(TAR) #if !defined(TAR)
, ArchiveResult , ArchiveResult
#endif #endif
@ -2252,27 +2278,6 @@ upgradeGHCup mtarget force' = do
--[ Other ]-- --[ Other ]--
------------- -------------
-- | Does basic checks for isolated installs
-- Isolated Directory:
-- 1. if it doesn't exist -> proceed
-- 2. if it exists and is empty -> proceed
-- 3. if it exists and is non-empty -> panic and leave the house
isolatedInstallSanityCheck :: ( MonadIO m
, MonadThrow m
) =>
FilePath ->
Excepts '[IsolatedDirNotEmpty] m ()
isolatedInstallSanityCheck isoDir = do
dirExists <- liftIO $ doesDirectoryExist isoDir
if not dirExists
then pure ()
else do
len <- liftIO $ length <$> listDirectory isoDir
let isDirEmpty = len == 0
if isDirEmpty
then pure ()
else (throwE $ IsolatedDirNotEmpty isoDir)
-- | Creates @ghc-x.y.z@ and @ghc-x.y@ symlinks. This is used for -- | Creates @ghc-x.y.z@ and @ghc-x.y@ symlinks. This is used for

View File

@ -134,13 +134,12 @@ instance Pretty AlreadyInstalled where
pPrint (AlreadyInstalled tool ver') = pPrint (AlreadyInstalled tool ver') =
text [i|#{tool}-#{prettyShow ver'} is already installed|] text [i|#{tool}-#{prettyShow ver'} is already installed|]
-- | The Directory for isolated install already exists and is not empty -- | The Directory is supposed to be empty, but wasn't.
-- | This is done to prevent any overwriting data DirNotEmpty = DirNotEmpty {path :: FilePath}
data IsolatedDirNotEmpty = IsolatedDirNotEmpty {path :: FilePath}
instance Pretty IsolatedDirNotEmpty where instance Pretty DirNotEmpty where
pPrint (IsolatedDirNotEmpty path) = do pPrint (DirNotEmpty path) = do
text [i| The directory for isolated install already exists and is NOT EMPTY : #{path}|] text [i|The directory was expected to be empty, but isn't: #{path}|]
-- | The tool is not installed. Some operations rely on a tool -- | The tool is not installed. Some operations rely on a tool
-- to be installed (such as setting the current GHC version). -- to be installed (such as setting the current GHC version).