Skip to content

Commit 16660c4

Browse files
authored
Merge pull request #6732 from commercialhaskell/refactor
2 parents 3089c3d + 9a22a1d commit 16660c4

File tree

5 files changed

+30
-16
lines changed

5 files changed

+30
-16
lines changed

src/Stack/Build/Installed.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ import Stack.Types.Installed
4444
import Stack.Types.SourceMap
4545
( DepPackage (..), ProjectPackage (..), SourceMap (..) )
4646

47+
-- | For the given t'SourceMap', yield a dictionary of package names for a
48+
-- project's packages and dependencies, and pairs of their relevant database
49+
-- (write-only or mutable) and package versions.
4750
toInstallMap :: MonadIO m => SourceMap -> m InstallMap
4851
toInstallMap sourceMap = do
4952
projectInstalls <-

src/Stack/Build/Target.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ module Stack.Build.Target
6464
( -- * Types
6565
Target (..)
6666
, NeedTargets (..)
67-
, PackageType (..)
6867
, parseTargets
6968
-- * Convenience helpers
7069
, gpdVersion
@@ -245,6 +244,7 @@ parseRawTarget t =
245244
-- Resolve the raw targets
246245
--------------------------------------------------------------------------------
247246

247+
-- | A type representing results of resolving a raw target.
248248
data ResolveResult = ResolveResult
249249
{ name :: !PackageName
250250
, rawInput :: !RawInput
@@ -559,10 +559,13 @@ combineResolveResults results = do
559559
-- OK, let's do it!
560560
--------------------------------------------------------------------------------
561561

562+
-- | Parse targets and dependencies from the given command line arguments and
563+
-- source map.
562564
parseTargets ::
563565
HasBuildConfig env
564566
=> NeedTargets
565567
-> Bool
568+
-- ^ Should Haddock documentation be built for the package?
566569
-> BuildOptsCLI
567570
-> SMActual GlobalPackage
568571
-> RIO env SMTargets

src/Stack/BuildPlan.hs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ module Stack.BuildPlan
2020
, DepErrors
2121
, removeSrcPkgDefaultFlags
2222
, selectBestSnapshot
23-
, showItems
2423
) where
2524

2625
import qualified Data.Foldable as F
@@ -194,8 +193,8 @@ gpdPackageDeps gpd compilerVersion platform flags =
194193
, platform
195194
}
196195

197-
-- Remove any src package flags having default values
198-
-- Remove any package entries with no flags set
196+
-- | For the given list of packages and dictionary of packages and Cabal flags,
197+
-- remove flags that have defaults and packages with no remaining flags.
199198
removeSrcPkgDefaultFlags ::
200199
[C.GenericPackageDescription]
201200
-> Map PackageName (Map FlagName Bool)
@@ -210,12 +209,8 @@ removeSrcPkgDefaultFlags gpds flags =
210209
in Just $ Map.differenceWith diff f1 f2
211210

212211
gpdDefaultFlags gpd =
213-
let tuples = map getDefault (C.genPackageFlags gpd)
214-
in Map.singleton (gpdPackageName gpd) (Map.fromList tuples)
215-
216-
getDefault f
217-
| C.flagDefault f = (C.flagName f, True)
218-
| otherwise = (C.flagName f, False)
212+
let pairs = map (C.flagName &&& C.flagDefault) (C.genPackageFlags gpd)
213+
in Map.singleton (gpdPackageName gpd) (Map.fromList pairs)
219214

220215
-- | Find the set of @FlagName@s necessary to get the given
221216
-- @GenericPackageDescription@ to compile against the given @BuildPlan@. Will
@@ -305,11 +300,17 @@ checkPackageDeps myName deps packages =
305300
, neededBy = Map.singleton myName range
306301
}
307302

303+
-- | A type synoynm for a dictionary of packages and failures to satisfy
304+
-- packages' dependency constraints.
308305
type DepErrors = Map PackageName DepError
309306

307+
-- | A type representing failures to satisfy packages' dependency constraints.
310308
data DepError = DepError
311309
{ version :: !(Maybe Version)
310+
-- ^ If available, the available version of the package.
312311
, neededBy :: !(Map PackageName VersionRange)
312+
-- ^ A dictionary of the packages requiring the package and the permitted
313+
-- range of versions.
313314
}
314315
deriving Show
315316

@@ -344,6 +345,8 @@ checkBundleBuildPlan platform compiler pool flags gpds =
344345

345346
dupError _ _ = impureThrow DuplicatePackagesBug
346347

348+
-- | A type representing the results of evaluating how well a snapshot satisfies
349+
-- the dependencies of a set of packages and a set of Cabal flags.
347350
data BuildPlanCheck
348351
= BuildPlanCheckOk (Map PackageName (Map FlagName Bool))
349352
| BuildPlanCheckPartial (Map PackageName (Map FlagName Bool)) DepErrors

src/Stack/Package.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -828,11 +828,11 @@ topSortPackageComponent package target includeDirectTarget =
828828
| not includeDirectTarget && packageType == PTProject = id
829829
| otherwise = \v -> v |> component.qualifiedName
830830

831-
-- | Process a package's internal components in the order of their topological sort.
832-
-- The first iteration will effect the component depending on no other component etc,
833-
-- iterating by increasing amount of required dependencies.
834-
-- 'PackageType' with value 'PTProject' here means the component is a direct target
835-
-- and 'PTDependency' means it's a dependency of a direct target.
831+
-- | Process a package's internal components in the order of their topological
832+
-- sort. The first iteration will effect the component depending on no other
833+
-- component etc, iterating by increasing amount of required dependencies.
834+
-- 'PackageType' with value 'PTProject' here means the component is a direct
835+
-- target and 'PTDependency' means it's a dependency of a direct target.
836836
topProcessPackageComponent ::
837837
forall b.
838838
Package

src/Stack/Types/SourceMap.hs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,12 @@ data Target
111111
| TargetComps !(Set NamedComponent)
112112
-- ^ Only build specific components
113113

114-
data PackageType = PTProject | PTDependency
114+
-- | A type representing types of packages.
115+
data PackageType
116+
= PTProject
117+
-- ^ The package is a project package.
118+
| PTDependency
119+
-- ^ The package is other than a project package and a dependency.
115120
deriving (Eq, Show)
116121

117122
-- | A source map with information on the wanted (but not actual) compiler. This

0 commit comments

Comments
 (0)