From 974112016ea6d25d0efbc485fcedda635a446659 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Sat, 9 Jul 2022 23:50:20 +0200 Subject: [PATCH] Allow to run 'cabal update' automatically before the HLS build --- app/ghcup/GHCup/OptParse/Compile.hs | 7 +++++-- lib/GHCup/HLS.hs | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/ghcup/GHCup/OptParse/Compile.hs b/app/ghcup/GHCup/OptParse/Compile.hs index 3ec5d32..efcefad 100644 --- a/app/ghcup/GHCup/OptParse/Compile.hs +++ b/app/ghcup/GHCup/OptParse/Compile.hs @@ -85,6 +85,7 @@ data HLSCompileOptions = HLSCompileOptions { targetHLS :: HLS.HLSVer , jobs :: Maybe Int , setCompile :: Bool + , updateCabal :: Bool , ovewrwiteVer :: Either Bool Version , isolateDir :: Maybe FilePath , cabalProject :: Maybe (Either FilePath URI) @@ -152,8 +153,8 @@ Examples: These need to be available in PATH prior to compilation. Examples: - # compile 1.7.0.0 from hackage for 8.10.7 - ghcup compile hls --hackage-version 1.7.0.0 --ghc 8.10.7 + # compile 1.7.0.0 from hackage for 8.10.7, running 'cabal update' before the build + ghcup compile hls --hackage-version 1.7.0.0 --ghc 8.10.7 --cabal-update # compile 1.7.0.0 from official source dist for ghc 8.10.5 and 8.10.7, passing '--allow-newer' to cabal ghcup compile hls -v 1.7.0.0 -j 12 --ghc 8.10.5 --ghc 8.10.7 -- --allow-newer # compile from master for ghc 9.2.3 using 'git describe' to name the binary and ignore the pinned index state @@ -335,6 +336,7 @@ hlsCompileOpts = ) ) <*> fmap (fromMaybe True) (invertableSwitch "set" Nothing True (help "Don't set as active version after install")) + <*> switch (long "cabal-update" <> help "Run 'cabal update' before the build") <*> ( (Right <$> option @@ -524,6 +526,7 @@ compile compileCommand settings Dirs{..} runAppState runLogger = do (maybe GHCupInternal IsolateDir isolateDir) cabalProject cabalProjectLocal + updateCabal patches cabalArgs GHCupInfo { _ghcupDownloads = dls } <- lift getGHCupInfo diff --git a/lib/GHCup/HLS.hs b/lib/GHCup/HLS.hs index 8aeb218..2c08864 100644 --- a/lib/GHCup/HLS.hs +++ b/lib/GHCup/HLS.hs @@ -337,6 +337,7 @@ compileHLS :: ( MonadMask m -> InstallDir -> Maybe (Either FilePath URI) -> Maybe URI + -> Bool -> Maybe (Either FilePath [URI]) -- ^ patches -> [Text] -- ^ additional args to cabal install -> Excepts '[ NoDownload @@ -349,11 +350,14 @@ compileHLS :: ( MonadMask m , BuildFailed , NotInstalled ] m Version -compileHLS targetHLS ghcs jobs ov installDir cabalProject cabalProjectLocal patches cabalArgs = do +compileHLS targetHLS ghcs jobs ov installDir cabalProject cabalProjectLocal updateCabal patches cabalArgs = do PlatformRequest { .. } <- lift getPlatformReq GHCupInfo { _ghcupDownloads = dls } <- lift getGHCupInfo Dirs { .. } <- lift getDirs + when updateCabal $ reThrowAll @_ @'[ProcessError] DownloadFailed $ do + lift $ logInfo "Updating cabal DB" + lEM $ exec "cabal" ["update"] (Just $ fromGHCupPath tmpDir) Nothing (workdir, tmpUnpack, tver, git_describe) <- case targetHLS of -- unpack from version tarball