Allow to apply patches for compiling from source

This commit is contained in:
2020-04-08 22:57:57 +02:00
parent 5382fd9aca
commit 6a79782650
4 changed files with 58 additions and 6 deletions

View File

@@ -435,6 +435,7 @@ compileGHC :: ( MonadMask m
-> Either Version (Path Abs) -- ^ version to bootstrap with
-> Maybe Int -- ^ jobs
-> Maybe (Path Abs) -- ^ build config
-> Maybe (Path Abs)
-> Excepts
'[ AlreadyInstalled
, BuildFailed
@@ -442,11 +443,12 @@ compileGHC :: ( MonadMask m
, DownloadFailed
, GHCupSetError
, NoDownload
, PatchFailed
, UnknownArchive
]
m
()
compileGHC dls tver bstrap jobs mbuildConfig = do
compileGHC dls tver bstrap jobs mbuildConfig patchdir = do
lift $ $(logDebug) [i|Requested to compile: #{tver} with #{bstrap}|]
whenM (liftIO $ toolAlreadyInstalled GHC tver)
(throwE $ AlreadyInstalled GHC tver)
@@ -497,12 +499,18 @@ GhcWithLlvmCodeGen = YES|]
-> Path Abs
-> Path Abs
-> Excepts
'[NoDownload , FileDoesNotExistError , ProcessError]
'[ NoDownload
, FileDoesNotExistError
, PatchFailed
, ProcessError
]
m
()
compile bghc ghcdir workdir = do
lift $ $(logInfo) [i|configuring build|]
forM_ patchdir $ \dir -> liftE $ applyPatches dir workdir
-- force ld.bfd for build (others seem to misbehave, like lld from FreeBSD)
newEnv <- addToCurrentEnv [("LD", "ld.bfd")]
@@ -563,16 +571,18 @@ compileCabal :: ( MonadReader Settings m
-> Version -- ^ version to install
-> Either Version (Path Abs) -- ^ version to bootstrap with
-> Maybe Int
-> Maybe (Path Abs)
-> Excepts
'[ BuildFailed
, DigestError
, DownloadFailed
, NoDownload
, PatchFailed
, UnknownArchive
]
m
()
compileCabal dls tver bghc jobs = do
compileCabal dls tver bghc jobs patchdir = do
lift $ $(logDebug) [i|Requested to compile: #{tver} with ghc-#{bghc}|]
-- download source tarball
@@ -595,10 +605,12 @@ compileCabal dls tver bghc jobs = do
where
compile :: (MonadThrow m, MonadLogger m, MonadIO m)
=> Path Abs
-> Excepts '[ProcessError] m ()
-> Excepts '[ProcessError , PatchFailed] m ()
compile workdir = do
lift $ $(logInfo) [i|Building (this may take a while)...|]
forM_ patchdir $ \dir -> liftE $ applyPatches dir workdir
ghcEnv <- case bghc of
Right path -> do
-- recover the version from /foo/ghc-6.5.4

View File

@@ -88,6 +88,10 @@ data NoLocationHeader = NoLocationHeader
data TooManyRedirs = TooManyRedirs
deriving Show
-- | A patch could not be applied.
data PatchFailed = PatchFailed
deriving Show
-------------------------

View File

@@ -334,3 +334,23 @@ make args workdir = do
has_gmake <- isJust <$> searchPath spaths [rel|gmake|]
let mymake = if has_gmake then "gmake" else "make"
execLogged mymake True args [rel|ghc-make|] workdir Nothing
-- | Try to apply patches in order. Fails with 'PatchFailed'
-- on first failure.
applyPatches :: (MonadLogger m, MonadIO m)
=> Path Abs -- ^ dir containing patches
-> Path Abs -- ^ dir to apply patches in
-> Excepts '[PatchFailed] m ()
applyPatches pdir ddir = do
patches <- liftIO $ getDirsFiles pdir
forM_ (sort patches) $ \patch' -> do
lift $ $(logInfo) [i|Applying patch #{patch'}|]
(fmap (either (const Nothing) Just) $ liftIO $ exec
"patch"
True
["-p1", "-i", toFilePath patch']
(Just ddir)
Nothing
)
!? PatchFailed