Compare commits
1 Commits
issue-150
...
fix-ghcToo
| Author | SHA1 | Date | |
|---|---|---|---|
|
928f4a97de
|
@@ -416,7 +416,7 @@ if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then
|
|||||||
|
|
||||||
case $hls_answer in
|
case $hls_answer in
|
||||||
[Yy]*)
|
[Yy]*)
|
||||||
_eghcup --cache install hls || warn "HLS installation failed, continuing anyway"
|
eghcup --cache install hls || warn "HLS installation failed, continuing anyway"
|
||||||
break ;;
|
break ;;
|
||||||
[Nn]* | "")
|
[Nn]* | "")
|
||||||
break ;;
|
break ;;
|
||||||
@@ -443,7 +443,7 @@ if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then
|
|||||||
|
|
||||||
case $stack_answer in
|
case $stack_answer in
|
||||||
[Yy]*)
|
[Yy]*)
|
||||||
_eghcup --cache install stack || warn "Stack installation failed, continuing anyway"
|
eghcup --cache install stack || warn "Stack installation failed, continuing anyway"
|
||||||
break ;;
|
break ;;
|
||||||
[Nn]* | "")
|
[Nn]* | "")
|
||||||
break ;;
|
break ;;
|
||||||
|
|||||||
@@ -333,65 +333,11 @@ if (!(Test-Path -Path ('{0}' -f $MsysDir))) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Print-Msg -msg 'Creating shortcuts...'
|
Print-Msg -msg 'Creating shortcuts...'
|
||||||
$uninstallShortCut = @'
|
|
||||||
Write-Host 'Removing ghcup toolchain' -ForegroundColor Green
|
|
||||||
ghcup nuke
|
|
||||||
|
|
||||||
Write-Host 'Unsetting GHCUP_INSTALL_BASE_PREFIX' -ForegroundColor Green
|
|
||||||
[Environment]::SetEnvironmentVariable('GHCUP_INSTALL_BASE_PREFIX', $null, [System.EnvironmentVariableTarget]::User)
|
|
||||||
|
|
||||||
$ghcupMsys2 = [System.Environment]::GetEnvironmentVariable('GHCUP_MSYS2', 'user')
|
|
||||||
$GhcupBasePrefixEnv = [System.Environment]::GetEnvironmentVariable('GHCUP_INSTALL_BASE_PREFIX', 'user')
|
|
||||||
|
|
||||||
if ($ghcupMsys2) {
|
|
||||||
$msys2Dir = [IO.Path]::GetFullPath($ghcupMsys2)
|
|
||||||
$baseDir = [IO.Path]::GetFullPath('{0}\ghcup' -f $GhcupBasePrefixEnv)
|
|
||||||
|
|
||||||
if ($msys2Dir.StartsWith($baseDir)) {
|
|
||||||
Write-Host 'Unsetting GHCUP_MSYS2' -ForegroundColor Green
|
|
||||||
[Environment]::SetEnvironmentVariable('GHCUP_MSYS2', $null, [System.EnvironmentVariableTarget]::User)
|
|
||||||
} else {
|
|
||||||
Write-Host ('GHCUP_MSYS2 env variable is set to a non-standard location {0}. Environment variable not unset. Uninstall manually.' -f $msys2Dir) -ForegroundColor Magenta
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Write-Host 'Unsetting GHCUP_MSYS2' -ForegroundColor Green
|
|
||||||
[Environment]::SetEnvironmentVariable('GHCUP_MSYS2', $null, [System.EnvironmentVariableTarget]::User)
|
|
||||||
}
|
|
||||||
|
|
||||||
Write-Host 'Removing ghcup from PATH env var' -ForegroundColor Green
|
|
||||||
$path = [System.Environment]::GetEnvironmentVariable(
|
|
||||||
'PATH',
|
|
||||||
'user'
|
|
||||||
)
|
|
||||||
$path = ($path.Split(';') | Where-Object { $_ -ne ('{0}\bin' -f $baseDir) }) -join ';'
|
|
||||||
[System.Environment]::SetEnvironmentVariable(
|
|
||||||
'PATH',
|
|
||||||
$path,
|
|
||||||
'user'
|
|
||||||
)
|
|
||||||
|
|
||||||
Write-Host 'Removing desktop files' -ForegroundColor Green
|
|
||||||
$DesktopDir = [Environment]::GetFolderPath("Desktop")
|
|
||||||
Remove-Item -LiteralPath ('{0}\Install GHC dev dependencies.lnk' -f $DesktopDir) -Force
|
|
||||||
Remove-Item -LiteralPath ('{0}\Mingw haskell shell.lnk' -f $DesktopDir) -Force
|
|
||||||
Remove-Item -LiteralPath ('{0}\Mingw package management docs.url' -f $DesktopDir) -Force
|
|
||||||
|
|
||||||
Write-Host ('CABAL_DIR env variable is still set to {0} and will be used by cabal regardless of ghcup. You may want to uninstall this manually.' -f [System.Environment]::GetEnvironmentVariable('CABAL_DIR', 'user')) -ForegroundColor Magenta
|
|
||||||
Write-Host 'You may remove this script now.' -ForegroundColor Magenta
|
|
||||||
|
|
||||||
if ($Host.Name -eq "ConsoleHost")
|
|
||||||
{
|
|
||||||
Write-Host "Press any key to continue..."
|
|
||||||
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyUp") > $null
|
|
||||||
}
|
|
||||||
'@
|
|
||||||
|
|
||||||
$DesktopDir = [Environment]::GetFolderPath("Desktop")
|
$DesktopDir = [Environment]::GetFolderPath("Desktop")
|
||||||
$GhcInstArgs = '-mingw64 -mintty -c "pacman --noconfirm -S --needed base-devel gettext autoconf make libtool automake python p7zip patch unzip"'
|
$GhcInstArgs = '-mingw64 -mintty -c "pacman --noconfirm -S --needed base-devel gettext autoconf make libtool automake python p7zip patch unzip"'
|
||||||
Create-Shortcut -SourceExe ('{0}\msys2_shell.cmd' -f $MsysDir) -ArgumentsToSourceExe $GhcInstArgs -DestinationPath ('{0}\Install GHC dev dependencies.lnk' -f $DesktopDir)
|
Create-Shortcut -SourceExe ('{0}\msys2_shell.cmd' -f $MsysDir) -ArgumentsToSourceExe $GhcInstArgs -DestinationPath ('{0}\Install GHC dev dependencies.lnk' -f $DesktopDir)
|
||||||
Create-Shortcut -SourceExe ('{0}\msys2_shell.cmd' -f $MsysDir) -ArgumentsToSourceExe '-mingw64' -DestinationPath ('{0}\Mingw haskell shell.lnk' -f $DesktopDir)
|
Create-Shortcut -SourceExe ('{0}\msys2_shell.cmd' -f $MsysDir) -ArgumentsToSourceExe '-mingw64' -DestinationPath ('{0}\Mingw haskell shell.lnk' -f $DesktopDir)
|
||||||
Create-Shortcut -SourceExe 'https://www.msys2.org/docs/package-management' -ArgumentsToSourceExe '' -DestinationPath ('{0}\Mingw package management docs.url' -f $DesktopDir)
|
Create-Shortcut -SourceExe 'https://www.msys2.org/docs/package-management' -ArgumentsToSourceExe '' -DestinationPath ('{0}\Mingw package management docs.url' -f $DesktopDir)
|
||||||
$null = New-Item -Path $DesktopDir -Name "Uninstall Haskell.ps1" -ItemType "file" -Force -Value $uninstallShortCut
|
|
||||||
|
|
||||||
Print-Msg -msg ('Adding {0}\bin to Users Path...' -f $GhcupDir)
|
Print-Msg -msg ('Adding {0}\bin to Users Path...' -f $GhcupDir)
|
||||||
Add-EnvPath -Path ('{0}\bin' -f ([System.IO.Path]::GetFullPath("$GhcupDir"))) -Container 'User'
|
Add-EnvPath -Path ('{0}\bin' -f ([System.IO.Path]::GetFullPath("$GhcupDir"))) -Container 'User'
|
||||||
|
|||||||
@@ -1393,14 +1393,12 @@ rmGhcupDirs = do
|
|||||||
rmEnvFile :: (MonadCatch m, MonadLogger m, MonadIO m) => FilePath -> m ()
|
rmEnvFile :: (MonadCatch m, MonadLogger m, MonadIO m) => FilePath -> m ()
|
||||||
rmEnvFile enFilePath = do
|
rmEnvFile enFilePath = do
|
||||||
$logInfo "Removing Ghcup Environment File"
|
$logInfo "Removing Ghcup Environment File"
|
||||||
hideErrorDef [doesNotExistErrorType, permissionErrorType] ()
|
hideError doesNotExistErrorType $ liftIO $ deleteFile enFilePath
|
||||||
$ liftIO $ deleteFile enFilePath
|
|
||||||
|
|
||||||
rmConfFile :: (MonadCatch m, MonadLogger m, MonadIO m) => FilePath -> m ()
|
rmConfFile :: (MonadCatch m, MonadLogger m, MonadIO m) => FilePath -> m ()
|
||||||
rmConfFile confFilePath = do
|
rmConfFile confFilePath = do
|
||||||
$logInfo "removing Ghcup Config File"
|
$logInfo "removing Ghcup Config File"
|
||||||
hideErrorDef [doesNotExistErrorType, permissionErrorType] ()
|
hideError doesNotExistErrorType $ liftIO $ deleteFile confFilePath
|
||||||
$ liftIO $ deleteFile confFilePath
|
|
||||||
|
|
||||||
rmDir :: (MonadLogger m, MonadIO m, MonadCatch m) => FilePath -> m ()
|
rmDir :: (MonadLogger m, MonadIO m, MonadCatch m) => FilePath -> m ()
|
||||||
rmDir dir = do
|
rmDir dir = do
|
||||||
@@ -1450,7 +1448,7 @@ rmGhcupDirs = do
|
|||||||
|
|
||||||
deleteFile :: FilePath -> IO ()
|
deleteFile :: FilePath -> IO ()
|
||||||
deleteFile filepath = do
|
deleteFile filepath = do
|
||||||
hideErrorDef [InappropriateType, permissionErrorType] () $ rmFile filepath
|
hideError InappropriateType $ rmFile filepath
|
||||||
|
|
||||||
removeDirIfEmptyOrIsSymlink :: (MonadCatch m, MonadIO m) => FilePath -> m ()
|
removeDirIfEmptyOrIsSymlink :: (MonadCatch m, MonadIO m) => FilePath -> m ()
|
||||||
removeDirIfEmptyOrIsSymlink filepath =
|
removeDirIfEmptyOrIsSymlink filepath =
|
||||||
|
|||||||
@@ -765,49 +765,22 @@ ghcToolFiles ver = do
|
|||||||
whenM (fmap not $ liftIO $ doesDirectoryExist ghcdir)
|
whenM (fmap not $ liftIO $ doesDirectoryExist ghcdir)
|
||||||
(throwE (NotInstalled GHC ver))
|
(throwE (NotInstalled GHC ver))
|
||||||
|
|
||||||
files <- liftIO $ listDirectory bindir
|
files <- liftIO (listDirectory bindir >>= filterM (doesFileExist . (bindir </>)))
|
||||||
-- figure out the <ver> suffix, because this might not be `Version` for
|
pure (getUniqueTools . groupToolFiles . fmap (dropSuffix exeExt) $ files)
|
||||||
-- alpha/rc releases, but x.y.a.somedate.
|
|
||||||
|
|
||||||
ghcIsHadrian <- liftIO $ isHadrian bindir
|
|
||||||
onlyUnversioned <- case ghcIsHadrian of
|
|
||||||
Right () -> pure id
|
|
||||||
Left (fmap (dropSuffix exeExt) -> [ghc, ghc_ver])
|
|
||||||
| (Just symver) <- stripPrefix (ghc <> "-") ghc_ver
|
|
||||||
, not (null symver) -> pure $ filter (\x -> not $ symver `isInfixOf` x)
|
|
||||||
_ -> fail "Fatal: Could not find internal GHC version"
|
|
||||||
|
|
||||||
pure $ onlyUnversioned $ fmap (dropSuffix exeExt) files
|
|
||||||
where
|
where
|
||||||
isNotAnyInfix xs t = foldr (\a b -> not (a `isInfixOf` t) && b) True xs
|
|
||||||
-- GHC is moving some builds to Hadrian for bindists,
|
|
||||||
-- which doesn't create versioned binaries.
|
|
||||||
-- https://gitlab.haskell.org/haskell/ghcup-hs/issues/31
|
|
||||||
isHadrian :: FilePath -- ^ ghcbin path
|
|
||||||
-> IO (Either [String] ()) -- ^ Right for Hadrian
|
|
||||||
isHadrian dir = do
|
|
||||||
-- Non-hadrian has e.g. ["ghc", "ghc-8.10.4"]
|
|
||||||
-- which also requires us to discover the internal version
|
|
||||||
-- to filter the correct tool files.
|
|
||||||
-- We can't use the symlink on windows, so we fall back to some
|
|
||||||
-- more complicated logic.
|
|
||||||
fs <- fmap
|
|
||||||
-- regex over-matches
|
|
||||||
(filter (isNotAnyInfix ["haddock", "ghc-pkg", "ghci"]))
|
|
||||||
$ liftIO $ findFiles
|
|
||||||
dir
|
|
||||||
(makeRegexOpts compExtended
|
|
||||||
execBlank
|
|
||||||
-- for cross, this won't be "ghc", but e.g.
|
|
||||||
-- "armv7-unknown-linux-gnueabihf-ghc"
|
|
||||||
([s|^([a-zA-Z0-9_-]*[a-zA-Z0-9_]-)?ghc.*$|] :: ByteString)
|
|
||||||
)
|
|
||||||
if | length fs == 1 -> pure $ Right () -- hadrian
|
|
||||||
| length fs == 2 -> pure $ Left
|
|
||||||
(sortOn length fs) -- legacy make, result should
|
|
||||||
-- be ["ghc", "ghc-8.10.4"]
|
|
||||||
| otherwise -> fail "isHadrian failed!"
|
|
||||||
|
|
||||||
|
groupToolFiles :: [FilePath] -> [[(FilePath, String)]]
|
||||||
|
groupToolFiles = groupBy (\(a, _) (b, _) -> a == b) . fmap (splitOnPVP "-")
|
||||||
|
|
||||||
|
getUniqueTools :: [[(FilePath, String)]] -> [String]
|
||||||
|
getUniqueTools = filter (isNotAnyInfix blackListedTools) . nub . fmap fst . filter ((== "") . snd) . concat
|
||||||
|
|
||||||
|
blackListedTools :: [String]
|
||||||
|
blackListedTools = ["haddock-ghc"]
|
||||||
|
|
||||||
|
isNotAnyInfix :: [String] -> String -> Bool
|
||||||
|
isNotAnyInfix xs t = foldr (\a b -> not (a `isInfixOf` t) && b) True xs
|
||||||
|
|
||||||
|
|
||||||
-- | This file, when residing in @~\/.ghcup\/ghc\/\<ver\>\/@ signals that
|
-- | This file, when residing in @~\/.ghcup\/ghc\/\<ver\>\/@ signals that
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import Control.Monad.IO.Class
|
|||||||
import Control.Monad.Trans.Class ( lift )
|
import Control.Monad.Trans.Class ( lift )
|
||||||
import Data.Bifunctor
|
import Data.Bifunctor
|
||||||
import Data.ByteString ( ByteString )
|
import Data.ByteString ( ByteString )
|
||||||
import Data.List ( nub )
|
import Data.List ( nub, intercalate )
|
||||||
import Data.Foldable
|
import Data.Foldable
|
||||||
import Data.String
|
import Data.String
|
||||||
import Data.Text ( Text )
|
import Data.Text ( Text )
|
||||||
@@ -47,6 +47,7 @@ import GHC.IO.Exception
|
|||||||
import qualified Data.ByteString as B
|
import qualified Data.ByteString as B
|
||||||
import qualified Data.ByteString.Lazy as L
|
import qualified Data.ByteString.Lazy as L
|
||||||
import qualified Data.Strict.Maybe as S
|
import qualified Data.Strict.Maybe as S
|
||||||
|
import qualified Data.List.Split as Split
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import qualified Data.Text.Encoding as E
|
import qualified Data.Text.Encoding as E
|
||||||
import qualified Data.Text.Encoding.Error as E
|
import qualified Data.Text.Encoding.Error as E
|
||||||
@@ -425,3 +426,19 @@ isNewLine w
|
|||||||
| w == _lf = True
|
| w == _lf = True
|
||||||
| w == _cr = True
|
| w == _cr = True
|
||||||
| otherwise = False
|
| otherwise = False
|
||||||
|
|
||||||
|
|
||||||
|
-- | Split on a PVP suffix.
|
||||||
|
--
|
||||||
|
-- >>> splitOnPVP "-" "ghc-iserv-dyn-9.3.20210706" == ("ghc-iserv-dyn", "9.3.20210706")
|
||||||
|
-- >>> splitOnPVP "-" "ghc-iserv-dyn" == ("ghc-iserv-dyn", "")
|
||||||
|
splitOnPVP :: String -> String -> (String, String)
|
||||||
|
splitOnPVP c s = case Split.splitOn c s of
|
||||||
|
[] -> def
|
||||||
|
[_] -> def
|
||||||
|
xs
|
||||||
|
| let l = last xs
|
||||||
|
, (Right _) <- pvp (T.pack l) -> (intercalate c (init xs), l)
|
||||||
|
| otherwise -> def
|
||||||
|
where
|
||||||
|
def = (s, "")
|
||||||
|
|||||||
Reference in New Issue
Block a user