From a186b077637acb5aa2eae3485d01001bd39a61f3 Mon Sep 17 00:00:00 2001 From: Brian McKenna Date: Thu, 18 Jun 2020 14:03:25 +0000 Subject: [PATCH 1/3] Support Hadrian provided bindists Fixes #31 --- lib/GHCup/Utils.hs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/GHCup/Utils.hs b/lib/GHCup/Utils.hs index 43d9f32..73d900c 100644 --- a/lib/GHCup/Utils.hs +++ b/lib/GHCup/Utils.hs @@ -54,7 +54,7 @@ import System.IO.Error import System.Posix.FilePath ( getSearchPath , takeFileName ) -import System.Posix.Files.ByteString ( readSymbolicLink ) +import System.Posix.Files.ByteString ( getFileStatus, isSymbolicLink, readSymbolicLink ) import Text.Regex.Posix import URI.ByteString @@ -417,13 +417,20 @@ ghcToolFiles ver = do ([s|^([a-zA-Z0-9_-]*[a-zA-Z0-9_]-)?ghc$|] :: ByteString) ) - (Just symver) <- - (B.stripPrefix (toFilePath ghcbin <> "-") . takeFileName) - <$> (liftIO $ readSymbolicLink $ toFilePath (bindir ghcbin)) - when (B.null symver) - (throwIO $ userError $ "Fatal: ghc symlink target is broken") + let ghcbinPath = toFilePath (bindir ghcbin) + ghcIsLink <- isSymbolicLink <$> (liftIO $ getFileStatus ghcbinPath) + onlyUnversioned <- if ghcIsLink + then do + (Just symver) <- + (B.stripPrefix (toFilePath ghcbin <> "-") . takeFileName) + <$> (liftIO $ readSymbolicLink ghcbinPath) + when (B.null symver) + (throwIO $ userError $ "Fatal: ghc symlink target is broken") + pure $ filter (\x -> not $ symver `B.isSuffixOf` toFilePath x) + else + pure id - pure . filter (\x -> not $ symver `B.isSuffixOf` toFilePath x) $ files + pure $ onlyUnversioned files -- | This file, when residing in ~/.ghcup/ghc// signals that From d276bfb3ec7042ec4342e03c2ac3aa1ad2316002 Mon Sep 17 00:00:00 2001 From: Brian McKenna Date: Fri, 19 Jun 2020 23:06:46 +0000 Subject: [PATCH 2/3] Extract Hadrian logic to isHadrian function with comment --- lib/GHCup/Utils.hs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/GHCup/Utils.hs b/lib/GHCup/Utils.hs index 73d900c..09f1294 100644 --- a/lib/GHCup/Utils.hs +++ b/lib/GHCup/Utils.hs @@ -418,19 +418,23 @@ ghcToolFiles ver = do ) let ghcbinPath = toFilePath (bindir ghcbin) - ghcIsLink <- isSymbolicLink <$> (liftIO $ getFileStatus ghcbinPath) - onlyUnversioned <- if ghcIsLink - then do + ghcIsHadrian <- liftIO $ isHadrian ghcbinPath + onlyUnversioned <- if ghcIsHadrian + then pure id + else do (Just symver) <- (B.stripPrefix (toFilePath ghcbin <> "-") . takeFileName) <$> (liftIO $ readSymbolicLink ghcbinPath) when (B.null symver) (throwIO $ userError $ "Fatal: ghc symlink target is broken") pure $ filter (\x -> not $ symver `B.isSuffixOf` toFilePath x) - else - pure id pure $ onlyUnversioned files + where + -- 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 :: ByteString -> IO Bool + isHadrian = (not . isSymbolicLink <$>) . getFileStatus -- | This file, when residing in ~/.ghcup/ghc// signals that From febe6fcb35fe6fab31ae9c5c568d18ed8eaa88f3 Mon Sep 17 00:00:00 2001 From: Brian McKenna Date: Sat, 20 Jun 2020 03:38:34 +0000 Subject: [PATCH 3/3] Fix behaviour of non-Hadrian builds getFileStatus will resolve symbolic links. getSymbolicLinkStatus doesn't. --- lib/GHCup/Utils.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/GHCup/Utils.hs b/lib/GHCup/Utils.hs index 09f1294..6a6104b 100644 --- a/lib/GHCup/Utils.hs +++ b/lib/GHCup/Utils.hs @@ -54,7 +54,7 @@ import System.IO.Error import System.Posix.FilePath ( getSearchPath , takeFileName ) -import System.Posix.Files.ByteString ( getFileStatus, isSymbolicLink, readSymbolicLink ) +import System.Posix.Files.ByteString ( getSymbolicLinkStatus, isSymbolicLink, readSymbolicLink ) import Text.Regex.Posix import URI.ByteString @@ -434,7 +434,7 @@ ghcToolFiles ver = do -- 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 :: ByteString -> IO Bool - isHadrian = (not . isSymbolicLink <$>) . getFileStatus + isHadrian = (not . isSymbolicLink <$>) . getSymbolicLinkStatus -- | This file, when residing in ~/.ghcup/ghc// signals that