Skip to content

Commit 5fd0fa8

Browse files
committed
Merge branch 'issue-892'
2 parents d145260 + 5f73320 commit 5fd0fa8

File tree

24 files changed

+843
-183
lines changed

24 files changed

+843
-183
lines changed

app/ghcup/BrickMain.hs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import Brick.Widgets.List ( listSelectedFocusedAttr
3030
, listAttr
3131
)
3232
import Codec.Archive
33+
import Control.Applicative
3334
import Control.Exception.Safe
3435
#if !MIN_VERSION_base(4,13,0)
3536
import Control.Monad.Fail ( MonadFail )
@@ -432,7 +433,7 @@ filterVisible v t e | lInstalled e = True
432433
(lTool e `notElem` hiddenTools)
433434

434435

435-
install' :: (MonadReader AppState m, MonadIO m, MonadThrow m, MonadFail m, MonadMask m, MonadUnliftIO m)
436+
install' :: (MonadReader AppState m, MonadIO m, MonadThrow m, MonadFail m, MonadMask m, MonadUnliftIO m, Alternative m)
436437
=> BrickState
437438
-> (Int, ListResult)
438439
-> m (Either String ())
@@ -463,6 +464,11 @@ install' _ (_, ListResult {..}) = do
463464
, ToolShadowed
464465
, UninstallFailed
465466
, MergeFileTreeError
467+
, NoCompatiblePlatform
468+
, GHCup.Errors.ParseError
469+
, UnsupportedSetupCombo
470+
, DistroNotFound
471+
, NoCompatibleArch
466472
]
467473

468474
run (do
@@ -509,7 +515,7 @@ install' _ (_, ListResult {..}) = do
509515
<> "Also check the logs in ~/.ghcup/logs"
510516

511517

512-
set' :: (MonadReader AppState m, MonadIO m, MonadThrow m, MonadFail m, MonadMask m, MonadUnliftIO m)
518+
set' :: (MonadReader AppState m, MonadIO m, MonadThrow m, MonadFail m, MonadMask m, MonadUnliftIO m, Alternative m)
513519
=> BrickState
514520
-> (Int, ListResult)
515521
-> m (Either String ())

app/ghcup/Main.hs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ toSettings options = do
9090
gpgSetting = fromMaybe (fromMaybe (Types.gpgSetting defaultSettings) uGPGSetting) optGpg
9191
platformOverride = optPlatform <|> (uPlatformOverride <|> Types.platformOverride defaultSettings)
9292
mirrors = fromMaybe (Types.mirrors defaultSettings) uMirrors
93+
stackSetupSource = fromMaybe (Types.stackSetupSource defaultSettings) uStackSetupSource
94+
stackSetup = fromMaybe (Types.stackSetup defaultSettings) uStackSetup
9395
in (Settings {..}, keyBindings)
9496
#if defined(INTERNAL_DOWNLOADER)
9597
defaultDownloader = Internal
@@ -339,11 +341,11 @@ Report bugs at <https://github.com/haskell/ghcup-hs/issues>|]
339341
, NextVerNotFound
340342
, NoToolVersionSet
341343
] m Bool
342-
alreadyInstalling (Install (Right InstallOptions{..})) (GHC, ver) = cmp' GHC instVer ver
343-
alreadyInstalling (Install (Left (InstallGHC InstallOptions{..}))) (GHC, ver) = cmp' GHC instVer ver
344-
alreadyInstalling (Install (Left (InstallCabal InstallOptions{..}))) (Cabal, ver) = cmp' Cabal instVer ver
345-
alreadyInstalling (Install (Left (InstallHLS InstallOptions{..}))) (HLS, ver) = cmp' HLS instVer ver
346-
alreadyInstalling (Install (Left (InstallStack InstallOptions{..}))) (Stack, ver) = cmp' Stack instVer ver
344+
alreadyInstalling (Install (Right InstallGHCOptions{..})) (GHC, ver) = cmp' GHC instVer ver
345+
alreadyInstalling (Install (Left (InstallGHC InstallGHCOptions{..}))) (GHC, ver) = cmp' GHC instVer ver
346+
alreadyInstalling (Install (Left (InstallCabal InstallOptions{..}))) (Cabal, ver) = cmp' Cabal instVer ver
347+
alreadyInstalling (Install (Left (InstallHLS InstallOptions{..}))) (HLS, ver) = cmp' HLS instVer ver
348+
alreadyInstalling (Install (Left (InstallStack InstallOptions{..}))) (Stack, ver) = cmp' Stack instVer ver
347349
alreadyInstalling (Compile (CompileGHC GHCCompileOptions{ ovewrwiteVer = Just over }))
348350
(GHC, ver) = cmp' GHC (Just $ GHCVersion (mkTVer over)) ver
349351
alreadyInstalling (Compile (CompileGHC GHCCompileOptions{ targetGhc = GHC.SourceDist tver }))

data/config.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@ url-source:
8282
# - Right: "file:///home/jule/git/ghcup-hs/ghcup-prereleases.yaml"
8383
# - Right: "file:///home/jule/git/ghcup-hs/ghcup-custom.yaml"
8484

85+
# For stack's setup-info, this works similar, e.g.:
86+
# stack-setup-source:
87+
# AddSource:
88+
# - Left:
89+
# ghc:
90+
# linux64-tinfo6:
91+
# 9.4.7:
92+
# url: "https://downloads.haskell.org/~ghc/9.4.7/ghc-9.4.7-x86_64-fedora27-linux.tar.xz"
93+
# content-length: 179117892
94+
# sha256: 216b76b7c6383e6ad9ba82533f323f8550e52893a8b9fa33c7b9dc4201ac766a
95+
96+
8597
# This is a way to override platform detection, e.g. when you're running
8698
# a Ubuntu derivate based on 18.04, you could do:
8799
#

docs/guide.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,38 @@ stack config set install-ghc false --global
246246
stack config set system-ghc true --global
247247
```
248248

249+
### Using stack's setup-info metadata to install GHC
250+
251+
You can now use stack's [setup-info metadata](https://github.com/commercialhaskell/stackage-content/blob/master/stack/stack-setup-2.yaml)
252+
to install GHC. For that, you can invoke ghcup like so:
253+
254+
```sh
255+
ghcup install ghc --stack-setup 9.4.7
256+
```
257+
258+
To make this permanent, you can add the following to you `~/.ghcup/config.yaml`:
259+
260+
```yaml
261+
stack-setup: true
262+
```
263+
264+
You can customize or add sections to the setup-info similar to how the [stack documentation](https://docs.haskellstack.org/en/stable/yaml_configuration/#setup-info) explains it. E.g. to change the 9.4.7 bindist, you might do:
265+
266+
```yaml
267+
stack-setup-source:
268+
AddSource:
269+
- Left:
270+
ghc:
271+
linux64-tinfo6:
272+
9.4.7:
273+
url: "https://downloads.haskell.org/~ghc/9.4.7/ghc-9.4.7-x86_64-fedora27-linux.tar.xz"
274+
content-length: 179117892
275+
sha256: 216b76b7c6383e6ad9ba82533f323f8550e52893a8b9fa33c7b9dc4201ac766a
276+
```
277+
278+
The main caveat with using this method is that there's no guarantee that GHCup will pick a compatible HLS bindist
279+
when you try to install HLS.
280+
249281
### Windows
250282

251283
On windows, you may find the following config options useful too:

ghcup.cabal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ library
117117
GHCup.Types
118118
GHCup.Types.JSON
119119
GHCup.Types.JSON.Utils
120+
GHCup.Types.JSON.Versions
120121
GHCup.Types.Optics
122+
GHCup.Types.Stack
121123
GHCup.Utils
122124
GHCup.Utils.Dirs
123125
GHCup.Version

lib-opt/GHCup/OptParse.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ data Options = Options
8888
}
8989

9090
data Command
91-
= Install (Either InstallCommand InstallOptions)
91+
= Install (Either InstallCommand InstallGHCOptions)
9292
| Test TestCommand
9393
| InstallCabalLegacy InstallOptions
9494
| Set (Either SetCommand SetOptions)

lib-opt/GHCup/OptParse/Config.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ updateSettings usl usr =
135135
gpgSetting' = uGPGSetting usl <|> uGPGSetting usr
136136
platformOverride' = uPlatformOverride usl <|> uPlatformOverride usr
137137
mirrors' = uMirrors usl <|> uMirrors usr
138-
in UserSettings cache' metaCache' metaMode' noVerify' verbose' keepDirs' downloader' (updateKeyBindings (uKeyBindings usl) (uKeyBindings usr)) urlSource' noNetwork' gpgSetting' platformOverride' mirrors'
138+
stackSetupSource' = uStackSetupSource usl <|> uStackSetupSource usr
139+
stackSetup' = uStackSetup usl <|> uStackSetup usr
140+
in UserSettings cache' metaCache' metaMode' noVerify' verbose' keepDirs' downloader' (updateKeyBindings (uKeyBindings usl) (uKeyBindings usr)) urlSource' noNetwork' gpgSetting' platformOverride' mirrors' stackSetupSource' stackSetup'
139141
where
140142
updateKeyBindings :: Maybe UserKeyBindings -> Maybe UserKeyBindings -> Maybe UserKeyBindings
141143
updateKeyBindings Nothing Nothing = Nothing

lib-opt/GHCup/OptParse/Install.hs

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import qualified Data.Text as T
5050
----------------
5151

5252

53-
data InstallCommand = InstallGHC InstallOptions
53+
data InstallCommand = InstallGHC InstallGHCOptions
5454
| InstallCabal InstallOptions
5555
| InstallHLS InstallOptions
5656
| InstallStack InstallOptions
@@ -63,6 +63,15 @@ data InstallCommand = InstallGHC InstallOptions
6363
--[ Options ]--
6464
---------------
6565

66+
data InstallGHCOptions = InstallGHCOptions
67+
{ instVer :: Maybe ToolVersion
68+
, instBindist :: Maybe URI
69+
, instSet :: Bool
70+
, isolateDir :: Maybe FilePath
71+
, forceInstall :: Bool
72+
, addConfArgs :: [T.Text]
73+
, useStackSetup :: Maybe Bool
74+
} deriving (Eq, Show)
6675

6776
data InstallOptions = InstallOptions
6877
{ instVer :: Maybe ToolVersion
@@ -93,14 +102,14 @@ installCabalFooter = [s|Discussion:
93102
--[ Parsers ]--
94103
---------------
95104

96-
installParser :: Parser (Either InstallCommand InstallOptions)
105+
installParser :: Parser (Either InstallCommand InstallGHCOptions)
97106
installParser =
98107
(Left <$> subparser
99108
( command
100109
"ghc"
101110
( InstallGHC
102111
<$> info
103-
(installOpts (Just GHC) <**> helper)
112+
(installGHCOpts <**> helper)
104113
( progDesc "Install GHC"
105114
<> footerDoc (Just $ text installGHCFooter)
106115
)
@@ -134,7 +143,7 @@ installParser =
134143
)
135144
)
136145
)
137-
<|> (Right <$> installOpts Nothing)
146+
<|> (Right <$> installGHCOpts)
138147
where
139148
installHLSFooter :: String
140149
installHLSFooter = [s|Discussion:
@@ -210,6 +219,12 @@ installOpts tool =
210219
Just GHC -> False
211220
Just _ -> True
212221

222+
installGHCOpts :: Parser InstallGHCOptions
223+
installGHCOpts =
224+
(\InstallOptions{..} b -> let useStackSetup = b in InstallGHCOptions{..})
225+
<$> installOpts (Just GHC)
226+
<*> invertableSwitch "stack-setup" (Just 's') False (help "Set as active version after install")
227+
213228

214229

215230

@@ -291,6 +306,11 @@ type InstallGHCEffects = '[ AlreadyInstalled
291306
, UninstallFailed
292307
, UnknownArchive
293308
, InstallSetError
309+
, NoCompatiblePlatform
310+
, GHCup.Errors.ParseError
311+
, UnsupportedSetupCombo
312+
, DistroNotFound
313+
, NoCompatibleArch
294314
]
295315

296316
runInstGHC :: AppState
@@ -308,21 +328,21 @@ runInstGHC appstate' =
308328
-------------------
309329

310330

311-
install :: Either InstallCommand InstallOptions -> Settings -> IO AppState -> (ReaderT LeanAppState IO () -> IO ()) -> IO ExitCode
331+
install :: Either InstallCommand InstallGHCOptions -> Settings -> IO AppState -> (ReaderT LeanAppState IO () -> IO ()) -> IO ExitCode
312332
install installCommand settings getAppState' runLogger = case installCommand of
313-
(Right iopts) -> do
333+
(Right iGHCopts) -> do
314334
runLogger (logWarn "This is an old-style command for installing GHC. Use 'ghcup install ghc' instead.")
315-
installGHC iopts
316-
(Left (InstallGHC iopts)) -> installGHC iopts
317-
(Left (InstallCabal iopts)) -> installCabal iopts
318-
(Left (InstallHLS iopts)) -> installHLS iopts
319-
(Left (InstallStack iopts)) -> installStack iopts
335+
installGHC iGHCopts
336+
(Left (InstallGHC iGHCopts)) -> installGHC iGHCopts
337+
(Left (InstallCabal iopts)) -> installCabal iopts
338+
(Left (InstallHLS iopts)) -> installHLS iopts
339+
(Left (InstallStack iopts)) -> installStack iopts
320340
where
321-
installGHC :: InstallOptions -> IO ExitCode
322-
installGHC InstallOptions{..} = do
341+
installGHC :: InstallGHCOptions -> IO ExitCode
342+
installGHC InstallGHCOptions{..} = do
323343
s'@AppState{ dirs = Dirs{ .. } } <- liftIO getAppState'
324344
(case instBindist of
325-
Nothing -> runInstGHC s' $ do
345+
Nothing -> runInstGHC s'{ settings = maybe settings (\b -> settings {stackSetup = b}) useStackSetup } $ do
326346
(v, vi) <- liftE $ fromVersion instVer GHC
327347
liftE $ runBothE' (installGHCBin
328348
v

lib-opt/GHCup/OptParse/Run.hs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ type RunEffects = '[ AlreadyInstalled
187187
, ProcessError
188188
, UninstallFailed
189189
, MergeFileTreeError
190+
, NoCompatiblePlatform
191+
, GHCup.Errors.ParseError
192+
, UnsupportedSetupCombo
193+
, DistroNotFound
194+
, NoCompatibleArch
190195
]
191196

192197
runLeanRUN :: (MonadUnliftIO m, MonadIO m)
@@ -226,6 +231,7 @@ run :: forall m .
226231
, MonadCatch m
227232
, MonadIO m
228233
, MonadUnliftIO m
234+
, Alternative m
229235
)
230236
=> RunOptions
231237
-> IO AppState
@@ -255,7 +261,9 @@ run RunOptions{..} runAppState leanAppstate runLogger = do
255261
liftIO $ putStr tmp
256262
pure ExitSuccess
257263
(cmd:args) -> do
258-
newEnv <- liftIO $ addToPath tmp runAppendPATH
264+
newEnv <- liftIO $ addToPath [tmp] runAppendPATH
265+
let pathVar = if isWindows then "Path" else "PATH"
266+
forM_ (Map.lookup pathVar . Map.fromList $ newEnv) $ liftIO . setEnv pathVar
259267
#ifndef IS_WINDOWS
260268
void $ liftIO $ SPP.executeFile cmd True args (Just newEnv)
261269
pure ExitSuccess
@@ -329,6 +337,7 @@ run RunOptions{..} runAppState leanAppstate runLogger = do
329337
, MonadThrow m
330338
, MonadIO m
331339
, MonadCatch m
340+
, Alternative m
332341
)
333342
=> Toolchain
334343
-> FilePath
@@ -354,6 +363,11 @@ run RunOptions{..} runAppState leanAppstate runLogger = do
354363
, CopyError
355364
, UninstallFailed
356365
, MergeFileTreeError
366+
, NoCompatiblePlatform
367+
, GHCup.Errors.ParseError
368+
, UnsupportedSetupCombo
369+
, DistroNotFound
370+
, NoCompatibleArch
357371
] (ResourceT (ReaderT AppState m)) ()
358372
installToolChainFull Toolchain{..} tmp = do
359373
case ghcVer of

0 commit comments

Comments
 (0)