Skip to content

Commit 572476e

Browse files
authored
Merge pull request #6729 from commercialhaskell/reorg
Move types into own modules, for consistency
2 parents 707dcb5 + 981d5d4 commit 572476e

File tree

18 files changed

+214
-139
lines changed

18 files changed

+214
-139
lines changed

package.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,12 @@ library:
317317
- Stack.Types.GhcPkgId
318318
- Stack.Types.GlobalOpts
319319
- Stack.Types.GlobalOptsMonoid
320+
- Stack.Types.HpcReportOpts
320321
- Stack.Types.Installed
321322
- Stack.Types.InterfaceOpt
322323
- Stack.Types.IsMutable
323324
- Stack.Types.LockFileBehavior
325+
- Stack.Types.LsOpts
324326
- Stack.Types.MsysEnvironment
325327
- Stack.Types.NamedComponent
326328
- Stack.Types.Nix

src/Stack/Build/ExecutePackage.hs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -347,22 +347,24 @@ announceTask ee taskType action = logInfo $
347347
(packageNamePrefix ee (pkgName (taskTypePackageIdentifier taskType)))
348348
<> action
349349

350-
-- Implements running a package's build, used to implement 'ATBuild' and
351-
-- 'ATBuildFinal' tasks. In particular this does the following:
350+
-- | Implements running a package's build, used to implement
351+
-- 'Control.Concurrent.Execute.ATBuild' and
352+
-- 'Control.Concurrent.Execute.ATBuildFinal' tasks. In particular this does the
353+
-- following:
352354
--
353-
-- * Checks if the package exists in the precompiled cache, and if so,
354-
-- add it to the database instead of performing the build.
355+
-- * Checks if the package exists in the precompiled cache, and if so, add it to
356+
-- the database instead of performing the build.
355357
--
356358
-- * Runs the configure step if needed ('ensureConfig')
357359
--
358360
-- * Runs the build step
359361
--
360362
-- * Generates haddocks
361363
--
362-
-- * Registers the library and copies the built executables into the
363-
-- local install directory. Note that this is literally invoking Cabal
364-
-- with @copy@, and not the copying done by @stack install@ - that is
365-
-- handled by 'copyExecutables'.
364+
-- * Registers the library and copies the built executables into the local
365+
-- install directory. Note that this is literally invoking Cabal with @copy@,
366+
-- and not the copying done by @stack install@ - that is handled by
367+
-- 'Stack.Build.copyExecutables'.
366368
singleBuild ::
367369
forall env. (HasEnvConfig env, HasRunner env)
368370
=> ActionContext

src/Stack/Coverage.hs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@ Generate HPC (Haskell Program Coverage) reports.
1414
-}
1515

1616
module Stack.Coverage
17-
( HpcReportOpts (..)
18-
, hpcReportCmd
17+
( hpcReportCmd
1918
, deleteHpcReports
2019
, updateTixFile
2120
, generateHpcReport
22-
, generateHpcReportForTargets
2321
, generateHpcUnifiedReport
2422
, generateHpcMarkupIndex
2523
) where
@@ -67,6 +65,7 @@ import Stack.Types.BuildOptsCLI
6765
( BuildOptsCLI (..), defaultBuildOptsCLI )
6866
import Stack.Types.EnvConfig
6967
( EnvConfig (..), HasEnvConfig (..), hpcReportDir )
68+
import Stack.Types.HpcReportOpts ( HpcReportOpts (..) )
7069
import Stack.Types.NamedComponent ( NamedComponent (..) )
7170
import Stack.Types.Package ( Package (..), packageIdentifier )
7271
import Stack.Types.Runner ( Runner )
@@ -112,15 +111,6 @@ instance Pretty CoveragePrettyException where
112111

113112
instance Exception CoveragePrettyException
114113

115-
-- | Type representing command line options for the @stack hpc report@ command.
116-
data HpcReportOpts = HpcReportOpts
117-
{ inputs :: [Text]
118-
, all :: Bool
119-
, destDir :: Maybe String
120-
, openBrowser :: Bool
121-
}
122-
deriving Show
123-
124114
-- | Function underlying the @stack hpc report@ command.
125115
hpcReportCmd :: HpcReportOpts -> RIO Runner ()
126116
hpcReportCmd hropts = do
@@ -431,6 +421,7 @@ generateHpcReportForTargets opts tixFiles targetNames = do
431421
void $ liftIO $ openBrowser (toFilePath reportPath)
432422
else displayReportPath "The" report (pretty reportPath)
433423

424+
-- | Generates the HTML unified coverage report.
434425
generateHpcUnifiedReport :: HasEnvConfig env => RIO env ()
435426
generateHpcUnifiedReport = do
436427
outputDir <- hpcReportDir
@@ -528,6 +519,7 @@ unionTixes tixes = (Map.keys errs, Tix (Map.elems outputs))
528519
Right (TixModule k hash1 len1 (zipWith (+) tix1 tix2))
529520
merge _ _ = Left ()
530521

522+
-- | Generates the HTML index report.
531523
generateHpcMarkupIndex :: HasEnvConfig env => RIO env ()
532524
generateHpcMarkupIndex = do
533525
outputDir <- hpcReportDir

src/Stack/IDE.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ import Stack.Types.SourceMap
3737
( ProjectPackage (..), SMWanted (..), ppComponentsMaybe )
3838
import System.IO ( putStrLn )
3939

40-
-- Type representing output stream choices for the @stack ide packages@ and
40+
-- | Type representing output stream choices for the @stack ide packages@ and
4141
-- @stack ide targets@ commands.
4242
data OutputStream
4343
= OutputLogInfo
4444
-- ^ To the same output stream as other log information.
4545
| OutputStdout
4646
-- ^ To the standard output stream.
4747

48-
-- Type representing output choices for the @stack ide packages@ command.
48+
-- | Type representing output choices for the @stack ide packages@ command.
4949
data ListPackagesCmd
5050
= ListPackageNames
5151
-- ^ Package names.

src/Stack/Ls.hs

Lines changed: 8 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,7 @@ Types and functions related to Stack's @ls@ command.
1212
-}
1313

1414
module Stack.Ls
15-
( LsCmdOpts (..)
16-
, LsCmds (..)
17-
, SnapshotOpts (..)
18-
, LsView (..)
19-
, ListDepsOpts (..)
20-
, ListDepsFormat (..)
21-
, ListDepsFormatOpts (..)
22-
, ListDepsTextFilter (..)
23-
, ListGlobalsOpts (..)
24-
, ListStylesOpts (..)
25-
, ListToolsOpts (..)
26-
, lsCmd
15+
( lsCmd
2716
) where
2817

2918
import Control.Monad.Extra ( whenJust )
@@ -67,6 +56,13 @@ import Stack.Types.DependencyTree
6756
import Stack.Types.DotOpts ( DotOpts (..) )
6857
import Stack.Types.DumpPackage ( DumpPackage (..) )
6958
import Stack.Types.EnvConfig ( EnvConfig (..), installationRootDeps )
59+
import Stack.Types.LsOpts
60+
( LsCmdOpts (..), LsCmds (..), ListDepsFormat (..)
61+
, ListDepsFormatOpts (..), ListDepsOpts (..)
62+
, ListDepsTextFilter (..), ListGlobalsOpts (..)
63+
, ListStylesOpts (..), ListToolsOpts (..), LsView (..)
64+
, SnapshotOpts (..)
65+
)
7066
import Stack.Types.Runner ( HasRunner, Runner, terminalL )
7167
import Stack.Types.SourceMap ( SMWanted (..) )
7268
import System.Console.ANSI.Codes
@@ -87,33 +83,6 @@ instance Exception LsException where
8783
++ "Failure to parse values as a snapshot: "
8884
++ show val
8985

90-
-- | Type representing command line options for the @stack ls@ command.
91-
newtype LsCmdOpts
92-
= LsCmdOpts { lsCmds :: LsCmds }
93-
94-
-- | Type representing subcommands for the @stack ls@ command.
95-
data LsCmds
96-
= LsSnapshot SnapshotOpts
97-
| LsGlobals ListGlobalsOpts
98-
| LsDependencies ListDepsOpts
99-
| LsStyles ListStylesOpts
100-
| LsTools ListToolsOpts
101-
102-
-- | Type representing command line options for the @stack ls snapshots@
103-
-- command.
104-
data SnapshotOpts = SnapshotOpts
105-
{ viewType :: LsView
106-
, ltsSnapView :: Bool
107-
, nightlySnapView :: Bool
108-
}
109-
deriving (Eq, Ord, Show)
110-
111-
-- | Type representing subcommands for the @stack ls snapshots@ command.
112-
data LsView
113-
= Local
114-
| Remote
115-
deriving (Eq, Ord, Show)
116-
11786
-- | Type representing Stackage snapshot types.
11887
data SnapshotType
11988
= Lts
@@ -122,57 +91,6 @@ data SnapshotType
12291
-- ^ Stackage Nightly
12392
deriving (Eq, Ord, Show)
12493

125-
-- | Type representing command line options for the @stack ls globals@ command.
126-
newtype ListGlobalsOpts = ListGlobalsOpts
127-
{ globalHints :: Bool
128-
-- ^ Use global hints instead of relying on an actual GHC installation.
129-
}
130-
131-
-- | Type representing command line options for the @stack ls dependencies@
132-
-- command.
133-
data ListDepsOpts = ListDepsOpts
134-
{ format :: !ListDepsFormat
135-
-- ^ Format of printing dependencies
136-
, dotOpts :: !DotOpts
137-
-- ^ The normal dot options.
138-
}
139-
140-
-- | Type representing formats for printing dependencies.
141-
data ListDepsFormat
142-
= ListDepsText ListDepsFormatOpts [ListDepsTextFilter]
143-
| ListDepsTree ListDepsFormatOpts
144-
| ListDepsJSON
145-
| ListDepsConstraints
146-
147-
-- | Type representing command line options for the @stack ls dependencies text@
148-
-- command and similar @cabal@, @tree@ and @json@ commands.
149-
data ListDepsFormatOpts = ListDepsFormatOpts
150-
{ sep :: !Text
151-
-- ^ Separator between the package name and details.
152-
, license :: !Bool
153-
-- ^ Print dependency licenses instead of versions.
154-
}
155-
156-
-- | Type representing items to filter the results of @stack ls dependencies@.
157-
data ListDepsTextFilter
158-
= FilterPackage PackageName
159-
-- ^ Item is a package name.
160-
| FilterLocals
161-
-- ^ Item represents all project packages.
162-
163-
-- | Type representing command line options for the @stack ls stack-colors@ and
164-
-- @stack ls stack-colours@ commands.
165-
data ListStylesOpts = ListStylesOpts
166-
{ basic :: Bool
167-
, sgr :: Bool
168-
, example :: Bool
169-
}
170-
deriving (Eq, Ord, Show)
171-
172-
-- | Type representing command line options for the @stack ls tools@ command.
173-
newtype ListToolsOpts
174-
= ListToolsOpts { filter :: String }
175-
17694
data Snapshot = Snapshot
17795
{ snapId :: Text
17896
, title :: Text

src/Stack/Options/HpcReportParser.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import Options.Applicative
1616
( Parser, completer, help, long, metavar, strOption, switch )
1717
import Options.Applicative.Builder.Extra
1818
( dirCompleter, fileExtCompleter, textArgument )
19-
import Stack.Coverage ( HpcReportOpts (..) )
2019
import Stack.Options.Completion ( targetCompleter )
2120
import Stack.Prelude
21+
import Stack.Types.HpcReportOpts ( HpcReportOpts (..) )
2222

2323
-- | Parser for @stack hpc report@.
2424
hpcReportOptsParser :: Parser HpcReportOpts

src/Stack/Options/LsParser.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ import qualified Options.Applicative as OA
1919
import Options.Applicative ( idm )
2020
import Options.Applicative.Builder.Extra ( boolFlags, textOption )
2121
import Stack.Constants ( globalFooter )
22-
import Stack.Ls
22+
import Stack.Options.DotParser ( dotOptsParser )
23+
import Stack.Prelude hiding ( sep )
24+
import Stack.Types.LsOpts
2325
( ListDepsFormat (..), ListDepsFormatOpts (..)
2426
, ListDepsOpts (..), ListDepsTextFilter (..)
2527
, ListGlobalsOpts (..), ListStylesOpts (..)
2628
, ListToolsOpts (..), LsCmdOpts (..), LsCmds (..)
2729
, LsView (..), SnapshotOpts (..), ListGlobalsOpts
2830
)
29-
import Stack.Options.DotParser ( dotOptsParser )
30-
import Stack.Prelude hiding ( sep )
3131

3232
-- | Parse command line arguments for Stack's @ls@ command.
3333
lsOptsParser :: OA.Parser LsCmdOpts

src/Stack/Options/SetupParser.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import qualified Options.Applicative as OA
1919
import qualified Options.Applicative.Builder.Extra as OA
2020
import qualified Options.Applicative.Types as OA
2121
import Stack.Prelude
22-
import Stack.SetupCmd ( SetupCmdOpts (..) )
22+
import Stack.Types.SetupOpts ( SetupCmdOpts (..) )
2323

2424
-- | Parse command line arguments for Stack's @setup@ command.
2525
setupOptsParser :: OA.Parser SetupCmdOpts

src/Stack/Path.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ Types and functions related to Stack's @path@ command.
1414

1515
module Stack.Path
1616
( EnvConfigPathInfo
17-
, UseHaddocks
1817
, path
1918
, pathsFromRunner
2019
, pathsFromConfig
@@ -170,6 +169,8 @@ fillEnvConfigPathInfo = do
170169
, compiler
171170
}
172171

172+
-- | Type representing information needed to generate an appropriate string for
173+
-- paths of interest to a user which require an 'EnvConfig'.
173174
data EnvConfigPathInfo = EnvConfigPathInfo
174175
{ buildConfig :: !BuildConfig
175176
, snapDb :: !(Path Abs Dir)
@@ -240,7 +241,7 @@ pathsFromRunner = ("Global Stack root directory", stackRootOptionName')
240241
-- can choose a specific path to list like @--stack-root@. But really it's
241242
-- mainly for the documentation aspect.
242243
--
243-
-- When printing output we generate @Config@ and pass it to the function
244+
-- When printing output we generate t'Config' and pass it to the function
244245
-- to generate an appropriate string. Trailing slashes are removed, see #506.
245246
pathsFromConfig :: [(String, Text, Config -> Text)]
246247
pathsFromConfig =
@@ -264,7 +265,7 @@ pathsFromConfig =
264265
-- can choose a specific path to list like @--project-root@. But really it's
265266
-- mainly for the documentation aspect.
266267
--
267-
-- When printing output we generate @EnvConfigPathInfo@ and pass it to the
268+
-- When printing output we generate t'EnvConfigPathInfo' and pass it to the
268269
-- function to generate an appropriate string. Trailing slashes are removed, see
269270
-- #506.
270271
pathsFromEnvConfig :: [(String, Text, UseHaddocks (EnvConfigPathInfo -> Text))]

src/Stack/Setup.hs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,7 @@ defaultSetupInfoYaml :: String
624624
defaultSetupInfoYaml =
625625
"https://raw.githubusercontent.com/commercialhaskell/stackage-content/master/stack/stack-setup-2.yaml"
626626

627+
-- | Type representing setup configurations.
627628
data SetupOpts = SetupOpts
628629
{ installGhcIfMissing :: !Bool
629630
, installMsysIfMissing :: !Bool
@@ -2638,7 +2639,7 @@ utf8EnvVars =
26382639

26392640
-- Binary Stack upgrades
26402641

2641-
-- | Information on a binary release of Stack
2642+
-- | Information on a binary release of Stack.
26422643
data StackReleaseInfo
26432644
= SRIGitHub !Value
26442645
-- ^ Metadata downloaded from GitHub releases about available binaries.
@@ -2651,11 +2652,14 @@ data HaskellStackOrg = HaskellStackOrg
26512652
}
26522653
deriving Show
26532654

2655+
-- | Download information on a binary release of Stack. If there is no given
2656+
-- GitHub user, GitHub repository and version, then first tries
2657+
-- @haskellstack.org@.
26542658
downloadStackReleaseInfo ::
26552659
(HasLogFunc env, HasPlatform env)
2656-
=> Maybe String -- GitHub org
2657-
-> Maybe String -- GitHub repo
2658-
-> Maybe String -- ^ optional version
2660+
=> Maybe String -- ^ Optional GitHub user.
2661+
-> Maybe String -- ^ Optional GitHub repository.
2662+
-> Maybe String -- ^ Optional version.
26592663
-> RIO env StackReleaseInfo
26602664
downloadStackReleaseInfo Nothing Nothing Nothing = do
26612665
platform <- view platformL
@@ -2762,6 +2766,9 @@ downloadStackReleaseInfoGitHub morg mrepo mver = liftIO $ do
27622766
then pure $ SRIGitHub $ getResponseBody res
27632767
else prettyThrowIO $ StackReleaseInfoNotFound url
27642768

2769+
-- | Yield a list of the preferred GHC variants for the platform. The first item
2770+
-- of each pair indicates if the operating system is Windows. The second item
2771+
-- is the name of the GHC variant in Stack's @setup-info@ dictionary.
27652772
preferredPlatforms ::
27662773
(MonadReader env m, HasPlatform env, MonadThrow m)
27672774
=> m [(Bool, String)]
@@ -2790,6 +2797,7 @@ preferredPlatforms = do
27902797
| otherwise = ["-static", ""]
27912798
pure $ map (\suffix -> (isWindows, concat [os, "-", arch, suffix])) suffixes
27922799

2800+
-- | Download a Stack executable.
27932801
downloadStackExe ::
27942802
HasConfig env
27952803
=> [(Bool, String)] -- ^ acceptable platforms
@@ -3000,6 +3008,7 @@ performPathChecking newExeFile currExeFile = do
30003008
<> flow "sudo file copy worked!"
30013009
| otherwise -> throwM e
30023010

3011+
-- | If available, yields the version of the given binary release of Stack.
30033012
getDownloadVersion :: StackReleaseInfo -> Maybe Version
30043013
getDownloadVersion (SRIGitHub val) = do
30053014
Object o <- Just val

0 commit comments

Comments
 (0)