Skip to content

Commit 2e38b85

Browse files
committed
Re #2407 Move ExtraDirs out of Stack.Types.Config
1 parent 5ddd9e8 commit 2e38b85

File tree

11 files changed

+106
-89
lines changed

11 files changed

+106
-89
lines changed

package.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ library:
282282
- Stack.Types.DumpPackage
283283
- Stack.Types.EnvConfig
284284
- Stack.Types.EnvSettings
285+
- Stack.Types.ExtraDirs
285286
- Stack.Types.GHCDownloadInfo
286287
- Stack.Types.GHCVariant
287288
- Stack.Types.GhcOptionKey
@@ -296,6 +297,7 @@ library:
296297
- Stack.Types.PackageName
297298
- Stack.Types.Platform
298299
- Stack.Types.Project
300+
- Stack.Types.ProjectAndConfigMonoid
299301
- Stack.Types.ProjectConfig
300302
- Stack.Types.PvpBounds
301303
- Stack.Types.Resolver

src/Stack/Build/Execute.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ import Stack.Types.BuildConfig
141141
( BuildConfig (..), HasBuildConfig (..), projectRootL )
142142
import Stack.Types.Compiler
143143
( ActualCompiler (..), WhichCompiler (..)
144-
, compilerVersionString, getGhcVersion
144+
, compilerVersionString, getGhcVersion, whichCompilerL
145145
)
146146
import Stack.Types.CompilerPaths
147147
( CompilerPaths (..), GhcPkgExe (..), HasCompiler (..)
@@ -151,7 +151,6 @@ import Stack.Types.Config
151151
( BenchmarkOpts (..), BuildOpts (..), BuildOptsCLI (..)
152152
, CabalVerbosity (..), Config (..), HaddockOpts (..)
153153
, HasConfig (..), TestOpts (..), buildOptsL, stackRootL
154-
, whichCompilerL
155154
)
156155
import Stack.Types.DumpLogs ( DumpLogs (..) )
157156
import Stack.Types.DumpPackage ( DumpPackage (..) )

src/Stack/Config.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,8 @@ import Stack.Types.ColorWhen ( ColorWhen (..) )
105105
import Stack.Types.Compiler ( defaultCompilerRepository )
106106
import Stack.Types.Config
107107
( BuildOpts (..), Config (..), HasConfig (..)
108-
, ProjectAndConfigMonoid (..), askLatestSnapshotUrl
109-
, configProjectRoot, parseProjectAndConfigMonoid
110-
, platformOnlyRelDir, stackRootL, workDirL
108+
, askLatestSnapshotUrl, configProjectRoot, platformOnlyRelDir
109+
, stackRootL, workDirL
111110
)
112111
import Stack.Types.Config.Exception
113112
( ConfigException (..), ConfigPrettyException (..)
@@ -120,6 +119,8 @@ import Stack.Types.GlobalOpts ( GlobalOpts (..) )
120119
import Stack.Types.Nix ( nixEnable )
121120
import Stack.Types.Platform ( PlatformVariant (..) )
122121
import Stack.Types.Project ( Project (..) )
122+
import Stack.Types.ProjectAndConfigMonoid
123+
( ProjectAndConfigMonoid (..), parseProjectAndConfigMonoid )
123124
import Stack.Types.ProjectConfig ( ProjectConfig (..) )
124125
import Stack.Types.PvpBounds ( PvpBounds (..), PvpBoundsType (..) )
125126
import Stack.Types.Resolver ( AbstractResolver (..), Snapshots (..) )

src/Stack/Setup.hs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,16 @@ import Stack.Types.Compiler
117117
( ActualCompiler (..), CompilerException (..)
118118
, CompilerRepository (..), WhichCompiler (..)
119119
, compilerVersionText, getGhcVersion, isWantedCompiler
120-
, wantedToActual, whichCompiler
120+
, wantedToActual, whichCompiler, whichCompilerL
121121
)
122122
import Stack.Types.CompilerBuild
123123
( CompilerBuild (..), compilerBuildName, compilerBuildSuffix
124124
)
125125
import Stack.Types.CompilerPaths
126126
( CompilerPaths (..), GhcPkgExe (..), HasCompiler (..) )
127127
import Stack.Types.Config
128-
( BuildOptsCLI (..), Config (..), ExtraDirs (..)
129-
, HasConfig (..), envOverrideSettingsL
130-
, ghcInstallHook, platformOnlyRelDir, whichCompilerL
128+
( BuildOptsCLI (..), Config (..), HasConfig (..)
129+
, envOverrideSettingsL, ghcInstallHook
131130
)
132131
import Stack.Types.Docker ( dockerStackExeArgName )
133132
import Stack.Types.DownloadInfo ( DownloadInfo (..) )
@@ -138,12 +137,15 @@ import Stack.Types.EnvConfig
138137
, packageDatabaseLocal
139138
)
140139
import Stack.Types.EnvSettings ( EnvSettings (..), minimalEnvSettings )
140+
import Stack.Types.ExtraDirs ( ExtraDirs (..) )
141141
import Stack.Types.GHCDownloadInfo ( GHCDownloadInfo (..) )
142142
import Stack.Types.GHCVariant
143143
( GHCVariant (..), HasGHCVariant (..), ghcVariantName
144144
, ghcVariantSuffix
145145
)
146-
import Stack.Types.Platform ( HasPlatform (..), PlatformVariant (..) )
146+
import Stack.Types.Platform
147+
( HasPlatform (..), PlatformVariant (..)
148+
, platformOnlyRelDir )
147149
import Stack.Types.Runner ( HasRunner (..) )
148150
import Stack.Types.SetupInfo ( SetupInfo (..) )
149151
import Stack.Types.SourceMap ( SMActual (..), SourceMap (..) )

src/Stack/Setup/Installed.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ import RIO.Process
3333
import Stack.Constants
3434
import Stack.Prelude
3535
import Stack.Types.Compiler
36-
import Stack.Types.Config
36+
import Stack.Types.Config ( Config (..), HasConfig (..) )
37+
import Stack.Types.ExtraDirs ( ExtraDirs (..) )
3738

3839
data Tool
3940
= Tool PackageIdentifier -- ^ e.g. ghc-7.8.4, msys2-20150512

src/Stack/Types/Compiler.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module Stack.Types.Compiler
1717
, wantedToActual
1818
, actualToWanted
1919
, parseActualCompiler
20+
, whichCompilerL
2021
) where
2122

2223
import Data.Aeson
@@ -141,3 +142,6 @@ instance FromJSON CompilerRepository where
141142
defaultCompilerRepository :: CompilerRepository
142143
defaultCompilerRepository =
143144
CompilerRepository "https://gitlab.haskell.org/ghc/ghc.git"
145+
146+
whichCompilerL :: Getting r ActualCompiler WhichCompiler
147+
whichCompilerL = to whichCompiler

src/Stack/Types/Config.hs

Lines changed: 2 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ module Stack.Types.Config
2020
, askLatestSnapshotUrl
2121
, configProjectRoot
2222
-- * Details
23-
-- ** Project & ProjectAndConfigMonoid
24-
, ProjectAndConfigMonoid (..)
25-
, parseProjectAndConfigMonoid
2623
-- * Paths
2724
, bindirSuffix
2825
, docDirSuffix
@@ -32,40 +29,26 @@ module Stack.Types.Config
3229
-- * Command-related types
3330
, module X
3431
-- * Lens helpers
35-
, ExtraDirs (..)
3632
, buildOptsL
3733
, globalOptsL
3834
, globalOptsBuildOptsMonoidL
3935
, stackRootL
4036
, stackGlobalConfigL
41-
, whichCompilerL
4237
, envOverrideSettingsL
4338
-- * Helper logging functions
4439
, prettyStackDevL
4540
) where
4641

47-
import Pantry.Internal.AesonExtended
48-
( Value, WithJSONWarnings (..), (...:), (..:?), (..!=)
49-
, jsonSubWarnings, jsonSubWarningsT, jsonSubWarningsTT
50-
, withObjectWarnings
51-
)
52-
import qualified Data.Set as Set
53-
import qualified Data.Yaml as Yaml
5442
import Distribution.System ( Platform )
55-
import Generics.Deriving.Monoid ( mappenddefault, memptydefault )
5643
import Path ( (</>), parent, reldir, relfile )
5744
import RIO.Process ( HasProcessContext (..), ProcessContext )
5845
import Stack.Constants ( bindirSuffix, docDirSuffix )
5946
import Stack.Prelude
6047
import Stack.Types.ApplyGhcOptions ( ApplyGhcOptions (..) )
6148
import Stack.Types.CabalConfigKey ( CabalConfigKey )
62-
import Stack.Types.Compiler
63-
( ActualCompiler (..), CompilerRepository, WhichCompiler
64-
, whichCompiler
65-
)
49+
import Stack.Types.Compiler ( CompilerRepository )
6650
import Stack.Types.CompilerBuild ( CompilerBuild )
67-
import Stack.Types.ConfigMonoid
68-
( ConfigMonoid (..), parseConfigMonoidObject)
51+
import Stack.Types.ConfigMonoid ( ConfigMonoid (..) )
6952
import Stack.Types.Docker ( DockerOpts )
7053
import Stack.Types.DumpLogs ( DumpLogs )
7154
import Stack.Types.EnvSettings ( EnvSettings )
@@ -244,46 +227,6 @@ ghcInstallHook = do
244227
hd <- hooksDir
245228
pure (hd </> [relfile|ghc-install.sh|])
246229

247-
data ProjectAndConfigMonoid
248-
= ProjectAndConfigMonoid !Project !ConfigMonoid
249-
250-
parseProjectAndConfigMonoid ::
251-
Path Abs Dir
252-
-> Value
253-
-> Yaml.Parser (WithJSONWarnings (IO ProjectAndConfigMonoid))
254-
parseProjectAndConfigMonoid rootDir =
255-
withObjectWarnings "ProjectAndConfigMonoid" $ \o -> do
256-
packages <- o ..:? "packages" ..!= [RelFilePath "."]
257-
deps <- jsonSubWarningsTT (o ..:? "extra-deps") ..!= []
258-
flags' <- o ..:? "flags" ..!= mempty
259-
let flags = unCabalStringMap <$> unCabalStringMap
260-
(flags' :: Map (CabalString PackageName) (Map (CabalString FlagName) Bool))
261-
262-
resolver <- jsonSubWarnings $ o ...: ["snapshot", "resolver"]
263-
mcompiler <- o ..:? "compiler"
264-
msg <- o ..:? "user-message"
265-
config <- parseConfigMonoidObject rootDir o
266-
extraPackageDBs <- o ..:? "extra-package-dbs" ..!= []
267-
mcurator <- jsonSubWarningsT (o ..:? "curator")
268-
drops <- o ..:? "drop-packages" ..!= mempty
269-
pure $ do
270-
deps' <- mapM (resolvePaths (Just rootDir)) deps
271-
resolver' <- resolvePaths (Just rootDir) resolver
272-
let project = Project
273-
{ projectUserMsg = msg
274-
, projectResolver = resolver'
275-
, projectCompiler = mcompiler -- FIXME make sure resolver' isn't SLCompiler
276-
, projectExtraPackageDBs = extraPackageDBs
277-
, projectPackages = packages
278-
, projectDependencies =
279-
concatMap toList (deps' :: [NonEmpty RawPackageLocation])
280-
, projectFlags = flags
281-
, projectCurator = mcurator
282-
, projectDropPackages = Set.map unCabalString drops
283-
}
284-
pure $ ProjectAndConfigMonoid project config
285-
286-
287230
-----------------------------------
288231
-- Lens classes
289232
-----------------------------------
@@ -344,20 +287,6 @@ stackGlobalConfigL :: HasConfig s => Lens' s (Path Abs File)
344287
stackGlobalConfigL =
345288
configL.lens configUserConfigPath (\x y -> x { configUserConfigPath = y })
346289

347-
data ExtraDirs = ExtraDirs
348-
{ edBins :: ![Path Abs Dir]
349-
, edInclude :: ![Path Abs Dir]
350-
, edLib :: ![Path Abs Dir]
351-
}
352-
deriving (Show, Generic)
353-
354-
instance Semigroup ExtraDirs where
355-
(<>) = mappenddefault
356-
357-
instance Monoid ExtraDirs where
358-
mempty = memptydefault
359-
mappend = (<>)
360-
361290
buildOptsL :: HasConfig s => Lens' s BuildOpts
362291
buildOptsL = configL.lens
363292
configBuild
@@ -373,9 +302,6 @@ globalOptsBuildOptsMonoidL =
373302
configMonoidBuildOpts
374303
(\x y -> x { configMonoidBuildOpts = y })
375304

376-
whichCompilerL :: Getting r ActualCompiler WhichCompiler
377-
whichCompilerL = to whichCompiler
378-
379305
envOverrideSettingsL ::
380306
HasConfig env
381307
=> Lens' env (EnvSettings -> IO ProcessContext)

src/Stack/Types/ExtraDirs.hs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{-# LANGUAGE NoImplicitPrelude #-}
2+
3+
module Stack.Types.ExtraDirs
4+
( ExtraDirs (..)
5+
) where
6+
7+
import Generics.Deriving.Monoid ( mappenddefault, memptydefault )
8+
import Stack.Prelude
9+
10+
data ExtraDirs = ExtraDirs
11+
{ edBins :: ![Path Abs Dir]
12+
, edInclude :: ![Path Abs Dir]
13+
, edLib :: ![Path Abs Dir]
14+
}
15+
deriving (Show, Generic)
16+
17+
instance Semigroup ExtraDirs where
18+
(<>) = mappenddefault
19+
20+
instance Monoid ExtraDirs where
21+
mempty = memptydefault
22+
mappend = (<>)
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+
4+
module Stack.Types.ProjectAndConfigMonoid
5+
( ProjectAndConfigMonoid (..)
6+
, parseProjectAndConfigMonoid
7+
) where
8+
9+
import qualified Data.Set as Set
10+
import qualified Data.Yaml as Yaml
11+
import Pantry.Internal.AesonExtended
12+
( WithJSONWarnings, Value, (...:), (..:?), (..!=)
13+
, jsonSubWarnings, jsonSubWarningsT, jsonSubWarningsTT
14+
, withObjectWarnings )
15+
import Stack.Prelude
16+
import Stack.Types.ConfigMonoid
17+
( ConfigMonoid, parseConfigMonoidObject )
18+
import Stack.Types.Project ( Project (..) )
19+
20+
data ProjectAndConfigMonoid
21+
= ProjectAndConfigMonoid !Project !ConfigMonoid
22+
23+
parseProjectAndConfigMonoid ::
24+
Path Abs Dir
25+
-> Value
26+
-> Yaml.Parser (WithJSONWarnings (IO ProjectAndConfigMonoid))
27+
parseProjectAndConfigMonoid rootDir =
28+
withObjectWarnings "ProjectAndConfigMonoid" $ \o -> do
29+
packages <- o ..:? "packages" ..!= [RelFilePath "."]
30+
deps <- jsonSubWarningsTT (o ..:? "extra-deps") ..!= []
31+
flags' <- o ..:? "flags" ..!= mempty
32+
let flags = unCabalStringMap <$> unCabalStringMap
33+
(flags' :: Map (CabalString PackageName) (Map (CabalString FlagName) Bool))
34+
35+
resolver <- jsonSubWarnings $ o ...: ["snapshot", "resolver"]
36+
mcompiler <- o ..:? "compiler"
37+
msg <- o ..:? "user-message"
38+
config <- parseConfigMonoidObject rootDir o
39+
extraPackageDBs <- o ..:? "extra-package-dbs" ..!= []
40+
mcurator <- jsonSubWarningsT (o ..:? "curator")
41+
drops <- o ..:? "drop-packages" ..!= mempty
42+
pure $ do
43+
deps' <- mapM (resolvePaths (Just rootDir)) deps
44+
resolver' <- resolvePaths (Just rootDir) resolver
45+
let project = Project
46+
{ projectUserMsg = msg
47+
, projectResolver = resolver'
48+
, projectCompiler = mcompiler -- FIXME make sure resolver' isn't SLCompiler
49+
, projectExtraPackageDBs = extraPackageDBs
50+
, projectPackages = packages
51+
, projectDependencies =
52+
concatMap toList (deps' :: [NonEmpty RawPackageLocation])
53+
, projectFlags = flags
54+
, projectCurator = mcurator
55+
, projectDropPackages = Set.map unCabalString drops
56+
}
57+
pure $ ProjectAndConfigMonoid project config

src/test/Stack/ConfigSpec.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ import Stack.Runners
2828
import Stack.Types.BuildConfig ( BuildConfig (..), projectRootL )
2929
import Stack.Types.Config
3030
( BenchmarkOpts (..), BuildOpts (..), CabalVerbosity (..)
31-
, Config (..), ProjectAndConfigMonoid (..), TestOpts (..)
32-
, parseProjectAndConfigMonoid
31+
, Config (..), TestOpts (..)
3332
)
3433
import Stack.Types.ConfigMonoid
3534
( ConfigMonoid (..), parseConfigMonoid )
3635
import Stack.Types.GlobalOpts ( GlobalOpts (..) )
3736
import Stack.Types.Project ( Project (..) )
37+
import Stack.Types.ProjectAndConfigMonoid
38+
( ProjectAndConfigMonoid (..), parseProjectAndConfigMonoid )
3839
import Stack.Options.GlobalParser ( globalOptsFromMonoid )
3940
import System.Directory
4041
import System.Environment

stack.cabal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ library
262262
Stack.Types.DumpPackage
263263
Stack.Types.EnvConfig
264264
Stack.Types.EnvSettings
265+
Stack.Types.ExtraDirs
265266
Stack.Types.GHCDownloadInfo
266267
Stack.Types.GHCVariant
267268
Stack.Types.GhcOptionKey
@@ -276,6 +277,7 @@ library
276277
Stack.Types.PackageName
277278
Stack.Types.Platform
278279
Stack.Types.Project
280+
Stack.Types.ProjectAndConfigMonoid
279281
Stack.Types.ProjectConfig
280282
Stack.Types.PvpBounds
281283
Stack.Types.Resolver

0 commit comments

Comments
 (0)