Skip to content

Commit ee042b8

Browse files
committed
Fix #6121 Make use of Casa optional, and more configurable
1 parent f5ea28e commit ee042b8

File tree

10 files changed

+132
-18
lines changed

10 files changed

+132
-18
lines changed

ChangeLog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ Other enhancements:
2828
* `stack --verbose` excludes lengthy information about build plan construction
2929
in the debug output by default. The new `stack --[no-]plan-in-log` flag
3030
enables or disables the inclusion of the information in the debug output.
31+
* In YAML configuration files, the `casa` key is introduced, which takes
32+
precedence over the existing `casa-repo-prefix` key. The latter is deprecated.
33+
The new key also allows Stack's use of a Casa (content-addressable storage
34+
archive) server to be disabled and the maximum number of keys per request to
35+
be configured. The defaults are unchanged.
3136

3237
Bug fixes:
3338

doc/yaml_configuration.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,17 +474,39 @@ of the same name. For further information, see the
474474
[`stack build` command](build_command.md) documentation and the
475475
[users guide](GUIDE.md#the-build-command).
476476

477+
### casa
478+
479+
:octicons-tag-24: UNRELEASED
480+
481+
Default:
482+
483+
~~~yaml
484+
casa:
485+
enable: true # Use a Casa server?
486+
repo-prefix: https://casa.fpcomplete.com # Unless casa-repo-prefix is set.
487+
max-keys-per-request: 1280 # Maximum number of keys per request.
488+
~~~
489+
490+
This option specifies whether or not Stack should use a Casa
491+
(content-addressable storage archive) server to cache Cabal files and all other
492+
files in packages; and, if so, the prefix for the URL used to pull information
493+
from the server and the maximum number of keys per request. For further
494+
information, see this blog post about
495+
[Casa and Stack](https://www.fpcomplete.com/blog/casa-and-stack/).
496+
497+
`repo-prefix` replaces [`casa-repo-prefix`](#casa-repo-prefix) (which is
498+
deprecated) and has precedence if both keys are set.
499+
477500
### casa-repo-prefix
478501

479502
[:octicons-tag-24: 2.3.1](https://github.com/commercialhaskell/stack/releases/tag/v2.3.1)
480503

504+
Deprecated in favour of [`casa`](#casa), which takes precedence if present.
505+
481506
Default: `https://casa.fpcomplete.com`
482507

483508
This option specifies the prefix for the URL used to pull information from the
484-
Casa (content-addressable storage archive) server that is used by Stack to cache
485-
Cabal files and all other files in packages. For further information, see this
486-
blog post about
487-
[Casa and Stack](https://www.fpcomplete.com/blog/casa-and-stack/).
509+
Casa server.
488510

489511
### color
490512

package.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ dependencies:
9595
- neat-interpolation
9696
- open-browser
9797
- optparse-applicative >= 0.18.1.0
98-
- pantry >= 0.8.2.2
98+
- pantry >= 0.8.3
9999
- path
100100
- path-io
101101
# In order for Cabal (the tool) to build Stack, it needs to be told of the

src/Stack/Config.hs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ import Stack.Types.Config.Exception
114114
, ParseAbsolutePathException (..), packageIndicesWarning )
115115
import Stack.Types.ConfigMonoid
116116
( ConfigMonoid (..), parseConfigMonoid )
117+
import Stack.Types.Casa ( CasaOptsMonoid (..) )
117118
import Stack.Types.Docker ( DockerOptsMonoid (..), dockerEnable )
118119
import Stack.Types.DumpLogs ( DumpLogs (..) )
119120
import Stack.Types.GlobalOpts ( GlobalOpts (..) )
@@ -482,16 +483,33 @@ configFromConfigMonoid
482483
addr' = display $ T.dropWhileEnd (=='/') addr
483484
let configStackDeveloperMode =
484485
fromFirst stackDeveloperModeDefault configMonoidStackDeveloperMode
486+
configCasa = if fromFirstTrue $ casaMonoidEnable configMonoidCasaOpts
487+
then
488+
let casaRepoPrefix = fromFirst
489+
(fromFirst defaultCasaRepoPrefix configMonoidCasaRepoPrefix)
490+
(casaMonoidRepoPrefix configMonoidCasaOpts)
491+
casaMaxKeysPerRequest = fromFirst
492+
defaultCasaMaxPerRequest
493+
(casaMonoidMaxKeysPerRequest configMonoidCasaOpts)
494+
in Just (casaRepoPrefix, casaMaxKeysPerRequest)
495+
else Nothing
485496
withNewLogFunc go useColor'' stylesUpdate' $ \logFunc -> do
486497
let configRunner = configRunner'' & logFuncL .~ logFunc
487-
withLocalLogFunc logFunc $ handleMigrationException $
488-
withPantryConfig
498+
withLocalLogFunc logFunc $ handleMigrationException $ do
499+
logDebug $ case configCasa of
500+
Nothing -> "Use of Casa server disabled."
501+
Just (repoPrefix, maxKeys) ->
502+
"Use of Casa server enabled: ("
503+
<> fromString (show repoPrefix)
504+
<> ", "
505+
<> fromString (show maxKeys)
506+
<> ")."
507+
withPantryConfig'
489508
pantryRoot
490509
pic
491510
(maybe HpackBundled HpackCommand $ getFirst configMonoidOverrideHpack)
492511
clConnectionCount
493-
(fromFirst defaultCasaRepoPrefix configMonoidCasaRepoPrefix)
494-
defaultCasaMaxPerRequest
512+
configCasa
495513
snapLoc
496514
(\configPantryConfig -> initUserStorage
497515
(configStackRoot </> relFileStorage)

src/Stack/Types/Casa.hs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{-# LANGUAGE NoImplicitPrelude #-}
2+
{-# LANGUAGE OverloadedStrings #-}
3+
{-# LANGUAGE RecordWildCards #-}
4+
5+
-- | Casa configuration types.
6+
7+
module Stack.Types.Casa
8+
( CasaOptsMonoid (..)
9+
) where
10+
11+
import Casa.Client ( CasaRepoPrefix )
12+
import Generics.Deriving.Monoid ( mappenddefault, memptydefault )
13+
import Pantry.Internal.AesonExtended
14+
( FromJSON (..), WithJSONWarnings, (..:?), withObjectWarnings
15+
)
16+
import Stack.Prelude
17+
18+
-- | An uninterpreted representation of Casa configuration options.
19+
-- Configurations may be "cascaded" using mappend (left-biased).
20+
data CasaOptsMonoid = CasaOptsMonoid
21+
{ casaMonoidEnable :: !FirstTrue
22+
, casaMonoidRepoPrefix :: !(First CasaRepoPrefix)
23+
, casaMonoidMaxKeysPerRequest :: !(First Int)
24+
}
25+
deriving (Generic, Show)
26+
27+
-- | Decode uninterpreted Casa configuration options from JSON/YAML.
28+
instance FromJSON (WithJSONWarnings CasaOptsMonoid) where
29+
parseJSON = withObjectWarnings "CasaOptsMonoid"
30+
( \o -> do
31+
casaMonoidEnable <- FirstTrue <$> o ..:? casaEnableName
32+
casaMonoidRepoPrefix <- First <$> o ..:? casaRepoPrefixName
33+
casaMonoidMaxKeysPerRequest <-
34+
First <$> o ..:? casaMaxKeysPerRequestName
35+
pure CasaOptsMonoid {..}
36+
)
37+
38+
-- | Left-biased combine Casa configuration options
39+
instance Semigroup CasaOptsMonoid where
40+
(<>) = mappenddefault
41+
42+
-- | Left-biased combine Casa configurations options
43+
instance Monoid CasaOptsMonoid where
44+
mempty = memptydefault
45+
mappend = (<>)
46+
47+
-- | Casa configuration enable setting name.
48+
casaEnableName :: Text
49+
casaEnableName = "enable"
50+
51+
-- | Casa configuration repository prefix setting name.
52+
casaRepoPrefixName :: Text
53+
casaRepoPrefixName = "repo-prefix"
54+
55+
-- | Casa configuration maximum keys per request setting name.
56+
casaMaxKeysPerRequestName :: Text
57+
casaMaxKeysPerRequestName = "max-keys-per-request"

src/Stack/Types/Config.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ module Stack.Types.Config
2727
, prettyStackDevL
2828
) where
2929

30+
import Casa.Client ( CasaRepoPrefix )
3031
import Distribution.System ( Platform )
3132
import Path ( (</>), parent, reldir, relfile )
3233
import RIO.Process ( HasProcessContext (..), ProcessContext )
@@ -182,6 +183,8 @@ data Config = Config
182183
-- ^ Use --no-run and --compile options when using `stack script`
183184
, configStackDeveloperMode :: !Bool
184185
-- ^ Turn on Stack developer mode for additional messages?
186+
, configCasa :: !(Maybe (CasaRepoPrefix, Int))
187+
-- ^ Optional Casa configuration
185188
}
186189

187190
-- | The project root directory, if in a project.

src/Stack/Types/ConfigMonoid.hs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import Stack.Types.AllowNewerDeps ( AllowNewerDeps )
3232
import Stack.Types.ApplyGhcOptions ( ApplyGhcOptions (..) )
3333
import Stack.Types.ApplyProgOptions ( ApplyProgOptions (..) )
3434
import Stack.Types.BuildOpts ( BuildOptsMonoid )
35+
import Stack.Types.Casa ( CasaOptsMonoid )
3536
import Stack.Types.CabalConfigKey ( CabalConfigKey )
3637
import Stack.Types.ColorWhen ( ColorWhen )
3738
import Stack.Types.Compiler ( CompilerRepository )
@@ -166,7 +167,10 @@ data ConfigMonoid = ConfigMonoid
166167
-- ^ See 'configHideSourcePaths'
167168
, configMonoidRecommendUpgrade :: !FirstTrue
168169
-- ^ See 'configRecommendUpgrade'
170+
, configMonoidCasaOpts :: !CasaOptsMonoid
171+
-- ^ Casa configuration options.
169172
, configMonoidCasaRepoPrefix :: !(First CasaRepoPrefix)
173+
-- ^ Casa repository prefix (deprecated).
170174
, configMonoidSnapshotLocation :: !(First Text)
171175
-- ^ Custom location of LTS/Nightly snapshots
172176
, configMonoidNoRunCompile :: !FirstFalse
@@ -333,7 +337,8 @@ parseConfigMonoidObject rootDir obj = do
333337
FirstTrue <$> obj ..:? configMonoidHideSourcePathsName
334338
configMonoidRecommendUpgrade <-
335339
FirstTrue <$> obj ..:? configMonoidRecommendUpgradeName
336-
340+
configMonoidCasaOpts <-
341+
jsonSubWarnings (obj ..:? configMonoidCasaOptsName ..!= mempty)
337342
configMonoidCasaRepoPrefix <-
338343
First <$> obj ..:? configMonoidCasaRepoPrefixName
339344
configMonoidSnapshotLocation <-
@@ -509,6 +514,9 @@ configMonoidHideSourcePathsName = "hide-source-paths"
509514
configMonoidRecommendUpgradeName :: Text
510515
configMonoidRecommendUpgradeName = "recommend-stack-upgrade"
511516

517+
configMonoidCasaOptsName :: Text
518+
configMonoidCasaOptsName = "casa"
519+
512520
configMonoidCasaRepoPrefixName :: Text
513521
configMonoidCasaRepoPrefixName = "casa-repo-prefix"
514522

stack.cabal

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ library
314314
Stack.Internal.BuildInfo
315315
Stack.PackageFile
316316
Stack.Types.Cache
317+
Stack.Types.Casa
317318
Stack.Types.Dependency
318319
Stack.Types.PackageFile
319320
Stack.Types.Storage
@@ -361,7 +362,7 @@ library
361362
, neat-interpolation
362363
, open-browser
363364
, optparse-applicative >=0.18.1.0
364-
, pantry >=0.8.2.2
365+
, pantry >=0.8.3
365366
, path
366367
, path-io
367368
, persistent >=2.14.0.0 && <2.15
@@ -471,7 +472,7 @@ executable stack
471472
, neat-interpolation
472473
, open-browser
473474
, optparse-applicative >=0.18.1.0
474-
, pantry >=0.8.2.2
475+
, pantry >=0.8.3
475476
, path
476477
, path-io
477478
, persistent >=2.14.0.0 && <2.15
@@ -576,7 +577,7 @@ executable stack-integration-test
576577
, open-browser
577578
, optparse-applicative >=0.18.1.0
578579
, optparse-generic
579-
, pantry >=0.8.2.2
580+
, pantry >=0.8.3
580581
, path
581582
, path-io
582583
, persistent >=2.14.0.0 && <2.15
@@ -685,7 +686,7 @@ test-suite stack-test
685686
, neat-interpolation
686687
, open-browser
687688
, optparse-applicative >=0.18.1.0
688-
, pantry >=0.8.2.2
689+
, pantry >=0.8.3
689690
, path
690691
, path-io
691692
, persistent >=2.14.0.0 && <2.15

stack.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ extra-deps:
99
- ansi-terminal-types-0.11.5@sha256:f78440dfd95c4509e88855ac7cc2d9566ddf956a92c1290404cac93ad1a1b00a,1482
1010
- fsnotify-0.4.1.0@sha256:44540beabea36aeeef930aa4d5f28091d431904bc9923b6ac4d358831c651235,2854
1111
- optparse-applicative-0.18.1.0@sha256:b4cf8d9018e5e67cb1f14edb5130b6d05ad8bc1b5f6bd4efaa6ec0b7f28f559d,5132
12-
- pantry-0.8.2.2@sha256:579aa8538c0fde65f9c08fb97d1d5aee8f59e5cc44e5f8feb350ec54bd2b14a6,6026
12+
- pantry-0.8.3@sha256:3717b64fa283624832cf2ed5042c5f4ec549276633d1e1c6845c6c0d462a17dc,5750
1313
- persistent-2.14.5.0@sha256:c3c7a6a200930f956b2a6bb15b9d2cd512980692f6a2d95368a6db335c34c916,7199
1414
- rio-prettyprint-0.1.4.0@sha256:1f8eb3ead0ef33d3736d53e1de5e9b2c91a0c207cdca23321bd74c401e85f23a,1301
1515
# lts-20.23 specifies Cabal-3.6.3.0

stack.yaml.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ packages:
3333
original:
3434
hackage: optparse-applicative-0.18.1.0@sha256:b4cf8d9018e5e67cb1f14edb5130b6d05ad8bc1b5f6bd4efaa6ec0b7f28f559d,5132
3535
- completed:
36-
hackage: pantry-0.8.2.2@sha256:579aa8538c0fde65f9c08fb97d1d5aee8f59e5cc44e5f8feb350ec54bd2b14a6,6026
36+
hackage: pantry-0.8.3@sha256:3717b64fa283624832cf2ed5042c5f4ec549276633d1e1c6845c6c0d462a17dc,5750
3737
pantry-tree:
38-
sha256: f979dadd233a05272bfee435de5d66532692532453d199adb902079a75cb878d
38+
sha256: 1b991741e05313c0029adb8c014a1205068cebdd9d63a70e041ad79e1cd48c15
3939
size: 2970
4040
original:
41-
hackage: pantry-0.8.2.2@sha256:579aa8538c0fde65f9c08fb97d1d5aee8f59e5cc44e5f8feb350ec54bd2b14a6,6026
41+
hackage: pantry-0.8.3@sha256:3717b64fa283624832cf2ed5042c5f4ec549276633d1e1c6845c6c0d462a17dc,5750
4242
- completed:
4343
hackage: persistent-2.14.5.0@sha256:c3c7a6a200930f956b2a6bb15b9d2cd512980692f6a2d95368a6db335c34c916,7199
4444
pantry-tree:

0 commit comments

Comments
 (0)