Skip to content

Commit 2c3c9d0

Browse files
committed
Minor refactoring around DumpPackage
1 parent ece2652 commit 2c3c9d0

File tree

5 files changed

+28
-26
lines changed

5 files changed

+28
-26
lines changed

src/Stack/Build/ConstructPlan.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ import Stack.Types.ConfigureOpts ( BaseConfigOpts (..) )
6565
import qualified Stack.Types.ConfigureOpts as ConfigureOpts
6666
import Stack.Types.Curator ( Curator (..) )
6767
import Stack.Types.Dependency ( DepValue (..), isDepTypeLibrary )
68-
import Stack.Types.DumpPackage ( DumpPackage (..), dpParentLibIdent )
68+
import Stack.Types.DumpPackage ( DumpPackage (..), sublibParentPkgId )
6969
import Stack.Types.EnvConfig ( EnvConfig (..), HasEnvConfig (..) )
7070
import Stack.Types.EnvSettings
7171
( EnvSettings (..), minimalEnvSettings )
@@ -371,7 +371,7 @@ mkUnregisterLocal tasks dirtyReason localDumpPkgs initialBuildSteps =
371371
where
372372
gid = dp.ghcPkgId
373373
ident = dp.packageIdent
374-
mParentLibId = dpParentLibIdent dp
374+
mParentLibId = sublibParentPkgId dp
375375
deps = dp.depends
376376

377377
maybeUnregisterReason ::

src/Stack/Build/Installed.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import Stack.Prelude
2222
import Stack.SourceMap ( getPLIVersion, loadVersion )
2323
import Stack.Types.CompilerPaths ( getGhcPkgExe )
2424
import Stack.Types.DumpPackage
25-
( DumpPackage (..), SublibDump (..), dpParentLibIdent )
25+
( DumpPackage (..), SublibDump (..), sublibParentPkgId )
2626
import Stack.Types.EnvConfig
2727
( HasEnvConfig, packageDatabaseDeps, packageDatabaseExtra
2828
, packageDatabaseLocal
@@ -199,7 +199,7 @@ isAllowed installMap pkgDb dp = case Map.lookup name installMap of
199199
-- If the sourceMap has nothing to say about this package,
200200
-- check if it represents a sub-library first
201201
-- See: https://github.com/commercialhaskell/stack/issues/3899
202-
case dpParentLibIdent dp of
202+
case sublibParentPkgId dp of
203203
Just (PackageIdentifier parentLibName version') ->
204204
case Map.lookup parentLibName installMap of
205205
Nothing -> checkNotFound

src/Stack/Build/Source.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ import Stack.Package
3131
import Stack.PackageFile ( getPackageFile )
3232
import Stack.Prelude
3333
import Stack.SourceMap
34-
( DumpedGlobalPackage, getCompilerInfo, immutableLocSha
35-
, mkProjectPackage, pruneGlobals
34+
( getCompilerInfo, immutableLocSha, mkProjectPackage
35+
, pruneGlobals
3636
)
3737
import Stack.Types.ApplyGhcOptions ( ApplyGhcOptions (..) )
3838
import Stack.Types.ApplyProgOptions ( ApplyProgOptions (..) )
@@ -48,6 +48,7 @@ import Stack.Types.CabalConfigKey ( CabalConfigKey (..) )
4848
import Stack.Types.CompilerPaths ( HasCompiler, getCompilerPath )
4949
import Stack.Types.Config ( Config (..), HasConfig (..), buildOptsL )
5050
import Stack.Types.Curator ( Curator (..) )
51+
import Stack.Types.DumpPackage ( DumpedGlobalPackage )
5152
import Stack.Types.EnvConfig
5253
( EnvConfig (..), HasEnvConfig (..), HasSourceMap (..)
5354
, actualCompilerVersionL

src/Stack/SourceMap.hs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ module Stack.SourceMap
1010
, loadVersion
1111
, getPLIVersion
1212
, loadGlobalHints
13-
, DumpedGlobalPackage
1413
, actualFromGhc
1514
, actualFromHints
1615
, globalCondCheck
@@ -39,7 +38,8 @@ import Stack.Types.Compiler
3938
import Stack.Types.CompilerPaths
4039
( CompilerPaths (..), GhcPkgExe, HasCompiler (..) )
4140
import Stack.Types.Config ( HasConfig )
42-
import Stack.Types.DumpPackage ( DumpPackage (..) )
41+
import Stack.Types.DumpPackage
42+
( DumpPackage (..), DumpedGlobalPackage )
4343
import Stack.Types.Platform ( HasPlatform (..) )
4444
import Stack.Types.Runner ( rslInLogL )
4545
import Stack.Types.SourceMap
@@ -167,8 +167,6 @@ globalsFromHints compiler = do
167167
]
168168
pure mempty
169169

170-
type DumpedGlobalPackage = DumpPackage
171-
172170
actualFromGhc ::
173171
(HasConfig env, HasCompiler env)
174172
=> SMWanted

src/Stack/Types/DumpPackage.hs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
module Stack.Types.DumpPackage
66
( DumpPackage (..)
77
, SublibDump (..)
8-
, dpParentLibIdent
8+
, DumpedGlobalPackage
9+
, sublibParentPkgId
910
) where
1011

1112
import qualified Distribution.License as C
@@ -14,17 +15,17 @@ import Stack.Prelude
1415
import Stack.Types.Component ( StackUnqualCompName )
1516
import Stack.Types.GhcPkgId ( GhcPkgId )
1617

17-
-- | Type representing dump information for a single package, as output by the
18-
-- @ghc-pkg describe@ command.
18+
-- | Type representing dump information for a single installed package, as
19+
-- output by the @ghc-pkg describe@ command.
1920
data DumpPackage = DumpPackage
2021
{ ghcPkgId :: !GhcPkgId
2122
-- ^ The @id@ field.
2223
, packageIdent :: !PackageIdentifier
2324
-- ^ The @name@ and @version@ fields. The @name@ field is the munged package
24-
-- name. If the package is not for a sub library, its munged name is its
25+
-- name. If the package is not for a sub-library, its munged name is its
2526
-- name.
2627
, sublib :: !(Maybe SublibDump)
27-
-- ^ The sub library information if it's a sub-library.
28+
-- ^ The sub-library information, if it is a sub-library.
2829
, license :: !(Maybe C.License)
2930
, libDirs :: ![FilePath]
3031
-- ^ The @library-dirs@ field.
@@ -40,20 +41,22 @@ data DumpPackage = DumpPackage
4041
}
4142
deriving (Eq, Read, Show)
4243

43-
-- | ghc-pkg has a notion of sublibraries when using ghc-pkg dump. We can only
44-
-- know it's different through the fields it shows.
44+
-- | An installed package for a sub-library of a Cabal package has additional
45+
-- fields.
4546
data SublibDump = SublibDump
4647
{ packageName :: PackageName
47-
-- ^ "package-name" field from ghc-pkg
48+
-- ^ The @package-name@ field.
4849
, libraryName :: StackUnqualCompName
49-
-- ^ "lib-name" field from ghc-pkg
50+
-- ^ The @lib-name@ field.
5051
}
5152
deriving (Eq, Read, Show)
5253

53-
dpParentLibIdent :: DumpPackage -> Maybe PackageIdentifier
54-
dpParentLibIdent dp = case (dp.sublib, dp.packageIdent) of
55-
(Nothing, _) -> Nothing
56-
(Just sublibDump, PackageIdentifier _ v) ->
57-
Just $ PackageIdentifier libParentPackageName v
58-
where
59-
SublibDump { packageName = libParentPackageName } = sublibDump
54+
-- | Type synonym representing dump information for a single installed package
55+
-- in the global package database.
56+
type DumpedGlobalPackage = DumpPackage
57+
58+
-- | If the given 'DumpPackage' is for a sub-library of a Cabal package, yields
59+
-- the package identifier of the Cabal package.
60+
sublibParentPkgId :: DumpPackage -> Maybe PackageIdentifier
61+
sublibParentPkgId dp = dp.sublib <&> \subLibDump ->
62+
PackageIdentifier subLibDump.packageName dp.packageIdent.pkgVersion

0 commit comments

Comments
 (0)