Allow to apply patches for compiling from source

This commit is contained in:
Julian Ospald 2020-04-08 22:57:57 +02:00
parent 5382fd9aca
commit 6a79782650
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
4 changed files with 58 additions and 6 deletions

View File

@ -111,6 +111,7 @@ data CompileOptions = CompileOptions
, bootstrapGhc :: Either Version (Path Abs) , bootstrapGhc :: Either Version (Path Abs)
, jobs :: Maybe Int , jobs :: Maybe Int
, buildConfig :: Maybe (Path Abs) , buildConfig :: Maybe (Path Abs)
, patchDir :: Maybe (Path Abs)
} }
data UpgradeOpts = UpgradeInplace data UpgradeOpts = UpgradeInplace
@ -342,6 +343,19 @@ compileOpts =
"Absolute path to build config file" "Absolute path to build config file"
) )
) )
<*> optional
(option
(eitherReader
(\x ->
bimap show id . parseAbs . E.encodeUtf8 . T.pack $ x :: Either
String
(Path Abs)
)
)
(short 'p' <> long "patchdir" <> metavar "PATCH_DIR" <> help
"Absolute path to patch directory (applied in order, uses -p1)"
)
)
versionParser :: Parser Version versionParser :: Parser Version
@ -564,6 +578,7 @@ main = do
, DigestError , DigestError
, GHCupSetError , GHCupSetError
, NoDownload , NoDownload
, PatchFailed
, UnknownArchive , UnknownArchive
, DownloadFailed , DownloadFailed
] ]
@ -577,6 +592,7 @@ main = do
, NoDownload , NoDownload
, DigestError , DigestError
, BuildFailed , BuildFailed
, PatchFailed
, DownloadFailed , DownloadFailed
] ]
@ -698,7 +714,7 @@ Check the logs at ~/.ghcup/logs and the build directory #{tmpdir} for more clues
void void
$ (runCompileGHC $ do $ (runCompileGHC $ do
liftE liftE
$ compileGHC dls targetVer bootstrapGhc jobs buildConfig $ compileGHC dls targetVer bootstrapGhc jobs buildConfig patchDir
) )
>>= \case >>= \case
VRight _ -> VRight _ ->
@ -719,7 +735,7 @@ Check the logs at ~/.ghcup/logs and the build directory #{tmpdir} for more clues
Compile (CompileCabal CompileOptions {..}) -> Compile (CompileCabal CompileOptions {..}) ->
void void
$ (runCompileCabal $ do $ (runCompileCabal $ do
liftE $ compileCabal dls targetVer bootstrapGhc jobs liftE $ compileCabal dls targetVer bootstrapGhc jobs patchDir
) )
>>= \case >>= \case
VRight _ -> VRight _ ->

View File

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

View File

@ -88,6 +88,10 @@ data NoLocationHeader = NoLocationHeader
data TooManyRedirs = TooManyRedirs data TooManyRedirs = TooManyRedirs
deriving Show 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|] has_gmake <- isJust <$> searchPath spaths [rel|gmake|]
let mymake = if has_gmake then "gmake" else "make" let mymake = if has_gmake then "gmake" else "make"
execLogged mymake True args [rel|ghc-make|] workdir Nothing 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