From f8548fefb3e6e98a9b53604272850b75108225fa Mon Sep 17 00:00:00 2001 From: James Hobson Date: Wed, 12 Jan 2022 10:01:48 +0100 Subject: [PATCH 1/3] Added support for quilt series files when patching --- lib/GHCup/Utils.hs | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/GHCup/Utils.hs b/lib/GHCup/Utils.hs index a95d685..555e455 100644 --- a/lib/GHCup/Utils.hs +++ b/lib/GHCup/Utils.hs @@ -879,20 +879,27 @@ makeOut args workdir = do executeOut mymake args workdir --- | Try to apply patches in order. Fails with 'PatchFailed' --- on first failure. +-- | Try to apply patches in order. The order is determined by +-- a quilt series file (in the patch directory) if one exists, +-- else the patches are applied in lexicographical order. +-- Fails with 'PatchFailed' on first failure. applyPatches :: (MonadReader env m, HasDirs env, HasLog env, MonadIO m) => FilePath -- ^ dir containing patches -> FilePath -- ^ dir to apply patches in -> Excepts '[PatchFailed] m () -applyPatches pdir ddir = do - patches <- (fmap . fmap) (pdir ) $ liftIO $ findFiles - pdir - (makeRegexOpts compExtended - execBlank - ([s|.+\.(patch|diff)$|] :: ByteString) - ) - forM_ (sort patches) $ \patch' -> applyPatch patch' ddir +applyPatches pdir ddir = do + seriesExists <- liftIO (doesFileExist (pdir "series")) + patches <- if seriesExists + then + liftIO $ map (pdir ) . lines <$> readFile (pdir "series") + else + (fmap . fmap) (pdir ) $ liftIO $ sort <$> findFiles + pdir + (makeRegexOpts compExtended + execBlank + ([s|.+\.(patch|diff)$|] :: ByteString) + ) + forM_ patches $ \patch' -> applyPatch patch' ddir applyPatch :: (MonadReader env m, HasDirs env, HasLog env, MonadIO m) From 5d431683700d82a2202f89a2835a5f8d5cf133e8 Mon Sep 17 00:00:00 2001 From: James Hobson Date: Wed, 12 Jan 2022 10:06:38 +0100 Subject: [PATCH 2/3] Updated help message for ghcup compile ghc -h --- app/ghcup/GHCup/OptParse/Compile.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/ghcup/GHCup/OptParse/Compile.hs b/app/ghcup/GHCup/OptParse/Compile.hs index 28e1506..ca7867b 100644 --- a/app/ghcup/GHCup/OptParse/Compile.hs +++ b/app/ghcup/GHCup/OptParse/Compile.hs @@ -212,7 +212,7 @@ ghcCompileOpts = (fmap Left $ option str (short 'p' <> long "patchdir" <> metavar "PATCH_DIR" <> help - "Absolute path to patch directory (applies all .patch and .diff files in order using -p1)" + "Absolute path to patch directory (applies all .patch and .diff files in order using -p1. This order is determined by a quilt series file if it exists, or the patches are lexicographically ordered)" ) ) ) From 3fd9fae66a353a0f42f9f67d2a5ec8eb081953d0 Mon Sep 17 00:00:00 2001 From: James Hobson Date: Wed, 12 Jan 2022 13:31:10 +0100 Subject: [PATCH 3/3] Changed to use IO Exceptions --- lib/GHCup/Utils.hs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/GHCup/Utils.hs b/lib/GHCup/Utils.hs index 555e455..fb6212f 100644 --- a/lib/GHCup/Utils.hs +++ b/lib/GHCup/Utils.hs @@ -887,18 +887,19 @@ applyPatches :: (MonadReader env m, HasDirs env, HasLog env, MonadIO m) => FilePath -- ^ dir containing patches -> FilePath -- ^ dir to apply patches in -> Excepts '[PatchFailed] m () -applyPatches pdir ddir = do - seriesExists <- liftIO (doesFileExist (pdir "series")) - patches <- if seriesExists - then - liftIO $ map (pdir ) . lines <$> readFile (pdir "series") - else - (fmap . fmap) (pdir ) $ liftIO $ sort <$> findFiles +applyPatches pdir ddir = do + let lexicographical = (fmap . fmap) (pdir ) $ sort <$> findFiles pdir (makeRegexOpts compExtended execBlank ([s|.+\.(patch|diff)$|] :: ByteString) ) + let quilt = map (pdir ) . lines <$> readFile (pdir "series") + + patches <- liftIO $ quilt `catchIO` (\e -> + if isDoesNotExistError e || isPermissionError e then + lexicographical + else throwIO e) forM_ patches $ \patch' -> applyPatch patch' ddir