From 170f0f4652af0bed9dc1c4bc622ef3b5a9b7c417 Mon Sep 17 00:00:00 2001 From: Divam Date: Sun, 8 Dec 2024 18:04:24 +0900 Subject: [PATCH 1/2] Fix use of 'boot' file to determine workdir; apply patches in 'compile ghc --remote-source-dist' --- lib/GHCup/GHC.hs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/GHCup/GHC.hs b/lib/GHCup/GHC.hs index 7c9b8ca1..e1ffebc2 100644 --- a/lib/GHCup/GHC.hs +++ b/lib/GHCup/GHC.hs @@ -868,20 +868,23 @@ compileGHC targetGhc crossTarget vps bstrap hghc jobs mbuildConfig patches aargs tmpDownload <- lift withGHCupTmpDir tmpUnpack <- lift mkGhcupTmpDir tar <- liftE $ download uri Nothing Nothing Nothing (fromGHCupPath tmpDownload) Nothing False - (bf, tver) <- liftE $ cleanUpOnError @'[UnknownArchive, ArchiveResult, ProcessError] tmpUnpack $ do + (workdir, tver) <- liftE $ cleanUpOnError @'[UnknownArchive, ArchiveResult, ProcessError, PatchFailed, DownloadFailed, DigestError, ContentLengthError, GPGError] tmpUnpack $ do liftE $ unpackToDir (fromGHCupPath tmpUnpack) tar - let regex = [s|^(.*/)*boot$|] :: B.ByteString - [bootFile] <- liftIO $ findFilesDeep + + -- bootstrapped ghc renames boot to boot.source + let regex = [s|^(.*/)*boot(.source)*$|] :: B.ByteString + (boot:_) <- liftIO $ findFilesDeep tmpUnpack - (makeRegexOpts compExtended - execBlank - regex - ) - tver <- liftE $ catchAllE @_ @'[ProcessError, ParseError, NotFoundInPATH] @'[] (\_ -> pure Nothing) $ fmap Just $ getGHCVer - (appendGHCupPath tmpUnpack (takeDirectory bootFile)) - pure (bootFile, tver) + (makeRegexOpts compExtended execBlank regex) + + let workdir = appendGHCupPath tmpUnpack (takeDirectory boot) + + lift $ logDebug $ "GHC compile workdir: " <> T.pack (fromGHCupPath workdir) + + liftE $ applyAnyPatch patches (fromGHCupPath workdir) - let workdir = appendGHCupPath tmpUnpack (takeDirectory bf) + tver <- liftE $ catchAllE @_ @'[ProcessError, ParseError, NotFoundInPATH] @'[] (\_ -> pure Nothing) $ fmap Just $ getGHCVer workdir + pure (workdir, tver) ov <- case vps of Just vps' -> fmap Just $ expandVersionPattern tver "" "" "" "" vps' From 7757dd281623989bcf1a3034d59d6a9035373731 Mon Sep 17 00:00:00 2001 From: Divam Date: Sun, 15 Dec 2024 17:21:42 +0900 Subject: [PATCH 2/2] Separate boot step from getGHCVer --- lib/GHCup/GHC.hs | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/GHCup/GHC.hs b/lib/GHCup/GHC.hs index e1ffebc2..978b16f6 100644 --- a/lib/GHCup/GHC.hs +++ b/lib/GHCup/GHC.hs @@ -868,7 +868,7 @@ compileGHC targetGhc crossTarget vps bstrap hghc jobs mbuildConfig patches aargs tmpDownload <- lift withGHCupTmpDir tmpUnpack <- lift mkGhcupTmpDir tar <- liftE $ download uri Nothing Nothing Nothing (fromGHCupPath tmpDownload) Nothing False - (workdir, tver) <- liftE $ cleanUpOnError @'[UnknownArchive, ArchiveResult, ProcessError, PatchFailed, DownloadFailed, DigestError, ContentLengthError, GPGError] tmpUnpack $ do + (workdir, tver) <- liftE $ cleanUpOnError @'[UnknownArchive, ArchiveResult, ProcessError, PatchFailed, DownloadFailed, DigestError, ContentLengthError, GPGError, NotFoundInPATH] tmpUnpack $ do liftE $ unpackToDir (fromGHCupPath tmpUnpack) tar -- bootstrapped ghc renames boot to boot.source @@ -883,6 +883,9 @@ compileGHC targetGhc crossTarget vps bstrap hghc jobs mbuildConfig patches aargs liftE $ applyAnyPatch patches (fromGHCupPath workdir) + -- bootstrap, if necessary + liftE $ bootAndGenVersion workdir + tver <- liftE $ catchAllE @_ @'[ProcessError, ParseError, NotFoundInPATH] @'[] (\_ -> pure Nothing) $ fmap Just $ getGHCVer workdir pure (workdir, tver) @@ -937,6 +940,8 @@ compileGHC targetGhc crossTarget vps bstrap hghc jobs mbuildConfig patches aargs liftE $ applyAnyPatch patches (fromGHCupPath tmpUnpack) -- bootstrap + liftE $ bootAndGenVersion tmpUnpack + tver <- liftE $ catchAllE @_ @'[ProcessError, ParseError, NotFoundInPATH] @'[] (\_ -> pure Nothing) $ fmap Just $ getGHCVer tmpUnpack liftE $ catchWarn $ lEM @_ @'[ProcessError] $ darwinNotarization _rPlatform (fromGHCupPath tmpUnpack) @@ -1038,6 +1043,24 @@ compileGHC targetGhc crossTarget vps bstrap hghc jobs mbuildConfig patches aargs pure installVer where + bootAndGenVersion :: ( MonadReader env m + , HasSettings env + , HasDirs env + , HasLog env + , MonadIO m + , MonadThrow m + ) + => GHCupPath + -> Excepts '[ProcessError, NotFoundInPATH] m () + bootAndGenVersion tmpUnpack = do + let bootFile = fromGHCupPath tmpUnpack "boot" + hasBootFile <- liftIO $ doesFileExist bootFile + when hasBootFile $ do + lift $ logDebug "Doing ghc-bootstrap" + lEM $ execLogged "python3" ["./boot"] (Just $ fromGHCupPath tmpUnpack) "ghc-bootstrap" Nothing + -- This configure is to generate VERSION file + liftE $ configureWithGhcBoot Nothing [] (Just $ fromGHCupPath tmpUnpack) "ghc-bootstrap" + getGHCVer :: ( MonadReader env m , HasSettings env , HasDirs env @@ -1048,8 +1071,6 @@ compileGHC targetGhc crossTarget vps bstrap hghc jobs mbuildConfig patches aargs => GHCupPath -> Excepts '[ProcessError, ParseError, NotFoundInPATH] m Version getGHCVer tmpUnpack = do - lEM $ execLogged "python3" ["./boot"] (Just $ fromGHCupPath tmpUnpack) "ghc-bootstrap" Nothing - liftE $ configureWithGhcBoot Nothing [] (Just $ fromGHCupPath tmpUnpack) "ghc-bootstrap" let versionFile = fromGHCupPath tmpUnpack "VERSION" hasVersionFile <- liftIO $ doesFileExist versionFile if hasVersionFile