diff --git a/lib/GHCup/GHC.hs b/lib/GHCup/GHC.hs index 7c9b8ca1..978b16f6 100644 --- a/lib/GHCup/GHC.hs +++ b/lib/GHCup/GHC.hs @@ -868,20 +868,26 @@ 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, NotFoundInPATH] 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) + + -- bootstrap, if necessary + liftE $ bootAndGenVersion 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' @@ -934,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) @@ -1035,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 @@ -1045,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